stabilized login, first successfull stream of cards accross clients
This commit is contained in:
Binary file not shown.
@ -1,5 +1,6 @@
|
||||
import json
|
||||
import socket
|
||||
import time
|
||||
from Classes.Game.Player import Player
|
||||
|
||||
|
||||
@ -24,7 +25,7 @@ class GameManager:
|
||||
|
||||
# card management
|
||||
def spawnCard(self, card, owner, x, y):
|
||||
self.logger("spawning card")
|
||||
# self.logger.info("spawning card")
|
||||
|
||||
self.__cards.append(card)
|
||||
|
||||
@ -37,9 +38,12 @@ class GameManager:
|
||||
}
|
||||
|
||||
for userAddr in self.__players.keys():
|
||||
self.logger.info(f"send to client {self.__players[userAddr]['player'].getID() != owner}")
|
||||
if self.__players[userAddr]["player"].getID() != owner:
|
||||
self.__players[userAddr]["socket"].send(json.dumps(payload).encode())
|
||||
try:
|
||||
self.logger.info(f"send to client {self.__players[userAddr]['player'].getID() != owner}")
|
||||
if self.__players[userAddr]["player"].getID() != owner:
|
||||
self.__players[userAddr]["socket"].send(json.dumps(payload).encode())
|
||||
except:
|
||||
pass
|
||||
|
||||
# game round management
|
||||
# this section manages the flow of rounds this should inherit itself
|
||||
@ -64,7 +68,7 @@ class GameManager:
|
||||
# this section mostly only used by the networking and event handling classes
|
||||
# other parts should never need to interface with this unless really required
|
||||
# =============================================================================
|
||||
def startGame(self, tcpSocket:socket):
|
||||
def startGame(self):
|
||||
self.__state = "running"
|
||||
|
||||
players = list(self.__players.values())
|
||||
@ -97,11 +101,11 @@ class GameManager:
|
||||
},
|
||||
}
|
||||
|
||||
print(f"user {userAddr}")
|
||||
tcpSocket.send(json.dumps(payload).encode())
|
||||
print(f"user {player_data["socket"]}")
|
||||
player_data["socket"].send(json.dumps(payload).encode())
|
||||
except Exception as e:
|
||||
self.logger.error(f"failed to start game due to error: {e}")
|
||||
break
|
||||
pass
|
||||
# handles notifying all players that the game starts
|
||||
pass
|
||||
|
||||
@ -130,9 +134,20 @@ class GameManager:
|
||||
}
|
||||
self.logger.info(f"new length of user dictionary: {len(self.__players)}")
|
||||
|
||||
payload = {
|
||||
"event":"loginresponse",
|
||||
"status": "success",
|
||||
"id": player.getID(),
|
||||
"name": player.getName()
|
||||
}
|
||||
|
||||
socket.send(json.dumps(payload).encode())
|
||||
|
||||
|
||||
# counts participating players and starts the game if enough have joined
|
||||
if len(self.__players) >= 2:
|
||||
time.sleep(1)
|
||||
self.logger.info("2 players have join game starts")
|
||||
self.startGame(socket)
|
||||
self.startGame()
|
||||
|
||||
return self.__players
|
@ -90,12 +90,6 @@ class NetworkManager:
|
||||
self.__gameManager.getLogger().info(f"connected users {len(self.__gameManager.getPlayers())}")
|
||||
|
||||
self.__gameManager.getLogger().info(f"confirming login for user")
|
||||
self.send({
|
||||
"event":"loginresponse",
|
||||
"status": "success",
|
||||
"id": user[client_address]["player"].getID(),
|
||||
"name": user[client_address]["player"].getName()
|
||||
}, client_address)
|
||||
|
||||
self.__eventHandler[client_address].handleTCPEvents(messageJson, self.__gameManager, client_address)
|
||||
self.__gameManager.getLogger().info(f"Received message from {client_address}: {message}")
|
||||
|
Binary file not shown.
Binary file not shown.
BIN
OLD_Server/Classes/System/Utils/__pycache__/Path.cpython-312.pyc
Normal file
BIN
OLD_Server/Classes/System/Utils/__pycache__/Path.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.
Binary file not shown.
Reference in New Issue
Block a user