Пример #1
0
 def unload():
     minqlx.console_print("^1The specqueue script, version 2.08.4 or higher, is required for the bots script."
                          " Include specqueue in the server configuration to use the bots script.")
     self.msg("^1The specqueue script, version 2.08.4 or higher, is required for the bots script."
              " Include specqueue in the server configuration to use the bots script.")
     minqlx.console_command("qlx {}unload {}"
                            .format(self.get_cvar("qlx_commandPrefix"), self.__class__.__name__))
Пример #2
0
 def reset_players_models(self, msg=None):
     try:
         sleep = msg if msg else 0.2
         time.sleep(sleep)
         players = self.players().copy()
         for pid, model in self._player_models.items():
             try:
                 player = self.player(pid)
             except minqlx.NonexistentPlayerError:
                 continue
             count = len(players)
             while count > 0:
                 count -= 1
                 if players[count].id == pid:
                     del players[count]
                     break
             player.model = model
         for pl in players:
             if str(pl.steam_id)[0] == "9":
                 name = re.sub(r"\^[0-9]", "", pl.name)
                 pl.model = self.quake_bots[name][1]
             elif pl.model:
                 pl.model = pl.model
             else:
                 pl.model = "sarge"
         return True
     except Exception as e:
         minqlx.console_print("^1bots reset_players_models Exception: {}".format(e))
Пример #3
0
 def process_round_end(self):
     try:
         if self.vote_active and self.get_cvar("qlx_balanceDoVoteEnd", bool) and\
                 time.time() - self.vote_start_time >= 5:
             voter_perc = self.get_cvar("qlx_balanceDoVotePerc", int)
             if voter_perc > 0:
                 teams = self.teams()
                 voters = len(teams["red"]) + len(teams["blue"])
                 if self.vote_count[
                         0] / voters * 100 >= voter_perc and self.vote_count[
                             0] > self.vote_count[1]:
                     time.sleep(1)
                     self.force_vote(True)
                 else:
                     self.force_vote(False)
             else:
                 if self.vote_count[0] > self.vote_count[1]:
                     time.sleep(1)
                     self.force_vote(True)
                 else:
                     self.force_vote(False)
             self.vote_active = False
     except Exception as e:
         minqlx.console_print(
             "^doVote handle_round_end Exception: {}".format(e))
Пример #4
0
 def set_bots(self, player, msg, channel):
     if len(msg) < 2:
         player.tell("^3A bot amount needs to be provided: ^1{}setbots <num> ^3(set to 0 to disable bots,"
                     " 'unset' to clear admin setting)"
                     .format(self.get_cvar("qlx_commandPrefix")))
     else:
         target_num = None
         if msg[1] == "unset":
             self.user_max_bots = False
             target_num = self.get_cvar("qlx_botsMaxBots", int) if\
                 self.get_cvar("qlx_botsMaxBots", int) <= self.get_cvar("teamsize", int) else\
                 self.get_cvar("teamsize", int)
         try:
             team_size = self.get_max_team_size()
             if not target_num:
                 target_num = int(msg[1])
             if target_num > team_size:
                 player.tell("^3The target bots can't be larger than the allowed players per team.")
                 return
             elif target_num == self.max_bots:
                 player.tell("^3The bots size is already {}.".format(target_num))
                 return
             self.max_bots = target_num
             self.user_max_bots = True
             action = self.needed_bot_action()
             minqlx.console_print("^6Action: {}".format(action))
             if action == 1:
                 self.check_for_extra_bots()
                 minqlx.console_print("^1Kicking Bot Due to max bots change")
             elif action == 2:
                 self.add_bots()
         except ValueError:
             player.tell("^3The amount must be an integer or 'unset'.")
Пример #5
0
 def force_switch_vote(self, caller, vote):
     try:
         self.callvote(
             "qlx {}force_agree".format(self.get_cvar("qlx_commandPrefix")),
             "Force the suggested player switch?")
         minqlx.client_command(caller.id, "vote yes")
         self.msg("{}^7 called vote /cv {}".format(caller.name, vote))
         voter_perc = self.get_cvar("qlx_balanceDoVotePerc", int)
         self.vote_active = True
         self.vote_count[0] = 1
         self.vote_count[1] = 0
         self.vote_count[2] = thread_number = random.randrange(0, 10000000)
         teams = self.teams()
         if voter_perc > 0:
             voters = len(teams["red"]) + len(teams["blue"])
             time.sleep(28.7)
             if self.vote_active and self.vote_count[2] == thread_number and\
                     self.vote_count[0] / voters * 100 >= voter_perc and self.vote_count[0] > self.vote_count[1]:
                 self.force_vote(True)
                 self.vote_active = False
         else:
             time.sleep(28.7)
             if self.vote_active and self.vote_count[
                     2] == thread_number and self.vote_count[
                         0] > self.vote_count[1]:
                 self.force_vote(True)
                 self.vote_active = False
         return
     except Exception as e:
         minqlx.console_print(
             "^1doVote check_force_switch_vote Exception: {}".format(e))
