theoretically reworked packet structure for gamestart event + fixed client issue flooding the server with packets

This commit is contained in:
2024-01-15 10:26:14 +01:00
parent afa2d779a1
commit 1a9f49f5e9
30 changed files with 205 additions and 34 deletions

View File

@ -7,10 +7,10 @@ from Classes.System.Components.InputHandler import InputHandler
# send from the server to tell the player the game starts
# gives the client its and the opponents stats (not cards!!)
def GameStart(world: World, handCards:list, inputHandler:InputHandler, owner:Player, opponent:Player):
def GameStart(world: World, handCards:list, inputHandler:InputHandler, opponent:Player):
index:int = 0
world.setEnemy(opponent)
for card in handCards:
world.AddToPlayerHand(Card(pygame.Vector2(500 + (index + 100), 1050), f"Assets/Cards/{card}/", inputHandler, owner))
world.AddToPlayerHand(Card(pygame.Vector2(500 + (index + 100), 1050), f"Assets/Cards/{card}/", inputHandler, world.getPlayer()))

View File

@ -16,7 +16,9 @@ def Login(tcpClient:TCPClient):
tcpClient.send(payload)
# server response for login event
def LoginResponse(message:json):
def LoginResponse(message:dict, world:World):
# checks if the response on the login request is successfull
if message["status"] != "success":
print("login failed")
print("login failed")
else:
world.setPlayer(Player(0,0, message["username"], message["id"]))

View File

@ -3,7 +3,7 @@ from Classes.Game.World import World
from Classes.System.Components.InputHandler import InputHandler
# the event the client sends to the server when it places a card
def PlaceCard(tcpClient, card):
def PlaceCard(tcpClient, card, id):
# todo: send card information to the server
# todo: required info is:
# - position
@ -13,6 +13,7 @@ def PlaceCard(tcpClient, card):
"event":"placecard",
"card": card.getID(),
"type": card.getType(),
"user": id,
"x": card.getPos().x,
"y": card.getPos().y,
}