Exemplo n.º 1
0
    def pull_processor(self, data):
        _action = data['action']

        # from game_server or client: api_key
        if _action == actions.connect:
            end_user = db.get_user_from_api_key(data['api_key'])
            self.connected[end_user.user.shared_key] = time.time()
            print logging.debug("Connect " + data['api_key'], "[Info]")

        elif _action == actions.alive:
            self.connected[data['shared_key']] = float(data['time'])

        # from client api_key,
        elif _action == actions.get_games:
            # TODO if client doesnt exist then raise error
            client = db.get_user_from_api_key(data['api_key'])
            print logging.debug(actions.get_games, '[Info]')
            self.send({'shared_key': client.user.shared_key, }, action=actions.get_games, key=client.server_shared_key)

        # from game server
        elif _action == actions.game_list:
            # replace server shared key with client shared key
            data['shared_key'] = data['client_shared_key']
            key = data['client_shared_key']
            # remove that field
            data = data_filter(data, ['client_shared_key', ])
            # publish to that key
            self.send(data, action=actions.game_list, key=key)

        # from client select game shared_key
        elif _action == actions.select_game:
            client = db.get_user_from_shared_key(data['shared_key'])
            self.send(data, action=actions.select_game, key=client.server_shared_key)


        # from client new game: shared_key
        elif _action == actions.new_game:
            client = db.get_user_from_shared_key(data['shared_key'])
            data['session_key'] = session_key_gen()
            # send server
            self.send(data, action=actions.new_game, key=client.server_shared_key)
            data = data_filter(data, ['shared_key', ])
            # send to client
            self.send(data, action=actions.game_session, key=client.user.shared_key)

        # from client, to make things faster server_shared_key is also sent
        elif _action == actions.event:
            key = data['server_shared_key']
            data = data_filter(data, ['server_shared_key'])
            self.send(data, action=actions.event, key=key)

        # from server. forward this to all clients
        elif _action == actions.game_state:
            session_key = data['session_key']
            data = data_filter(data, ['session_key'])
            self.send(data, action=actions.game_state, key=session_key)
Exemplo n.º 2
0
    def pull_processor(self, data):
        _action = data['actions']

        # from game_server or client
        if _action == actions.connect:
            print logging.debug("Connect " + data['api_key'], "[Info]")

        # from client
        elif _action == actions.get_games:
            # TODO if client doesnt exist then raise error
            client = db.get_user_from_api_key(data['api_key'])
            print logging.debug(actions.get_games, '[Info]')
            self.send({'shared_key': client.user.shared_key}, action=actions.get_games, key=client.server_shared_key)

        # from game server
        elif _action == actions.game_list:
            # replace server shared key with client shared key
            data['shared_key'] = data['client_shared_key']
            key = data['client_shared_key']
            # remove that field
            data = data_filter(data, ['client_shared_key', ])
            # publish to that key
            self.send(data, action=actions.game_list, key=key)

        # from client select game
        elif _action == actions.select_game:
            # TODO
            pass

        # from client new game
        elif _action == actions.new_game:
            #TODO
            pass
Exemplo n.º 3
0
    def pull_processor(self, data):
        _action = data['actions']

        # from game_server or client
        if _action == actions.connect:
            print logging.debug("Connect " + data['api_key'], "[Info]")

        # from client
        elif _action == actions.get_games:
            # TODO if client doesnt exist then raise error
            client = db.get_user_from_api_key(data['api_key'])
            print logging.debug(actions.get_games, '[Info]')
            self.send({'shared_key': client.user.shared_key},
                      action=actions.get_games,
                      key=client.server_shared_key)

        # from game server
        elif _action == actions.game_list:
            # replace server shared key with client shared key
            data['shared_key'] = data['client_shared_key']
            key = data['client_shared_key']
            # remove that field
            data = data_filter(data, [
                'client_shared_key',
            ])
            # publish to that key
            self.send(data, action=actions.game_list, key=key)

        # from client select game
        elif _action == actions.select_game:
            # TODO
            pass

        # from client new game
        elif _action == actions.new_game:
            #TODO
            pass