Пример #6
0
 def exec_cmd_speedkill(self, player, msg):
     try:
         if len(msg) > 1:
             player = self.player_id(msg[1], player)
         p_steam_id = player.steam_id
         total = 0
         rocket = self.db.smembers(
             PLAYER_KEY.format(p_steam_id) + ":speedkill")
         players = self.teams()["spectator"] + self.teams(
         )["red"] + self.teams()["blue"] + self.teams()["free"]
         msg = ""
         for p in rocket:
             total += int(self.db[PLAYER_KEY.format(p_steam_id) +
                                  ":speedkill:" + str(p)])
             for pl in players:
                 if p == str(pl.steam_id):
                     count = self.db[PLAYER_KEY.format(p_steam_id) +
                                     ":speedkill:" + p]
                     msg += pl.name + ": ^1" + count + "^7 "
         if total:
             self.msg(
                 "^4Speed Kill^7 Stats for {}: Total ^4Speed^7 Kills: ^1{}".
                 format(player, total))
             self.msg("^4Highest Kill Speed^7: ^3{}".format(
                 self.db[PLAYER_KEY.format(player.steam_id) +
                         ":highspeed"].split(".")[0]))
             if msg:
                 self.msg("^4Victims^7: {}".format(msg))
         else:
             self.msg("{} has not ^4speed^7 killed anybody on this server.".
                      format(player))
     except Exception as e:
         minqlx.console_print(
             "^kills exec_cmd_speedkill Exception: {}".format([e]))
Пример #7
0
 def callvote_to_spec(self, caller, vote, player_name, player_id):
     try:
         self.callvote("put {} spec".format(player_id),
                       "Move {} to spectate?".format(player_name))
         minqlx.client_command(caller.id, "vote yes")
         self.msg("{}^7 called vote /cv {}".format(caller.name, vote))
         voter_perc = self.get_cvar("qlx_protectPlayerPercForVote", int)
         self.vote_count[0] = 1
         self.vote_count[1] = 0
         thread_number = random.randrange(1, 10000000)
         self.vote_count[2] = thread_number
         if voter_perc > 0:
             teams = self.teams()
             voters = len(teams["red"]) + len(teams["blue"])
             time.sleep(28.7)
             if self.vote_count[2] == thread_number and self.vote_count[0] / voters * 100 >= voter_perc and\
                     self.vote_count[0] > self.vote_count[1]:
                 self.force_vote(True)
         else:
             time.sleep(28.7)
             if self.vote_count[2] == thread_number and self.vote_count[
                     0] > self.vote_count[1]:
                 self.force_vote(True)
         self.vote_count[2] = 0
         return
     except Exception as e:
         minqlx.console_print(
             "^1protect.py callvote_to_spec Exception: {}".format([e]))
Пример #8
0
 def exec_cmd_airrail(self, player, msg):
     try:
         if len(msg) > 1:
             player = self.player_id(msg[1], player)
         p_steam_id = player.steam_id
         total = 0
         pummels = self.db.smembers(
             PLAYER_KEY.format(p_steam_id) + ":airrail")
         players = self.teams()["spectator"] + self.teams(
         )["red"] + self.teams()["blue"] + self.teams()["free"]
         msg = ""
         for p in pummels:
             total += int(self.db[PLAYER_KEY.format(p_steam_id) +
                                  ":airrail:" + str(p)])
             for pl in players:
                 if p == str(pl.steam_id):
                     count = self.db[PLAYER_KEY.format(p_steam_id) +
                                     ":airrail:" + p]
                     msg += pl.name + ": ^1" + count + "^7 "
         if total:
             self.msg(
                 "^4Air Rail^7 Stats for {}: Total ^4Air Rails^7: ^1{}".
                 format(player, total))
             if msg:
                 self.msg("^4Victims^7: {}".format(msg))
         else:
             self.msg("{} ^7has not ^4air railed^7 anybody on this server.".
                      format(player))
     except Exception as e:
         minqlx.console_print(
             "^kills exec_cmd_airrail Exception: {}".format([e]))
