fixed variable errors
This commit is contained in:
parent
b98b9821dc
commit
160fce0484
Binary file not shown.
@ -66,7 +66,7 @@ class GameManager:
|
||||
|
||||
tcpSocket.send(json.dumps(payload).encode())
|
||||
except Exception as e:
|
||||
print(f"failed to start game due to error: {e}")
|
||||
self.logger.error(f"failed to start game due to error: {e}")
|
||||
break
|
||||
# handles notifying all players that the game starts
|
||||
pass
|
||||
@ -88,16 +88,16 @@ class GameManager:
|
||||
# returns the new dict in which the new player now is added
|
||||
def addPlayers(self, player:Player, socket:socket, clientAddr) -> dict:
|
||||
|
||||
self.__gameManager.getLogger().info(f"creating user with id: {player.getID}")
|
||||
self.logger.info(f"creating user with id: {player.getID}")
|
||||
self.__players[clientAddr] = {
|
||||
player: player,
|
||||
socket:socket
|
||||
"player": player,
|
||||
"socket":socket
|
||||
}
|
||||
self.__gameManager.getLogger().info(f"new length of user dictionary: {len(self.__players)}")
|
||||
self.logger.info(f"new length of user dictionary: {len(self.__players)}")
|
||||
|
||||
# counts participating players and starts the game if enough have joined
|
||||
if len(self.__players) == 2:
|
||||
self.__gameManager.getLogger().info("2 players have join game starts")
|
||||
self.logger.info("2 players have join game starts")
|
||||
self.startGame(socket)
|
||||
|
||||
return self.__players
|
@ -6,7 +6,7 @@ import threading
|
||||
from Classes.Game.Player import Player
|
||||
from Classes.System.GameManager import GameManager
|
||||
|
||||
from Classes.System.Network.EventHandler import UDPEventHandler, TCPEventHandler
|
||||
from Classes.System.Network.EventHandler import TCPEventHandler
|
||||
from Classes.System.World import World
|
||||
|
||||
class NetworkManager:
|
||||
@ -84,16 +84,16 @@ class NetworkManager:
|
||||
# if enough users for a round are connected the server has to start the game
|
||||
if user not in self.__gameManager.getPlayers():
|
||||
if messageJson["event"] == "login":
|
||||
self.logger.__gameManager.getLogger().info("user logging in")
|
||||
self.logger.__gameManager.getLogger().info("task passed off to gameManager")
|
||||
self.__gameManager.getLogger().info("user logging in")
|
||||
self.__gameManager.getLogger().info("task passed off to gameManager")
|
||||
user = self.__gameManager.addPlayers(Player(messageJson["username"], messageJson["deck"]), client_socket, client_address)
|
||||
self.__gameManager.getLogger().info(f"connected users {len(self.__gameManager.getPlayers())}")
|
||||
|
||||
self.__gameManager.getLogger().info(f"confirming login for user")
|
||||
self.send({
|
||||
"event":"loginresponse",
|
||||
"id": user["player"].getID(),
|
||||
})
|
||||
"id": user[client_address]["player"].getID(),
|
||||
}, client_address)
|
||||
|
||||
self.__eventHandler[client_address].handleTCPEvents(messageJson, self.__gameManager, client_address)
|
||||
self.__gameManager.getLogger().info(f"Received message from {client_address}: {message}")
|
||||
@ -109,8 +109,8 @@ class NetworkManager:
|
||||
except json.JSONDecodeError as e:
|
||||
self.__gameManager.getLogger().error(f"JSON decoding error receiving data from {client_address}: {e}")
|
||||
|
||||
except Exception as e:
|
||||
self.__gameManager.getLogger().error(f"Error receiving data from {client_address}: {e}")
|
||||
# except Exception as e:
|
||||
# self.__gameManager.getLogger().error(f"UknownError receiving data from {client_address} due to error: {e}")
|
||||
|
||||
def broadcast(self, payload:dict):
|
||||
for user in self.__gameManager.getPlayers().values():
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Game Server/Classes/System/__pycache__/Logger.cpython-312.pyc
Normal file
BIN
Game Server/Classes/System/__pycache__/Logger.cpython-312.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
29
Game Server/log/sokyhrdv.log
Normal file
29
Game Server/log/sokyhrdv.log
Normal file
@ -0,0 +1,29 @@
|
||||
19:08:13,964 root INFO starting up server
|
||||
19:08:13,964 root INFO starting up game manager
|
||||
19:08:13,965 root INFO preparing to start server
|
||||
19:08:13,965 root INFO starting up network manager
|
||||
19:08:13,965 root INFO starting up network manager
|
||||
19:08:13,965 root INFO starting up tcp server
|
||||
19:08:13,967 root INFO starting up thread for client socket accepting
|
||||
19:08:18,567 root INFO Connected with ('127.0.0.1', 54324)
|
||||
19:08:18,567 root INFO starting client handler thread for client at address ('127.0.0.1', 54324)
|
||||
19:08:18,580 root INFO decoded message {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}
|
||||
19:08:18,588 root INFO user in message None
|
||||
19:08:18,588 root INFO user logging in
|
||||
19:08:18,589 root INFO task passed off to gameManager
|
||||
19:08:18,589 root INFO creating user with id: <bound method Player.getID of <Classes.Game.Player.Player object at 0x000001E4CF425BD0>>
|
||||
19:08:18,589 root INFO new length of user dictionary: 1
|
||||
19:08:18,589 root INFO connected users 1
|
||||
19:08:18,589 root INFO confirming login for user
|
||||
19:08:18,590 root INFO incommingevent {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}
|
||||
19:08:18,590 root INFO Received message from ('127.0.0.1', 54324): {"event": "login", "username": "player", "deck": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}
|
||||
19:10:33,867 root ERROR Connection with ('127.0.0.1', 54324) forcibly closed by remote host.
|
||||
19:10:36,58 root INFO Connected with ('127.0.0.1', 54355)
|
||||
19:10:36,58 root INFO starting client handler thread for client at address ('127.0.0.1', 54355)
|
||||
19:10:36,60 root INFO decoded message {'event': 'login', 'username': 'player', 'deck': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}
|
||||
19:10:36,60 root INFO user in message None
|
||||
19:10:36,60 root INFO user logging in
|
||||
19:10:36,62 root INFO task passed off to gameManager
|
||||
19:10:36,63 root INFO creating user with id: <bound method Player.getID of <Classes.Game.Player.Player object at 0x000001E4CF425C10>>
|
||||
19:10:36,63 root INFO new length of user dictionary: 2
|
||||
19:10:36,63 root INFO 2 players have join game starts
|
Loading…
x
Reference in New Issue
Block a user