+NEW PLAN: PUT THE PLAYER CLASS INIT STUFF INSIDE THE MATCHMAKER MANAGE_INCOMING PARTS! LETS ME GET AWAY WITH MORE STUFF SERVER-WISE I THINK
+
+
Basic infrastructure for web work:
have a player manager class thread which checks main game state and sends it out every so often (1/15 seconds?) (can also form ground work for computer players
def __init__(self, players):
self.players = players
self.game_state = gamestate.GameState()
- for player in self.players:
+ for player in self.players: # CAUTION HERE, MIGHT NEED TO MODIFY
player.run()
def run(self):
threading.Timer(SPF, self.run).start()
import websockets
import threading
-
-class Player(threading.Thread):
+# planning:
+# I think I can properly initialise the async websocket stuff in the init method, then the other methods will probably be fine? There may be problems with send_data and asyncio stuff, but get_status is definitely fine as-is
+class Player():
def __init__(self, socket):
- super().__init__()
- self.game = None
self.socket = socket
self.status = 'x'
self.status_lock = threading.Lock()
- async def run(self):
- print('fired')
- msg = await self.socket.recv()
- print('recv')
- # should be 'u' or 'd', if neither
- with self.status_lock:
- if len(msg) > 0:
- self.status = msg[0]
- else:
- self.status = 'x'
- # needs to be re-ran at this point? probably
def send_data(self, data):
# to be used by the game thread thingy
- self.socket.send(data)
+ asyncio.run(self.socket.send(data))
def get_status(self):
with self.status_lock:
stat = self.status