Пример #9
0
 def find_player(self, name):
     try:
         found_player = None
         found_count = 0
         # Remove color codes from the supplied string
         player_name = re.sub(r"\^[0-9]", "", name).lower()
         # search through the list of connected players for a name match
         for player in self.players():
             if player_name in re.sub(r"\^[0-9]", "", player.name).lower():
                 # if match is found return player, player id
                 found_player = player
                 found_count += 1
         # if only one match was found return player, player id
         if found_count == 1:
             return found_player, int(
                 str([found_player]).split(":")[0].split("(")[1])
         # if more than one match is found return 0, -1
         elif found_count > 1:
             return 0, -1
         # if no match is found return -1, -1
         else:
             return -1, -1
     except Exception as e:
         minqlx.console_print(
             "^1specqueue find_player Exception: {}".format([e]))
Пример #10
0
 def bots_handle_map(self, mapname, factory):
     minqlx.console_print("^3Map Event: {}".format(mapname))
     self.bot_map = True
     self.checking_bots = [False, False, False]
     self.in_countdown = False
     self.kicking_bots = False
     self.checking_not_bot_map = False
     self.max_bots = self.get_cvar("qlx_botsMaxBots", int) if \
         self.get_cvar("qlx_botsMaxBots", int) <= self.get_cvar("teamsize", int) else self.get_cvar("teamsize", int)
     self.user_max_bots = False
     if self.bot_game_timer:
         self.bot_game_timer.cancel()
         self.bot_game_timer = None
     if self.get_cvar("bot_enable", bool):
         if self.get_cvar("qlx_botsBotOnlyGames", bool):
             self.bot_game_timer = Timer(60, self.start_all_bots_game)
             self.bot_game_timer.start()
         bot_status = self.needed_bot_action()
         msg = ["nothing", "kick", "add"]
         minqlx.console_print("^3Bot Status: ^4{}".format(msg[bot_status]))
         if bot_status == 1:
             @minqlx.delay(2)
             def kick():
                 self.kick_bot()
             kick()
         elif bot_status == 2:
             @minqlx.delay(2)
             def add():
                 self.add_bots()
             add()
Пример #11
0
 def cycle_fun_weapons(self, fw_id=None):
     if self.fw_active and self.game.state == "warmup" and fw_id == self.fw_id:
         for used in self.fw_weapons:
             cvar_list = self.WEAPONS_DFLTS[used]
             for cvar in cvar_list:
                 minqlx.console_command("set {}".format(cvar))
         max_players = self.get_max_players()
         if len(self.fw_weapons) >= len(self.WEAPON_NAMES):
             self.fw_weapons = []
         numbers = [n for n in range(0, len(self.WEAPON_NAMES))]
         numbers = [n for n in numbers if n not in self.fw_weapons]
         choice = random.choice(numbers)
         self.fw_weapons.append(choice)
         if max_players <= self.get_cvar("qlx_fwPlayerSplit", int):
             minqlx.console_print("Using WEAPONS settings for {}".format(
                 self.WEAPON_NAMES[choice]))
             for setting in self.WEAPONS[choice]:
                 minqlx.console_command("set {}".format(setting))
         else:
             minqlx.console_print("Using WEAPONS2 settings for {}".format(
                 self.WEAPON_NAMES[choice]))
             for setting in self.WEAPONS2[choice]:
                 minqlx.console_command("set {}".format(setting))
         players = self.players()
         for player in players:
             player.center_print(
                 "^2Fun Warmup weapon is ^1{} \n^2for the next ^1{} ^2seconds."
                 .format(self.WEAPON_NAMES[choice], self.fw_interval))
         self.msg(
             "^2Fun Warmup weapon is ^1{} ^2for the next ^1{} ^2seconds.".
             format(self.WEAPON_NAMES[self.fw_weapons[-1]],
                    self.fw_interval))
         Timer(self.fw_interval, self.cycle_fun_weapons, [fw_id]).start()
     elif not self.fw_active:
         self.set_normal_mode()
Пример #12
0
 def votelimiter_voteban(self, player, msg, channel):
     try:
         if int(msg[1]) not in self.vote_banned:
             self.vote_banned.append(int(msg[1]))
     except Exception as e:
         minqlx.console_print(
             "Error adding player ID to votelimiter voteban: {} : {}".
             format(type(e).__name__, e.args))
Пример #13
0
 def remove_from_spec(self, player):
     try:
         self._spec.remove_from_spec(player.steam_id)
     except Exception as e:
         if self.logging_enabled:
             minqlx.log_exception(self)
         minqlx.console_print(
             "Battle Royale Remove from Spec error: {}".format(e))
