Exemple #1
0
    def parse_response(self, data):
        _action = data['action']
        if _action == actions.get_games:
            data['client_shared_key'] = data['shared_key']
            data['games'] = Protocol.get_games(self, data['client_shared_key'])
            self.send(data, action=actions.game_list, shared=True)

        if _action == actions.new_game:
            new_instance = Instance(data['session_key'])
            new_instance = Protocol.new_game(new_instance, data['shared_key'])
            self.instances.append(new_instance)

        if _action == actions.select_game:
            for instance in self.instances:
                if instance.session_key == data['session_key']:
                    instance.join_instance(data['shared_key'])

        if _action == actions.event:
            #todo
            pass
Exemple #2
0
    def parse_response(self, data):
        _action = data['action']
        if _action == actions.get_games:
            data['client_shared_key'] = data['shared_key']
            data['games'] = Protocol.get_games(self, data['client_shared_key'])
            self.send(data, action=actions.game_list, shared=True)

        if _action == actions.new_game:
            new_instance=Instance(data['session_key'])
            new_instance = Protocol.new_game(new_instance,data['shared_key'])
            self.instances.append(new_instance)

        if _action == actions.select_game:
            for instance in self.instances:
                if instance.session_key == data['session_key']:
                    instance.join_instance(data['shared_key'])

        if _action == actions.event:
            #todo
            pass
    def parse_response(self, data):
        _action = data['action']
        if _action == actions.get_games:
            data['client_shared_key'] = data['shared_key']
            data['games'] = Protocol.get_games(self, data['client_shared_key'])
            self.send(data, action=actions.game_list, shared=True)

        if _action == actions.new_game:
            new_instance=Instance(data['session_key'])
            new_instance = Protocol.new_game(new_instance,data['shared_key'])
            self.instances.append(new_instance)

        if _action == actions.select_game:
            instance = self.get_instance(data['session_key'])
            instance.join_instance(data['shared_key'])

        if _action == actions.event:
            instance = self.get_instance(data['session_key'])
            # set game state to processed game state
            # todo make game_state modification lock and process type
            instance.game_state = Protocol.event(data)
            data=instance.game_state.to_json()
            data['session_key']=instance.session_key
            self.send(data,action=actions.game_state,shared=True)

        if _action == actions.dead:
            instance = self.get_instance(data['session_key'])
            instance.leave_instance(data['shared_key'])
            Protocol.dead(data)
            if instance.status == 'removed':
                del instance

        if _action == actions.disconnect:
            instance = self.get_instance(data['session_key'])
            instance.leave_instance(data['shared_key'])
            Protocol.disconnect(data)
            if instance.status == 'removed':
                del instance