def _define_methods(self): d = self._define_proxy_method r = self._control.server d(frostbite.commands.Version, r.version, filter=lambda r: r.split(" ")) d(frostbite.commands.ServerInfo, r.info, filter=lambda i: ServerState.from_dict(i).to_packet_array()) d(frostbite.commands.AdminListPlayers, r.list_all_players, filter=lambda p: PlayerCollection.from_dict(p).to_packet_array()) d(frostbite.commands.FrostbiteVariable, r.get_variable, filter=lambda v: [v], extract_args=lambda m:[m.words[0]]) d(frostbite.commands.MapListList, r.list_maps, filter=lambda m: MapList.from_dict(m).to_packet_array()) d(frostbite.commands.MapListGetMapIndices, r.get_map_indices) d(frostbite.commands.MapListRestartRound, r.restart_round) d(frostbite.commands.MapListRunNextRound, r.next_round) d(frostbite.commands.MapListEndRound, r.end_round, extract_args=lambda m:[m.winning_team]) d(frostbite.commands.AdminSay, r.say, extract_args=lambda m:[m.message]) for var in frostbite.commands.variable_types: type = frostbite.commands.variable_types[var] self._command_to_method[type] = self._command_to_method[frostbite.commands.FrostbiteVariable]
scope = packet.words[1] if scope == "all": return AdminListPlayers(scope="all") elif scope == "team": team_id = packet.words[2] return AdminListPlayers(scope="team", team=team_id) else: raise Exception define_message_type("version", response=lambda s, p, c: " ".join(p.words[1:]), doc="Asks for the server's version.") define_message_type( "serverInfo", response=lambda s, p, c: ServerState.from_packet_array(p.words[1:]), doc="Asks for basic info from the server.") define_message_type("login.hashed", args=["password"], response=lambda s, p, c: p.words[1] if len(p.words) > 1 else p.words[0], doc="Begins or ends a hashed login sequence.") define_event_type( "player.onAuthenticated", args=["name"], doc="Event raised when a player authenticates to the server.") define_event_type("player.onJoin", args=["name", "guid"], doc="Event raised when a player joins the server.") define_event_type("player.onLeave", args=["name", "info"],
return AdminSay(message=message, scope="team", team=team_id) else: raise Exception def _list_players_generator(packet): scope = packet.words[1] if scope == "all": return AdminListPlayers(scope="all") elif scope == "team": team_id = packet.words[2] return AdminListPlayers(scope="team", team=team_id) else: raise Exception define_message_type("version", response=lambda s,p,c: " ".join(p.words[1:]), doc="Asks for the server's version.") define_message_type("serverInfo", response=lambda s,p,c:ServerState.from_packet_array(p.words[1:]), doc="Asks for basic info from the server.") define_message_type("login.hashed", args=["password"], response=lambda s,p,c: p.words[1] if len(p.words) > 1 else p.words[0], doc="Begins or ends a hashed login sequence.") define_event_type("player.onAuthenticated", args=["name"], doc="Event raised when a player authenticates to the server.") define_event_type("player.onJoin", args=["name", "guid"], doc="Event raised when a player joins the server.") define_event_type("player.onLeave", args=["name", "info"], doc="Event raised when a player leaves the server.") define_event_type("player.onSpawn", args=["name", "team"], doc="Event raised when a player spawns.") define_event_type("player.onKill", args=["killer", "killed", "weapon", "headshot"], doc="Event raised when a player is killed.") define_event_type("player.onChat", args=["name", "text"], doc="Event raised when a player or the server sends a message.") define_event_type("player.onSquadChange", args=["name", "team", "squad"], doc="Event raised when a player changes squads.") define_event_type("player.onTeamChange", args=["name", "team", "squad"], doc="Event raised when a player changes teams.") define_event_type("punkBuster.onMessage", args=["message"], doc="Event raised when PunkBuster emits a message.") define_event_type("server.onLevelLoaded", args=["name", "gamemode", "rounds_played", "rounds_total"], doc="Event raised when the server loads a new level.") define_event_type("server.onRoundOver", args=["winning_team"], doc="Event raised when the server ends a round.") define_event_type("server.onRoundOverPlayers", args=["players"], doc="Event raised when the server ends a round, containing player info.") define_event_type("server.onRoundOverTeamScores", args=["team_scores"], doc="Event raised when the server ends a round, containing team scores.") define_message_type("admin.eventsEnabled", args=["enable"], doc="Asks the server to begin sending events.")
def _handle_command(self, server, seq, command): if isinstance(command, frostbite.commands.LoginHashed): if command.password is None: server.send(seq, frostbite.commands.ResponsePacket("OK", "1234")) else: server.send(seq, frostbite.commands.ResponsePacket("OK")) elif isinstance(command, frostbite.commands.Version): server.send(seq, frostbite.commands.ResponsePacket("OK", "TestServer 1")) elif isinstance(command, frostbite.commands.ServerInfo): state = ServerState("testServer", 1, 16, "testmode0", "MP_Test", 1, 2, 2, [200, 200], 200, "", True, True, False, "1234", "200", "", "1.0", False, "US", "SF", "US") server.send(seq, frostbite.commands.ResponsePacket("OK", *state.to_packet_array())) elif isinstance(command, frostbite.commands.MapListRunNextRound): self.last_command = "next_round" server.send(seq, frostbite.commands.ResponsePacket("OK")) elif isinstance(command, frostbite.commands.MapListRestartRound): self.last_command = "restart_round" server.send(seq, frostbite.commands.ResponsePacket("OK")) elif isinstance(command, frostbite.commands.MapListEndRound): self.last_command = "end_round %s" % command.winning_team server.send(seq, frostbite.commands.ResponsePacket("OK")) elif isinstance(command, frostbite.commands.MapListList): maps = MapList([Map("MP_Test1", "TestMode0", 2), Map("MP_Test2", "TestMode1", 5)]) server.send(seq, frostbite.commands.ResponsePacket("OK", *maps.to_packet_array())) elif isinstance(command, frostbite.commands.MapListGetMapIndices): server.send(seq, frostbite.commands.ResponsePacket("OK", "0", "1")) elif isinstance(command, frostbite.commands.MapListAdd): self.last_command = "add_map %s %s %s" % (command.map_name, command.gamemode, command.rounds) server.send(seq, frostbite.commands.ResponsePacket("OK")) elif isinstance(command, frostbite.commands.MapListSetNextMapIndex): self.last_command = "set_next_map %s" % command.index server.send(seq, frostbite.commands.ResponsePacket("OK")) elif isinstance(command, frostbite.commands.MapListClear): self.last_command = "clear_map_list" server.send(seq, frostbite.commands.ResponsePacket("OK")) elif isinstance(command, frostbite.commands.MapListSave): self.last_command = "save_map_list" server.send(seq, frostbite.commands.ResponsePacket("OK")) elif isinstance(command, frostbite.commands.MapListRemove): self.last_command = "remove_map %s" % command.index server.send(seq, frostbite.commands.ResponsePacket("OK")) elif isinstance(command, frostbite.commands.AdminListPlayers): list = PlayerCollection(["field1", "field2", "field3"], [["what", "the", "crap"]]) server.send(seq, frostbite.commands.ResponsePacket("OK", *list.to_packet_array())) elif isinstance(command, frostbite.commands.AdminKickPlayer): self.last_command = "kick_player %s %s" % (command.player_name, command.reason) server.send(seq, frostbite.commands.ResponsePacket("OK")) elif isinstance(command, frostbite.commands.AdminKillPlayer): self.last_command = "kill_player %s" % (command.player_name) server.send(seq, frostbite.commands.ResponsePacket("OK")) elif isinstance(command, frostbite.commands.BanListAdd): self.last_command = "add_ban %s %s %s %s" % (command.id_type, command.id, command.timeout, command.reason) server.send(seq, frostbite.commands.ResponsePacket("OK")) elif isinstance(command, frostbite.commands.BanListList): list = [Ban("guid", "random-id", "forever", "100", "no reason")] flat = [] for b in list: flat.extend(b.to_packet_array()) server.send(seq, frostbite.commands.ResponsePacket("OK", len(list), *flat)) elif isinstance(command, frostbite.commands.AdminSay): self.last_command = "say %s %s" % (command.scope, command.message) server.send(seq, frostbite.commands.ResponsePacket("OK")) else: server.send(seq, frostbite.commands.ResponsePacket("OK"))