Пример #14
0
 def def_change_map(self):
     current_map = "{} {}".format(self.get_cvar("mapname"),
                                  self.get_cvar("g_factory"))
     default_map = self.get_cvar("qlx_mmDefaultMap").strip()
     if current_map != default_map:
         minqlx.console_print("^1Changing map to {}".format(default_map))
         self.map_changed = True
         minqlx.console_command("map {}".format(
             self.get_cvar("qlx_mmDefaultMap")))
Пример #15
0
    def show_sid_info(self, asker, msg):
        try:
            pid = int(msg[1])
            if 0 <= pid <= 63:
                sid = str(self.player(pid).steam_id)
            else:
                sid = str(pid)
            if len(sid) != 17 or sid[0] == "9":
                asker.tell("^1Please enter a valid player ID or Steam ID.")
                return
        except TypeError:
            asker.tell("^1Include a Steam ID or a connected Player ID.")
            return
        except minqlx.NonexistentPlayerError:
            asker.tell("^1That Player ID is not a connected player.")
            return
        except Exception as e:
            minqlx.console_print(
                "^1players_db show_sid_info Exception: {}".format([e]))
            return
        names = list(self.db.lrange(PLAYER_KEY.format(sid), 0, -1))
        count = 1
        shared_by = {}
        if len(names):
            asker.tell(
                "^6These are the names found for steam id ^7{}^6:".format(sid))
            for name in names:
                asker.tell("^1Name {}^7: {}".format(count, name))
                count += 1
        else:
            asker.tell("^6No information for ^7{} ^6was found.".format(sid))
            return
        ip_list = self.db.smembers(PLAYER_KEY.format(sid) + ":ips")
        count = 0
        ip_line = []
        for ip in ip_list:
            shared = self.db.smembers("minqlx:ips:{}".format(ip))
            if len(shared) > 1:
                shared_by[ip] = shared
            if count == 0 or count % 5:
                ip_line.append(ip)
            else:
                asker.tell("^1IPs: ^2{}".format("^1, ^2".join(ip_line)))
                ip_line = [ip]
            count += 1
        if len(ip_line):
            asker.tell("^1IPs: ^2{}".format("^1, ^2".join(ip_line)))

        if len(shared_by):
            for key, value in shared_by.items():
                ip_list = list(value)
                asker.tell("^1IP ^7{} ^1used by steam IDs^7: ^2{}".format(
                    key, "^1, ^2".join(ip_list[0:3])))
                del ip_list[0:3]
                while len(ip_list):
                    asker.tell("^2{}".format("^1, ^2".join(ip_list[0:5])))
                    del ip_list[0:5]
Пример #16
0
 def remove_from_queue(self, player):
     try:
         if player in self._queue:
             self._queue.remove_from_queue(player.steam_id, player)
     except Exception as e:
         if self.logging_enabled:
             minqlx.log_exception(self)
         minqlx.console_print(
             "Battle Royale Remove from Queue error: {}".format(e))
Пример #17
0
 def add_spectators(self):
     try:
         for player in self.teams()["spectator"]:
             self.add_to_spec(player)
     except Exception as e:
         if self.logging_enabled:
             minqlx.log_exception(self)
         minqlx.console_print(
             "Battle Royale Add Spectators error: {}".format(e))
Пример #18
0
 def bots_handle_console_print(self, text):
     if self.bot_map:
         if "BotAISetupClient failed" in text or "Fatal:" in text and "aas" in text:
             self.kicking_bots = True
             self.bot_map = False
             minqlx.console_print(text)
             minqlx.console_print("^1Bots not supported on map {}. ^3Will attempt a map change if server is"
                                  " empty of real players.".format(self.get_cvar("mapname")))
             self.non_bot_map()
Пример #19
0
 def add_to_queue(self, player):
     try:
         self.remove_from_spec(player)
         self._queue.add_to_queue(player.steam_id, player)
     except Exception as e:
         if self.logging_enabled:
             minqlx.log_exception(self)
         minqlx.console_print(
             "Battle Royale Add to Queue error: {}".format(e))
Пример #20
0
 def sound_play(self, path):
     try:
         for p in self.players():
             if self.db.get_flag(p,
                                 "essentials:sounds_enabled",
                                 default=True):
                 super().play_sound(path, p)
     except Exception as e:
         minqlx.console_print("^kills sound_play Exception: {}".format([e]))
     self._playing_sound = False
Пример #21
0
 def handle_vote_count(self, player, yes):
     if self.vote_count[2]:
         try:
             if yes:
                 self.vote_count[0] += 1
             else:
                 self.vote_count[1] += 1
         except Exception as e:
             minqlx.console_print(
                 "^1doVote handle_vote_count Exception: {}".format(e))
