diff --git a/readme.md b/readme.md index 62b2608..c99d121 100644 --- a/readme.md +++ b/readme.md @@ -2,3 +2,79 @@ ## Introduction Source.Python Admin is an open-source project that uses the [Source.Python](https://github.com/Source-Python-Dev-Team/Source.Python) framework to allow for easy Administration on Source-engine servers. + +## Front Ends +Source.Python Admin lets you gain control to its features via multiple front ends. +The front ends are: +- **Command** Front End +- **Popup/Menu** Front End +- **MoTD** Front End +- **Web** Front End + +Here's a table showing what front ends are currently supported by each included plugin: + +Plugin | Command | Popup/Menu | MoTD | Web +------ | ------- | ---------- | ---- | --- +Communication Management | No | **Yes** | No | No +Kick/Ban | No | **Yes** | **Yes** | No +Life Management | **Yes** | **Yes** | **Yes** | No +Team Management | No | **Yes** | No | No +Tracking | **Yes** | **Yes** | No | No + +### Command Front End +Command front end allows executing features through chat and client commands. +#### Syntax: +- `!spa ` - public chat command +- `/spa ` - private chat command +- `spa ` - client command + +The difference between public and private chat commands is that the private one suppresses the command string, so that nobody receives a chat message containing it. +Client commands are run via player's game console. + +Player-based features (those have some kind of a player target) can also be executed via command front end. +#### Syntax (`!spa`, `/spa` and `spa` prefixes are omitted here, but otherwise are required): +` ` + +Where *player filter* is one of the following: +- `name` - this filter targets player by their name; *filter argument* is required in this case. +- `steamid`, `steam` - this filter targets player by their SteamID; *filter argument* is required in this case. +- `index` - this filter targets player by their entity index; *filter argument* is required in this case. +- `@` - this filter targets player using one of the template player filters; *filter argument* is omitted in this case; *built-in template filter* is one of the following: + - `me`, `self` - targets the command issuer. + - `all` - targets all players on the server. + - `bot` - targets all bots on the server (including GOTV/SourceTV). + - `human` - targets all human players on the server; opposite to `bot`. + - `dead` - targets all dead players on the server. + - `alive` - targets all alive players on the server; opposite to `dead`. + - `un` - targets all unassigned players (those who didn't select their team). + - `spec` - targets all spectators. + - `t` - targets all team #2 players (terrorists, rebels, RED team etc). + - `ct` - targets all team #3 players (counter-terrorists, combines, BLU team etc). + - depending on the game, additional team filters might be defined. +- `#` - this filter targets player by their UserID (as reported by the `status` console command); *filter argument* is omitted in this case; *userid* is the target's UserID. +- `!` - this filter targets all players, but only not those who would otherwise be targeted by *inverted player filter*; *filter argument* is passed to the inverted player filter. + +#### Examples: +- `/spa slay @all` - slays all players on the server +- `/spa slay !@me` - slays all players except the player who issues the command +- `/spa resurrect name iPlayer` - resurrects the player whose name matches "iPlayer" + +### Popup/Menu Front End +This front end provides access to the features via in-game radio menus. +The main menu can be accessed by either running `spa menu` command in game console or typing `!spa menu` or `/spa menu` in game chat. +To get this menu to show up, the client must have `admin.base` permission. + +### MoTD Front End +This front end provides allows to administrate the server from the in-game MoTD screen, providing the most impressive experience with the interactive graphical interface. +Its main screen shows up after running `spa motd` in game console or typing `!spa motd` or `/spa motd` in game chat. +The admin must have `admin.base` permission to open the MoTD front end. + +### Web Front End +Web front end is the only front end that allows admins to access Source.Python Admin features remotely, without even playing on the server. +All it requires is a web-browser, then the admin can sign in via Steam OpenID. +Web front end works in two modes: offline and online. + +- **online** mode provides an access to the regular set of the features; +- **offline** mode works directly with the server database - this is useful, for example, for banning players even when the game server is offline. + +The switching between online and offline modes is done automatically. diff --git a/srcds/addons/source-python/data/plugins/admin/memory/csgo/CBaseServer.ini b/srcds/addons/source-python/data/plugins/admin/memory/csgo/CBaseServer.ini deleted file mode 100644 index 029ef44..0000000 --- a/srcds/addons/source-python/data/plugins/admin/memory/csgo/CBaseServer.ini +++ /dev/null @@ -1,14 +0,0 @@ -[virtual_function] - # bool CBaseServer::CheckChallengeType(CBaseClient*, int, ns_address const&, int, char const*, int) - [[check_challenge_type]] - offset_linux = 63 - offset_windows = 62 - arguments = POINTER, INT, POINTER, INT, STRING, INT - return_type = BOOL - - # void CBaseServer::RejectConnection(ns_address const&, char const*, ...) - [[reject_connection]] - offset_linux = 53 - offset_windows = 52 - convention_windows = CDECL - arguments = POINTER, STRING diff --git a/srcds/addons/source-python/data/plugins/admin/memory/cstrike/CBaseServer.ini b/srcds/addons/source-python/data/plugins/admin/memory/cstrike/CBaseServer.ini deleted file mode 100644 index 790fd48..0000000 --- a/srcds/addons/source-python/data/plugins/admin/memory/cstrike/CBaseServer.ini +++ /dev/null @@ -1,13 +0,0 @@ -[virtual_function] - # bool CBaseServer::CheckChallengeType(CBaseClient *, int, netadr_s &, int, char const*, int, int) - [[check_challenge_type]] - offset_linux = 58 - offset_windows = 57 - arguments = POINTER, INT, POINTER, INT, STRING, INT, INT - return_type = BOOL - - # void CBaseServer::RejectConnection(netadr_s const&, int, char const*) - [[reject_connection]] - offset_linux = 48 - offset_windows = 47 - arguments = POINTER, INT, STRING diff --git a/srcds/addons/source-python/plugins/admin/admin.py b/srcds/addons/source-python/plugins/admin/admin.py index 51254c9..03e4f64 100644 --- a/srcds/addons/source-python/plugins/admin/admin.py +++ b/srcds/addons/source-python/plugins/admin/admin.py @@ -10,9 +10,10 @@ from .core import models from .core.clients import clients from .core.events.storage import admin_resource_list +from .core.helpers import chat_message from .core.listeners import (on_spa_loaded_listener_manager, on_spa_unloaded_listener_manager) -from .core.frontends.menus import AdminMenuSection +from .core.frontends.menus import main_menu from .core.frontends.motd import MainPage from .core.orm import Base, engine from .core.plugins.command import admin_command_manager @@ -26,39 +27,33 @@ Base.metadata.create_all(engine) -# ============================================================================= -# >> GLOBAL VARIABLES -# ============================================================================= -main_menu = AdminMenuSection(None, strings_common['title main'], 'admin') - - # ============================================================================= # >> LOAD & UNLOAD FUNCTIONS # ============================================================================= def load(): admin_resource_list.load_all_events() on_spa_loaded_listener_manager.notify() - clients.broadcast(strings_common['load']) + chat_message(strings_common['load']) def unload(): admin_command_manager.unload_all_plugins() on_spa_unloaded_listener_manager.notify() - clients.broadcast(strings_common['unload']) + chat_message(strings_common['unload']) # ============================================================================= # >> MAIN COMMANDS # ============================================================================= -@TypedClientCommand(['amenu'], 'admin.base') -@TypedSayCommand(['!amenu'], 'admin.base') -@TypedSayCommand(['/amenu'], 'admin.base') +@TypedClientCommand(['spa', 'menu'], 'admin.base') +@TypedSayCommand(['!spa', 'menu'], 'admin.base') +@TypedSayCommand(['/spa', 'menu'], 'admin.base') # TODO: Suppress the message def _admin_command(command_info): main_menu.popup.send(command_info.index) -@TypedClientCommand(['ascreen'], 'admin.motd') -@TypedSayCommand(['!ascreen'], 'admin.motd') -@TypedSayCommand(['/ascreen'], 'admin.motd') +@TypedClientCommand(['spa', 'motd'], 'admin.base') +@TypedSayCommand(['!spa', 'motd'], 'admin.base') +@TypedSayCommand(['/spa', 'motd'], 'admin.base') # TODO: Suppress the message def _admin_command(command_info): MainPage.send(command_info.index) diff --git a/srcds/addons/source-python/plugins/admin/core/clients.py b/srcds/addons/source-python/plugins/admin/core/clients.py index 29860eb..6d67dfe 100644 --- a/srcds/addons/source-python/plugins/admin/core/clients.py +++ b/srcds/addons/source-python/plugins/admin/core/clients.py @@ -3,14 +3,12 @@ # ============================================================================= # Source.Python from auth.manager import auth_manager -from filters.players import PlayerIter from listeners.tick import Delay -from messages import SayText2 from players.dictionary import PlayerDictionary from players.entity import Player # Source.Python Admin -from .strings import strings_common +from .helpers import chat_message # ============================================================================= @@ -73,8 +71,7 @@ def send_popup(self, popup): popup.send(self.player.index) def tell(self, message): - SayText2(strings_common['chat_base'].tokenized(message=message)).send( - self.player.index) + chat_message(message, (self.player.index,)) def sync_execution(self, callback, args=(), kwargs=None): self.player.delay(0, callback, args, kwargs) @@ -87,13 +84,4 @@ def name(self): def steamid(self): return self.player.steamid - -class ClientDictionary(PlayerDictionary): - @staticmethod - def broadcast(message): - say_text2 = SayText2(strings_common['chat_base'].tokenized( - message=message)) - - say_text2.send(PlayerIter('human')) - -clients = ClientDictionary(Client) +clients = PlayerDictionary(Client) diff --git a/srcds/addons/source-python/plugins/admin/core/features.py b/srcds/addons/source-python/plugins/admin/core/features.py index 8b5fa54..8549a5a 100644 --- a/srcds/addons/source-python/plugins/admin/core/features.py +++ b/srcds/addons/source-python/plugins/admin/core/features.py @@ -42,7 +42,7 @@ def execute(self, client): raise NotImplementedError -class PlayerBasedFeature(BaseFeature): +class BasePlayerBasedFeature(BaseFeature): feature_abstract = True # Allow clients to execute this feature on themselves? @@ -52,14 +52,6 @@ class PlayerBasedFeature(BaseFeature): # permissions to execute this command, too? allow_execution_on_equal_priority = False - def execute(self, client, player): - """Execute the feature on the given player. - - :param client: Client that performs the action. - :param player: Player to perform the action on. - """ - raise NotImplementedError - def filter(self, client, player): """Determine if a client is able to execute the feature on the given player. @@ -72,8 +64,20 @@ def filter(self, client, player): if not self.allow_execution_on_self and client.player == player: return False - if self.allow_execution_on_equal_priority: + if self.allow_execution_on_equal_priority or client.player == player: return True another_client = clients[player.index] return not another_client.has_permission(self.flag) + + +class PlayerBasedFeature(BasePlayerBasedFeature): + feature_abstract = True + + def execute(self, client, player): + """Execute the feature on the given player. + + :param client: Client that performs the action. + :param player: Player to perform the action on. + """ + raise NotImplementedError diff --git a/srcds/addons/source-python/plugins/admin/core/frontends/commands.py b/srcds/addons/source-python/plugins/admin/core/frontends/commands.py new file mode 100644 index 0000000..f6b799a --- /dev/null +++ b/srcds/addons/source-python/plugins/admin/core/frontends/commands.py @@ -0,0 +1,183 @@ +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Source.Python +from commands import CommandReturn +from commands.typed import TypedClientCommand, TypedSayCommand +from core import AutoUnload +from filters.players import PlayerIter + +# Source.Python Admin +from admin.core.clients import clients + + +# ============================================================================= +# >> FUNCTIONS +# ============================================================================= +def filter_player(filter_str, filter_args, issuer, player): + if filter_str[0] == '!': + return not filter_player(filter_str[1:], filter_args, issuer, player) + + if filter_str[0] == '@': + player_filter = filter_str[1:] + if player_filter in PlayerIter.filters: + return PlayerIter.filters[player_filter](player) + + if player_filter in ('me', 'self'): + return issuer == player + + return False + + if filter_str[0] == '#': + try: + userid = int(filter_str[1:]) + except ValueError: + return False + + return player.userid == userid + + if filter_str.lower() == 'name': + return player.name.casefold() == filter_args.casefold() + + if filter_str.lower() in ('steamid', 'steam'): + return player.steamid.lower() == filter_args.lower() + + if filter_str.lower() == 'index': + try: + index = int(filter_args) + except ValueError: + return False + + return player.index == index + + return False + + +def iter_filter_targets(filter_str, filter_args, issuer): + for player in PlayerIter(): + if filter_player(filter_str, filter_args, issuer, player): + yield player + + +# ============================================================================= +# >> CLASSES +# ============================================================================= +class BaseFeatureCommand(AutoUnload): + def __init__(self, commands, feature): + if isinstance(commands, str): + commands = [commands, ] + + commands = list(commands) + + self.feature = feature + + self._public_chat_command = TypedSayCommand( + ['!spa', ] + commands, feature.flag + ) + + self._private_chat_command = TypedSayCommand( + ['/spa', ] + commands, feature.flag + ) + + self._client_command = TypedClientCommand( + ['spa', ] + commands, feature.flag + ) + + self._public_chat_command(self._get_public_chat_callback()) + self._private_chat_command(self._get_private_chat_callback()) + self._client_command(self._get_client_callback()) + + def _get_public_chat_callback(self): + raise NotImplementedError + + def _get_private_chat_callback(self): + raise NotImplementedError + + def _get_client_callback(self): + raise NotImplementedError + + def _unload_instance(self): + self._public_chat_command._unload_instance() + self._private_chat_command._unload_instance() + self._client_command._unload_instance() + + +class FeatureCommand(BaseFeatureCommand): + def _execute(self, command_info): + client = clients[command_info.index] + + # Sync execution to avoid issuer replacement if the feature itself + # is going to execute any commands + client.sync_execution(self.feature.execute, (client,)) + + def _get_public_chat_callback(self): + def public_chat_callback(command_info): + self._execute(command_info) + return CommandReturn.CONTINUE + + return public_chat_callback + + def _get_private_chat_callback(self): + def private_chat_callback(command_info): + self._execute(command_info) + return CommandReturn.BLOCK + + return private_chat_callback + + def _get_client_callback(self): + def client_callback(command_info): + self._execute(command_info) + + return client_callback + + +class BasePlayerBasedFeatureCommand(BaseFeatureCommand): + deny_mass_execution = False + + def _get_target_players(self, client, filter_str, filter_args): + players = [] + for player in iter_filter_targets( + filter_str, filter_args, client.player): + + if not self.feature.filter(client, player): + continue + + players.append(player) + + if self.deny_mass_execution and len(players) > 1: + return [] + + return players + + +class PlayerBasedFeatureCommand(BasePlayerBasedFeatureCommand): + def _execute(self, command_info, filter_str, filter_args): + client = clients[command_info.index] + for player in self._get_target_players( + client, filter_str, filter_args): + + client.sync_execution(self.feature.execute, (client, player)) + + def _get_public_chat_callback(self): + def public_chat_callback( + command_info, filter_str:str, filter_args:str=""): + + self._execute(command_info, filter_str, filter_args) + return CommandReturn.CONTINUE + + return public_chat_callback + + def _get_private_chat_callback(self): + def private_chat_callback( + command_info, filter_str:str, filter_args:str=""): + + self._execute(command_info, filter_str, filter_args) + return CommandReturn.BLOCK + + return private_chat_callback + + def _get_client_callback(self): + def client_callback(command_info, filter_str:str, filter_args:str=""): + self._execute(command_info, filter_str, filter_args) + + return client_callback diff --git a/srcds/addons/source-python/plugins/admin/core/frontends/menus.py b/srcds/addons/source-python/plugins/admin/core/frontends/menus.py index 37f89a0..9bfdd76 100644 --- a/srcds/addons/source-python/plugins/admin/core/frontends/menus.py +++ b/srcds/addons/source-python/plugins/admin/core/frontends/menus.py @@ -8,6 +8,7 @@ # Source.Python Admin from ..clients import clients +from ..config import config from ..helpers import format_player_name from ..strings import strings_common @@ -21,7 +22,7 @@ # ============================================================================= # >> CLASSES # ============================================================================= -class AdminMenuEntry: +class MenuEntry: """Represent a selectable entry in main admin menu or its submenus.""" def __init__(self, parent, title, id_=None): self._parent = parent @@ -50,7 +51,7 @@ def select(self, client): raise NotImplementedError -class AdminMenuSection(AdminMenuEntry, list): +class MenuSection(MenuEntry, list): """Represents a selectable section of other entries in admin menus.""" def __init__(self, parent, title, id_=None): super().__init__(parent, title, id_) @@ -77,7 +78,7 @@ def build_callback(popup, index): continue selectable = item.is_selectable(client) - if isinstance(item, AdminMenuSection): + if isinstance(item, MenuSection): title = strings_menus['extensible'].tokenized( item=item.title) else: @@ -93,13 +94,13 @@ def build_callback(popup, index): def add_entry(self, entry): """Add another entry to this section then sort again. - :param AdminMenuEntry entry: Given entry. + :param MenuEntry entry: Given entry. :return: Passed entry without alteration. - :rtype: AdminMenuEntry + :rtype: MenuEntry """ self.append(entry) self.sort(key=lambda entry_: (self.order.index(entry_.id) - if entry_.id in self.order else -1)) + if entry_.id in self.order else 999)) return entry @@ -144,14 +145,19 @@ def select(self, client): client.send_popup(self.popup) + def load_order(self, order): + self.order = order[:] + self.sort(key=lambda entry_: (self.order.index(entry_.id) + if entry_.id in self.order else 999)) + -class AdminCommand(AdminMenuEntry): +class MenuCommand(MenuEntry): """Base class for entry that is bound to execute a feature.""" def __init__(self, feature, parent, title, id_=None): - """Initialize AdminCommand instance. + """Initialize MenuCommand instance. :param feature: Feature instance this entry is bound to execute. - :param parent: Parent AdminMenuSection instance. + :param parent: Parent MenuSection instance. :param title: TranslationStrings instance. :param str|None id_: String ID that will be used to sort this item. """ @@ -222,18 +228,18 @@ def __init__(self): self.options = [] -class BasePlayerBasedAdminCommand(AdminCommand): +class BasePlayerBasedMenuCommand(MenuCommand): """Base class for entry that is bound to perform a command on the players. """ # Allow selecting multiple players at once? allow_multiple_choices = True def __init__(self, feature, parent, title, id_=None): - """Initialize BasePlayerBasedAdminCommand instance. + """Initialize BasePlayerBasedMenuCommand instance. :param feature: PlayerBasedFeature instance this entry is bound to execute. - :param parent: Parent AdminMenuSection instance. + :param parent: Parent MenuSection instance. :param title: TranslationStrings instance. :param str|None id_: String ID that will be used to sort this item. """ @@ -531,7 +537,7 @@ def select(self, client): client.send_popup(self.popup) -class PlayerBasedAdminCommand(BasePlayerBasedAdminCommand): +class PlayerBasedMenuCommand(BasePlayerBasedMenuCommand): base_filter = 'all' def _get_player_id(self, player): @@ -539,3 +545,12 @@ def _get_player_id(self, player): def _iter(self): yield from PlayerIter(self.base_filter) + + +# ============================================================================= +# >> MAIN MENU +# ============================================================================= +main_menu = MenuSection(None, strings_common['title main'], 'admin') +main_menu.load_order(list(map( + lambda x: x.strip(), config['menus']['order'].split(',') +))) diff --git a/srcds/addons/source-python/plugins/admin/core/frontends/motd.py b/srcds/addons/source-python/plugins/admin/core/frontends/motd.py index 1cfe828..0d3ec54 100644 --- a/srcds/addons/source-python/plugins/admin/core/frontends/motd.py +++ b/srcds/addons/source-python/plugins/admin/core/frontends/motd.py @@ -523,6 +523,13 @@ def listener_on_client_active(index): @OnClientDisconnect def listener_on_client_disconnect(index): - player = Player(index) + try: + player = Player(index) + except ValueError: + + # If player disconnects before activation, Player instantiation will + # raise. Well, we'd never have such player in any of the pages anyways. + return + for ws_player_based_page in _ws_player_based_pages: ws_player_based_page.send_remove_id(player) diff --git a/srcds/addons/source-python/plugins/admin/core/helpers.py b/srcds/addons/source-python/plugins/admin/core/helpers.py index 7677965..5c2f163 100644 --- a/srcds/addons/source-python/plugins/admin/core/helpers.py +++ b/srcds/addons/source-python/plugins/admin/core/helpers.py @@ -2,7 +2,7 @@ # >> IMPORTS # ============================================================================= # Source.Python -from messages import SayText2 +from messages import HudDestination, SayText2, TextMsg from translations.manager import language_manager # Source.Python Admin @@ -43,6 +43,16 @@ def format_player_name(player_name): def log_admin_action(message): - SayText2(strings_common['chat_base'].tokenized(message=message)).send() + chat_message(message) admin_performed_actions_logger.log_message( message.get_string(language_manager.default)) + + +def chat_message(message, targets=()): + SayText2( + strings_common['chat_base'].tokenized(message=message) + ).send(*targets) + + +def console_message(message, targets=()): + TextMsg(message, HudDestination.CONSOLE).send(*targets) diff --git a/srcds/addons/source-python/plugins/admin/core/memory.py b/srcds/addons/source-python/plugins/admin/core/memory.py deleted file mode 100644 index 504d1d9..0000000 --- a/srcds/addons/source-python/plugins/admin/core/memory.py +++ /dev/null @@ -1,25 +0,0 @@ -# ============================================================================= -# >> IMPORTS -# ============================================================================= -# Source.Python -from core import GAME_NAME -from engines.server import server -from memory import get_object_pointer, make_object -from memory.manager import TypeManager - -# Source.Python Admin -from .paths import ADMIN_DATA_PATH - - -# ============================================================================= -# >> GLOBAL VARIABLES -# ============================================================================= -manager = TypeManager() -server_ptr = get_object_pointer(server) - -CustomServer = manager.create_type_from_file( - 'CBaseServer', - ADMIN_DATA_PATH / 'memory' / GAME_NAME / 'CBaseServer.ini' -) - -custom_server = make_object(CustomServer, server_ptr) diff --git a/srcds/addons/source-python/plugins/admin/core/orm.py b/srcds/addons/source-python/plugins/admin/core/orm.py index 8cebf75..e7dba65 100644 --- a/srcds/addons/source-python/plugins/admin/core/orm.py +++ b/srcds/addons/source-python/plugins/admin/core/orm.py @@ -19,3 +19,21 @@ )) Base = declarative_base() Session = sessionmaker(bind=engine) + + +# ============================================================================= +# >> CLASSES +# ============================================================================= +class SessionContext: + def __init__(self): + self.session = None + + def __enter__(self): + self.session = Session() + return self.session + + def __exit__(self, exc_type, exc_val, exc_tb): + if exc_type is not None: + self.session.rollback() + self.session.close() + self.session = None diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/__init__.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/__init__.py new file mode 100644 index 0000000..6690808 --- /dev/null +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/__init__.py @@ -0,0 +1 @@ +"""Block player text/voice chat""" diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/admin_comm_management.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/admin_comm_management.py new file mode 100644 index 0000000..5ba7ec9 --- /dev/null +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/admin_comm_management.py @@ -0,0 +1,67 @@ +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Source.Python Admin +from admin.core.frontends.menus import main_menu, MenuSection + +# Included Plugin +from .blocks.base import BlockCommMenuCommand +from .blocks.chat import ( + block_chat_feature, blocked_chat_user_manager, unblock_any_chat_feature, + unblock_my_chat_feature, UnblockAnyChatMenuCommand, + UnblockMyChatMenuCommand) +from .blocks.voice import ( + block_voice_feature, blocked_voice_user_manager, unblock_any_voice_feature, + unblock_my_voice_feature, UnblockAnyVoiceMenuCommand, + UnblockMyVoiceMenuCommand) +from .strings import plugin_strings + + +# ============================================================================= +# >> MENU ENTRIES +# ============================================================================= +menu_section = main_menu.add_entry(MenuSection( + main_menu, plugin_strings['section_title main'], 'comm_management')) + +menu_section_chat = menu_section.add_entry(MenuSection( + menu_section, plugin_strings['section_title chat'])) + +menu_section_voice = menu_section.add_entry(MenuSection( + menu_section, plugin_strings['section_title voice'])) + +menu_section_chat.add_entry(BlockCommMenuCommand( + block_chat_feature, + menu_section_chat, + plugin_strings['popup_title block_chat'])) + +menu_section_voice.add_entry(BlockCommMenuCommand( + block_voice_feature, + menu_section_voice, + plugin_strings['popup_title block_voice'])) + +menu_section_chat.add_entry(UnblockAnyChatMenuCommand( + unblock_any_chat_feature, + menu_section_chat, + plugin_strings['popup_title unblock_chat_any'])) + +menu_section_voice.add_entry(UnblockAnyVoiceMenuCommand( + unblock_any_voice_feature, + menu_section_voice, + plugin_strings['popup_title unblock_voice_any'])) + +menu_section_chat.add_entry(UnblockMyChatMenuCommand( + unblock_my_chat_feature, + menu_section_chat, + plugin_strings['popup_title unblock_chat'])) + +menu_section_voice.add_entry(UnblockMyVoiceMenuCommand( + unblock_my_voice_feature, + menu_section_voice, + plugin_strings['popup_title unblock_voice'])) + + +# ============================================================================= +# >> SYNCHRONOUS DATABASE OPERATIONS +# ============================================================================= +blocked_chat_user_manager.refresh() +blocked_voice_user_manager.refresh() diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/base.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/base.py new file mode 100644 index 0000000..a2a1991 --- /dev/null +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/base.py @@ -0,0 +1,361 @@ +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Python +import json +from time import time + +# Source.Python +from listeners.tick import GameThread +from menus import PagedMenu, PagedOption +from players.dictionary import PlayerDictionary +from steam import SteamID + +# Site-Package +from sqlalchemy.sql.expression import and_, or_ + +# Source.Python Admin +from admin.core.clients import clients +from admin.core.features import BaseFeature +from admin.core.frontends.menus import MenuCommand, PlayerBasedMenuCommand +from admin.core.helpers import format_player_name +from admin.core.orm import SessionContext +from admin.core.paths import ADMIN_CFG_PATH, get_server_file +from admin.core.strings import strings_common + +# Included Plugin +from ..strings import plugin_strings + + +# ============================================================================= +# >> FUNCTIONS +# ============================================================================= +def load_stock_block_durations(): + with open(get_server_file( + ADMIN_CFG_PATH / "included_plugins" / "admin_comm_management" / + "block_durations.json")) as f: + + block_durations_json = json.load(f) + + block_durations_json.sort() + + return block_durations_json + + +def format_block_duration(seconds): + if seconds < 0: + return plugin_strings['duration permanent'] + + minutes, seconds = divmod(seconds, 60) + hours, minutes = divmod(minutes, 60) + days, hours = divmod(hours, 24) + + if days: + return plugin_strings['duration days'].tokenized( + days=days, hours=hours, mins=minutes, secs=seconds) + + if hours: + return plugin_strings['duration hours'].tokenized( + hours=hours, mins=minutes, secs=seconds) + + if minutes: + return plugin_strings['duration minutes'].tokenized( + mins=minutes, secs=seconds) + + return plugin_strings['duration seconds'].tokenized(secs=seconds) + + +# ============================================================================= +# >> CLASSES +# ============================================================================= +class _BlockedCommUserInfo: + def __init__(self, steamid64, id_, name, blocked_by, expires_at): + self.steamid64 = steamid64 + self.id = id_ + self.name = name + self.blocked_by = blocked_by + self.expires_at = expires_at + + +class BlockedCommUserManager(dict): + model = None + + def _convert_steamid_to_db_format(self, steamid): + return str(SteamID.parse(steamid).to_uint64()) + + def _on_change(self): + pass + + def refresh(self): + self.clear() + + with SessionContext() as session: + blocked_users = session.query(self.model).all() + + current_time = time() + for blocked_user in blocked_users: + if blocked_user.is_unblocked: + continue + + if 0 <= blocked_user.expires_at < current_time: + continue + + self[blocked_user.steamid64] = _BlockedCommUserInfo( + blocked_user.steamid64, blocked_user.id, blocked_user.name, + blocked_user.blocked_by, blocked_user.expires_at + ) + + self._on_change() + + def is_blocked(self, steamid): + steamid64 = self._convert_steamid_to_db_format(steamid) + + if steamid64 not in self: + return False + + if self[steamid64].expires_at < 0: + return True + + if self[steamid64].expires_at < time(): + del self[steamid64] + return False + + return True + + def save_block_to_database(self, blocked_by, steamid, name, duration): + steamid = self._convert_steamid_to_db_format(steamid) + blocked_by = self._convert_steamid_to_db_format(blocked_by) + + with SessionContext() as session: + blocked_user = self.model(steamid, name, blocked_by, duration) + + session.add(blocked_user) + session.commit() + + self[steamid] = _BlockedCommUserInfo( + steamid, blocked_user.id, name, blocked_by, + blocked_user.expires_at) + + self._on_change() + + def get_all_blocks( + self, steamid=None, blocked_by=None, expired=None, unblocked=None): + + result = [] + + with SessionContext() as session: + query = session.query(self.model) + + if steamid is not None: + steamid = self._convert_steamid_to_db_format(steamid) + query = query.filter_by(steamid64=steamid) + + if blocked_by is not None: + blocked_by = self._convert_steamid_to_db_format(blocked_by) + query = query.filter_by(blocked_by=blocked_by) + + if expired is not None: + current_time = int(time()) + if expired: + query = query.filter(and_( + self.model.expires_at < current_time, + self.model.expires_at >= 0 + )) + else: + query = query.filter(or_( + self.model.expires_at >= current_time, + self.model.expires_at < 0 + )) + + if unblocked is not None: + query = query.filter_by(is_unblocked=unblocked) + + for blocked_user in query.all(): + result.append(_BlockedCommUserInfo( + blocked_user.steamid64, blocked_user.id, blocked_user.name, + blocked_user.blocked_by, blocked_user.expires_at + )) + + return result + + def get_active_blocks(self, blocked_by=None): + if blocked_by is not None: + blocked_by = self._convert_steamid_to_db_format(blocked_by) + + current_time = time() + + result = [] + for blocked_comm_user_info in self.values(): + if ( + blocked_by is not None and + blocked_comm_user_info.blocked_by != blocked_by): + + continue + + if blocked_comm_user_info.expires_at < current_time: + continue + + result.append(blocked_comm_user_info) + + return result + + def lift_block(self, id_, unblocked_by): + unblocked_by = self._convert_steamid_to_db_format(unblocked_by) + + with SessionContext() as session: + blocked_user = session.query(self.model).filter_by(id=id_).first() + + if blocked_user is None: + return + + blocked_user.lift_block(unblocked_by) + + session.commit() + + for steamid64, blocked_comm_user_info in self.items(): + if blocked_comm_user_info.id != id_: + continue + + del self[steamid64] + break + + self._on_change() + + +class BlockCommFeature(BaseFeature): + feature_abstract = True + blocked_comm_user_manager = None + + def execute(self, client, player, duration): + if player.is_fake_client() or player.is_hltv(): + client.tell(plugin_strings['error bot_cannot_block']) + return + + GameThread( + target=self.blocked_comm_user_manager.save_block_to_database, + args=( + client.steamid, + player.steamid, + player.name, + duration + ) + ).start() + + def filter(self, client, player): + if self.blocked_comm_user_manager.is_blocked(player.steamid): + return False + + if client.player == player: + return False + + another_client = clients[player.index] + return not another_client.has_permission(self.flag) + + +class BlockCommMenuCommand(PlayerBasedMenuCommand): + base_filter = 'human' + + def __init__(self, feature, parent, title, id_=None): + super().__init__(feature, parent, title, id_) + + self._selected_players = PlayerDictionary(lambda index: ()) + + self.duration_popup = PagedMenu( + parent_menu=self.popup, + title=plugin_strings['popup_title duration']) + + @self.duration_popup.register_build_callback + def build_callback(popup, index): + popup.clear() + + for block_duration in stock_block_durations: + popup.append(PagedOption( + text=format_block_duration(block_duration), + value=(self._selected_players[index], block_duration) + )) + + @self.duration_popup.register_select_callback + def select_callback(popup, index, option): + client = clients[index] + + for player in self._filter_player_ids(client, option.value[0]): + self.feature.execute(client, player, option.value[1]) + + def _player_select(self, client, player_ids): + index = client.player.index + self._selected_players[index] = player_ids + + client.send_popup(self.duration_popup) + + +class UnblockCommFeature(BaseFeature): + feature_abstract = True + blocked_comm_user_manager = None + + def execute(self, client, blocked_comm_user_info): + GameThread( + target=self.blocked_comm_user_manager.lift_block, + args=(blocked_comm_user_info.id, client.steamid) + ).start() + + +class _UnblockCommMenuCommand(MenuCommand): + popup_title = None + + def __init__(self, feature, parent, title, id_=None): + super().__init__(feature, parent, title, id_) + + self.popup = PagedMenu(title=self.popup_title) + + if parent is not None: + self.popup.parent_menu = parent.popup + + @self.popup.register_select_callback + def select_callback(popup, index, option): + self._blocked_comm_user_info_select(clients[index], option.value) + + @self.popup.register_build_callback + def build_callback(popup, index): + popup.clear() + + client = clients[index] + for blocked_comm_user_info in self._get_blocks(client): + popup.append(PagedOption( + text=plugin_strings['block_record'].tokenized( + id=blocked_comm_user_info.steamid64, + name=format_player_name(blocked_comm_user_info.name) + ), + value=blocked_comm_user_info + )) + + def _get_blocks(self, client): + raise NotImplementedError + + def _blocked_comm_user_info_select(self, client, blocked_comm_user_info): + if not self.is_visible(client) or not self.is_selectable(client): + client.tell(strings_common['unavailable']) + return + + self.feature.execute(client, blocked_comm_user_info) + + self._parent.select(client) + + def select(self, client): + client.send_popup(self.popup) + + +class UnblockAnyCommMenuCommand(_UnblockCommMenuCommand): + def _get_blocks(self, client): + return self.feature.blocked_comm_user_manager.get_active_blocks() + + +class UnblockMyCommMenuCommand(_UnblockCommMenuCommand): + def _get_blocks(self, client): + return self.feature.blocked_comm_user_manager.get_active_blocks( + blocked_by=client.steamid) + + +# ============================================================================= +# >> GLOBAL VARIABLES +# ============================================================================= +stock_block_durations = load_stock_block_durations() diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/chat.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/chat.py new file mode 100644 index 0000000..b09e586 --- /dev/null +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/chat.py @@ -0,0 +1,92 @@ +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Source.Python +from commands import CommandReturn +from commands.say import SayFilter + +# Source.Python Admin +from admin.core.clients import clients +from admin.core.helpers import log_admin_action + +# Included Plugin +from ..models import BlockedChatUser +from ..strings import plugin_strings +from .base import ( + BlockCommFeature, BlockedCommUserManager, UnblockAnyCommMenuCommand, + UnblockCommFeature, UnblockMyCommMenuCommand) + + +# ============================================================================= +# >> CLASSES +# ============================================================================= +class _BlockedChatUserManager(BlockedCommUserManager): + model = BlockedChatUser + +# The singleton object for the _BlockedChatUserManager class. +blocked_chat_user_manager = _BlockedChatUserManager() + + +class _BlockChatFeature(BlockCommFeature): + flag = "admin.admin_comm_management.block_chat" + blocked_comm_user_manager = blocked_chat_user_manager + + def execute(self, client, player, duration): + super().execute(client, player, duration) + + log_admin_action(plugin_strings['message chat_blocked'].tokenized( + admin_name=client.name, + player_name=player.name, + )) + +# The singleton object of the _BlockChatFeature class. +block_chat_feature = _BlockChatFeature() + + +class _UnblockChatFeature(UnblockCommFeature): + feature_abstract = True + blocked_comm_user_manager = blocked_chat_user_manager + + def execute(self, client, blocked_comm_user_info): + super().execute(client, blocked_comm_user_info) + + log_admin_action(plugin_strings['message chat_unblocked'].tokenized( + admin_name=client.name, + player_name=blocked_comm_user_info.name, + )) + + +class _UnblockAnyChatFeature(_UnblockChatFeature): + flag = "admin.admin_comm_management.unblock_any_chat" + +# The singleton object of the _UnblockAnyChatFeature class. +unblock_any_chat_feature = _UnblockAnyChatFeature() + + +class _UnblockMyChatFeature(_UnblockChatFeature): + flag = "admin.admin_comm_management.block_chat" + +# The singleton object of the _UnblockMyChatFeature class. +unblock_my_chat_feature = _UnblockMyChatFeature() + + +class UnblockAnyChatMenuCommand(UnblockAnyCommMenuCommand): + popup_title = plugin_strings['popup_title unblock_chat_any'] + + +class UnblockMyChatMenuCommand(UnblockMyCommMenuCommand): + popup_title = plugin_strings['popup_title unblock_chat'] + + +# ============================================================================= +# >> COMMAND FILTERS +# ============================================================================= +@SayFilter +def say_filter(command, index, team_only): + client = clients[index] + + if blocked_chat_user_manager.is_blocked(client.steamid): + client.tell(plugin_strings['error chat_block']) + return CommandReturn.BLOCK + + return CommandReturn.CONTINUE diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/voice.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/voice.py new file mode 100644 index 0000000..5e1fbd3 --- /dev/null +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/voice.py @@ -0,0 +1,120 @@ +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Source.Python +from filters.players import PlayerIter +from listeners import OnClientActive +from listeners.tick import Delay +from players.dictionary import PlayerDictionary +from players.voice import mute_manager + +# Source.Python Admin +from admin.core.helpers import log_admin_action + +# Included Plugin +from ..models import BlockedVoiceUser +from ..strings import plugin_strings +from .base import ( + BlockCommFeature, BlockedCommUserManager, UnblockAnyCommMenuCommand, + UnblockCommFeature, UnblockMyCommMenuCommand) + + +# ============================================================================= +# >> FUNCTIONS +# ============================================================================= +def sync_voice_blocked_players(): + for player in PlayerIter('human'): + if blocked_voice_user_manager.is_blocked(player.steamid): + mute_manager.mute_player(player.index) + else: + mute_manager.unmute_player(player.index) + + +# ============================================================================= +# >> CLASSES +# ============================================================================= +class _BlockedVoiceUserManager(BlockedCommUserManager): + model = BlockedVoiceUser + + def _on_change(self): + sync_voice_blocked_players() + +# The singleton object for the _BlockedVoiceUserManager class. +blocked_voice_user_manager = _BlockedVoiceUserManager() + + +class _BlockVoiceFeature(BlockCommFeature): + flag = "admin.admin_comm_management.block_voice" + blocked_comm_user_manager = blocked_voice_user_manager + + def execute(self, client, player, duration): + super().execute(client, player, duration) + + if player_unmute_delays[player.index] is not None: + if player_unmute_delays[player.index].running: + player_unmute_delays[player.index].cancel() + player_unmute_delays[player.index] = None + + if duration >= 0: + player_unmute_delays[player.index] = Delay( + duration + 0.1, sync_voice_blocked_players) + + log_admin_action(plugin_strings['message voice_blocked'].tokenized( + admin_name=client.name, + player_name=player.name, + )) + +# The singleton object of the _BlockVoiceFeature class. +block_voice_feature = _BlockVoiceFeature() + + +class _UnblockVoiceFeature(UnblockCommFeature): + feature_abstract = True + blocked_comm_user_manager = blocked_voice_user_manager + + def execute(self, client, blocked_comm_user_info): + super().execute(client, blocked_comm_user_info) + + log_admin_action(plugin_strings['message voice_unblocked'].tokenized( + admin_name=client.name, + player_name=blocked_comm_user_info.name, + )) + + +class _UnblockAnyVoiceFeature(_UnblockVoiceFeature): + flag = "admin.admin_comm_management.unblock_any_voice" + +# The singleton object of the _UnblockAnyVoiceFeature class. +unblock_any_voice_feature = _UnblockAnyVoiceFeature() + + +class _UnblockMyVoiceFeature(_UnblockVoiceFeature): + flag = "admin.admin_comm_management.block_voice" + +# The singleton object of the _UnblockMyVoiceFeature class. +unblock_my_voice_feature = _UnblockMyVoiceFeature() + + +class UnblockAnyVoiceMenuCommand(UnblockAnyCommMenuCommand): + popup_title = plugin_strings['popup_title unblock_voice_any'] + + +class UnblockMyVoiceMenuCommand(UnblockMyCommMenuCommand): + popup_title = plugin_strings['popup_title unblock_voice'] + + +class _PlayerUnmuteDelaysDictionary(PlayerDictionary): + def on_automatically_removed(self, index): + delay = self[index] + delay.cancel() + +# The singleton object of the _PlayerUnmuteDelaysDictionary class. +player_unmute_delays = _PlayerUnmuteDelaysDictionary(lambda index: None) + + +# ============================================================================= +# >> LISTENERS +# ============================================================================= +@OnClientActive +def listener_on_client_active(index): + sync_voice_blocked_players() diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/info.ini b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/info.ini new file mode 100644 index 0000000..64446cd --- /dev/null +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/info.ini @@ -0,0 +1,4 @@ +verbose_name = "Admin Communication Management" +author = "Source-Python-Dev-Team" +description = "Provide communication blocking functionality." +public_convar = False diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/info.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/info.py new file mode 100644 index 0000000..4b52f7e --- /dev/null +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/info.py @@ -0,0 +1,13 @@ +"""Contains plugin information.""" + +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Source.Python Admin +from admin.core.plugins.info import AdminPluginInfo + + +# ============================================================================= +# >> PLUGIN INFO +# ============================================================================= +info = AdminPluginInfo(__name__) diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/models.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/models.py new file mode 100644 index 0000000..0010d73 --- /dev/null +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/models.py @@ -0,0 +1,55 @@ +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Python +from time import time + +# Site-Package +from sqlalchemy import Boolean, Column, Integer, String + +# Source.Python Admin +from admin.core.config import config +from admin.core.orm import Base + + +# ============================================================================= +# >> MODEL CLASSES +# ============================================================================= +class _BlockedCommUser(Base): + __abstract__ = True + + id = Column(Integer, primary_key=True) + steamid64 = Column(String(32)) + name = Column(String(64)) + blocked_by = Column(String(32)) + + blocked_at = Column(Integer) + expires_at = Column(Integer) + + is_unblocked = Column(Boolean) + unblocked_by = Column(String(32)) + + def __init__(self, steamid64, name, blocked_by, duration): + super().__init__() + + current_time = time() + + self.steamid64 = steamid64 + self.name = name + self.blocked_by = blocked_by + self.blocked_at = int(current_time) + self.expires_at = int(current_time + duration) + self.is_unblocked = False + self.unblocked_by = "" + + def lift_block(self, unblocked_by): + self.is_unblocked = True + self.unblocked_by = unblocked_by + + +class BlockedChatUser(_BlockedCommUser): + __tablename__ = config['database']['prefix'] + "blocked_chat_user" + + +class BlockedVoiceUser(_BlockedCommUser): + __tablename__ = config['database']['prefix'] + "blocked_voice_user" diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/strings.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/strings.py new file mode 100644 index 0000000..12a7705 --- /dev/null +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/strings.py @@ -0,0 +1,11 @@ +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Source.Python Admin +from admin.core.plugins.strings import PluginStrings + + +# ============================================================================= +# >> GLOBAL VARIABLES +# ============================================================================= +plugin_strings = PluginStrings("admin_comm_management") diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/admin_kick_ban.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/admin_kick_ban.py index 6873dbf..d18e090 100644 --- a/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/admin_kick_ban.py +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/admin_kick_ban.py @@ -5,27 +5,28 @@ from players.helpers import get_client_language # Source.Python Admin -from admin.admin import main_menu from admin.core.features import PlayerBasedFeature from admin.core.frontends.menus import ( - AdminCommand, AdminMenuSection, PlayerBasedAdminCommand) + main_menu, MenuSection, PlayerBasedMenuCommand) from admin.core.frontends.motd import ( main_motd, MOTDSection, MOTDPageEntry, PlayerBasedFeaturePage) from admin.core.helpers import log_admin_action # Included Plugin from .bans.ip_address import ( - ban_ip_address_feature, banned_ip_address_manager, - BanIPAddressMenuCommand, BanIPAddressPage, - lift_any_ip_address_ban_popup_feature, lift_ip_address_ban_popup_feature, - LiftIPAddressBanPage, review_ip_address_ban_popup_feature, - ReviewIPAddressBanPage, search_bad_ip_address_bans_popup_feature) + ban_ip_address_feature, banned_ip_address_manager, BanIPAddressMenuCommand, + BanIPAddressPage, lift_ip_address_ban_feature, + LiftAnyIPAddressBanMenuCommand, LiftIPAddressBanPage, + LiftMyIPAddressBanMenuCommand, remove_bad_ip_address_ban_feature, + RemoveBadIPAddressBanMenuCommand, review_ip_address_ban_feature, + ReviewIPAddressBanMenuCommand, ReviewIPAddressBanPage) from .bans.steamid import ( - ban_steamid_feature, banned_steamid_manager, - BanSteamIDMenuCommand, BanSteamIDPage, - lift_any_steamid_ban_popup_feature, lift_steamid_ban_popup_feature, - LiftSteamIDBanPage, review_steamid_ban_popup_feature, - ReviewSteamIDBanPage, search_bad_steamid_bans_popup_feature) + ban_steamid_feature, banned_steamid_manager, BanSteamIDMenuCommand, + BanSteamIDPage, lift_steamid_ban_feature, + LiftAnySteamIDBanMenuCommand, LiftSteamIDBanPage, + LiftMySteamIDBanMenuCommand, remove_bad_steamid_ban_feature, + RemoveBadSteamIDBanMenuCommand, review_steamid_ban_feature, + ReviewSteamIDBanMenuCommand, ReviewSteamIDBanPage) from .strings import plugin_strings @@ -51,7 +52,7 @@ def execute(self, client, player): kick_feature = _KickFeature() -class _KickMenuCommand(PlayerBasedAdminCommand): +class _KickMenuCommand(PlayerBasedMenuCommand): allow_multiple_choices = False @@ -68,28 +69,15 @@ class _KickPage(PlayerBasedFeaturePage): # ============================================================================= # >> MENU ENTRIES # ============================================================================= -menu_section = main_menu.add_entry(AdminMenuSection( - main_menu, plugin_strings['section_title main'])) +menu_section = main_menu.add_entry(MenuSection( + main_menu, plugin_strings['section_title main'], 'kick_ban')) -menu_section_steamid = menu_section.add_entry(AdminMenuSection( +menu_section_steamid = menu_section.add_entry(MenuSection( menu_section, plugin_strings['section_title steamid_bans'])) -menu_section_ip_address = menu_section.add_entry(AdminMenuSection( +menu_section_ip_address = menu_section.add_entry(MenuSection( menu_section, plugin_strings['section_title ip_address_bans'])) -lift_steamid_ban_popup_feature.ban_popup.parent_menu = ( - menu_section_steamid.popup) -lift_ip_address_ban_popup_feature.ban_popup.parent_menu = ( - menu_section_ip_address.popup) -lift_any_steamid_ban_popup_feature.ban_popup.parent_menu = ( - menu_section_steamid.popup) -lift_any_ip_address_ban_popup_feature.ban_popup.parent_menu = ( - menu_section_ip_address.popup) -review_steamid_ban_popup_feature.ban_popup.parent_menu = ( - menu_section_steamid.popup) -review_ip_address_ban_popup_feature.ban_popup.parent_menu = ( - menu_section_ip_address.popup) - menu_section.add_entry(_KickMenuCommand( kick_feature, menu_section, @@ -105,43 +93,43 @@ class _KickPage(PlayerBasedFeaturePage): menu_section_ip_address, plugin_strings['popup_title ban_ip_address'])) -menu_section_steamid.add_entry(AdminCommand( - review_steamid_ban_popup_feature, +menu_section_steamid.add_entry(ReviewSteamIDBanMenuCommand( + review_steamid_ban_feature, menu_section_steamid, plugin_strings['popup_title review_steamid'])) -menu_section_ip_address.add_entry(AdminCommand( - review_ip_address_ban_popup_feature, +menu_section_ip_address.add_entry(ReviewIPAddressBanMenuCommand( + review_ip_address_ban_feature, menu_section_ip_address, plugin_strings['popup_title review_ip_address'])) -menu_section_steamid.add_entry(AdminCommand( - lift_steamid_ban_popup_feature, +menu_section_steamid.add_entry(LiftMySteamIDBanMenuCommand( + lift_steamid_ban_feature, menu_section_steamid, plugin_strings['popup_title lift_steamid'])) -menu_section_ip_address.add_entry(AdminCommand( - lift_ip_address_ban_popup_feature, +menu_section_ip_address.add_entry(LiftMyIPAddressBanMenuCommand( + lift_ip_address_ban_feature, menu_section_ip_address, plugin_strings['popup_title lift_ip_address'])) -menu_section_steamid.add_entry(AdminCommand( - lift_any_steamid_ban_popup_feature, +menu_section_steamid.add_entry(LiftAnySteamIDBanMenuCommand( + lift_steamid_ban_feature, menu_section_steamid, plugin_strings['popup_title lift_reviewed_steamid'])) -menu_section_ip_address.add_entry(AdminCommand( - lift_any_ip_address_ban_popup_feature, +menu_section_ip_address.add_entry(LiftAnyIPAddressBanMenuCommand( + lift_ip_address_ban_feature, menu_section_ip_address, plugin_strings['popup_title lift_reviewed_ip_address'])) -menu_section_steamid.add_entry(AdminCommand( - search_bad_steamid_bans_popup_feature, +menu_section_steamid.add_entry(RemoveBadSteamIDBanMenuCommand( + remove_bad_steamid_ban_feature, menu_section_steamid, plugin_strings['popup_title search_bad_bans'])) -menu_section_ip_address.add_entry(AdminCommand( - search_bad_ip_address_bans_popup_feature, +menu_section_ip_address.add_entry(RemoveBadIPAddressBanMenuCommand( + remove_bad_ip_address_ban_feature, menu_section_ip_address, plugin_strings['popup_title search_bad_bans'])) diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/base.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/base.py index 7439e8e..8b01df0 100644 --- a/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/base.py +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/base.py @@ -9,20 +9,23 @@ # Source.Python from listeners.tick import GameThread from menus import PagedMenu, PagedOption, SimpleMenu, SimpleOption, Text +from players.dictionary import PlayerDictionary from players.helpers import get_client_language from steam import SteamID from translations.manager import language_manager # Site-Package -from sqlalchemy.sql.expression import and_ +from sqlalchemy.sql.expression import and_, or_ # Source.Python Admin from admin.core.clients import clients -from admin.core.features import BaseFeature, Feature +from admin.core.features import BaseFeature +from admin.core.frontends.menus import MenuCommand from admin.core.frontends.motd import BaseFeaturePage from admin.core.helpers import format_player_name, log_admin_action -from admin.core.orm import Session +from admin.core.orm import SessionContext from admin.core.paths import ADMIN_CFG_PATH, get_server_file +from admin.core.strings import strings_common # Included Plugin from ..strings import plugin_strings @@ -121,25 +124,22 @@ def _convert_steamid_to_db_format(self, steamid): def refresh(self): self.clear() - session = Session() + with SessionContext() as session: + banned_users = session.query(self.model).all() - banned_users = session.query(self.model).all() + current_time = time() + for banned_user in banned_users: + if banned_user.is_unbanned: + continue - current_time = time() - for banned_user in banned_users: - if banned_user.is_unbanned: - continue - - if -1 < banned_user.expires_at < current_time: - continue + if 0 <= banned_user.expires_at < current_time: + continue - self[banned_user.uniqueid] = _BannedPlayerInfo( - banned_user.uniqueid, banned_user.id, banned_user.name, - banned_user.banned_by, banned_user.reviewed, - banned_user.expires_at, banned_user.reason, banned_user.notes - ) - - session.close() + self[banned_user.uniqueid] = _BannedPlayerInfo( + banned_user.uniqueid, banned_user.id, banned_user.name, + banned_user.banned_by, banned_user.reviewed, + banned_user.expires_at, banned_user.reason, + banned_user.notes) def is_banned(self, uniqueid): uniqueid = self._convert_uniqueid_to_db_format(uniqueid) @@ -160,69 +160,66 @@ def save_ban_to_database(self, banned_by, uniqueid, name, duration): uniqueid = self._convert_uniqueid_to_db_format(uniqueid) banned_by = self._convert_steamid_to_db_format(banned_by) - session = Session() - - banned_user = self.model(uniqueid, name, banned_by, duration) + with SessionContext() as session: + banned_user = self.model(uniqueid, name, banned_by, duration) - session.add(banned_user) - session.commit() - - self[uniqueid] = _BannedPlayerInfo( - uniqueid, banned_user.id, name, banned_by, False, - banned_user.expires_at, "", "") + session.add(banned_user) + session.commit() - session.close() + self[uniqueid] = _BannedPlayerInfo( + uniqueid, banned_user.id, name, banned_by, False, + banned_user.expires_at, "", "") def remove_ban_from_database(self, ban_id): - session = Session() + with SessionContext() as session: + banned_user = session.query( + self.model).filter_by(id=ban_id).first() - banned_user = session.query(self.model).filter_by(id=ban_id).first() - if banned_user is not None: - session.delete(banned_user) - session.commit() - - session.close() + if banned_user is not None: + session.delete(banned_user) + session.commit() def get_all_bans(self, uniqueid=None, banned_by=None, reviewed=None, expired=None, unbanned=None): result = [] - session = Session() - - query = session.query(self.model) - - if uniqueid is not None: - uniqueid = self._convert_uniqueid_to_db_format(uniqueid) - query = query.filter(self.model.uniqueid == uniqueid) - - if banned_by is not None: - banned_by = self._convert_steamid_to_db_format(banned_by) - query = query.filter_by(banned_by=banned_by) - - if reviewed is not None: - query = query.filter_by(reviewed=reviewed) - if expired is not None: - current_time = int(time()) - if expired: - query = query.filter(and_( - self.model.expires_at < current_time, - self.model.expires_at > -1 + with SessionContext() as session: + query = session.query(self.model) + + if uniqueid is not None: + uniqueid = self._convert_uniqueid_to_db_format(uniqueid) + query = query.filter_by(uniqueid=uniqueid) + + if banned_by is not None: + banned_by = self._convert_steamid_to_db_format(banned_by) + query = query.filter_by(banned_by=banned_by) + + if reviewed is not None: + query = query.filter_by(reviewed=reviewed) + + if expired is not None: + current_time = int(time()) + if expired: + query = query.filter(and_( + self.model.expires_at < current_time, + self.model.expires_at >= 0 + )) + else: + query = query.filter(or_( + self.model.expires_at >= current_time, + self.model.expires_at < 0 + )) + + if unbanned is not None: + query = query.filter_by(is_unbanned=unbanned) + + for banned_user in query.all(): + result.append(_BannedPlayerInfo( + banned_user.uniqueid, banned_user.id, banned_user.name, + banned_user.banned_by, banned_user.reviewed, + banned_user.expires_at, banned_user.reason, banned_user.notes )) - else: - query = query.filter(self.model.expires_at >= current_time) - - if unbanned is not None: - query = query.filter_by(is_unbanned=unbanned) - - for banned_user in query.all(): - result.append(_BannedPlayerInfo( - banned_user.uniqueid, banned_user.id, banned_user.name, - banned_user.banned_by, banned_user.reviewed, - banned_user.expires_at, banned_user.reason, banned_user.notes - )) - - session.close() return result @@ -254,19 +251,17 @@ def get_active_bans(self, banned_by=None, reviewed=None): return result def review_ban(self, ban_id, reason, duration): - session = Session() + with SessionContext() as session: + banned_user = session.query( + self.model).filter_by(id=ban_id).first() - banned_user = session.query(self.model).filter_by(id=ban_id).first() - - if banned_user is None: - session.close() - return + if banned_user is None: + return - banned_user.review(reason, duration) - expires_at = banned_user.expires_at + banned_user.review(reason, duration) + expires_at = banned_user.expires_at - session.commit() - session.close() + session.commit() for banned_player_info in self.values(): if banned_player_info.id != ban_id: @@ -280,18 +275,16 @@ def review_ban(self, ban_id, reason, duration): def lift_ban(self, ban_id, unbanned_by): unbanned_by = self._convert_steamid_to_db_format(unbanned_by) - session = Session() + with SessionContext() as session: + banned_user = session.query( + self.model).filter_by(id=ban_id).first() - banned_user = session.query(self.model).filter_by(id=ban_id).first() - - if banned_user is None: - session.close() - return + if banned_user is None: + return - banned_user.lift_ban(unbanned_by) + banned_user.lift_ban(unbanned_by) - session.commit() - session.close() + session.commit() for uniqueid, banned_player_info in self.items(): if banned_player_info.id != ban_id: @@ -301,53 +294,47 @@ def lift_ban(self, ban_id, unbanned_by): break -class LiftBanMOTDFeature(BaseFeature): +class LiftBanFeature(BaseFeature): feature_abstract = True banned_uniqueid_manager = None ws_lift_ban_pages = None - def get_bans(self, client): - yield from self.banned_uniqueid_manager.get_active_bans( - banned_by=client.steamid, reviewed=False) - - def get_ban_by_id(self, client, ban_id): - for banned_player_info in self.get_bans(client): - if banned_player_info.id == ban_id: - return banned_player_info - return None - - def execute(self, client, ban_id, player_name): + def execute(self, client, banned_player_info): GameThread( target=self.banned_uniqueid_manager.lift_ban, - args=(ban_id, client.steamid) + args=(banned_player_info.id, client.steamid) ).start() for ws_lift_ban_page in self.ws_lift_ban_pages: - ws_lift_ban_page.send_remove_ban_id(ban_id) + ws_lift_ban_page.send_remove_ban_id(banned_player_info.id) log_admin_action(plugin_strings['message ban_lifted'].tokenized( admin_name=client.name, - player_name=player_name, + player_name=banned_player_info.name, )) -class LiftBanPopupFeature(Feature): - feature_abstract = True +class _LiftBanMenuCommand(MenuCommand): popup_title = None - banned_uniqueid_manager = None - def __init__(self): - self.ban_popup = PagedMenu(title=self.popup_title) + def __init__(self, feature, parent, title, id_=None): + super().__init__(feature, parent, title, id_) - @self.ban_popup.register_build_callback + self.popup = PagedMenu(title=self.popup_title) + + if parent is not None: + self.popup.parent_menu = parent.popup + + @self.popup.register_select_callback + def select_callback(popup, index, option): + self._popups_done(clients[index], option.value) + + @self.popup.register_build_callback def build_callback(popup, index): - client = clients[index] popup.clear() - bans = self.banned_uniqueid_manager.get_active_bans( - banned_by=client.steamid, reviewed=False) - - for banned_player_info in bans: + client = clients[index] + for banned_player_info in self._get_bans(client): popup.append(PagedOption( text=plugin_strings['ban_record'].tokenized( id=banned_player_info.uniqueid, @@ -355,54 +342,32 @@ def build_callback(popup, index): value=banned_player_info )) - @self.ban_popup.register_select_callback - def select_callback(popup, index, option): - client = clients[index] + def _popups_done(self, client, banned_player_info): + if not self.is_visible(client) or not self.is_selectable(client): + client.tell(strings_common['unavailable']) + return - GameThread( - target=self.banned_uniqueid_manager.lift_ban, - args=(option.value.id, client.steamid) - ).start() + self.feature.execute(client, banned_player_info) - log_admin_action(plugin_strings['message ban_lifted'].tokenized( - admin_name=client.name, - player_name=option.value.name, - )) + self._parent.select(client) - def execute(self, client): - client.send_popup(self.ban_popup) + def _get_bans(self, client): + raise NotImplementedError + def select(self, client): + client.send_popup(self.popup) -class LiftAnyBanPopupFeature(Feature): - feature_abstract = True - popup_title = None - banned_uniqueid_manager = None - def __init__(self): - # (_BannedPlayerInfo instance, whether confirmed or not) - self._selected_ban = (None, False) +class LiftAnyBanMenuCommand(_LiftBanMenuCommand): + def __init__(self, feature, parent, title, id_=None): + super().__init__(feature, parent, title, id_) - self.ban_popup = PagedMenu(title=self.popup_title) + self._selected_bans = PlayerDictionary(lambda index: None) self.confirm_popup = SimpleMenu() - @self.ban_popup.register_build_callback - def build_callback(popup, index): - popup.clear() - - # Get all bans - bans = self.banned_uniqueid_manager.get_active_bans() - - for banned_player_info in bans: - popup.append(PagedOption( - text=plugin_strings['ban_record'].tokenized( - id=banned_player_info.uniqueid, - name=format_player_name(banned_player_info.name)), - value=(banned_player_info, False) - )) - - @self.ban_popup.register_select_callback + @self.popup.register_select_callback def select_callback(popup, index, option): - self._selected_ban = option.value + self._selected_bans[index] = option.value clients[index].send_popup(self.confirm_popup) @self.confirm_popup.register_build_callback @@ -410,20 +375,20 @@ def build_callback(popup, index): popup.clear() popup.append(Text(plugin_strings['ban_record'].tokenized( - name=self._selected_ban[0].name, - id=self._selected_ban[0].uniqueid + name=self._selected_bans[index].name, + id=self._selected_bans[index].uniqueid ))) popup.append(Text( plugin_strings['ban_record admin_steamid'].tokenized( - admin_steamid=self._selected_ban[0].banned_by))) + admin_steamid=self._selected_bans[index].banned_by))) popup.append(Text(plugin_strings['ban_record reason'].tokenized( - reason=self._selected_ban[0].reason))) + reason=self._selected_bans[index].reason))) - if self._selected_ban[0].notes: + if self._selected_bans[index].notes: popup.append(Text(plugin_strings['ban_record notes'].tokenized( - notes=self._selected_ban[0].notes))) + notes=self._selected_bans[index].notes))) popup.append(Text( plugin_strings['lift_reviewed_ban_confirmation'])) @@ -431,12 +396,12 @@ def build_callback(popup, index): popup.append(SimpleOption( choice_index=1, text=plugin_strings['lift_reviewed_ban_confirmation no'], - value=(self._selected_ban[0], False), + value=(self._selected_bans[index], False), )) popup.append(SimpleOption( choice_index=2, text=plugin_strings['lift_reviewed_ban_confirmation yes'], - value=(self._selected_ban[0], True), + value=(self._selected_bans[index], True), )) @self.confirm_popup.register_select_callback @@ -444,69 +409,56 @@ def select_callback(popup, index, option): if not option.value[1]: return - client = clients[index] + self._popups_done(clients[index], option.value[0]) - GameThread( - target=self.banned_uniqueid_manager.lift_ban, - args=(option.value[0].id, client.steamid) - ).start() + def _get_bans(self, client): + return self.feature.banned_uniqueid_manager.get_active_bans() - log_admin_action(plugin_strings['message ban_lifted'].tokenized( - admin_name=client.name, - player_name=option.value[0].name, - )) - def execute(self, client): - client.send_popup(self.ban_popup) +class LiftMyBanMenuCommand(_LiftBanMenuCommand): + def _get_bans(self, client): + return self.feature.banned_uniqueid_manager.get_active_bans( + banned_by=client.steamid, reviewed=False) -class ReviewBanMOTDFeature(BaseFeature): +class ReviewBanFeature(BaseFeature): feature_abstract = True banned_uniqueid_manager = None ws_review_ban_pages = None - def get_bans(self, client): - yield from self.banned_uniqueid_manager.get_active_bans( - banned_by=client.steamid, reviewed=False) - - def get_ban_by_id(self, client, ban_id): - for banned_player_info in self.get_bans(client): - if banned_player_info.id == ban_id: - return banned_player_info - return None - - def execute(self, client, ban_id, reason, duration, player_name): + def execute(self, client, banned_player_info, reason, duration): GameThread( target=self.banned_uniqueid_manager.review_ban, - args=(ban_id, reason, duration) + args=(banned_player_info.id, reason, duration) ).start() for ws_review_ban_page in self.ws_review_ban_pages: - ws_review_ban_page.send_remove_ban_id(ban_id) + ws_review_ban_page.send_remove_ban_id(banned_player_info.id) log_admin_action(plugin_strings['message ban_reviewed'].tokenized( admin_name=client.name, - player_name=player_name, + player_name=banned_player_info.name, duration=format_ban_duration(duration) )) -class ReviewBanPopupFeature(Feature): - feature_abstract = True +class ReviewBanMenuCommand(MenuCommand): popup_title = None - banned_uniqueid_manager = None - def __init__(self): + def __init__(self, feature, parent, title, id_=None): + super().__init__(feature, parent, title, id_) + # (_BannedPlayerInfo instance, reason, duration) - self._selected_ban = (None, "", -1) + self._selected_bans = PlayerDictionary(lambda index: (None, "", -1)) self.ban_popup = PagedMenu(title=self.popup_title) + if parent is not None: + self.ban_popup.parent_menu = parent.popup + self.reason_popup = PagedMenu(title=self.popup_title, parent_menu=self.ban_popup) - # We do not allow returning back to reason popup from duration popup, - # because we won't have valid self._selected_ban to build a reason - # popup with. Hence we don't provide parent_menu here. + # TODO: Provide parent menu self.duration_popup = PagedMenu(title=self.popup_title) @self.ban_popup.register_build_callback @@ -514,10 +466,7 @@ def build_callback(popup, index): client = clients[index] popup.clear() - bans = self.banned_uniqueid_manager.get_active_bans( - banned_by=client.steamid, reviewed=False) - - for banned_player_info in bans: + for banned_player_info in self._get_bans(client): popup.append(PagedOption( text=plugin_strings['ban_record'].tokenized( id=banned_player_info.uniqueid, @@ -527,7 +476,7 @@ def build_callback(popup, index): @self.ban_popup.register_select_callback def select_callback(popup, index, option): - self._selected_ban = option.value + self._selected_bans[index] = option.value clients[index].send_popup(self.reason_popup) @self.reason_popup.register_build_callback @@ -538,7 +487,7 @@ def build_callback(popup, index): popup.append(PagedOption( text=stock_ban_reason.translation, value=( - self._selected_ban[0], + self._selected_bans[index][0], stock_ban_reason.translation.get_string( language_manager.default), stock_ban_reason.duration, @@ -547,80 +496,100 @@ def build_callback(popup, index): @self.reason_popup.register_select_callback def select_callback(popup, index, option): - self._selected_ban = option.value + self._selected_bans[index] = option.value clients[index].send_popup(self.duration_popup) @self.duration_popup.register_build_callback def build_callback(popup, index): popup.clear() - if self._selected_ban[2] is not None: + if self._selected_bans[index][2] is not None: popup.append(PagedOption( text=plugin_strings['default_duration'].tokenized( - default=format_ban_duration(self._selected_ban[2])), - value=self._selected_ban + default=format_ban_duration( + self._selected_bans[index][2])), + value=self._selected_bans[index] )) for stock_ban_duration in stock_ban_durations: popup.append(PagedOption( text=format_ban_duration(stock_ban_duration), value=( - self._selected_ban[0], - self._selected_ban[1], + self._selected_bans[index][0], + self._selected_bans[index][1], stock_ban_duration, ) )) @self.duration_popup.register_select_callback def select_callback(popup, index, option): - client = clients[index] + self._popups_done( + clients[index], + option.value[0], option.value[1], option.value[2]) - GameThread( - target=self.banned_uniqueid_manager.review_ban, - args=(option.value[0].id, option.value[1], option.value[2]) - ).start() + def _popups_done(self, client, banned_player_info, reason, duration): + if not self.is_visible(client) or not self.is_selectable(client): + client.tell(strings_common['unavailable']) + return - log_admin_action(plugin_strings['message ban_reviewed'].tokenized( - admin_name=client.name, - player_name=option.value[0].name, - duration=format_ban_duration(option.value[2]) - )) + self.feature.execute(client, banned_player_info, reason, duration) + + self._parent.select(client) + + def _get_bans(self, client): + return self.feature.banned_uniqueid_manager.get_active_bans( + banned_by=client.steamid, reviewed=False) - def execute(self, client): + def select(self, client): client.send_popup(self.ban_popup) -class SearchBadBansPopupFeature(Feature): +class RemoveBadBanFeature(BaseFeature): feature_abstract = True - popup_title = None banned_uniqueid_manager = None + ws_remove_bad_ban_pages = None - def __init__(self): - # (_BannedPlayerInfo instance, whether to remove or not) - self._selected_ban = None + def execute(self, client, banned_player_info): + GameThread( + target=self.banned_uniqueid_manager.remove_ban_from_database, + args=(banned_player_info.id,) + ).start() + + log_admin_action(plugin_strings['message ban_removed'].tokenized( + admin_name=client.name, + ban_id=banned_player_info.id + )) + + +class RemoveBadBanMenuCommand(MenuCommand): + popup_title = None + + def __init__(self, feature, parent, title, id_=None): + super().__init__(feature, parent, title, id_) + + self._selected_bans = PlayerDictionary(lambda index: None) self.ban_popup = PagedMenu(title=self.popup_title) + if parent is not None: + self.ban_popup.parent_menu = parent.popup + self.remove_popup = SimpleMenu() @self.ban_popup.register_build_callback def build_callback(popup, index): popup.clear() - # Get expired, unreviewed, unlifted bans - bans = self.banned_uniqueid_manager.get_all_bans( - unbanned=False, reviewed=False, expired=True) - - for banned_player_info in bans: + for banned_player_info in self._get_bans(clients[index]): popup.append(PagedOption( text=plugin_strings['ban_record'].tokenized( id=banned_player_info.uniqueid, name=format_player_name(banned_player_info.name)), - value=(banned_player_info, False) + value=banned_player_info )) @self.ban_popup.register_select_callback def select_callback(popup, index, option): - self._selected_ban = option.value + self._selected_bans[index] = option.value clients[index].send_popup(self.remove_popup) @self.remove_popup.register_build_callback @@ -628,17 +597,17 @@ def build_callback(popup, index): popup.clear() popup.append(Text(plugin_strings['ban_record'].tokenized( - name=self._selected_ban[0].name, - id=self._selected_ban[0].uniqueid + name=self._selected_bans[index].name, + id=self._selected_bans[index].uniqueid ))) popup.append(Text( plugin_strings['ban_record admin_steamid'].tokenized( - admin_steamid=self._selected_ban[0].banned_by))) + admin_steamid=self._selected_bans[index].banned_by))) - if self._selected_ban[0].notes: + if self._selected_bans[index].notes: popup.append(Text(plugin_strings['ban_record notes'].tokenized( - notes=self._selected_ban[0].notes))) + notes=self._selected_bans[index].notes))) popup.append(Text( plugin_strings['remove_bad_ban_confirmation'])) @@ -646,12 +615,12 @@ def build_callback(popup, index): popup.append(SimpleOption( choice_index=1, text=plugin_strings['remove_bad_ban_confirmation no'], - value=(self._selected_ban[0], False), + value=(self._selected_bans[index], False), )) popup.append(SimpleOption( choice_index=2, text=plugin_strings['remove_bad_ban_confirmation yes'], - value=(self._selected_ban[0], True), + value=(self._selected_bans[index], True), )) @self.remove_popup.register_select_callback @@ -659,19 +628,23 @@ def select_callback(popup, index, option): if not option.value[1]: return - client = clients[index] + self._popups_done(clients[index], option.value[0]) - GameThread( - target=self.banned_uniqueid_manager.remove_ban_from_database, - args=(option.value[0].id, ) - ).start() + def _popups_done(self, client, banned_player_info): + if not self.is_visible(client) or not self.is_selectable(client): + client.tell(strings_common['unavailable']) + return - log_admin_action(plugin_strings['message ban_removed'].tokenized( - admin_name=client.name, - ban_id=option.value[0].id - )) + self.feature.execute(client, banned_player_info) - def execute(self, client): + self._parent.select(client) + + def _get_bans(self, client): + # Get expired, unreviewed, unlifted bans + return self.feature.banned_uniqueid_manager.get_all_bans( + unbanned=False, reviewed=False, expired=True) + + def select(self, client): client.send_popup(self.ban_popup) @@ -686,27 +659,40 @@ def send_remove_ban_id(self, ban_id): 'banId': ban_id, }) + def _get_bans(self, client): + raise NotImplementedError + + def _get_ban_by_id(self, client, ban_id): + for banned_player_info in self._get_bans(client): + if banned_player_info.id == ban_id: + return banned_player_info + return None + class LiftBanPage(_BaseBanPage): abstract = True page_abstract = True feature_page_abstract = True + def _get_bans(self, client): + return self.feature.banned_uniqueid_manager.get_active_bans( + banned_by=client.steamid, reviewed=False) + def on_page_data_received(self, data): client = clients[self.index] if data['action'] == "execute": ban_id = data['banId'] - banned_player_info = self.feature.get_ban_by_id(client, ban_id) + banned_player_info = self._get_ban_by_id(client, ban_id) if banned_player_info is None: # Might just as well log the ban id and the client, looks like # this client has tried to lift somebody else's ban return - client.sync_execution(self.feature.execute, ( - client, banned_player_info.id, banned_player_info.name)) + client.sync_execution( + self.feature.execute, (client, banned_player_info)) self.send_data({ 'feature-executed': "scheduled" @@ -716,7 +702,7 @@ def on_page_data_received(self, data): if data['action'] == "get-bans": ban_data = [] - for banned_player_info in self.feature.get_bans(client): + for banned_player_info in self._get_bans(client): ban_data.append({ 'uniqueid': str(banned_player_info.uniqueid), 'banId': banned_player_info.id, @@ -734,6 +720,10 @@ class ReviewBanPage(_BaseBanPage): page_abstract = True feature_page_abstract = True + def _get_bans(self, client): + return self.feature.banned_uniqueid_manager.get_active_bans( + banned_by=client.steamid, reviewed=False) + def on_page_data_received(self, data): client = clients[self.index] @@ -742,15 +732,15 @@ def on_page_data_received(self, data): reason = data['reason'] duration = data['duration'] - banned_player_info = self.feature.get_ban_by_id(client, ban_id) + banned_player_info = self._get_ban_by_id(client, ban_id) if banned_player_info is None: + # Might just as well log the ban id and the client, looks like # this client has tried to lift somebody else's ban return client.sync_execution(self.feature.execute, ( - client, banned_player_info.id, reason, duration, - banned_player_info.name)) + client, banned_player_info, reason, duration)) self.send_data({ 'feature-executed': "scheduled" @@ -784,7 +774,7 @@ def on_page_data_received(self, data): }) ban_data = [] - for banned_player_info in self.feature.get_bans(client): + for banned_player_info in self._get_bans(client): ban_data.append({ 'uniqueid': str(banned_player_info.uniqueid), 'banId': banned_player_info.id, diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/ip_address.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/ip_address.py index bfca583..e94ece8 100644 --- a/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/ip_address.py +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/ip_address.py @@ -15,14 +15,14 @@ # Included Plugin from ..config import plugin_config from ..left_player import ( - LeftPlayerBasedAdminCommand, LeftPlayerBasedFeature, + LeftPlayerBasedMenuCommand, LeftPlayerBasedFeature, LeftPlayerBasedFeaturePage, LeftPlayerIter) from ..models import BannedIPAddress from ..strings import plugin_strings from .base import ( - BannedUniqueIDManager, LiftBanMOTDFeature, LiftBanPopupFeature, - LiftAnyBanPopupFeature, ReviewBanMOTDFeature, ReviewBanPopupFeature, - LiftBanPage, ReviewBanPage, SearchBadBansPopupFeature) + BannedUniqueIDManager, LiftAnyBanMenuCommand, LiftBanFeature, LiftBanPage, + LiftMyBanMenuCommand, RemoveBadBanFeature, RemoveBadBanMenuCommand, + ReviewBanFeature, ReviewBanMenuCommand, ReviewBanPage) # ============================================================================= @@ -90,79 +90,66 @@ def execute(self, client, left_player): ban_ip_address_feature = _BanIPAddressFeature() -class _LiftIPAddressBanMOTDFeature(LiftBanMOTDFeature): - flag = "admin.admin_kick_ban.ban_ip_address" - banned_uniqueid_manager = banned_ip_address_manager - ws_lift_ban_pages = _ws_lift_ip_address_pages +class BanIPAddressMenuCommand(LeftPlayerBasedMenuCommand): + base_filter = 'human' + allow_multiple_choices = False -# The singleton object of the _LiftSteamIDBanMOTDFeature class. -lift_ip_address_ban_motd_feature = _LiftIPAddressBanMOTDFeature() + @staticmethod + def render_player_name(left_player): + return plugin_strings['player_name'].tokenized( + name=format_player_name(left_player.name), + id=extract_ip_address(left_player.address) + ) + def _iter(self): + for left_player in LeftPlayerIter(self.base_filter): + ip_address = extract_ip_address(left_player.address) + if banned_ip_address_manager.is_banned(ip_address): + continue + + yield left_player -class _LiftIPAddressBanPopupFeature(LiftBanPopupFeature): + +class _LiftIPAddressBanFeature(LiftBanFeature): flag = "admin.admin_kick_ban.ban_ip_address" - popup_title = plugin_strings['popup_title lift_ip_address'] banned_uniqueid_manager = banned_ip_address_manager + ws_lift_ban_pages = _ws_lift_ip_address_pages -# The singleton object of the _LiftIPAddressBanPopupFeature class. -lift_ip_address_ban_popup_feature = _LiftIPAddressBanPopupFeature() +# The singleton object of the _LiftIPAddressBanFeature class. +lift_ip_address_ban_feature = _LiftIPAddressBanFeature() -class _LiftAnyIPAddressBanPopupFeature(LiftAnyBanPopupFeature): - flag = "admin.admin_kick_ban.lift_reviewed_ip_address" +class LiftAnyIPAddressBanMenuCommand(LiftAnyBanMenuCommand): popup_title = plugin_strings['popup_title lift_reviewed_ip_address'] - banned_uniqueid_manager = banned_ip_address_manager -# The singleton object of the _LiftAnyIPAddressBanPopupFeature class. -lift_any_ip_address_ban_popup_feature = _LiftAnyIPAddressBanPopupFeature() + +class LiftMyIPAddressBanMenuCommand(LiftMyBanMenuCommand): + popup_title = plugin_strings['popup_title lift_ip_address'] -class _ReviewIPAddressBanMOTDFeature(ReviewBanMOTDFeature): +class _ReviewIPAddressBanFeature(ReviewBanFeature): flag = "admin.admin_kick_ban.ban_ip_address" banned_uniqueid_manager = banned_ip_address_manager ws_review_ban_pages = _ws_review_ip_address_ban_pages -# The singleton object of the _ReviewIPAddressBanMOTDFeature class. -review_ip_address_ban_motd_feature = _ReviewIPAddressBanMOTDFeature() +# The singleton object of the _ReviewIPAddressBanFeature class. +review_ip_address_ban_feature = _ReviewIPAddressBanFeature() -class _ReviewIPAddressBanPopupFeature(ReviewBanPopupFeature): - flag = "admin.admin_kick_ban.ban_ip_address" +class ReviewIPAddressBanMenuCommand(ReviewBanMenuCommand): popup_title = plugin_strings['popup_title review_ip_address'] - banned_uniqueid_manager = banned_ip_address_manager -# The singleton object of the _ReviewSteamIDBanPopupFeature class. -review_ip_address_ban_popup_feature = _ReviewIPAddressBanPopupFeature() - -class _SearchBadIPAddressBansPopupFeature(SearchBadBansPopupFeature): +class _RemoveBadIPAddressBanFeature(RemoveBadBanFeature): flag = "admin.admin_kick_ban.search_bad_ip_address_bans" - popup_title = plugin_strings['popup_title search_bad_bans'] banned_uniqueid_manager = banned_ip_address_manager -# The singleton object of the _SearchBadIPAddressBansPopupFeature class. -search_bad_ip_address_bans_popup_feature = ( - _SearchBadIPAddressBansPopupFeature()) - +# The singleton object of the _RemoveBadIPAddressBanFeature class. +remove_bad_ip_address_ban_feature = _RemoveBadIPAddressBanFeature() -class BanIPAddressMenuCommand(LeftPlayerBasedAdminCommand): - base_filter = 'human' - allow_multiple_choices = False - @staticmethod - def render_player_name(left_player): - return plugin_strings['player_name'].tokenized( - name=format_player_name(left_player.name), - id=extract_ip_address(left_player.address) - ) - - def _iter(self): - for left_player in LeftPlayerIter(self.base_filter): - ip_address = extract_ip_address(left_player.address) - if banned_ip_address_manager.is_banned(ip_address): - continue - - yield left_player +class RemoveBadIPAddressBanMenuCommand(RemoveBadBanMenuCommand): + popup_title = plugin_strings['popup_title search_bad_bans'] class BanIPAddressPage(LeftPlayerBasedFeaturePage): @@ -201,7 +188,7 @@ class LiftIPAddressBanPage(LiftBanPage): admin_plugin_id = "admin_kick_ban" admin_plugin_type = "included" page_id = "lift_ip_address" - feature = lift_ip_address_ban_motd_feature + feature = lift_ip_address_ban_feature def __init__(self, index, page_request_type): super().__init__(index, page_request_type) @@ -220,7 +207,7 @@ class ReviewIPAddressBanPage(ReviewBanPage): admin_plugin_id = "admin_kick_ban" admin_plugin_type = "included" page_id = "review_ip_address" - feature = review_ip_address_ban_motd_feature + feature = review_ip_address_ban_feature def __init__(self, index, page_request_type): super().__init__(index, page_request_type) diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/steamid.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/steamid.py index b60a49c..c2a0e8d 100644 --- a/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/steamid.py +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/steamid.py @@ -2,32 +2,39 @@ # >> IMPORTS # ============================================================================= # Source.Python -from core import GAME_NAME from engines.server import server from listeners import OnNetworkidValidated from listeners.tick import GameThread -from memory import make_object -from memory.hooks import PostHook -from players import Client from players.entity import Player from players.helpers import get_client_language -from translations.manager import language_manager # Source.Python Admin +from admin.core import admin_core_logger from admin.core.helpers import format_player_name, log_admin_action -from admin.core.memory import custom_server + +# Custom Package +try: + from connect_filter import ConnectFilter +except ImportError: + + # TODO: Don't log into core + admin_core_logger.log_message( + "ConnectFilter package is not installed, we won't be able to reject " + "banned SteamIDs early (before their validation)") + + ConnectFilter = lambda callback: callback # Included Plugin from ..config import plugin_config from ..left_player import ( - LeftPlayerBasedAdminCommand, LeftPlayerBasedFeature, + LeftPlayerBasedMenuCommand, LeftPlayerBasedFeature, LeftPlayerBasedFeaturePage, LeftPlayerIter) from ..models import BannedSteamID from ..strings import plugin_strings from .base import ( - BannedUniqueIDManager, LiftBanMOTDFeature, LiftBanPopupFeature, - LiftAnyBanPopupFeature, ReviewBanMOTDFeature, ReviewBanPopupFeature, - LiftBanPage, ReviewBanPage, SearchBadBansPopupFeature) + BannedUniqueIDManager, LiftAnyBanMenuCommand, LiftBanFeature, LiftBanPage, + LiftMyBanMenuCommand, RemoveBadBanFeature, RemoveBadBanMenuCommand, + ReviewBanFeature, ReviewBanMenuCommand, ReviewBanPage) # ============================================================================= @@ -111,77 +118,65 @@ def execute(self, client, left_player): ban_steamid_feature = _BanSteamIDFeature() -class _LiftSteamIDBanMOTDFeature(LiftBanMOTDFeature): - flag = "admin.admin_kick_ban.ban_steamid" - banned_uniqueid_manager = banned_steamid_manager - ws_lift_ban_pages = _ws_lift_steamid_pages +class BanSteamIDMenuCommand(LeftPlayerBasedMenuCommand): + base_filter = 'human' + allow_multiple_choices = False + + @staticmethod + def render_player_name(left_player): + return plugin_strings['player_name'].tokenized( + name=format_player_name(left_player.name), + id=left_player.steamid + ) -# The singleton object of the _LiftSteamIDBanMOTDFeature class. -lift_steamid_ban_motd_feature = _LiftSteamIDBanMOTDFeature() + def _iter(self): + for left_player in LeftPlayerIter(self.base_filter): + if banned_steamid_manager.is_banned(left_player.steamid): + continue + yield left_player -class _LiftSteamIDBanPopupFeature(LiftBanPopupFeature): + +class _LiftSteamIDBanFeature(LiftBanFeature): flag = "admin.admin_kick_ban.ban_steamid" - popup_title = plugin_strings['popup_title lift_steamid'] banned_uniqueid_manager = banned_steamid_manager + ws_lift_ban_pages = _ws_lift_steamid_pages -# The singleton object of the _LiftSteamIDBanPopupFeature class. -lift_steamid_ban_popup_feature = _LiftSteamIDBanPopupFeature() +# The singleton object of the _LiftSteamIDBanFeature class. +lift_steamid_ban_feature = _LiftSteamIDBanFeature() -class _LiftAnySteamIDBanPopupFeature(LiftAnyBanPopupFeature): - flag = "admin.admin_kick_ban.lift_reviewed_steamid" +class LiftAnySteamIDBanMenuCommand(LiftAnyBanMenuCommand): popup_title = plugin_strings['popup_title lift_reviewed_steamid'] - banned_uniqueid_manager = banned_steamid_manager -# The singleton object of the _LiftAnySteamIDBanPopupFeature class. -lift_any_steamid_ban_popup_feature = _LiftAnySteamIDBanPopupFeature() + +class LiftMySteamIDBanMenuCommand(LiftMyBanMenuCommand): + popup_title = plugin_strings['popup_title lift_steamid'] -class _ReviewSteamIDBanMOTDFeature(ReviewBanMOTDFeature): +class _ReviewSteamIDBanFeature(ReviewBanFeature): flag = "admin.admin_kick_ban.ban_steamid" banned_uniqueid_manager = banned_steamid_manager ws_review_ban_pages = _ws_review_steamid_ban_pages -# The singleton object of the _ReviewSteamIDBanMOTDFeature class. -review_steamid_ban_motd_feature = _ReviewSteamIDBanMOTDFeature() +# The singleton object of the _ReviewSteamIDBanFeature class. +review_steamid_ban_feature = _ReviewSteamIDBanFeature() -class _ReviewSteamIDBanPopupFeature(ReviewBanPopupFeature): - flag = "admin.admin_kick_ban.ban_steamid" +class ReviewSteamIDBanMenuCommand(ReviewBanMenuCommand): popup_title = plugin_strings['popup_title review_steamid'] - banned_uniqueid_manager = banned_steamid_manager -# The singleton object of the _ReviewSteamIDBanPopupFeature class. -review_steamid_ban_popup_feature = _ReviewSteamIDBanPopupFeature() - -class _SearchBadSteamIDBansPopupFeature(SearchBadBansPopupFeature): +class _RemoveBadSteamIDBanFeature(RemoveBadBanFeature): flag = "admin.admin_kick_ban.search_bad_steamid_bans" - popup_title = plugin_strings['popup_title search_bad_bans'] banned_uniqueid_manager = banned_steamid_manager -# The singleton object of the _SearchBadSteamIDBansPopupFeature class. -search_bad_steamid_bans_popup_feature = _SearchBadSteamIDBansPopupFeature() - - -class BanSteamIDMenuCommand(LeftPlayerBasedAdminCommand): - base_filter = 'human' - allow_multiple_choices = False - - @staticmethod - def render_player_name(left_player): - return plugin_strings['player_name'].tokenized( - name=format_player_name(left_player.name), - id=left_player.steamid - ) +# The singleton object of the _RemoveBadSteamIDBanFeature class. +remove_bad_steamid_ban_feature = _RemoveBadSteamIDBanFeature() - def _iter(self): - for left_player in LeftPlayerIter(self.base_filter): - if banned_steamid_manager.is_banned(left_player.steamid): - continue - yield left_player +class RemoveBadSteamIDBanMenuCommand(RemoveBadBanMenuCommand): + popup_title = plugin_strings['popup_title search_bad_bans'] class BanSteamIDPage(LeftPlayerBasedFeaturePage): @@ -219,7 +214,7 @@ class LiftSteamIDBanPage(LiftBanPage): admin_plugin_id = "admin_kick_ban" admin_plugin_type = "included" page_id = "lift_steamid" - feature = lift_steamid_ban_motd_feature + feature = lift_steamid_ban_feature def __init__(self, index, page_request_type): super().__init__(index, page_request_type) @@ -238,7 +233,7 @@ class ReviewSteamIDBanPage(ReviewBanPage): admin_plugin_id = "admin_kick_ban" admin_plugin_type = "included" page_id = "review_steamid" - feature = review_steamid_ban_motd_feature + feature = review_steamid_ban_feature def __init__(self, index, page_request_type): super().__init__(index, page_request_type) @@ -265,30 +260,15 @@ def listener_on_networkid_validated(name, steamid): if client is None: return - client.disconnect(plugin_strings['default_ban_reason'].get_string( - language_manager.default)) + client.disconnect(plugin_strings['default_ban_reason'].get_string()) # ============================================================================= -# >> HOOKS +# >> CONNECT FILTERS # ============================================================================= -@PostHook(custom_server.check_challenge_type) -def post_check_challenge_type(args, return_value=0): - client = make_object(Client, args[1] + 4) - if not banned_steamid_manager.is_banned(client.steamid): - return - - if GAME_NAME == 'csgo': - custom_server.reject_connection( - args[3], - plugin_strings['default_ban_reason'].get_string( - language_manager.default) - ) - else: - custom_server.reject_connection( - args[3], args[7], - plugin_strings['default_ban_reason'].get_string( - language_manager.default) - ) +@ConnectFilter +def connect_filter(client): + if banned_steamid_manager.is_banned(client.steamid): + return plugin_strings['default_ban_reason'] - return False + return None diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/left_player.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/left_player.py index 0dde718..778413e 100644 --- a/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/left_player.py +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/left_player.py @@ -9,7 +9,7 @@ # Source.Python Admin from admin.core.clients import RemoteClient from admin.core.features import BaseFeature -from admin.core.frontends.menus import BasePlayerBasedAdminCommand +from admin.core.frontends.menus import BasePlayerBasedMenuCommand from admin.core.frontends.motd import BasePlayerBasedFeaturePage # Included Plugin @@ -128,7 +128,7 @@ def filter(self, client, left_player): return not another_client.has_permission(self.flag) -class LeftPlayerBasedAdminCommand(BasePlayerBasedAdminCommand): +class LeftPlayerBasedMenuCommand(BasePlayerBasedMenuCommand): base_filter = 'all' def _get_player_id(self, player): @@ -203,7 +203,13 @@ def listener_on_client_active(index): @OnClientDisconnect def listener_on_client_disconnect(index): - left_player = LeftPlayer(index, disconnected=True) + try: + left_player = LeftPlayer(index, disconnected=True) + except ValueError: + + # Sometimes (if the client disconnects before activation) we're + # unable to get data of the disconnected player + return for left_player_ in _left_players: if left_player_.steamid == left_player.steamid: diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/models.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/models.py index 6191e75..f5bf4d3 100644 --- a/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/models.py +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/models.py @@ -15,7 +15,7 @@ # ============================================================================= # >> MODEL CLASSES # ============================================================================= -class BannedUser(Base): +class _BannedUser(Base): __abstract__ = True id = Column(Integer, primary_key=True) @@ -58,7 +58,7 @@ def lift_ban(self, unbanned_by): self.unbanned_by = unbanned_by -class BannedSteamID(BannedUser): +class BannedSteamID(_BannedUser): __tablename__ = config['database']['prefix'] + "banned_steamid" steamid64 = Column(String(32)) @@ -72,7 +72,7 @@ def set_uniqueid(self, uniqueid): uniqueid = property(get_uniqueid, set_uniqueid) -class BannedIPAddress(BannedUser): +class BannedIPAddress(_BannedUser): __tablename__ = config['database']['prefix'] + "banned_ip_address" ip_address = Column(String(48)) diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_life_management/admin_life_management.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_life_management/admin_life_management.py index a47fafe..3e66026 100644 --- a/srcds/addons/source-python/plugins/admin/plugins/included/admin_life_management/admin_life_management.py +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_life_management/admin_life_management.py @@ -6,10 +6,10 @@ from players.entity import Player # Source.Python Admin -from admin.admin import main_menu from admin.core.features import PlayerBasedFeature +from admin.core.frontends.commands import PlayerBasedFeatureCommand from admin.core.frontends.menus import ( - AdminMenuSection, PlayerBasedAdminCommand) + main_menu, MenuSection, PlayerBasedMenuCommand) from admin.core.frontends.motd import ( main_motd, MOTDSection, MOTDPageEntry, PlayerBasedFeaturePage) from admin.core.helpers import log_admin_action @@ -101,19 +101,26 @@ def on_error(self, error): _ws_resurrect_pages.remove(self) +# ============================================================================= +# >> COMMAND FRONTEND +# ============================================================================= +PlayerBasedFeatureCommand("slay", slay_feature) +PlayerBasedFeatureCommand("resurrect", resurrect_feature) + + # ============================================================================= # >> MENU ENTRIES # ============================================================================= -menu_section = main_menu.add_entry(AdminMenuSection( - main_menu, plugin_strings['section_title'])) +menu_section = main_menu.add_entry(MenuSection( + main_menu, plugin_strings['section_title'], 'life_management')) -slay_menu_command = menu_section.add_entry(PlayerBasedAdminCommand( +slay_menu_command = menu_section.add_entry(PlayerBasedMenuCommand( slay_feature, menu_section, plugin_strings['popup_title slay'] )) -resurrect_menu_command = menu_section.add_entry(PlayerBasedAdminCommand( +resurrect_menu_command = menu_section.add_entry(PlayerBasedMenuCommand( resurrect_feature, menu_section, plugin_strings['popup_title resurrect'] diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_team_management/admin_team_management.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_team_management/admin_team_management.py index 72a9c3d..e4a8ab6 100644 --- a/srcds/addons/source-python/plugins/admin/plugins/included/admin_team_management/admin_team_management.py +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_team_management/admin_team_management.py @@ -8,10 +8,9 @@ from players.teams import teams_by_number # Source.Python Admin -from admin.admin import main_menu from admin.core.features import PlayerBasedFeature from admin.core.frontends.menus import ( - AdminMenuSection, PlayerBasedAdminCommand) + main_menu, MenuSection, PlayerBasedMenuCommand) from admin.core.helpers import log_admin_action from admin.core.plugins.strings import PluginStrings @@ -100,36 +99,36 @@ class _DelayedMoveToCTFeature(_DelayedMoveToTeamFeature): # ============================================================================= # >> MENU ENTRIES # ============================================================================= -menu_section = main_menu.add_entry(AdminMenuSection( - main_menu, plugin_strings['section_title'])) +menu_section = main_menu.add_entry(MenuSection( + main_menu, plugin_strings['section_title'], 'team_management')) -move_to_spec_menu_command = menu_section.add_entry(PlayerBasedAdminCommand( +move_to_spec_menu_command = menu_section.add_entry(PlayerBasedMenuCommand( move_to_spec_feature, menu_section, plugin_strings['popup_title move_to_spec'] )) -move_to_t_menu_command = menu_section.add_entry(PlayerBasedAdminCommand( +move_to_t_menu_command = menu_section.add_entry(PlayerBasedMenuCommand( move_to_t_feature, menu_section, plugin_strings['popup_title move_to_t'] )) -move_to_ct_menu_command = menu_section.add_entry(PlayerBasedAdminCommand( +move_to_ct_menu_command = menu_section.add_entry(PlayerBasedMenuCommand( move_to_ct_feature, menu_section, plugin_strings['popup_title move_to_ct'] )) delayed_move_to_t_menu_command = menu_section.add_entry( - PlayerBasedAdminCommand( + PlayerBasedMenuCommand( delayed_move_to_t_feature, menu_section, plugin_strings['popup_title move_to_t_delayed'] )) delayed_move_to_ct_menu_command = menu_section.add_entry( - PlayerBasedAdminCommand( + PlayerBasedMenuCommand( delayed_move_to_ct_feature, menu_section, plugin_strings['popup_title move_to_ct_delayed'] diff --git a/srcds/addons/source-python/plugins/admin/plugins/included/admin_tracking/admin_tracking.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_tracking/admin_tracking.py index 1bb21fb..b68109c 100644 --- a/srcds/addons/source-python/plugins/admin/plugins/included/admin_tracking/admin_tracking.py +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_tracking/admin_tracking.py @@ -7,6 +7,7 @@ from time import localtime, strftime, time # Source.Python +from commands import CommandReturn from events import Event from listeners import OnClientActive from listeners.tick import GameThread @@ -16,13 +17,16 @@ from steam import SteamID # Source.Python Admin -from admin.admin import main_menu from admin.core.clients import clients from admin.core.helpers import extract_ip_address, format_player_name -from admin.core.features import PlayerBasedFeature +from admin.core.features import ( + BaseFeature, BasePlayerBasedFeature, PlayerBasedFeature) +from admin.core.frontends.commands import ( + BaseFeatureCommand, BasePlayerBasedFeatureCommand) from admin.core.frontends.menus import ( - AdminMenuSection, PlayerBasedAdminCommand) -from admin.core.orm import Session + main_menu, MenuSection, PlayerBasedMenuCommand) +from admin.core.helpers import chat_message, console_message +from admin.core.orm import SessionContext from admin.core.paths import ADMIN_CFG_PATH, get_server_file from admin.core.plugins.strings import PluginStrings @@ -33,20 +37,111 @@ # ============================================================================= # >> FUNCTIONS # ============================================================================= -def remove_old_database_records(): - session = Session() - max_record_life_seconds = ( - int(plugin_config['database']['max_record_life_days']) * 24 * 3600) +def _remove_old_database_records(): + with SessionContext() as session: + max_record_life_seconds = ( + int(plugin_config['database']['max_record_life_days']) * 24 * 3600) - ( - session - .query(DB_Record) - .filter(DB_Record.seen_at < time() - max_record_life_seconds) - .delete(synchronize_session=False) - ) + ( + session + .query(DB_Record) + .filter(DB_Record.seen_at < time() - max_record_life_seconds) + .delete(synchronize_session=False) + ) + + session.commit() + + +def _get_records_for_steamid(steamid): + records = [] + steamid64 = str(SteamID.parse(steamid).to_uint64()) + + # Firstly, add live records (if player is on the server) + for tracked_player in tracked_players.values(): + if tracked_player.steamid == steamid64: + for record in reversed(tracked_player): + records.append(_TrackRecordReport( + steamid64, + record.ip_address, + record.name, + record.seen_at, + live=True + )) + + break + + # Secondly, add records from the database + with SessionContext() as session: + + db_records = ( + session + .query(DB_Record) + .filter_by(steamid64=steamid64) + .order_by(DB_Record.seen_at.desc()) + .all() + ) + + for db_record in db_records: + records.append(_TrackRecordReport( + db_record.steamid64, + db_record.ip_address, + db_record.name, + db_record.seen_at, + live=False + )) + + return records + + +def _get_records_for_ip_address(ip_address): + records = [] + seen_steamids = [] + + # Firstly, add live records (if player is on the server) + for tracked_player in tracked_players.values(): + if not tracked_player: + continue + + record = tracked_player[-1] + + if record.ip_address != ip_address: + continue + + seen_steamids.append(tracked_player.steamid) - session.commit() - session.close() + records.append(_TrackRecordReport( + tracked_player.steamid, + ip_address, + record.name, + record.seen_at, + live=True + )) + + # Secondly, add records from the database + with SessionContext() as session: + db_records = ( + session + .query(DB_Record) + .filter_by(ip_address=ip_address) + .order_by(DB_Record.seen_at.desc()) + .all() + ) + + for db_record in db_records: + if db_record.steamid64 in seen_steamids: + continue + + seen_steamids.append(db_record.steamid64) + + records.append(_TrackRecordReport( + db_record.steamid64, + db_record.ip_address, + db_record.name, + db_record.seen_at, + live=False + )) + + return records # ============================================================================= @@ -60,6 +155,8 @@ def remove_old_database_records(): plugin_strings = PluginStrings("admin_tracking") +_last_shown_records = PlayerDictionary(lambda index: None) + # ============================================================================= # >> CLASSES @@ -99,41 +196,39 @@ def save_to_database(self): if self.steamid is None: return - session = Session() - - db_record = ( - session - .query(DB_Record) - .filter_by(steamid64=self.steamid) - .order_by(DB_Record.seen_at.desc()) - .first() - ) + with SessionContext() as session: + db_record = ( + session + .query(DB_Record) + .filter_by(steamid64=self.steamid) + .order_by(DB_Record.seen_at.desc()) + .first() + ) - if db_record is None: - last_name = last_ip_address = "" - else: - last_name = db_record.name - last_ip_address = db_record.ip_address + if db_record is None: + last_name = last_ip_address = "" + else: + last_name = db_record.name + last_ip_address = db_record.ip_address - for record in self: - if ( - record.name == last_name and - record.ip_address == last_ip_address - ): - continue + for record in self: + if ( + record.name == last_name and + record.ip_address == last_ip_address + ): + continue - db_record = DB_Record() - db_record.steamid64 = self.steamid - db_record.name = record.name - db_record.ip_address = record.ip_address - db_record.seen_at = record.seen_at + db_record = DB_Record() + db_record.steamid64 = self.steamid + db_record.name = record.name + db_record.ip_address = record.ip_address + db_record.seen_at = record.seen_at - session.add(db_record) + session.add(db_record) - last_name, last_ip_address = record.name, record.ip_address + last_name, last_ip_address = record.name, record.ip_address - session.commit() - session.close() + session.commit() self.clear() @@ -144,7 +239,7 @@ def on_automatically_removed(self, index): GameThread(target=tracked_player.save_to_database).start() -class _TrackPopupRecord: +class _TrackRecordReport: def __init__(self, steamid, ip_address, name, seen_at, live): self.steamid = steamid self.ip_address = ip_address @@ -162,7 +257,7 @@ class _TrackPopupFeature(PlayerBasedFeature): allow_execution_on_equal_priority = True def __init__(self): - self._selected_record = None + self._selected_records = PlayerDictionary(lambda index: None) self._records_to_show = None self.record_popup = PagedMenu( @@ -171,14 +266,15 @@ def __init__(self): self.track_popup = PagedMenu() self.dummy_popup = SimpleMenu() - self.dummy_popup.append(Text(plugin_strings['popup_text processing'])) + self.dummy_popup.append(Text(plugin_strings['processing'])) @self.record_popup.register_build_callback def build_callback(popup, index): popup.clear() - for record in self._records_to_show: - text = plugin_strings['popup_title record_title'].tokenized( + for i, record in enumerate(self._records_to_show, start=1): + text = plugin_strings['record_title'].tokenized( + id=i, seen_at=strftime( "%d %b %Y %H:%M:%S", localtime(record.seen_at) ), @@ -192,43 +288,44 @@ def build_callback(popup, index): popup.append(PagedOption( text=text, - value=record + value=(i, record) )) @self.record_popup.register_select_callback def select_callback(popup, index, option): client = clients[index] - self._selected_record = option.value + self._selected_records[index] = option.value client.send_popup(self.track_popup) @self.track_popup.register_build_callback def build_callback(popup, index): - popup.title = plugin_strings['popup_title record_title'].tokenized( + popup.title = plugin_strings['record_title'].tokenized( + id=self._selected_records[index][0], seen_at=strftime( "%d %b %Y %H:%M:%S", localtime( - self._selected_record.seen_at) + self._selected_records[index][1].seen_at) ), - name=format_player_name(self._selected_record.name) + name=format_player_name(self._selected_records[index][1].name) ) popup.clear() popup.append(Text(plugin_strings['popup_text name'].tokenized( - name=self._selected_record.name, # Non-formatted name + name=self._selected_records[index][1].name, ))) popup.append(Text(plugin_strings['popup_text steamid'].tokenized( - steamid=self._selected_record.steamid, + steamid=self._selected_records[index][1].steamid, ))) popup.append(Text( plugin_strings['popup_text ip_address'].tokenized( - ip_address=self._selected_record.ip_address, + ip_address=self._selected_records[index][1].ip_address, ))) popup.append(PagedOption( text=plugin_strings['popup_title search_for_ip'].tokenized( - ip_address=self._selected_record.ip_address), + ip_address=self._selected_records[index][1].ip_address), value=( _TrackPopupOption.SEARCH_BY_IP, - self._selected_record.ip_address + self._selected_records[index][1].ip_address ) )) @@ -244,97 +341,14 @@ def select_callback(popup, index, option): ).start() def _show_records_for_steamid(self, client, steamid): - self._records_to_show = [] - steamid64 = str(SteamID.parse(steamid).to_uint64()) - - # Firstly, add live records (if player is on the server) - for tracked_player in tracked_players.values(): - if tracked_player.steamid == steamid64: - for record in reversed(tracked_player): - self._records_to_show.append(_TrackPopupRecord( - steamid64, - record.ip_address, - record.name, - record.seen_at, - live=True - )) - - break - - # Secondly, add records from the database - session = Session() - - db_records = ( - session - .query(DB_Record) - .filter_by(steamid64=steamid64) - .order_by(DB_Record.seen_at.desc()) - .all() - ) - - session.close() - - for db_record in db_records: - self._records_to_show.append(_TrackPopupRecord( - db_record.steamid64, - db_record.ip_address, - db_record.name, - db_record.seen_at, - live=False - )) + self._records_to_show = _get_records_for_steamid(steamid) + _last_shown_records[client.player.index] = self._records_to_show[:] client.send_popup(self.record_popup) def _show_players_for_ip_address(self, client, ip_address): - self._records_to_show = [] - seen_steamids = [] - - # Firstly, add live records (if player is on the server) - for tracked_player in tracked_players.values(): - if not tracked_player: - continue - - record = tracked_player[-1] - - if record.ip_address != ip_address: - continue - - seen_steamids.append(tracked_player.steamid) - - self._records_to_show.append(_TrackPopupRecord( - tracked_player.steamid, - ip_address, - record.name, - record.seen_at, - live=True - )) - - # Secondly, add records from the database - session = Session() - - db_records = ( - session - .query(DB_Record) - .filter_by(ip_address=ip_address) - .order_by(DB_Record.seen_at.desc()) - .all() - ) - - session.close() - - for db_record in db_records: - if db_record.steamid64 in seen_steamids: - continue - - seen_steamids.append(db_record.steamid64) - - self._records_to_show.append(_TrackPopupRecord( - db_record.steamid64, - db_record.ip_address, - db_record.name, - db_record.seen_at, - live=False - )) + self._records_to_show = _get_records_for_ip_address(ip_address) + _last_shown_records[client.player.index] = self._records_to_show[:] client.send_popup(self.record_popup) @@ -359,24 +373,356 @@ def execute(self, client, player): track_popup_feature = _TrackPopupFeature() -class _TrackMenuCommand(PlayerBasedAdminCommand): +class _TrackPopupMenuCommand(PlayerBasedMenuCommand): base_filter = 'human' allow_multiple_choices = False +class _TextReportsMixin: + @classmethod + def _show_records(cls, client, message_func, records, start, end): + if records: + message_func(plugin_strings['result_count'].tokenized( + count=len(records), start=start, end=end)) + + for i, record in enumerate(records, start=1): + text = plugin_strings['record_title'].tokenized( + id=i, + seen_at=strftime( + "%d %b %Y %H:%M:%S", localtime(record.seen_at) + ), + name=format_player_name(record.name) + ) + + # If it's a live (unsaved) record, add a prefix + if record.live: + text = plugin_strings['prefix live_record'].tokenized( + text=text) + + message_func(text) + else: + message_func(plugin_strings['no_results']) + + _last_shown_records[client.player.index] = records[:] + + @classmethod + def _show_records_for_steamid( + cls, client, message_func, steamid, start_record_num): + + limit = int(plugin_config['text']['records_to_show_per_request']) + + try: + records = _get_records_for_steamid(steamid)[ + start_record_num-1:start_record_num+limit-1] + except ValueError: + message_func(plugin_strings['invalid_steamid']) + return + + cls._show_records( + client, message_func, records, start_record_num, + min(start_record_num + len(records), start_record_num + limit) - 1 + ) + + @classmethod + def _show_records_for_ip_address( + cls, client, message_func, ip_address, start_record_num): + + limit = int(plugin_config['text']['records_to_show_per_request']) + + records = _get_records_for_ip_address(ip_address)[ + start_record_num - 1:start_record_num + limit - 1] + + cls._show_records( + client, message_func, records, start_record_num, + min(start_record_num + len(records), start_record_num + limit) - 1 + ) + + +class _TrackSteamIDTextFeature(_TextReportsMixin, BasePlayerBasedFeature): + flag = "admin.admin_tracking.track" + + def filter(self, client, player): + # "track player" command will try to filter its results using our + # filter, and is the only reason we subclass BasePlayerBasedFeature + # instead of BaseFeature + return True + + def execute(self, client, message_func, steamid, start_record_num): + message_func(plugin_strings['processing']) + + GameThread( + target=self._show_records_for_steamid, + args=(client, message_func, steamid, start_record_num) + ).start() + +# The singleton object of the _TrackSteamIDTextFeature class. +track_steamid_text_feature = _TrackSteamIDTextFeature() + + +class _TrackSteamIDCommand(BaseFeatureCommand): + def _execute(self, command_info, message_func, steamid, start_record_num): + client = clients[command_info.index] + client.sync_execution( + self.feature.execute, + (client, message_func, steamid, start_record_num) + ) + + def _get_public_chat_callback(self): + def public_chat_callback( + command_info, steamid, start_record_num:int=1): + + def message_func(message): + chat_message(message, (command_info.index, )) + + self._execute( + command_info, message_func, steamid, start_record_num) + + return CommandReturn.CONTINUE + + return public_chat_callback + + def _get_private_chat_callback(self): + def private_chat_callback( + command_info, steamid, start_record_num:int=1): + + def message_func(message): + chat_message(message, (command_info.index, )) + + self._execute( + command_info, message_func, steamid, start_record_num) + + return CommandReturn.BLOCK + + return private_chat_callback + + def _get_client_callback(self): + def client_callback(command_info, steamid, start_record_num:int=1): + def message_func(message): + console_message(message, (command_info.index, )) + + self._execute( + command_info, message_func, steamid, start_record_num) + + return client_callback + + +class _TrackIPAddressTextFeature(_TextReportsMixin, BaseFeature): + flag = "admin.admin_tracking.track" + + def execute(self, client, message_func, ip_address, start_record_num): + message_func(plugin_strings['processing']) + + GameThread( + target=self._show_records_for_ip_address, + args=(client, message_func, ip_address, start_record_num) + ).start() + +# The singleton object of the _TrackIPAddressTextFeature class. +track_ip_address_text_feature = _TrackIPAddressTextFeature() + + +class _TrackIPAddressCommand(BaseFeatureCommand): + def _execute( + self, command_info, message_func, ip_address, start_record_num): + + client = clients[command_info.index] + client.sync_execution( + self.feature.execute, + (client, message_func, ip_address, start_record_num) + ) + + def _get_public_chat_callback(self): + def public_chat_callback( + command_info, ip_address, start_record_num:int=1): + + def message_func(message): + chat_message(message, (command_info.index, )) + + self._execute( + command_info, message_func, ip_address, start_record_num) + + return CommandReturn.CONTINUE + + return public_chat_callback + + def _get_private_chat_callback(self): + def private_chat_callback( + command_info, ip_address, start_record_num:int=1): + + def message_func(message): + chat_message(message, (command_info.index, )) + + self._execute( + command_info, message_func, ip_address, start_record_num) + + return CommandReturn.BLOCK + + return private_chat_callback + + def _get_client_callback(self): + def client_callback(command_info, ip_address, start_record_num:int=1): + def message_func(message): + console_message(message, (command_info.index, )) + + self._execute( + command_info, message_func, ip_address, start_record_num) + + return client_callback + + +class _TrackPlayerCommand(BasePlayerBasedFeatureCommand): + deny_mass_execution = True + + def _execute( + self, command_info, filter_str, filter_args, message_func, + start_record_num): + + client = clients[command_info.index] + + for player in self._get_target_players( + client, filter_str, filter_args): + + client.sync_execution( + self.feature.execute, + (client, message_func, player.steamid, start_record_num) + ) + + break + + else: + message_func(plugin_strings['failed_filter']) + + def _get_public_chat_callback(self): + def public_chat_callback( + command_info, filter_str:str, filter_args:str="", + start_record_num:int=1): + + def message_func(message): + chat_message(message, (command_info.index, )) + + self._execute(command_info, filter_str, filter_args, message_func, + start_record_num) + + return CommandReturn.CONTINUE + + return public_chat_callback + + def _get_private_chat_callback(self): + def private_chat_callback( + command_info, filter_str:str, filter_args:str="", + start_record_num:int=1): + + def message_func(message): + chat_message(message, (command_info.index, )) + + self._execute(command_info, filter_str, filter_args, message_func, + start_record_num) + + return CommandReturn.BLOCK + + return private_chat_callback + + def _get_client_callback(self): + def client_callback( + command_info, filter_str:str, filter_args:str="", + start_record_num:int=1): + + def message_func(message): + console_message(message, (command_info.index, )) + + self._execute(command_info, filter_str, filter_args, message_func, + start_record_num) + + return client_callback + + +class _DetailTextFeature(BaseFeature): + flag = "admin.admin_tracking.track" + + def execute(self, client, message_func, record_id): + if _last_shown_records[client.player.index] is None: + message_func(plugin_strings['no_results']) + return + + try: + record = _last_shown_records[client.player.index][record_id - 1] + except IndexError: + message_func(plugin_strings['no_results']) + return + + message_func(plugin_strings['detail'].tokenized( + id=record_id, + seen_at=strftime("%d %b %Y %H:%M:%S", localtime(record.seen_at)), + name=record.name, + steamid=record.steamid, + ip_address=record.ip_address, + )) + +# The singleton object of the _DetailTextFeature class. +detail_text_feature = _DetailTextFeature() + + +class _DetailCommand(BaseFeatureCommand): + def _execute(self, command_info, message_func, record_id): + client = clients[command_info.index] + client.sync_execution( + self.feature.execute, (client, message_func, record_id)) + + def _get_public_chat_callback(self): + def public_chat_callback(command_info, record_id:int): + def message_func(message): + chat_message(message, (command_info.index,)) + + self._execute(command_info, message_func, record_id) + + return CommandReturn.CONTINUE + + return public_chat_callback + + def _get_private_chat_callback(self): + def private_chat_callback(command_info, record_id:int): + def message_func(message): + chat_message(message, (command_info.index,)) + + self._execute(command_info, message_func, record_id) + + return CommandReturn.BLOCK + + return private_chat_callback + + def _get_client_callback(self): + def client_callback(command_info, record_id:int): + def message_func(message): + console_message(message, (command_info.index,)) + + self._execute(command_info, message_func, record_id) + + return client_callback + + # ============================================================================= # >> PLAYER DICTIONARY # ============================================================================= tracked_players = _TrackedPlayerDictionary(_TrackedPlayer) +# ============================================================================= +# >> COMMAND FRONTEND +# ============================================================================= +_TrackSteamIDCommand(["track", "steamid"], track_steamid_text_feature) +_TrackIPAddressCommand(["track", "ip"], track_ip_address_text_feature) +# _TrackPlayerCommand also uses SteamID, thus its feature is not a typo +_TrackPlayerCommand(["track", "player"], track_steamid_text_feature) +_DetailCommand(["track", "detail"], detail_text_feature) + + # ============================================================================= # >> MENU ENTRIES # ============================================================================= -menu_section = main_menu.add_entry(AdminMenuSection( - main_menu, plugin_strings['section_title'])) +menu_section = main_menu.add_entry(MenuSection( + main_menu, plugin_strings['section_title'], 'tracking')) -track_menu_command = menu_section.add_entry(_TrackMenuCommand( +track_menu_command = menu_section.add_entry(_TrackPopupMenuCommand( track_popup_feature, menu_section, plugin_strings['popup_title track'] @@ -386,7 +732,7 @@ class _TrackMenuCommand(PlayerBasedAdminCommand): # ============================================================================= # >> SYNCHRONOUS DATABASE OPERATIONS # ============================================================================= -remove_old_database_records() +_remove_old_database_records() # ============================================================================= diff --git a/srcds/cfg/source-python/admin/config.ini b/srcds/cfg/source-python/admin/config.ini index 58543fe..1828ea1 100644 --- a/srcds/cfg/source-python/admin/config.ini +++ b/srcds/cfg/source-python/admin/config.ini @@ -1,3 +1,6 @@ [database] uri=sqlite:///{admin_data_path}/spa.db prefix=spa_ + +[menus] +order=kick_ban,tracking,life_management,comm_management,team_management diff --git a/srcds/cfg/source-python/admin/included_plugins/admin_comm_management/block_durations.json b/srcds/cfg/source-python/admin/included_plugins/admin_comm_management/block_durations.json new file mode 100644 index 0000000..f9f718a --- /dev/null +++ b/srcds/cfg/source-python/admin/included_plugins/admin_comm_management/block_durations.json @@ -0,0 +1,12 @@ +[ + 300, + 900, + 1800, + 3600, + 10800, + 86400, + 604800, + 2592000, + 7776000, + 31536000 +] diff --git a/srcds/cfg/source-python/admin/included_plugins/admin_tracking/config.ini b/srcds/cfg/source-python/admin/included_plugins/admin_tracking/config.ini index 9f6523a..f0557c7 100644 --- a/srcds/cfg/source-python/admin/included_plugins/admin_tracking/config.ini +++ b/srcds/cfg/source-python/admin/included_plugins/admin_tracking/config.ini @@ -1,2 +1,5 @@ [database] max_record_life_days=180 + +[text] +records_to_show_per_request = 5 diff --git a/srcds/resource/source-python/translations/admin/included_plugins/admin_comm_management.ini b/srcds/resource/source-python/translations/admin/included_plugins/admin_comm_management.ini new file mode 100644 index 0000000..3c7a6a7 --- /dev/null +++ b/srcds/resource/source-python/translations/admin/included_plugins/admin_comm_management.ini @@ -0,0 +1,91 @@ +[section_title main] +en="Communication Management" +ru="Управление связью" + +[section_title chat] +en="Text Chat Communication" +ru="Связь по текстовому чату" + +[section_title voice] +en="Voice Chat Communication" +ru="Связь по голосовому чату" + +[popup_title block_chat] +en="Block player's text chat" +ru="Отключить чат игроку" + +[popup_title block_voice] +en="Block player's voice chat" +ru="Отключить чат игроку" + +[popup_title unblock_chat] +en="Unblock player's text chat" +ru="Включить чат игроку" + +[popup_title unblock_voice] +en="Unblock player's voice chat" +ru="Включить чат игроку" + +[popup_title unblock_chat_any] +en="Unblock ANY player's text chat" +ru="Включить чат ЛЮБОМУ игроку" + +[popup_title unblock_voice_any] +en="Unblock ANY player's voice chat" +ru="Включить чат ЛЮБОМУ игроку" + +[popup_title duration] +en="Select block duration" +ru="Выберите длительность отключения" + +[error bot_cannot_block] +en="Cannot block bot communication" +ru="Невозможно отключить чат боту" + +[error chat_block] +en="You have your chat blocked by an admin" +ru="Администратор заблокировал ваш чат" + +[error already_block_in_effect] +en="This player's chat is already blocked" +ru="У этого игрока уже отключён чат" + +[duration permanent] +en="Permanent Block" +ru="Отключение навсегда" + +[duration seconds] +en="{secs}s" +ru="{secs}с" + +[duration minutes] +en="{mins}m" +ru="{mins}м" + +[duration hours] +en="{hours}h {mins}m" +ru="{hours}ч {mins}м" + +[duration days] +en="{days}d {hours}h {mins}m" +ru="{days}дн {hours}ч {mins}м" + +[block_record] +en="{name} ({id})" +ru="{name} ({id})" + +[message chat_blocked] +en="Admin {admin_name} has blocked {player_name}'s text chat" +ru="Администратор {admin_name} отключил текстовый чат {player_name}" + +[message voice_blocked] +en="Admin {admin_name} has blocked {player_name}'s voice chat" +ru="Администратор {admin_name} отключил голосовой чат {player_name}" + +[message chat_unblocked] +en="Admin {admin_name} has unblocked {player_name}'s text chat" +ru="Администратор {admin_name} включил текстовый чат {player_name}" + +[message voice_unblocked] +en="Admin {admin_name} has unblocked {player_name}'s voice chat" +ru="Администратор {admin_name} включил голосовой чат {player_name}" diff --git a/srcds/resource/source-python/translations/admin/included_plugins/admin_tracking.ini b/srcds/resource/source-python/translations/admin/included_plugins/admin_tracking.ini index faa7b23..14a6247 100644 --- a/srcds/resource/source-python/translations/admin/included_plugins/admin_tracking.ini +++ b/srcds/resource/source-python/translations/admin/included_plugins/admin_tracking.ini @@ -14,9 +14,9 @@ ru="Выберите запись" en="* {text}" ru="* {text}" -[popup_title record_title] -en="{seen_at} - {name}" -ru="{seen_at} - {name}" +[record_title] +en="#{id}. {seen_at} - {name}" +ru="#{id}. {seen_at} - {name}" [popup_text name] en="Name: {name}" @@ -38,6 +38,26 @@ ru="Показать игроков с IP {ip_address}" en="Cannot track bots" ru="Нельзя отслеживать ботов" -[popup_text processing] +[processing] en="Your request is being processed..." ru="Ваш запрос обрабатывается..." + +[result_count] +en="Total entries: {count}, showing {start}-{end}" +ru="Всего записей: {count}, показаны {start}-{end}" + +[no_results] +en="No results" +ru="Нет результатов" + +[invalid_steamid] +en="Invalid SteamID" +ru="Некорректный SteamID" + +[detail] +en="#{id}. ({seen_at}) Name: {name}, SteamID: {steamid}, IP: {ip_address}" +ru="#{id}. ({seen_at}) Имя: {name}, SteamID: {steamid}, IP: {ip_address}" + +[failed_filter] +en="The player filter is either too broad or didn't find any players" +ru="Фильтр игроков нашёл либо несколько игроков, либо не нашёл никого"