fixed variable errors
This commit is contained in:
@ -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.
Reference in New Issue
Block a user