Пример #1
0
def toggle_votekick(rcon: RecordedRcon):
    config = AutoVoteKickConfig()

    condition_type = config.get_condition_type().upper()
    min_online = config.get_min_online_mods()
    min_ingame = config.get_min_ingame_mods()
    condition = all if condition_type == 'AND' else any
    online_mods_ = online_mods()
    ingame_mods_ = ingame_mods(rcon)

    ok_online = len(online_mods_) >= min_online
    ok_ingame = len(ingame_mods_) >= min_ingame

    if condition([ok_ingame, ok_online]):
        logger.debug(
            f"Turning votekick off {condition_type=} {min_online=} {min_ingame=} {ok_online=} {ok_ingame=} {online_mods_=} {ingame_mods_=}"
        )
        rcon.set_votekick_enabled(False)
    else:
        logger.debug(
            f"Turning votekick on {condition_type=} {min_online=} {min_ingame=} {ok_online=} {ok_ingame=} {online_mods_=} {ingame_mods_=}"
        )
        rcon.set_votekick_enabled(True)
Пример #2
0
def get_online_mods(request):
    return api_response(
        command="online_mods",
        result=online_mods(),
        failed=False,
    )
Пример #3
0
def get_online_mods():
    return [mod['username'] for mod in online_mods()]
Пример #4
0
import logging
import time
import os
from rcon.extended_commands import Rcon
from rcon.settings import SERVER_INFO
from rcon.audit import online_mods, ingame_mods
from rcon.user_config import AutoSettingsConfig
from datetime import datetime
import pytz

logger = logging.getLogger(__name__)

METRICS = {
    "player_count": lambda rcon: int(rcon.get_slots().split('/')[0]),
    "online_mods": lambda: len(online_mods()),
    "ingame_mods": lambda: len(ingame_mods()),
    "current_map": lambda rcon: rcon.get_map().replace('_RESTART', ''),
    "time_of_day": lambda tz: datetime.now(tz=tz),
}
CONFIG_DIR = os.getenv('CONFIG_DIR', 'config/')


class BaseCondition:
    def __init__(self, min=0, max=100, inverse=False, *args, **kwargs):
        self.min = int(min)
        self.max = int(max)
        self.inverse = bool(inverse)

        self.metric_name = ""
        self.metric_source = "rcon"