def __init__(self, server, client_id, peer): self.server = server self.last_update = time.time() self.id = client_id self.peer = peer self.combat_id = -1 self.state_manager = GameStateManager("DungeonGeneration", self.server.main, is_server=True)
class ClientHandle(): """Class for handling client requests""" def __init__(self, server, client_id, peer): self.server = server self.last_update = time.time() self.id = client_id self.peer = peer self.combat_id = -1 self.state_manager = GameStateManager("DungeonGeneration", self.server.main, is_server=True) def handle_request(self, data, peer): self.peer = peer if data: # Clean up the data a little id = data.split()[0] self.id = id.decode() self.data = data[len(id)+1:] # print("Message %s from %s" % (data, client_addr)) # for input in self.data.split(): # if input.startswith('state'): # state = input.replace('state', '') # if state == 'cmbt': # state = CombateState # elif state == 'dflt': # state = DefaultState # self.server.main['state'] = state(self.server.main, True) # self.server.main['state'].run(self, self.server.main) self.state_manager.run(self.server.main, self) def send(self, data): """Send a message to the client""" self.peer.send(0, enet.Packet(data))