def debug_list_players(self): """Print list of players in admin console""" for _player in self.players_controller.get_players_array(): echo("id=" + str(_player.cid) + " addr=" + str(_player.ip_addr) + " name='" + str(_player.name) + "' team=" + str(_player.team))
def list_names(self): """List all locked names in rcon console""" entrys = self.read() if not entrys: echo("There are no locked names.") return for entry in entrys: echo("name='" + str(entry["name"]) + "' region='" + str(entry["region"]) + "'")
def handle_player_leave(self, data): """Parse the 'client dropped' message""" id_start = data.find("=") + 1 id_end = data.find(" ", id_start) id_str = data[id_start:id_end] player = self.get_player_by_id(id_str) if player is None: echo("[WARNING] invalid player left id=" + str(id_str)) echo(" DATA=" + str(data)) self.save_and_delete_player(player)
def update_wins(self, is_red): """Save win""" global CAPS_RED global CAPS_BLUE CAPS_RED = 0 CAPS_BLUE = 0 if is_red: echo("red won") if self.players_controller.count_players() > self.settings.get( "win_players"): self.players_controller.team_won("red") else: echo("blue won") if self.players_controller.count_players() > self.settings.get( "win_players"): self.players_controller.team_won("blue")
def main_loop(_router: router.Router): """The main game loop""" while True: try: line = sys.stdin.readline() if not line: break if base.settings.Settings().get( "tw_version") is None or base.settings.Settings().get( "tw_version")[0:3] == "0.6": _router.handle_data(line[1:9], line[10:]) # cut off the timestamp else: # 0.7 has longer timestamps _router.handle_data(line[1:20], line[21:]) # cut off the timestamp except EOFError: # the telnet/netcat process finished; there's no more input echo("[WARNING] End of file error.") sys.exit(2) except UnicodeDecodeError: echo("[WARNING] UnicodeDecodeError! Please contact an admin.")
def check(self, name: str, ip_addr: str) -> bool: """Check if a given name is using a forbidden ip address""" if not self.settings.get("ipinfo_token") or self.settings.get( "ipinfo_token") == "": return True entrys = self.read() if not entrys: return True for entry in entrys: if not is_confusable(self.strip_null_chars(name), entry["name"]): continue data = self.ip_handler.getDetails(ip_addr) if not hasattr(data, "region"): return True region = data.region if region != entry["region"]: echo( "[locked-names] region missmatch '" + \ str(region) + "' != '" + str(entry["region"]) + "'" ) return False return True return True
def parse_error(err_type: str, err_msg: str): """Throw parser error""" echo("[ERROR:settings] " + str(err_type) + ": " + str(err_msg)) raise TemParseError(err_type + ": " + err_msg)
def exec_command(self, command, settings_file): """Execute admin command""" if command in ("cmdlist", "help", "info"): echo("Commands: !help, !list, !dev, !reload_settings !locked_names") elif command == "reload_settings": try: parse_settings.read_settings_file(settings_file) echo("[==== SETTINGS ====]") for key, value in self.settings.settings_dict.items(): sett_val = value[1] if str(key) == "discord_token": if sett_val and len(sett_val) > 6: sett_val = sett_val[:5] + "..." echo("[tem:setting] " + str(key) + " : " + str(sett_val)) except parse_settings.TemParseError as err: echo(str(err)) locked_names.get_instance(force=True) elif command == "list": self.debug_list_players() echo(str(self.players_controller.count_players()) + " players online") elif command == "dev": echo("debug=" + str(self.settings.get("debug")) + " stats=" + self.settings.get("stats_mode")) elif command == "locked_names": locked_names.get_instance().list_names()