예제 #1
0
파일: state.py 프로젝트: ppolewicz/txfbrcon
class StateAPI(object):
    def __init__(self, server, rcon):
        self.triggers = TriggerSystem()
        self.server = server
        self.rcon = rcon
    @defer.inlineCallbacks
    def connection_made(self):
        self.triggers.pre_connection_made()
        players = yield self.rcon.admin_listPlayers()
        for player in players:
            pl = players[player]
            self.server.add_player(pl['name'], pl['guid'])
        self.triggers.post_connection_made()
        self.server_info_hint()
    def connection_lost(self, reason):
        self.triggers.pre_connection_lost(reason)
        self.server.flush() # state is instantly invalidated due to missing events
        self.triggers.post_connection_lost(reason)
    def server_info_hint(self):
        server_info = yield self.rcon.updateServerInfo()
        self.triggers.pre_server_info(server_info)
        self.server.load_info(server_info)
        self.triggers.post_server_info(server_info)
    def player_joined(self, player_name, player_guid):
        player = self.server.search_for_player(player_name)
        self.triggers.pre_player_joined(player, player_guid)
        self.server.add_player(player, player_guid)
        self.triggers.post_player_joined(player, player_guid)
    def player_left(self, player_name, player_info_block):
        player = self.server.search_for_player(player_name)
        self.triggers.pre_player_left(player, player_info_block)
        self.server.remove_player(player)
        self.triggers.post_player_left(player, player_info_block)
    def player_kicked(self, player_name, kick_reason):
        player = self.server.search_for_player(player_name)
        self.triggers.pre_player_kicked(player, kick_reason)
        self.server.remove_player(player)
        self.triggers.post_player_kicked(player, kick_reason)
    def player_authenticated(self, player_name):
        player = self.server.search_for_player(player_name)
        if player is None:
            print "AUTHENTICATION ERROR: PLAYER '%s' DOES NOT EXIST BUT IS AUTHENTICATED" % player_name # TODO
            return
        self.triggers.pre_player_authenticated(player)
        player.authenticate()
        self.triggers.post_player_authenticated(player)
    def player_spawned(self, player_name, team_id):
        player = self.server.search_for_player(player_name)
        self.triggers.pre_player_spawned(player, team_id)
        self.server.process_spawn(player, team_id)
        self.triggers.post_player_spawned(player, team_id)
    def player_killed(self, killer_name, deadguy_name, weapon, is_headshot):
        killer = self.server.search_for_player(killer_name) or DeathCause(killer_name)
        deadguy = self.server.search_for_player(deadguy_name) or DeathCause(deadguy_name)
        self.triggers.pre_player_killed(killer, deadguy, weapon, is_headshot)
        self.server.process_kill(killer, deadguy, weapon, is_headshot)
        self.triggers.post_player_killed(killer, deadguy, weapon, is_headshot)
    def player_chat(self, player_name, message): # target_player_subset is documented argument... but the server doesn't send it
        if player_name == 'Server':
            pass # TODO: special trigger
            return
        player = self.server.search_for_player(player_name)
        self.triggers.pre_player_chat(player, message)
        pass
        self.triggers.post_player_chat(player, message)
    def player_team_changed(self, player_name, team_id, squad_id):
        player = self.server.search_for_player(player_name)
        self.triggers.pre_player_team_changed(player, team_id, squad_id)
        pass
        self.triggers.post_player_team_changed(player, team_id, squad_id)
    def player_squad_changed(self, player_name, team_id, squad_id):
        player = self.server.search_for_player(player_name)
        self.triggers.pre_player_squad_changed(player, team_id, squad_id)
        pass
        self.triggers.post_player_squad_changed(player, team_id, squad_id)
    def pb_message(self, message):
        self.triggers.pre_pb_message(message)
        pass
        self.triggers.post_pb_message(message)
    def server_loading_level(self, level_name, rounds_played, rounds_total):
        self.triggers.pre_server_loading_level(level_name, rounds_played, rounds_total)
        pass
        self.triggers.post_server_loading_level(level_name, rounds_played, rounds_total)
    def server_start_level(self):
        self.triggers.pre_server_start_level(self)
        pass
        self.triggers.post_server_start_level(self)
    def server_round_over(winning_team_id):
        self.triggers.pre_server_round_over(self, winning_team_id)
        pass
        self.triggers.post_server_round_over(winning_team_id)
    def server_round_over_playerdata(self, final_player_info_block):
        self.triggers.pre_server_round_over_playerdata(final_player_info_block)
        pass
        self.triggers.post_server_round_over_playerdata(final_player_info_block)
    def server_round_over_teamdata(self, final_team_scores):
        self.triggers.pre_server_round_over_teamdata(final_team_scores)
        pass
        self.triggers.post_server_round_over_teamdata(final_team_scores)