moved card placing and keeping of cards to world class
This commit is contained in:
@ -1,11 +1,13 @@
|
||||
import json
|
||||
import socket
|
||||
import threading
|
||||
|
||||
class Server:
|
||||
|
||||
__address:str
|
||||
__port:str
|
||||
__socket:socket
|
||||
__clientThread:threading.Thread
|
||||
|
||||
def __init__(self, address:str, port:str):
|
||||
self.__address = address
|
||||
@ -20,6 +22,17 @@ class Server:
|
||||
self.__socket.listen()
|
||||
print(f"server started on: {self.__address}:{self.__port}")
|
||||
|
||||
# server loop forwards connection to handleConnection
|
||||
while True:
|
||||
# accept incoming connection
|
||||
# TODO: validate this connection is a valid game connection
|
||||
client_socket, client_address = self.__socket.accept()
|
||||
|
||||
# create network thread for connection
|
||||
self.__clientThread = threading.Thread(target=self.handleConnection, args=(client_socket, client_address))
|
||||
self.__clientThread.start()
|
||||
|
||||
|
||||
# handles ticking the game loop server side converting data and passing of to the event handler
|
||||
def handleConnection(self, socket:socket, address):
|
||||
# states that a connection has been established
|
||||
@ -34,7 +47,7 @@ class Server:
|
||||
# decode message for handling
|
||||
message = data.decode()
|
||||
messageJson = json.loads(message)
|
||||
|
||||
|
||||
if messageJson["user"] in self.__users:
|
||||
self.handleEvents(messageJson)
|
||||
else:
|
||||
|
Reference in New Issue
Block a user