예제 #1
0
 def add_request_socket(self, ws):
     sock = ClientSocket(ws)
     while not sock.is_closed():
         data = sock.receive()
         if not data:
             sock.close()
             return
         data = self.command.parse(data)
         # Register
         if data and data.type == self.command_id.register and sock.get_id(
         ) is None:
             client_id = self.get_new_client_id()
             sock.set_id(client_id)
             if client_id:
                 sock.send(
                     self.command.build(
                         dict(type=self.command_id.register, id=client_id)),
                     True)
             else:
                 sock.send(
                     self.command.build(dict(type=self.command_id.error)),
                     True)
         # Position Update
         elif data.type == self.command_id.update:
             self.update_player_position(sock.client_id, data.x, data.y)
예제 #2
0
 def add_state_socket(self, ws):
     sock = ClientSocket(ws)
     data = sock.receive()
     if data:
         data = self.command.parse(data)
     if data and data.type == self.command_id.register:
         sock.set_id(data.id)
         self.sockets.append(sock)
     else:
         sock.close()