From e662eee3c5357b28b04621d78b02ebb8b96d1745 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 5 May 2017 20:45:02 +0300 Subject: [PATCH 01/31] Fixed an a bug in bans / tracking popups that'd lead to conflicts when multiple admins use these popups at the same time --- .../included/admin_kick_ban/bans/base.py | 62 +++++++++---------- .../included/admin_tracking/admin_tracking.py | 18 +++--- 2 files changed, 40 insertions(+), 40 deletions(-) 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..e9c0e90 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,6 +9,7 @@ # 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 @@ -380,7 +381,7 @@ class LiftAnyBanPopupFeature(Feature): def __init__(self): # (_BannedPlayerInfo instance, whether confirmed or not) - self._selected_ban = (None, False) + self._selected_bans = PlayerDictionary(lambda index: (None, False)) self.ban_popup = PagedMenu(title=self.popup_title) self.confirm_popup = SimpleMenu() @@ -402,7 +403,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.confirm_popup) @self.confirm_popup.register_build_callback @@ -410,20 +411,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][0].name, + id=self._selected_bans[index][0].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][0].banned_by))) popup.append(Text(plugin_strings['ban_record reason'].tokenized( - reason=self._selected_ban[0].reason))) + reason=self._selected_bans[index][0].reason))) - if self._selected_ban[0].notes: + if self._selected_bans[index][0].notes: popup.append(Text(plugin_strings['ban_record notes'].tokenized( - notes=self._selected_ban[0].notes))) + notes=self._selected_bans[index][0].notes))) popup.append(Text( plugin_strings['lift_reviewed_ban_confirmation'])) @@ -431,12 +432,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][0], 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][0], True), )) @self.confirm_popup.register_select_callback @@ -498,15 +499,13 @@ class ReviewBanPopupFeature(Feature): def __init__(self): # (_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) 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 @@ -527,7 +526,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 +537,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,26 +546,27 @@ 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, ) )) @@ -597,7 +597,7 @@ class SearchBadBansPopupFeature(Feature): def __init__(self): # (_BannedPlayerInfo instance, whether to remove or not) - self._selected_ban = None + self._selected_bans = PlayerDictionary(lambda index: (None, False)) self.ban_popup = PagedMenu(title=self.popup_title) self.remove_popup = SimpleMenu() @@ -620,7 +620,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.remove_popup) @self.remove_popup.register_build_callback @@ -628,17 +628,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][0].name, + id=self._selected_bans[index][0].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][0].banned_by))) - if self._selected_ban[0].notes: + if self._selected_bans[index][0].notes: popup.append(Text(plugin_strings['ban_record notes'].tokenized( - notes=self._selected_ban[0].notes))) + notes=self._selected_bans[index][0].notes))) popup.append(Text( plugin_strings['remove_bad_ban_confirmation'])) @@ -646,12 +646,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][0], 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][0], True), )) @self.remove_popup.register_select_callback 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..163ee7e 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 @@ -162,7 +162,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( @@ -199,7 +199,7 @@ def build_callback(popup, index): 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 @@ -207,28 +207,28 @@ def build_callback(popup, index): popup.title = plugin_strings['popup_title record_title'].tokenized( seen_at=strftime( "%d %b %Y %H:%M:%S", localtime( - self._selected_record.seen_at) + self._selected_records[index].seen_at) ), - name=format_player_name(self._selected_record.name) + name=format_player_name(self._selected_records[index].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].name, # Non-formatted name ))) popup.append(Text(plugin_strings['popup_text steamid'].tokenized( - steamid=self._selected_record.steamid, + steamid=self._selected_records[index].steamid, ))) popup.append(Text( plugin_strings['popup_text ip_address'].tokenized( - ip_address=self._selected_record.ip_address, + ip_address=self._selected_records[index].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].ip_address), value=( _TrackPopupOption.SEARCH_BY_IP, - self._selected_record.ip_address + self._selected_records[index].ip_address ) )) From cd0d0a0c9d63130c5700309673e86c7643ef2b44 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 14 Jul 2017 13:34:39 +0300 Subject: [PATCH 02/31] Changed naming schema in kick/ban models --- .../plugins/admin/plugins/included/admin_kick_ban/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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)) From d883a61868519368b2b03658e24a95775589f8e9 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 14 Jul 2017 15:31:07 +0300 Subject: [PATCH 03/31] Unnecessary to use == operator here --- .../plugins/admin/plugins/included/admin_kick_ban/bans/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e9c0e90..66870c1 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 @@ -194,7 +194,7 @@ def get_all_bans(self, uniqueid=None, banned_by=None, reviewed=None, if uniqueid is not None: uniqueid = self._convert_uniqueid_to_db_format(uniqueid) - query = query.filter(self.model.uniqueid == uniqueid) + query = query.filter_by(uniqueid=uniqueid) if banned_by is not None: banned_by = self._convert_steamid_to_db_format(banned_by) From 26931590ece9c3a00529aad79140c00fd8b1127e Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 14 Jul 2017 15:43:52 +0300 Subject: [PATCH 04/31] Fixed a bug in BannedUniqueIDManager.get_all_bans function that caused permanent bans not to show up in non-expired bans --- .../plugins/included/admin_kick_ban/bans/base.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 66870c1..78e4cb7 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 @@ -15,7 +15,7 @@ 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 @@ -131,7 +131,7 @@ def refresh(self): if banned_user.is_unbanned: continue - if -1 < banned_user.expires_at < current_time: + if 0 <= banned_user.expires_at < current_time: continue self[banned_user.uniqueid] = _BannedPlayerInfo( @@ -208,10 +208,13 @@ def get_all_bans(self, uniqueid=None, banned_by=None, reviewed=None, if expired: query = query.filter(and_( self.model.expires_at < current_time, - self.model.expires_at > -1 + self.model.expires_at >= 0 )) else: - query = query.filter(self.model.expires_at >= current_time) + 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) From f17ede948d62bc27fb1941d67d60d867cf68d9a3 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 14 Jul 2017 20:07:07 +0300 Subject: [PATCH 05/31] Fixed a bug when ex-admin could trigger a feature if he still had the popup frontend opened --- .../source-python/plugins/admin/core/frontends/menus.py | 4 ++++ 1 file changed, 4 insertions(+) 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..b46cba4 100644 --- a/srcds/addons/source-python/plugins/admin/core/frontends/menus.py +++ b/srcds/addons/source-python/plugins/admin/core/frontends/menus.py @@ -186,6 +186,10 @@ def is_selectable(self, client): return client.has_permission(self.feature.flag) def select(self, client): + if not self.is_visible(client) or not self.is_selectable(client): + client.tell(strings_common['unavailable']) + return + client.active_popup = None self.feature.execute(client) From fe7b6823c2eaa3534e679423b4ec30356e164f55 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 14 Jul 2017 20:23:27 +0300 Subject: [PATCH 06/31] Fixed a bug when ex-admin could trigger a player-based feature had he proceeded to the player selection before --- .../source-python/plugins/admin/core/frontends/menus.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 b46cba4..a2750ea 100644 --- a/srcds/addons/source-python/plugins/admin/core/frontends/menus.py +++ b/srcds/addons/source-python/plugins/admin/core/frontends/menus.py @@ -506,6 +506,10 @@ def _player_select(self, client, player_ids): :param list player_ids: Unfiltered list of IDs. """ + if not self.is_visible(client) or not self.is_selectable(client): + client.tell(strings_common['unavailable']) + return + client.active_popup = None for player in self._filter_player_ids(client, player_ids): @@ -528,10 +532,6 @@ def render_player_name(player): return format_player_name(player.name) def select(self, client): - if not self.is_visible(client) or not self.is_selectable(client): - client.tell(strings_common['unavailable']) - return - client.send_popup(self.popup) From 51c84b14772d094d64b0fad1d5235bc9ad1e7d85 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 14 Jul 2017 22:59:28 +0300 Subject: [PATCH 07/31] Fixed (harmless) ValueError's when player disconnects without ever activating --- .../admin/plugins/included/admin_kick_ban/left_player.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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..703a5c2 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 @@ -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: From b7967599f23a06b1a33cfab6746240fe1d368b7e Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 14 Jul 2017 23:12:11 +0300 Subject: [PATCH 08/31] Developed "Admin Communication Management" included plugin (without text chat support yet) --- .../admin_comm_management/__init__.py | 1 + .../admin_comm_management.py | 63 +++ .../admin_comm_management/blocks/base.py | 372 ++++++++++++++++++ .../admin_comm_management/blocks/voice.py | 120 ++++++ .../included/admin_comm_management/info.ini | 4 + .../included/admin_comm_management/info.py | 13 + .../included/admin_comm_management/models.py | 55 +++ .../included/admin_comm_management/strings.py | 11 + .../block_durations.json | 12 + .../admin_comm_management.ini | 91 +++++ 10 files changed, 742 insertions(+) create mode 100644 srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/__init__.py create mode 100644 srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/admin_comm_management.py create mode 100644 srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/base.py create mode 100644 srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/voice.py create mode 100644 srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/info.ini create mode 100644 srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/info.py create mode 100644 srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/models.py create mode 100644 srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/strings.py create mode 100644 srcds/cfg/source-python/admin/included_plugins/admin_comm_management/block_durations.json create mode 100644 srcds/resource/source-python/translations/admin/included_plugins/admin_comm_management.ini 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..1651fb4 --- /dev/null +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/admin_comm_management.py @@ -0,0 +1,63 @@ +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Source.Python Admin +from admin.admin import main_menu +from admin.core.frontends.menus import AdminMenuSection + +# Included Plugin +from .blocks.base import BlockCommAdminCommand +from .blocks.voice import ( + block_voice_feature, blocked_voice_user_manager, unblock_any_voice_feature, + unblock_my_voice_feature, UnblockAnyVoiceAdminCommand, + UnblockMyVoiceAdminCommand) +from .strings import plugin_strings + + +# ============================================================================= +# >> MENU ENTRIES +# ============================================================================= +menu_section = main_menu.add_entry(AdminMenuSection( + main_menu, plugin_strings['section_title main'])) + +menu_section_chat = menu_section.add_entry(AdminMenuSection( + menu_section, plugin_strings['section_title chat'])) + +menu_section_voice = menu_section.add_entry(AdminMenuSection( + menu_section, plugin_strings['section_title voice'])) + +#menu_section_chat.add_entry(BlockCommAdminCommand( +# block_chat_feature, +# menu_section_chat, +# plugin_strings['popup_title block_chat'])) + +menu_section_voice.add_entry(BlockCommAdminCommand( + block_voice_feature, + menu_section_voice, + plugin_strings['popup_title block_voice'])) + +#menu_section_chat.add_entry(UnblockAnyChatAdminCommand( +# unblock_any_chat_feature, +# menu_section_chat, +# plugin_strings['popup_title unblock_chat_any'])) + +menu_section_voice.add_entry(UnblockAnyVoiceAdminCommand( + unblock_any_voice_feature, + menu_section_voice, + plugin_strings['popup_title unblock_voice_any'])) + +#menu_section_voice.add_entry(UnblockMyChatAdminCommand( +# unblock_my_chat_feature, +# menu_section_chat, +# plugin_strings['popup_title unblock_chat'])) + +menu_section_voice.add_entry(UnblockMyVoiceAdminCommand( + 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..6a26e8f --- /dev/null +++ b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/base.py @@ -0,0 +1,372 @@ +# ============================================================================= +# >> 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 AdminCommand, PlayerBasedAdminCommand +from admin.core.helpers import format_player_name +from admin.core.orm import Session +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() + + session = 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 + ) + + session.close() + + 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) + + session = 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) + + session.close() + + self._on_change() + + def get_all_blocks( + self, steamid=None, blocked_by=None, expired=None, unblocked=None): + + result = [] + session = 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 + )) + + session.close() + + 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) + + session = Session() + + blocked_user = session.query(self.model).filter_by(id=id_).first() + + if blocked_user is None: + session.close() + return + + blocked_user.lift_block(unblocked_by) + + session.commit() + session.close() + + 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 BlockCommAdminCommand(PlayerBasedAdminCommand): + 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 _UnblockCommAdminCommand(AdminCommand): + 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 UnblockAnyCommAdminCommand(_UnblockCommAdminCommand): + def _get_blocks(self, client): + return self.feature.blocked_comm_user_manager.get_active_blocks() + + +class UnblockMyCommAdminCommand(_UnblockCommAdminCommand): + 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/voice.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/voice.py new file mode 100644 index 0000000..9ab1ef6 --- /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, UnblockAnyCommAdminCommand, + UnblockCommFeature, UnblockMyCommAdminCommand) + + +# ============================================================================= +# >> 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 UnblockAnyVoiceAdminCommand(UnblockAnyCommAdminCommand): + popup_title = plugin_strings['popup_title unblock_voice_any'] + + +class UnblockMyVoiceAdminCommand(UnblockMyCommAdminCommand): + 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/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/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}" From d65a1997284d46af66d543a21d1d482477a4dac1 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 14 Jul 2017 23:54:29 +0300 Subject: [PATCH 09/31] Fixed another harmless ValueError when player disconnects without activation --- .../source-python/plugins/admin/core/frontends/motd.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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) From 41ca6102fb1a834436d84f0548b63298af3a36e4 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 14 Jul 2017 23:55:22 +0300 Subject: [PATCH 10/31] Added text chat support to "Admin Communication Management" included plugin --- .../admin_comm_management.py | 30 +++--- .../admin_comm_management/blocks/chat.py | 92 +++++++++++++++++++ 2 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/chat.py 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 index 1651fb4..dc3fe22 100644 --- 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 @@ -7,6 +7,10 @@ # Included Plugin from .blocks.base import BlockCommAdminCommand +from .blocks.chat import ( + block_chat_feature, blocked_chat_user_manager, unblock_any_chat_feature, + unblock_my_chat_feature, UnblockAnyChatAdminCommand, + UnblockMyChatAdminCommand) from .blocks.voice import ( block_voice_feature, blocked_voice_user_manager, unblock_any_voice_feature, unblock_my_voice_feature, UnblockAnyVoiceAdminCommand, @@ -26,30 +30,30 @@ menu_section_voice = menu_section.add_entry(AdminMenuSection( menu_section, plugin_strings['section_title voice'])) -#menu_section_chat.add_entry(BlockCommAdminCommand( -# block_chat_feature, -# menu_section_chat, -# plugin_strings['popup_title block_chat'])) +menu_section_chat.add_entry(BlockCommAdminCommand( + block_chat_feature, + menu_section_chat, + plugin_strings['popup_title block_chat'])) menu_section_voice.add_entry(BlockCommAdminCommand( block_voice_feature, menu_section_voice, plugin_strings['popup_title block_voice'])) -#menu_section_chat.add_entry(UnblockAnyChatAdminCommand( -# unblock_any_chat_feature, -# menu_section_chat, -# plugin_strings['popup_title unblock_chat_any'])) +menu_section_chat.add_entry(UnblockAnyChatAdminCommand( + unblock_any_chat_feature, + menu_section_chat, + plugin_strings['popup_title unblock_chat_any'])) menu_section_voice.add_entry(UnblockAnyVoiceAdminCommand( unblock_any_voice_feature, menu_section_voice, plugin_strings['popup_title unblock_voice_any'])) -#menu_section_voice.add_entry(UnblockMyChatAdminCommand( -# unblock_my_chat_feature, -# menu_section_chat, -# plugin_strings['popup_title unblock_chat'])) +menu_section_chat.add_entry(UnblockMyChatAdminCommand( + unblock_my_chat_feature, + menu_section_chat, + plugin_strings['popup_title unblock_chat'])) menu_section_voice.add_entry(UnblockMyVoiceAdminCommand( unblock_my_voice_feature, @@ -59,5 +63,5 @@ # ============================================================================= # >> SYNCHRONOUS DATABASE OPERATIONS # ============================================================================= -#blocked_chat_user_manager.refresh() +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/chat.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/chat.py new file mode 100644 index 0000000..831834f --- /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, UnblockAnyCommAdminCommand, + UnblockCommFeature, UnblockMyCommAdminCommand) + + +# ============================================================================= +# >> 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 UnblockAnyChatAdminCommand(UnblockAnyCommAdminCommand): + popup_title = plugin_strings['popup_title unblock_chat_any'] + + +class UnblockMyChatAdminCommand(UnblockMyCommAdminCommand): + 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 From ddd645c6747d0fabc47dd34d4d9e4440fe26834e Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Sat, 15 Jul 2017 00:10:14 +0300 Subject: [PATCH 11/31] Made database sessions more safe --- .../source-python/plugins/admin/core/orm.py | 18 ++ .../admin_comm_management/blocks/base.py | 125 ++++++------- .../included/admin_kick_ban/bans/base.py | 167 ++++++++---------- .../included/admin_tracking/admin_tracking.py | 108 ++++++----- 4 files changed, 202 insertions(+), 216 deletions(-) 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/blocks/base.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_comm_management/blocks/base.py index 6a26e8f..5745a3b 100644 --- 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 @@ -19,7 +19,7 @@ from admin.core.features import BaseFeature from admin.core.frontends.menus import AdminCommand, PlayerBasedAdminCommand from admin.core.helpers import format_player_name -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 @@ -89,24 +89,21 @@ def _on_change(self): def refresh(self): self.clear() - session = Session() + with SessionContext() as session: + blocked_users = session.query(self.model).all() - blocked_users = session.query(self.model).all() + current_time = time() + for blocked_user in blocked_users: + if blocked_user.is_unblocked: + continue - current_time = time() - for blocked_user in blocked_users: - if blocked_user.is_unblocked: - continue + if 0 <= blocked_user.expires_at < current_time: + 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 - ) - - session.close() + 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() @@ -129,18 +126,15 @@ 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) - session = Session() - - blocked_user = self.model(steamid, name, blocked_by, duration) + with SessionContext() as session: + blocked_user = self.model(steamid, name, blocked_by, duration) - session.add(blocked_user) - session.commit() + session.add(blocked_user) + session.commit() - self[steamid] = _BlockedCommUserInfo( - steamid, blocked_user.id, name, blocked_by, - blocked_user.expires_at) - - session.close() + self[steamid] = _BlockedCommUserInfo( + steamid, blocked_user.id, name, blocked_by, + blocked_user.expires_at) self._on_change() @@ -148,41 +142,39 @@ def get_all_blocks( self, steamid=None, blocked_by=None, expired=None, unblocked=None): result = [] - session = 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 + 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 )) - 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 - )) - - session.close() return result @@ -210,18 +202,15 @@ def get_active_blocks(self, blocked_by=None): def lift_block(self, id_, unblocked_by): unblocked_by = self._convert_steamid_to_db_format(unblocked_by) - session = Session() + with SessionContext() as session: + blocked_user = session.query(self.model).filter_by(id=id_).first() - blocked_user = session.query(self.model).filter_by(id=id_).first() - - if blocked_user is None: - session.close() - return + if blocked_user is None: + return - blocked_user.lift_block(unblocked_by) + blocked_user.lift_block(unblocked_by) - session.commit() - session.close() + session.commit() for steamid64, blocked_comm_user_info in self.items(): if blocked_comm_user_info.id != id_: 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 78e4cb7..da6d211 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 @@ -22,7 +22,7 @@ from admin.core.features import BaseFeature, Feature 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 # Included Plugin @@ -122,25 +122,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 0 <= 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) @@ -161,73 +158,67 @@ 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_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 + 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 )) - 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 def get_active_bans(self, banned_by=None, reviewed=None): @@ -258,19 +249,17 @@ def get_active_bans(self, banned_by=None, reviewed=None): return result def review_ban(self, ban_id, reason, duration): - session = Session() - - banned_user = session.query(self.model).filter_by(id=ban_id).first() + with SessionContext() as session: + 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: @@ -284,18 +273,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() - - banned_user = session.query(self.model).filter_by(id=ban_id).first() + with SessionContext() as session: + 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: 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 163ee7e..5c059ce 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 @@ -22,7 +22,7 @@ from admin.core.features import PlayerBasedFeature from admin.core.frontends.menus import ( AdminMenuSection, PlayerBasedAdminCommand) -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.plugins.strings import PluginStrings @@ -34,19 +34,18 @@ # >> FUNCTIONS # ============================================================================= def remove_old_database_records(): - session = Session() - max_record_life_seconds = ( - int(plugin_config['database']['max_record_life_days']) * 24 * 3600) + 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() - session.close() + session.commit() # ============================================================================= @@ -99,41 +98,39 @@ def save_to_database(self): if self.steamid is None: return - session = Session() + with SessionContext() as session: + db_record = ( + session + .query(DB_Record) + .filter_by(steamid64=self.steamid) + .order_by(DB_Record.seen_at.desc()) + .first() + ) - 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() @@ -262,17 +259,15 @@ def _show_records_for_steamid(self, client, steamid): break # Secondly, add records from the database - session = Session() + with SessionContext() as session: - db_records = ( - 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( @@ -310,17 +305,14 @@ def _show_players_for_ip_address(self, client, ip_address): )) # 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() + 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: From 9a90c997e20f2f88907824d640896f000368ed1b Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Sat, 15 Jul 2017 00:21:45 +0300 Subject: [PATCH 12/31] Internal naming changes --- .../source-python/plugins/admin/admin.py | 4 +-- .../plugins/admin/core/frontends/menus.py | 36 +++++++++---------- .../admin_comm_management.py | 30 ++++++++-------- .../admin_comm_management/blocks/base.py | 10 +++--- .../admin_comm_management/blocks/chat.py | 8 ++--- .../admin_comm_management/blocks/voice.py | 8 ++--- .../included/admin_kick_ban/admin_kick_ban.py | 26 +++++++------- .../admin_kick_ban/bans/ip_address.py | 4 +-- .../included/admin_kick_ban/bans/steamid.py | 4 +-- .../included/admin_kick_ban/left_player.py | 4 +-- .../admin_life_management.py | 8 ++--- .../admin_team_management.py | 14 ++++---- .../included/admin_tracking/admin_tracking.py | 6 ++-- 13 files changed, 79 insertions(+), 83 deletions(-) diff --git a/srcds/addons/source-python/plugins/admin/admin.py b/srcds/addons/source-python/plugins/admin/admin.py index 51254c9..8f08e93 100644 --- a/srcds/addons/source-python/plugins/admin/admin.py +++ b/srcds/addons/source-python/plugins/admin/admin.py @@ -12,7 +12,7 @@ from .core.events.storage import admin_resource_list 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 MenuSection from .core.frontends.motd import MainPage from .core.orm import Base, engine from .core.plugins.command import admin_command_manager @@ -29,7 +29,7 @@ # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= -main_menu = AdminMenuSection(None, strings_common['title main'], 'admin') +main_menu = MenuSection(None, strings_common['title main'], 'admin') # ============================================================================= 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 a2750ea..1818be5 100644 --- a/srcds/addons/source-python/plugins/admin/core/frontends/menus.py +++ b/srcds/addons/source-python/plugins/admin/core/frontends/menus.py @@ -21,7 +21,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 +50,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 +77,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,9 +93,9 @@ 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) @@ -145,13 +145,13 @@ def select(self, client): client.send_popup(self.popup) -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. """ @@ -186,10 +186,6 @@ def is_selectable(self, client): return client.has_permission(self.feature.flag) def select(self, client): - if not self.is_visible(client) or not self.is_selectable(client): - client.tell(strings_common['unavailable']) - return - client.active_popup = None self.feature.execute(client) @@ -226,18 +222,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. """ @@ -506,10 +502,6 @@ def _player_select(self, client, player_ids): :param list player_ids: Unfiltered list of IDs. """ - if not self.is_visible(client) or not self.is_selectable(client): - client.tell(strings_common['unavailable']) - return - client.active_popup = None for player in self._filter_player_ids(client, player_ids): @@ -532,10 +524,14 @@ def render_player_name(player): return format_player_name(player.name) def select(self, client): + if not self.is_visible(client) or not self.is_selectable(client): + client.tell(strings_common['unavailable']) + return + client.send_popup(self.popup) -class PlayerBasedAdminCommand(BasePlayerBasedAdminCommand): +class PlayerBasedMenuCommand(BasePlayerBasedMenuCommand): base_filter = 'all' def _get_player_id(self, player): 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 index dc3fe22..fd1e79e 100644 --- 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 @@ -3,59 +3,59 @@ # ============================================================================= # Source.Python Admin from admin.admin import main_menu -from admin.core.frontends.menus import AdminMenuSection +from admin.core.frontends.menus import MenuSection # Included Plugin -from .blocks.base import BlockCommAdminCommand +from .blocks.base import BlockCommMenuCommand from .blocks.chat import ( block_chat_feature, blocked_chat_user_manager, unblock_any_chat_feature, - unblock_my_chat_feature, UnblockAnyChatAdminCommand, - UnblockMyChatAdminCommand) + 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, UnblockAnyVoiceAdminCommand, - UnblockMyVoiceAdminCommand) + unblock_my_voice_feature, UnblockAnyVoiceMenuCommand, + UnblockMyVoiceMenuCommand) from .strings import plugin_strings # ============================================================================= # >> MENU ENTRIES # ============================================================================= -menu_section = main_menu.add_entry(AdminMenuSection( +menu_section = main_menu.add_entry(MenuSection( main_menu, plugin_strings['section_title main'])) -menu_section_chat = menu_section.add_entry(AdminMenuSection( +menu_section_chat = menu_section.add_entry(MenuSection( menu_section, plugin_strings['section_title chat'])) -menu_section_voice = menu_section.add_entry(AdminMenuSection( +menu_section_voice = menu_section.add_entry(MenuSection( menu_section, plugin_strings['section_title voice'])) -menu_section_chat.add_entry(BlockCommAdminCommand( +menu_section_chat.add_entry(BlockCommMenuCommand( block_chat_feature, menu_section_chat, plugin_strings['popup_title block_chat'])) -menu_section_voice.add_entry(BlockCommAdminCommand( +menu_section_voice.add_entry(BlockCommMenuCommand( block_voice_feature, menu_section_voice, plugin_strings['popup_title block_voice'])) -menu_section_chat.add_entry(UnblockAnyChatAdminCommand( +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(UnblockAnyVoiceAdminCommand( +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(UnblockMyChatAdminCommand( +menu_section_chat.add_entry(UnblockMyChatMenuCommand( unblock_my_chat_feature, menu_section_chat, plugin_strings['popup_title unblock_chat'])) -menu_section_voice.add_entry(UnblockMyVoiceAdminCommand( +menu_section_voice.add_entry(UnblockMyVoiceMenuCommand( unblock_my_voice_feature, menu_section_voice, plugin_strings['popup_title unblock_voice'])) 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 index 5745a3b..a2a1991 100644 --- 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 @@ -17,7 +17,7 @@ # Source.Python Admin from admin.core.clients import clients from admin.core.features import BaseFeature -from admin.core.frontends.menus import AdminCommand, PlayerBasedAdminCommand +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 @@ -252,7 +252,7 @@ def filter(self, client, player): return not another_client.has_permission(self.flag) -class BlockCommAdminCommand(PlayerBasedAdminCommand): +class BlockCommMenuCommand(PlayerBasedMenuCommand): base_filter = 'human' def __init__(self, feature, parent, title, id_=None): @@ -299,7 +299,7 @@ def execute(self, client, blocked_comm_user_info): ).start() -class _UnblockCommAdminCommand(AdminCommand): +class _UnblockCommMenuCommand(MenuCommand): popup_title = None def __init__(self, feature, parent, title, id_=None): @@ -344,12 +344,12 @@ def select(self, client): client.send_popup(self.popup) -class UnblockAnyCommAdminCommand(_UnblockCommAdminCommand): +class UnblockAnyCommMenuCommand(_UnblockCommMenuCommand): def _get_blocks(self, client): return self.feature.blocked_comm_user_manager.get_active_blocks() -class UnblockMyCommAdminCommand(_UnblockCommAdminCommand): +class UnblockMyCommMenuCommand(_UnblockCommMenuCommand): def _get_blocks(self, client): return self.feature.blocked_comm_user_manager.get_active_blocks( blocked_by=client.steamid) 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 index 831834f..b09e586 100644 --- 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 @@ -13,8 +13,8 @@ from ..models import BlockedChatUser from ..strings import plugin_strings from .base import ( - BlockCommFeature, BlockedCommUserManager, UnblockAnyCommAdminCommand, - UnblockCommFeature, UnblockMyCommAdminCommand) + BlockCommFeature, BlockedCommUserManager, UnblockAnyCommMenuCommand, + UnblockCommFeature, UnblockMyCommMenuCommand) # ============================================================================= @@ -70,11 +70,11 @@ class _UnblockMyChatFeature(_UnblockChatFeature): unblock_my_chat_feature = _UnblockMyChatFeature() -class UnblockAnyChatAdminCommand(UnblockAnyCommAdminCommand): +class UnblockAnyChatMenuCommand(UnblockAnyCommMenuCommand): popup_title = plugin_strings['popup_title unblock_chat_any'] -class UnblockMyChatAdminCommand(UnblockMyCommAdminCommand): +class UnblockMyChatMenuCommand(UnblockMyCommMenuCommand): popup_title = plugin_strings['popup_title unblock_chat'] 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 index 9ab1ef6..5e1fbd3 100644 --- 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 @@ -15,8 +15,8 @@ from ..models import BlockedVoiceUser from ..strings import plugin_strings from .base import ( - BlockCommFeature, BlockedCommUserManager, UnblockAnyCommAdminCommand, - UnblockCommFeature, UnblockMyCommAdminCommand) + BlockCommFeature, BlockedCommUserManager, UnblockAnyCommMenuCommand, + UnblockCommFeature, UnblockMyCommMenuCommand) # ============================================================================= @@ -95,11 +95,11 @@ class _UnblockMyVoiceFeature(_UnblockVoiceFeature): unblock_my_voice_feature = _UnblockMyVoiceFeature() -class UnblockAnyVoiceAdminCommand(UnblockAnyCommAdminCommand): +class UnblockAnyVoiceMenuCommand(UnblockAnyCommMenuCommand): popup_title = plugin_strings['popup_title unblock_voice_any'] -class UnblockMyVoiceAdminCommand(UnblockMyCommAdminCommand): +class UnblockMyVoiceMenuCommand(UnblockMyCommMenuCommand): popup_title = plugin_strings['popup_title unblock_voice'] 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..0f487bf 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 @@ -8,7 +8,7 @@ from admin.admin import main_menu from admin.core.features import PlayerBasedFeature from admin.core.frontends.menus import ( - AdminCommand, AdminMenuSection, PlayerBasedAdminCommand) + MenuCommand, MenuSection, PlayerBasedMenuCommand) from admin.core.frontends.motd import ( main_motd, MOTDSection, MOTDPageEntry, PlayerBasedFeaturePage) from admin.core.helpers import log_admin_action @@ -51,7 +51,7 @@ def execute(self, client, player): kick_feature = _KickFeature() -class _KickMenuCommand(PlayerBasedAdminCommand): +class _KickMenuCommand(PlayerBasedMenuCommand): allow_multiple_choices = False @@ -68,13 +68,13 @@ class _KickPage(PlayerBasedFeaturePage): # ============================================================================= # >> MENU ENTRIES # ============================================================================= -menu_section = main_menu.add_entry(AdminMenuSection( +menu_section = main_menu.add_entry(MenuSection( main_menu, plugin_strings['section_title main'])) -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 = ( @@ -105,42 +105,42 @@ class _KickPage(PlayerBasedFeaturePage): menu_section_ip_address, plugin_strings['popup_title ban_ip_address'])) -menu_section_steamid.add_entry(AdminCommand( +menu_section_steamid.add_entry(MenuCommand( review_steamid_ban_popup_feature, menu_section_steamid, plugin_strings['popup_title review_steamid'])) -menu_section_ip_address.add_entry(AdminCommand( +menu_section_ip_address.add_entry(MenuCommand( review_ip_address_ban_popup_feature, menu_section_ip_address, plugin_strings['popup_title review_ip_address'])) -menu_section_steamid.add_entry(AdminCommand( +menu_section_steamid.add_entry(MenuCommand( lift_steamid_ban_popup_feature, menu_section_steamid, plugin_strings['popup_title lift_steamid'])) -menu_section_ip_address.add_entry(AdminCommand( +menu_section_ip_address.add_entry(MenuCommand( lift_ip_address_ban_popup_feature, menu_section_ip_address, plugin_strings['popup_title lift_ip_address'])) -menu_section_steamid.add_entry(AdminCommand( +menu_section_steamid.add_entry(MenuCommand( lift_any_steamid_ban_popup_feature, menu_section_steamid, plugin_strings['popup_title lift_reviewed_steamid'])) -menu_section_ip_address.add_entry(AdminCommand( +menu_section_ip_address.add_entry(MenuCommand( lift_any_ip_address_ban_popup_feature, menu_section_ip_address, plugin_strings['popup_title lift_reviewed_ip_address'])) -menu_section_steamid.add_entry(AdminCommand( +menu_section_steamid.add_entry(MenuCommand( search_bad_steamid_bans_popup_feature, menu_section_steamid, plugin_strings['popup_title search_bad_bans'])) -menu_section_ip_address.add_entry(AdminCommand( +menu_section_ip_address.add_entry(MenuCommand( search_bad_ip_address_bans_popup_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/ip_address.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/ip_address.py index bfca583..199c6cc 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,7 +15,7 @@ # 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 @@ -145,7 +145,7 @@ class _SearchBadIPAddressBansPopupFeature(SearchBadBansPopupFeature): _SearchBadIPAddressBansPopupFeature()) -class BanIPAddressMenuCommand(LeftPlayerBasedAdminCommand): +class BanIPAddressMenuCommand(LeftPlayerBasedMenuCommand): base_filter = 'human' allow_multiple_choices = False 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..b77ee31 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 @@ -20,7 +20,7 @@ # 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 @@ -165,7 +165,7 @@ class _SearchBadSteamIDBansPopupFeature(SearchBadBansPopupFeature): search_bad_steamid_bans_popup_feature = _SearchBadSteamIDBansPopupFeature() -class BanSteamIDMenuCommand(LeftPlayerBasedAdminCommand): +class BanSteamIDMenuCommand(LeftPlayerBasedMenuCommand): base_filter = 'human' allow_multiple_choices = False 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 703a5c2..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): 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..d694afd 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 @@ -9,7 +9,7 @@ from admin.admin import main_menu from admin.core.features import PlayerBasedFeature from admin.core.frontends.menus import ( - AdminMenuSection, PlayerBasedAdminCommand) + MenuSection, PlayerBasedMenuCommand) from admin.core.frontends.motd import ( main_motd, MOTDSection, MOTDPageEntry, PlayerBasedFeaturePage) from admin.core.helpers import log_admin_action @@ -104,16 +104,16 @@ def on_error(self, error): # ============================================================================= # >> MENU ENTRIES # ============================================================================= -menu_section = main_menu.add_entry(AdminMenuSection( +menu_section = main_menu.add_entry(MenuSection( main_menu, plugin_strings['section_title'])) -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..58eec61 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 @@ -11,7 +11,7 @@ from admin.admin import main_menu from admin.core.features import PlayerBasedFeature from admin.core.frontends.menus import ( - AdminMenuSection, PlayerBasedAdminCommand) + MenuSection, PlayerBasedMenuCommand) from admin.core.helpers import log_admin_action from admin.core.plugins.strings import PluginStrings @@ -100,36 +100,36 @@ class _DelayedMoveToCTFeature(_DelayedMoveToTeamFeature): # ============================================================================= # >> MENU ENTRIES # ============================================================================= -menu_section = main_menu.add_entry(AdminMenuSection( +menu_section = main_menu.add_entry(MenuSection( main_menu, plugin_strings['section_title'])) -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 5c059ce..7b7ce38 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 @@ -21,7 +21,7 @@ from admin.core.helpers import extract_ip_address, format_player_name from admin.core.features import PlayerBasedFeature from admin.core.frontends.menus import ( - AdminMenuSection, PlayerBasedAdminCommand) + MenuSection, PlayerBasedMenuCommand) from admin.core.orm import SessionContext from admin.core.paths import ADMIN_CFG_PATH, get_server_file from admin.core.plugins.strings import PluginStrings @@ -351,7 +351,7 @@ def execute(self, client, player): track_popup_feature = _TrackPopupFeature() -class _TrackMenuCommand(PlayerBasedAdminCommand): +class _TrackMenuCommand(PlayerBasedMenuCommand): base_filter = 'human' allow_multiple_choices = False @@ -365,7 +365,7 @@ class _TrackMenuCommand(PlayerBasedAdminCommand): # ============================================================================= # >> MENU ENTRIES # ============================================================================= -menu_section = main_menu.add_entry(AdminMenuSection( +menu_section = main_menu.add_entry(MenuSection( main_menu, plugin_strings['section_title'])) track_menu_command = menu_section.add_entry(_TrackMenuCommand( From b3580abc0125de457905b4cfab246414d4922292 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Sat, 15 Jul 2017 00:42:51 +0300 Subject: [PATCH 13/31] Moved `main_menu` creation from admin.admin to admin.core.frontends.menus --- srcds/addons/source-python/plugins/admin/admin.py | 8 +------- .../source-python/plugins/admin/core/frontends/menus.py | 3 +++ .../admin_comm_management/admin_comm_management.py | 3 +-- .../plugins/included/admin_kick_ban/admin_kick_ban.py | 3 +-- .../admin_life_management/admin_life_management.py | 3 +-- .../admin_team_management/admin_team_management.py | 3 +-- .../plugins/included/admin_tracking/admin_tracking.py | 3 +-- 7 files changed, 9 insertions(+), 17 deletions(-) diff --git a/srcds/addons/source-python/plugins/admin/admin.py b/srcds/addons/source-python/plugins/admin/admin.py index 8f08e93..d920a38 100644 --- a/srcds/addons/source-python/plugins/admin/admin.py +++ b/srcds/addons/source-python/plugins/admin/admin.py @@ -12,7 +12,7 @@ from .core.events.storage import admin_resource_list from .core.listeners import (on_spa_loaded_listener_manager, on_spa_unloaded_listener_manager) -from .core.frontends.menus import MenuSection +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,12 +26,6 @@ Base.metadata.create_all(engine) -# ============================================================================= -# >> GLOBAL VARIABLES -# ============================================================================= -main_menu = MenuSection(None, strings_common['title main'], 'admin') - - # ============================================================================= # >> LOAD & UNLOAD FUNCTIONS # ============================================================================= 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 1818be5..b6b8573 100644 --- a/srcds/addons/source-python/plugins/admin/core/frontends/menus.py +++ b/srcds/addons/source-python/plugins/admin/core/frontends/menus.py @@ -144,6 +144,9 @@ def select(self, client): client.send_popup(self.popup) +# Main section +main_menu = MenuSection(None, strings_common['title main'], 'admin') + class MenuCommand(MenuEntry): """Base class for entry that is bound to execute a feature.""" 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 index fd1e79e..9e4a511 100644 --- 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 @@ -2,8 +2,7 @@ # >> IMPORTS # ============================================================================= # Source.Python Admin -from admin.admin import main_menu -from admin.core.frontends.menus import MenuSection +from admin.core.frontends.menus import main_menu, MenuSection # Included Plugin from .blocks.base import BlockCommMenuCommand 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 0f487bf..00c97b0 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,10 +5,9 @@ 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 ( - MenuCommand, MenuSection, PlayerBasedMenuCommand) + main_menu, MenuCommand, MenuSection, PlayerBasedMenuCommand) from admin.core.frontends.motd import ( main_motd, MOTDSection, MOTDPageEntry, PlayerBasedFeaturePage) from admin.core.helpers import log_admin_action 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 d694afd..d21dfe0 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,9 @@ from players.entity import Player # Source.Python Admin -from admin.admin import main_menu from admin.core.features import PlayerBasedFeature from admin.core.frontends.menus import ( - MenuSection, PlayerBasedMenuCommand) + main_menu, MenuSection, PlayerBasedMenuCommand) from admin.core.frontends.motd import ( main_motd, MOTDSection, MOTDPageEntry, PlayerBasedFeaturePage) from admin.core.helpers import log_admin_action 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 58eec61..7838abf 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 ( - MenuSection, PlayerBasedMenuCommand) + main_menu, MenuSection, PlayerBasedMenuCommand) from admin.core.helpers import log_admin_action from admin.core.plugins.strings import PluginStrings 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 7b7ce38..dd90e46 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 @@ -16,12 +16,11 @@ 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.frontends.menus import ( - MenuSection, PlayerBasedMenuCommand) + main_menu, MenuSection, PlayerBasedMenuCommand) from admin.core.orm import SessionContext from admin.core.paths import ADMIN_CFG_PATH, get_server_file from admin.core.plugins.strings import PluginStrings From e764cae68af0b9df03326a6c0dfb0a6448818ac6 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Sat, 15 Jul 2017 02:40:12 +0300 Subject: [PATCH 14/31] Removed admin.core.memory and memory data files as that functionality is now released as a standalone "ConnectFilter" package (see https://forums.sourcepython.com/viewtopic.php?f=38&p=10610 ) --- .../plugins/admin/memory/csgo/CBaseServer.ini | 14 ------ .../admin/memory/cstrike/CBaseServer.ini | 13 ----- .../plugins/admin/core/memory.py | 25 ---------- .../included/admin_kick_ban/bans/steamid.py | 48 ++++++++----------- 4 files changed, 20 insertions(+), 80 deletions(-) delete mode 100644 srcds/addons/source-python/data/plugins/admin/memory/csgo/CBaseServer.ini delete mode 100644 srcds/addons/source-python/data/plugins/admin/memory/cstrike/CBaseServer.ini delete mode 100644 srcds/addons/source-python/plugins/admin/core/memory.py 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/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/plugins/included/admin_kick_ban/bans/steamid.py b/srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/steamid.py index b77ee31..5184dac 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,20 +2,27 @@ # >> 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 @@ -265,30 +272,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 +@ConnectFilter +def connect_filter(client): + if banned_steamid_manager.is_banned(client.steamid): + return plugin_strings['default_ban_reason'] - 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) - ) - - return False + return None From 497d00d071cbaab29c14b9ed226a5e719f145e0e Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Sat, 15 Jul 2017 18:46:54 +0300 Subject: [PATCH 15/31] Added command frontend --- .../plugins/admin/core/frontends/commands.py | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 srcds/addons/source-python/plugins/admin/core/frontends/commands.py 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..08dfc88 --- /dev/null +++ b/srcds/addons/source-python/plugins/admin/core/frontends/commands.py @@ -0,0 +1,173 @@ +# ============================================================================= +# >> IMPORTS +# ============================================================================= +# Source.Python +from commands import CommandReturn +from commands.typed import TypedClientCommand, TypedSayCommand +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: + def __init__(self, commands, feature): + if isinstance(commands, str): + commands = [commands, ] + + commands = list(commands) + + self.feature = feature + + TypedSayCommand( + ['!spa', ] + commands, feature.flag + )(self._get_public_chat_callback()) + + TypedSayCommand( + ['/spa', ] + commands, feature.flag + )(self._get_private_chat_callback()) + + TypedClientCommand( + ['spa', ] + commands, feature.flag + )(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 + + +class FeatureCommand(BaseFeatureCommand): + def _get_public_chat_callback(self): + def public_chat_callback(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, )) + + return CommandReturn.CONTINUE + + return public_chat_callback + + def _get_private_chat_callback(self): + def private_chat_callback(command_info): + client = clients[command_info.index] + client.sync_execution(self.feature.execute, (client,)) + return CommandReturn.BLOCK + + return private_chat_callback + + def _get_client_callback(self): + def client_callback(command_info): + client = clients[command_info.index] + client.sync_execution(self.feature.execute, (client,)) + + return client_callback + + +class PlayerBasedFeatureCommand(BaseFeatureCommand): + def _get_public_chat_callback(self): + def public_chat_callback( + command_info, filter_str:str, filter_args:str=""): + + client = clients[command_info.index] + + for player in iter_filter_targets( + filter_str, filter_args, client.player): + + if not self.feature.filter(client, player): + continue + + client.sync_execution(self.feature.execute, (client, player)) + + 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=""): + + client = clients[command_info.index] + + for player in iter_filter_targets( + filter_str, filter_args, client.player): + + if not self.feature.filter(client, player): + continue + + client.sync_execution(self.feature.execute, (client, player)) + + return CommandReturn.BLOCK + + return private_chat_callback + + def _get_client_callback(self): + def client_callback(command_info, filter_str:str, filter_args:str=""): + client = clients[command_info.index] + + for player in iter_filter_targets( + filter_str, filter_args, client.player): + + if not self.feature.filter(client, player): + continue + + client.sync_execution(self.feature.execute, (client, player)) + + return client_callback From 19bbdde6d95aa94f9c9e4598b9aff8146b279d07 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Sat, 15 Jul 2017 18:47:35 +0300 Subject: [PATCH 16/31] Added command frontend support to "Admin Life Management" included plugin --- .../admin_life_management/admin_life_management.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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 d21dfe0..9c7f806 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 @@ -7,6 +7,7 @@ # Source.Python Admin from admin.core.features import PlayerBasedFeature +from admin.core.frontends.commands import PlayerBasedFeatureCommand from admin.core.frontends.menus import ( main_menu, MenuSection, PlayerBasedMenuCommand) from admin.core.frontends.motd import ( @@ -100,6 +101,13 @@ def on_error(self, error): _ws_resurrect_pages.remove(self) +# ============================================================================= +# >> COMMAND FRONTEND +# ============================================================================= +PlayerBasedFeatureCommand("slay", slay_feature) +PlayerBasedFeatureCommand("resurrect", resurrect_feature) + + # ============================================================================= # >> MENU ENTRIES # ============================================================================= From 7eaaca0b4e86c44cb1845a430cd6289bce2159d0 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 18 Aug 2017 17:42:11 +0300 Subject: [PATCH 17/31] Refine commands front end --- .../plugins/admin/core/frontends/commands.py | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/srcds/addons/source-python/plugins/admin/core/frontends/commands.py b/srcds/addons/source-python/plugins/admin/core/frontends/commands.py index 08dfc88..3e105cf 100644 --- a/srcds/addons/source-python/plugins/admin/core/frontends/commands.py +++ b/srcds/addons/source-python/plugins/admin/core/frontends/commands.py @@ -93,49 +93,63 @@ def _get_client_callback(self): class FeatureCommand(BaseFeatureCommand): - def _get_public_chat_callback(self): - def public_chat_callback(command_info): - client = clients[command_info.index] + 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, )) + # 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): - client = clients[command_info.index] - client.sync_execution(self.feature.execute, (client,)) + self._execute(command_info) return CommandReturn.BLOCK return private_chat_callback def _get_client_callback(self): def client_callback(command_info): - client = clients[command_info.index] - client.sync_execution(self.feature.execute, (client,)) + self._execute(command_info) return client_callback class PlayerBasedFeatureCommand(BaseFeatureCommand): - def _get_public_chat_callback(self): - def public_chat_callback( - command_info, filter_str:str, filter_args:str=""): + def __init__(self, commands, feature, deny_mass_execution=False): + super().__init__(commands, feature) + + self._deny_mass_execution = deny_mass_execution + + def _execute(self, command_info, filter_str, filter_args): + client = clients[command_info.index] - client = clients[command_info.index] + players = [] + for player in iter_filter_targets( + filter_str, filter_args, client.player): - for player in iter_filter_targets( - filter_str, filter_args, client.player): + if not self.feature.filter(client, player): + continue - if not self.feature.filter(client, player): - continue + players.append(player) - client.sync_execution(self.feature.execute, (client, player)) + if self._deny_mass_execution and len(players) > 1: + return + for player in players: + 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 @@ -144,30 +158,13 @@ def _get_private_chat_callback(self): def private_chat_callback( command_info, filter_str:str, filter_args:str=""): - client = clients[command_info.index] - - for player in iter_filter_targets( - filter_str, filter_args, client.player): - - if not self.feature.filter(client, player): - continue - - client.sync_execution(self.feature.execute, (client, player)) - + 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=""): - client = clients[command_info.index] - - for player in iter_filter_targets( - filter_str, filter_args, client.player): - - if not self.feature.filter(client, player): - continue - - client.sync_execution(self.feature.execute, (client, player)) + self._execute(command_info, filter_str, filter_args) return client_callback From 35deb8c2e7e0874cf8e7fb94e299cab9295dce74 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 18 Aug 2017 17:42:46 +0300 Subject: [PATCH 18/31] Add command front end reference to readme.md --- readme.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/readme.md b/readme.md index 62b2608..0bd686d 100644 --- a/readme.md +++ b/readme.md @@ -2,3 +2,42 @@ ## 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 +### 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" From 1030ec7e72c80761535bae481e1625fd273c91b5 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 18 Aug 2017 17:43:47 +0300 Subject: [PATCH 19/31] Refactor Kick/Ban plugin --- .../included/admin_kick_ban/admin_kick_ban.py | 58 ++-- .../included/admin_kick_ban/bans/base.py | 306 +++++++++--------- .../admin_kick_ban/bans/ip_address.py | 91 +++--- .../included/admin_kick_ban/bans/steamid.py | 88 +++-- 4 files changed, 261 insertions(+), 282 deletions(-) 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 00c97b0..c2fbea6 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 @@ -7,24 +7,26 @@ # Source.Python Admin from admin.core.features import PlayerBasedFeature from admin.core.frontends.menus import ( - main_menu, MenuCommand, MenuSection, PlayerBasedMenuCommand) + 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 @@ -76,6 +78,7 @@ class _KickPage(PlayerBasedFeaturePage): 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 = ( @@ -88,6 +91,7 @@ class _KickPage(PlayerBasedFeaturePage): 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, @@ -104,43 +108,43 @@ class _KickPage(PlayerBasedFeaturePage): menu_section_ip_address, plugin_strings['popup_title ban_ip_address'])) -menu_section_steamid.add_entry(MenuCommand( - 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(MenuCommand( - 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(MenuCommand( - 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(MenuCommand( - 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(MenuCommand( - 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(MenuCommand( - 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(MenuCommand( - 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(MenuCommand( - 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 da6d211..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 @@ -19,11 +19,13 @@ # 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 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 @@ -292,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, @@ -346,52 +342,30 @@ 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_bans = PlayerDictionary(lambda index: (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_bans[index] = option.value clients[index].send_popup(self.confirm_popup) @@ -401,20 +375,20 @@ def build_callback(popup, index): popup.clear() popup.append(Text(plugin_strings['ban_record'].tokenized( - name=self._selected_bans[index][0].name, - id=self._selected_bans[index][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_bans[index][0].banned_by))) + admin_steamid=self._selected_bans[index].banned_by))) popup.append(Text(plugin_strings['ban_record reason'].tokenized( - reason=self._selected_bans[index][0].reason))) + reason=self._selected_bans[index].reason))) - if self._selected_bans[index][0].notes: + if self._selected_bans[index].notes: popup.append(Text(plugin_strings['ban_record notes'].tokenized( - notes=self._selected_bans[index][0].notes))) + notes=self._selected_bans[index].notes))) popup.append(Text( plugin_strings['lift_reviewed_ban_confirmation'])) @@ -422,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_bans[index][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_bans[index][0], True), + value=(self._selected_bans[index], True), )) @self.confirm_popup.register_select_callback @@ -435,63 +409,52 @@ 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_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) @@ -503,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, @@ -563,49 +523,68 @@ def build_callback(popup, index): @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 execute(self, client): + def _get_bans(self, client): + return self.feature.banned_uniqueid_manager.get_active_bans( + banned_by=client.steamid, reviewed=False) + + 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 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): - # (_BannedPlayerInfo instance, whether to remove or not) - self._selected_bans = PlayerDictionary(lambda index: (None, False)) + 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 @@ -618,17 +597,17 @@ def build_callback(popup, index): popup.clear() popup.append(Text(plugin_strings['ban_record'].tokenized( - name=self._selected_bans[index][0].name, - id=self._selected_bans[index][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_bans[index][0].banned_by))) + admin_steamid=self._selected_bans[index].banned_by))) - if self._selected_bans[index][0].notes: + if self._selected_bans[index].notes: popup.append(Text(plugin_strings['ban_record notes'].tokenized( - notes=self._selected_bans[index][0].notes))) + notes=self._selected_bans[index].notes))) popup.append(Text( plugin_strings['remove_bad_ban_confirmation'])) @@ -636,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_bans[index][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_bans[index][0], True), + value=(self._selected_bans[index], True), )) @self.remove_popup.register_select_callback @@ -649,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) + + self._parent.select(client) - def execute(self, 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) @@ -676,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" @@ -706,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, @@ -724,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] @@ -732,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" @@ -774,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 199c6cc..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 @@ -20,9 +20,9 @@ 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 + + @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 -# The singleton object of the _LiftSteamIDBanMOTDFeature class. -lift_ip_address_ban_motd_feature = _LiftIPAddressBanMOTDFeature() + 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()) - - -class BanIPAddressMenuCommand(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=extract_ip_address(left_player.address) - ) +# The singleton object of the _RemoveBadIPAddressBanFeature class. +remove_bad_ip_address_ban_feature = _RemoveBadIPAddressBanFeature() - 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 5184dac..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 @@ -32,9 +32,9 @@ 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) # ============================================================================= @@ -118,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 -# The singleton object of the _LiftSteamIDBanMOTDFeature class. -lift_steamid_ban_motd_feature = _LiftSteamIDBanMOTDFeature() + @staticmethod + def render_player_name(left_player): + return plugin_strings['player_name'].tokenized( + name=format_player_name(left_player.name), + id=left_player.steamid + ) + 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() - +# The singleton object of the _RemoveBadSteamIDBanFeature class. +remove_bad_steamid_ban_feature = _RemoveBadSteamIDBanFeature() -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 - ) - - 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): @@ -226,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) @@ -245,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) From 4843050007423572c8fddfb3c5c2317c36785a12 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Fri, 18 Aug 2017 17:47:01 +0300 Subject: [PATCH 20/31] Fix features failing to execute on the issuer when execution on equally prioritized players is disabled --- srcds/addons/source-python/plugins/admin/core/features.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srcds/addons/source-python/plugins/admin/core/features.py b/srcds/addons/source-python/plugins/admin/core/features.py index 8b5fa54..87c28f6 100644 --- a/srcds/addons/source-python/plugins/admin/core/features.py +++ b/srcds/addons/source-python/plugins/admin/core/features.py @@ -72,7 +72,7 @@ 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] From bbcb875d9f51ea0643948c516527e9d18f0beac8 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Sun, 20 Aug 2017 19:10:35 +0300 Subject: [PATCH 21/31] Add console_message and chat_message helpers --- srcds/addons/source-python/plugins/admin/admin.py | 5 +++-- .../source-python/plugins/admin/core/clients.py | 11 +---------- .../source-python/plugins/admin/core/helpers.py | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/srcds/addons/source-python/plugins/admin/admin.py b/srcds/addons/source-python/plugins/admin/admin.py index d920a38..9128958 100644 --- a/srcds/addons/source-python/plugins/admin/admin.py +++ b/srcds/addons/source-python/plugins/admin/admin.py @@ -10,6 +10,7 @@ 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 main_menu @@ -32,13 +33,13 @@ 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']) # ============================================================================= diff --git a/srcds/addons/source-python/plugins/admin/core/clients.py b/srcds/addons/source-python/plugins/admin/core/clients.py index 29860eb..082c230 100644 --- a/srcds/addons/source-python/plugins/admin/core/clients.py +++ b/srcds/addons/source-python/plugins/admin/core/clients.py @@ -87,13 +87,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/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) From 71ea5acc93bd2b05c3cbab0cc07a097f9f877b2f Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Sun, 20 Aug 2017 19:12:00 +0300 Subject: [PATCH 22/31] Add console_message and chat_message helpers (2) --- srcds/addons/source-python/plugins/admin/core/clients.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/srcds/addons/source-python/plugins/admin/core/clients.py b/srcds/addons/source-python/plugins/admin/core/clients.py index 082c230..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) From 785d9ee580afaf6c2f0622e78931fa94e866b40a Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Sun, 20 Aug 2017 22:59:44 +0300 Subject: [PATCH 23/31] Remove left-over --- .../included/admin_kick_ban/admin_kick_ban.py | 15 --------------- 1 file changed, 15 deletions(-) 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 c2fbea6..d9491ac 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 @@ -78,21 +78,6 @@ class _KickPage(PlayerBasedFeaturePage): 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, From feb9b457d9fdafe1e38ef5ac2a5e4d5c7f85b2ed Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Mon, 21 Aug 2017 02:33:44 +0300 Subject: [PATCH 24/31] Split PlayerBasedFeatureCommand in 2 classes --- .../plugins/admin/core/frontends/commands.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/srcds/addons/source-python/plugins/admin/core/frontends/commands.py b/srcds/addons/source-python/plugins/admin/core/frontends/commands.py index 3e105cf..00e39f6 100644 --- a/srcds/addons/source-python/plugins/admin/core/frontends/commands.py +++ b/srcds/addons/source-python/plugins/admin/core/frontends/commands.py @@ -121,15 +121,10 @@ def client_callback(command_info): return client_callback -class PlayerBasedFeatureCommand(BaseFeatureCommand): - def __init__(self, commands, feature, deny_mass_execution=False): - super().__init__(commands, feature) - - self._deny_mass_execution = deny_mass_execution - - def _execute(self, command_info, filter_str, filter_args): - client = clients[command_info.index] +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): @@ -139,10 +134,18 @@ def _execute(self, command_info, filter_str, filter_args): players.append(player) - if self._deny_mass_execution and len(players) > 1: - return + 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): - for player in players: client.sync_execution(self.feature.execute, (client, player)) def _get_public_chat_callback(self): From c765c63f17721645a841b49e5b2fe2efa7c6f053 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Mon, 21 Aug 2017 02:34:03 +0300 Subject: [PATCH 25/31] Split PlayerBasedFeature in 2 classes --- .../plugins/admin/core/features.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/srcds/addons/source-python/plugins/admin/core/features.py b/srcds/addons/source-python/plugins/admin/core/features.py index 87c28f6..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. @@ -77,3 +69,15 @@ def filter(self, client, player): 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 From 39ff195a5246de64e54bd10ea7e877be27eb86b9 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Mon, 21 Aug 2017 02:34:26 +0300 Subject: [PATCH 26/31] Add command frontend to Admin Tracking plugin --- .../included/admin_tracking/admin_tracking.py | 555 ++++++++++++++---- .../admin_tracking/config.ini | 3 + .../admin/included_plugins/admin_tracking.ini | 28 +- 3 files changed, 482 insertions(+), 104 deletions(-) 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 dd90e46..9cbfbf6 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 @@ -18,9 +19,13 @@ # Source.Python Admin 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 ( 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 @@ -32,7 +37,7 @@ # ============================================================================= # >> FUNCTIONS # ============================================================================= -def remove_old_database_records(): +def _remove_old_database_records(): with SessionContext() as session: max_record_life_seconds = ( int(plugin_config['database']['max_record_life_days']) * 24 * 3600) @@ -47,6 +52,98 @@ def remove_old_database_records(): 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) + + 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 + + # ============================================================================= # >> GLOBAL VARIABLES # ============================================================================= @@ -58,6 +155,8 @@ def remove_old_database_records(): plugin_strings = PluginStrings("admin_tracking") +_last_shown_records = PlayerDictionary(lambda index: None) + # ============================================================================= # >> CLASSES @@ -140,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 @@ -167,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) ), @@ -188,7 +288,7 @@ def build_callback(popup, index): popup.append(PagedOption( text=text, - value=record + value=(i, record) )) @self.record_popup.register_select_callback @@ -200,31 +300,32 @@ def select_callback(popup, index, option): @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_records[index].seen_at) + self._selected_records[index][1].seen_at) ), - name=format_player_name(self._selected_records[index].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_records[index].name, # Non-formatted name + name=self._selected_records[index][1].name, ))) popup.append(Text(plugin_strings['popup_text steamid'].tokenized( - steamid=self._selected_records[index].steamid, + steamid=self._selected_records[index][1].steamid, ))) popup.append(Text( plugin_strings['popup_text ip_address'].tokenized( - ip_address=self._selected_records[index].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_records[index].ip_address), + ip_address=self._selected_records[index][1].ip_address), value=( _TrackPopupOption.SEARCH_BY_IP, - self._selected_records[index].ip_address + self._selected_records[index][1].ip_address ) )) @@ -240,92 +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 - 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: - 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 - 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) - - 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) @@ -350,24 +373,356 @@ def execute(self, client, player): track_popup_feature = _TrackPopupFeature() -class _TrackMenuCommand(PlayerBasedMenuCommand): +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(MenuSection( main_menu, plugin_strings['section_title'])) -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'] @@ -377,7 +732,7 @@ class _TrackMenuCommand(PlayerBasedMenuCommand): # ============================================================================= # >> SYNCHRONOUS DATABASE OPERATIONS # ============================================================================= -remove_old_database_records() +_remove_old_database_records() # ============================================================================= 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_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="Фильтр игроков нашёл либо несколько игроков, либо не нашёл никого" From 2f9dae958c203e6a4fef0d4d28edb3393f37fa36 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Mon, 21 Aug 2017 03:01:11 +0300 Subject: [PATCH 27/31] Change command front end. amenu -> "spa menu", ascreen -> "spa motd" --- srcds/addons/source-python/plugins/admin/admin.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/srcds/addons/source-python/plugins/admin/admin.py b/srcds/addons/source-python/plugins/admin/admin.py index 9128958..03e4f64 100644 --- a/srcds/addons/source-python/plugins/admin/admin.py +++ b/srcds/addons/source-python/plugins/admin/admin.py @@ -45,15 +45,15 @@ def 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) From 1f83d98dbfe71f3ee6160f91734cbe058858e5eb Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Mon, 21 Aug 2017 03:24:52 +0300 Subject: [PATCH 28/31] Add front end table to readme.md --- readme.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/readme.md b/readme.md index 0bd686d..c99d121 100644 --- a/readme.md +++ b/readme.md @@ -4,6 +4,23 @@ 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: @@ -41,3 +58,23 @@ Where *player filter* is one of the following: - `/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. From 66c76856765676bec4754336badb56a99e6fc718 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Mon, 21 Aug 2017 07:52:14 +0300 Subject: [PATCH 29/31] Set constant order of the entries in the main menu --- .../plugins/admin/core/frontends/menus.py | 16 ++++++++++++++-- .../admin_comm_management.py | 3 ++- .../included/admin_kick_ban/admin_kick_ban.py | 2 +- .../admin_life_management.py | 2 +- .../admin_team_management.py | 2 +- .../included/admin_tracking/admin_tracking.py | 2 +- srcds/cfg/source-python/admin/config.ini | 3 +++ 7 files changed, 23 insertions(+), 7 deletions(-) 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 b6b8573..d3fc6f7 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 @@ -144,8 +145,10 @@ def select(self, client): client.send_popup(self.popup) -# Main section -main_menu = MenuSection(None, strings_common['title main'], 'admin') + 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 -1)) class MenuCommand(MenuEntry): @@ -542,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/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 index 9e4a511..5ba7ec9 100644 --- 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 @@ -21,7 +21,7 @@ # >> MENU ENTRIES # ============================================================================= menu_section = main_menu.add_entry(MenuSection( - main_menu, plugin_strings['section_title main'])) + main_menu, plugin_strings['section_title main'], 'comm_management')) menu_section_chat = menu_section.add_entry(MenuSection( menu_section, plugin_strings['section_title chat'])) @@ -59,6 +59,7 @@ menu_section_voice, plugin_strings['popup_title unblock_voice'])) + # ============================================================================= # >> SYNCHRONOUS DATABASE OPERATIONS # ============================================================================= 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 d9491ac..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 @@ -70,7 +70,7 @@ class _KickPage(PlayerBasedFeaturePage): # >> MENU ENTRIES # ============================================================================= menu_section = main_menu.add_entry(MenuSection( - main_menu, plugin_strings['section_title main'])) + main_menu, plugin_strings['section_title main'], 'kick_ban')) menu_section_steamid = menu_section.add_entry(MenuSection( menu_section, plugin_strings['section_title steamid_bans'])) 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 9c7f806..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 @@ -112,7 +112,7 @@ def on_error(self, error): # >> MENU ENTRIES # ============================================================================= menu_section = main_menu.add_entry(MenuSection( - main_menu, plugin_strings['section_title'])) + main_menu, plugin_strings['section_title'], 'life_management')) slay_menu_command = menu_section.add_entry(PlayerBasedMenuCommand( slay_feature, 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 7838abf..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 @@ -100,7 +100,7 @@ class _DelayedMoveToCTFeature(_DelayedMoveToTeamFeature): # >> MENU ENTRIES # ============================================================================= menu_section = main_menu.add_entry(MenuSection( - main_menu, plugin_strings['section_title'])) + main_menu, plugin_strings['section_title'], 'team_management')) move_to_spec_menu_command = menu_section.add_entry(PlayerBasedMenuCommand( move_to_spec_feature, 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 9cbfbf6..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 @@ -720,7 +720,7 @@ def message_func(message): # >> MENU ENTRIES # ============================================================================= menu_section = main_menu.add_entry(MenuSection( - main_menu, plugin_strings['section_title'])) + main_menu, plugin_strings['section_title'], 'tracking')) track_menu_command = menu_section.add_entry(_TrackPopupMenuCommand( track_popup_feature, 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 From 3ba93bef49144921b7f109e861ac52a918a3d1d1 Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Mon, 21 Aug 2017 08:43:12 +0300 Subject: [PATCH 30/31] Unknown entries should go to the end of the menu --- .../source-python/plugins/admin/core/frontends/menus.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 d3fc6f7..9bfdd76 100644 --- a/srcds/addons/source-python/plugins/admin/core/frontends/menus.py +++ b/srcds/addons/source-python/plugins/admin/core/frontends/menus.py @@ -100,7 +100,7 @@ def add_entry(self, entry): """ 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 @@ -148,7 +148,7 @@ def select(self, client): 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 -1)) + if entry_.id in self.order else 999)) class MenuCommand(MenuEntry): From cead3639bab2acce9da55a4e7f196c750160b27f Mon Sep 17 00:00:00 2001 From: KirillMysnik Date: Mon, 21 Aug 2017 09:10:33 +0300 Subject: [PATCH 31/31] Fix command front end not unregistering its callback when admin included/custom plugin is unloaded --- .../plugins/admin/core/frontends/commands.py | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/srcds/addons/source-python/plugins/admin/core/frontends/commands.py b/srcds/addons/source-python/plugins/admin/core/frontends/commands.py index 00e39f6..f6b799a 100644 --- a/srcds/addons/source-python/plugins/admin/core/frontends/commands.py +++ b/srcds/addons/source-python/plugins/admin/core/frontends/commands.py @@ -4,6 +4,7 @@ # Source.Python from commands import CommandReturn from commands.typed import TypedClientCommand, TypedSayCommand +from core import AutoUnload from filters.players import PlayerIter # Source.Python Admin @@ -61,7 +62,7 @@ def iter_filter_targets(filter_str, filter_args, issuer): # ============================================================================= # >> CLASSES # ============================================================================= -class BaseFeatureCommand: +class BaseFeatureCommand(AutoUnload): def __init__(self, commands, feature): if isinstance(commands, str): commands = [commands, ] @@ -70,17 +71,21 @@ def __init__(self, commands, feature): self.feature = feature - TypedSayCommand( + self._public_chat_command = TypedSayCommand( ['!spa', ] + commands, feature.flag - )(self._get_public_chat_callback()) + ) - TypedSayCommand( + self._private_chat_command = TypedSayCommand( ['/spa', ] + commands, feature.flag - )(self._get_private_chat_callback()) + ) - TypedClientCommand( + self._client_command = TypedClientCommand( ['spa', ] + commands, feature.flag - )(self._get_client_callback()) + ) + + 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 @@ -91,6 +96,11 @@ def _get_private_chat_callback(self): 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):