Пример #22
0
 def return_players_to_game(self):
     try:
         time.sleep(0.5)
         self.place_in_team(0)
         if self._rounds > 0:
             self.allready()
     except Exception as e:
         if self.logging_enabled:
             minqlx.log_exception(self)
         minqlx.console_print(
             "Battle Royale Return Players to Game error: {}".format(e))
Пример #23
0
 def add_to_spec(self, player):
     try:
         self._spec.add_to_spec(player.steam_id)
         if self.get_cvar("qlx_brTellWhenInSpecOnly", bool):
             player.center_print(
                 "^6Spectate Mode\n^7Type ^4!s ^7to show spectators.")
     except Exception as e:
         if self.logging_enabled:
             minqlx.log_exception(self)
         minqlx.console_print(
             "Battle Royale Add to Spec error: {}".format(e))
Пример #24
0
 def process_command(self, caller, command, args):
     _name = command.name
     _time = time.time()
     if not str(caller).startswith(
             "RconDummyPlayer") and _name in self._server_commands:
         if _name == self._command[0] and _time - self._command[1] < 0.1:
             return
         self._command = [_name, _time]
         minqlx.console_print("^1{} ^3issued command^7: {}".format(
             caller, args))
     return
Пример #25
0
    def handle_player_disconnect(self, player, reason):
        try:

            def check_player_count():
                if len(self.players()) == 0:
                    self.check_restart_time()

            Timer(10, check_player_count).start()
        except Exception as e:
            minqlx.console_print(
                "^1restartserver handle_player_disconnect Exceptions: {}".
                format(e))
Пример #26
0
 def set_team_size():
     team_size = self.get_max_team_size()
     max_bots = self.get_cvar("qlx_botsMaxBots", int) if not self.user_max_bots else self.max_bots
     target_bot_size = team_size if team_size < max_bots else max_bots
     if target_bot_size != self.max_bots:
         old_size = self.max_bots
         self.max_bots = target_bot_size
         if target_bot_size < old_size:
             self.check_for_extra_bots()
         elif target_bot_size > old_size:
             self.add_bots()
         minqlx.console_print("^1Bots max bots per team has been set to {}".format(self.max_bots))
Пример #27
0
 def handle_player_disconnect(self, player, reason):
     self.remove_from_spec(player)
     self.remove_from_queue(player)
     try:
         del self._wins[player.steam_id]
     except KeyError:
         pass
     except Exception as e:
         if self.logging_enabled:
             minqlx.log_exception(self)
         minqlx.console_print(
             "Battle Royale Player Disconnect Error: {}".format(e))
     self.check_for_opening(0.5)
Пример #28
0
 def set_normal_mode(self):
     msg = False
     if self.fw_active:
         msg = True
     self.fw_active = False
     minqlx.console_print("Fun Warm Up: Setting normal mode.")
     if msg:
         for player in self.players():
             player.center_print("^6Fun Warmup mode is ^3OFF")
             player.tell("^6Fun Warmup mode is ^3OFF")
     self.fw_weapons = []
     for setting in self.DFLT_CVARS:
         minqlx.console_command("set {}".format(setting))
Пример #29
0
 def player_name(self, steam_id):
     try:
         player = self.player(int(steam_id))
         if player is not None:
             name = player.name
         else:
             name = self.db.lindex(PLAYER_KEY.format(steam_id), 0)
     except minqlx.NonexistentPlayerError:
         name = self.db.lindex(PLAYER_KEY.format(steam_id), 0)
     except Exception as e:
         minqlx.console_print("^1players_db player_name Exception {}: {}".format(steam_id, [e]))
         name = self.db.lindex(PLAYER_KEY.format(steam_id), 0)
     return name
Пример #30
0
    def enter_perms(self, player):
        file = os.path.join(self.get_cvar("fs_homepath"), PERMS_FILE)
        try:
            h = open(file, "r")
        except Exception as e:
            minqlx.console_print("^1ERROR Opening perms file: {}".format(e))
            return minqlx.RET_STOP_ALL
        for player in h.readlines():
            info = player.split(":")
            self.db.set(PLAYER_DB_KEY.format(info[0], "permission"), int(info[1]))
        player.tell("^1Finished entering player permissions to the database.")
        h.close()

        return minqlx.RET_STOP_ALL
Пример #31
0
 def console(cls, text):
     """Prints text in the console."""
     minqlx.console_print(str(text))
Пример #32
0
 def reply(self, msg):
     minqlx.console_print(str(msg))