Skip to content

Commit e662eee

Browse files
author
KirillMysnik
committed
Fixed an a bug in bans / tracking popups that'd lead to conflicts when multiple admins use these popups at the same time
1 parent bf2af77 commit e662eee

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

srcds/addons/source-python/plugins/admin/plugins/included/admin_kick_ban/bans/base.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# Source.Python
1010
from listeners.tick import GameThread
1111
from menus import PagedMenu, PagedOption, SimpleMenu, SimpleOption, Text
12+
from players.dictionary import PlayerDictionary
1213
from players.helpers import get_client_language
1314
from steam import SteamID
1415
from translations.manager import language_manager
@@ -380,7 +381,7 @@ class LiftAnyBanPopupFeature(Feature):
380381

381382
def __init__(self):
382383
# (_BannedPlayerInfo instance, whether confirmed or not)
383-
self._selected_ban = (None, False)
384+
self._selected_bans = PlayerDictionary(lambda index: (None, False))
384385

385386
self.ban_popup = PagedMenu(title=self.popup_title)
386387
self.confirm_popup = SimpleMenu()
@@ -402,41 +403,41 @@ def build_callback(popup, index):
402403

403404
@self.ban_popup.register_select_callback
404405
def select_callback(popup, index, option):
405-
self._selected_ban = option.value
406+
self._selected_bans[index] = option.value
406407
clients[index].send_popup(self.confirm_popup)
407408

408409
@self.confirm_popup.register_build_callback
409410
def build_callback(popup, index):
410411
popup.clear()
411412

412413
popup.append(Text(plugin_strings['ban_record'].tokenized(
413-
name=self._selected_ban[0].name,
414-
id=self._selected_ban[0].uniqueid
414+
name=self._selected_bans[index][0].name,
415+
id=self._selected_bans[index][0].uniqueid
415416
)))
416417

417418
popup.append(Text(
418419
plugin_strings['ban_record admin_steamid'].tokenized(
419-
admin_steamid=self._selected_ban[0].banned_by)))
420+
admin_steamid=self._selected_bans[index][0].banned_by)))
420421

421422
popup.append(Text(plugin_strings['ban_record reason'].tokenized(
422-
reason=self._selected_ban[0].reason)))
423+
reason=self._selected_bans[index][0].reason)))
423424

424-
if self._selected_ban[0].notes:
425+
if self._selected_bans[index][0].notes:
425426
popup.append(Text(plugin_strings['ban_record notes'].tokenized(
426-
notes=self._selected_ban[0].notes)))
427+
notes=self._selected_bans[index][0].notes)))
427428

428429
popup.append(Text(
429430
plugin_strings['lift_reviewed_ban_confirmation']))
430431

431432
popup.append(SimpleOption(
432433
choice_index=1,
433434
text=plugin_strings['lift_reviewed_ban_confirmation no'],
434-
value=(self._selected_ban[0], False),
435+
value=(self._selected_bans[index][0], False),
435436
))
436437
popup.append(SimpleOption(
437438
choice_index=2,
438439
text=plugin_strings['lift_reviewed_ban_confirmation yes'],
439-
value=(self._selected_ban[0], True),
440+
value=(self._selected_bans[index][0], True),
440441
))
441442

442443
@self.confirm_popup.register_select_callback
@@ -498,15 +499,13 @@ class ReviewBanPopupFeature(Feature):
498499

499500
def __init__(self):
500501
# (_BannedPlayerInfo instance, reason, duration)
501-
self._selected_ban = (None, "", -1)
502+
self._selected_bans = PlayerDictionary(lambda index: (None, "", -1))
502503

503504
self.ban_popup = PagedMenu(title=self.popup_title)
504505
self.reason_popup = PagedMenu(title=self.popup_title,
505506
parent_menu=self.ban_popup)
506507

507-
# We do not allow returning back to reason popup from duration popup,
508-
# because we won't have valid self._selected_ban to build a reason
509-
# popup with. Hence we don't provide parent_menu here.
508+
# TODO: Provide parent menu
510509
self.duration_popup = PagedMenu(title=self.popup_title)
511510

512511
@self.ban_popup.register_build_callback
@@ -527,7 +526,7 @@ def build_callback(popup, index):
527526

528527
@self.ban_popup.register_select_callback
529528
def select_callback(popup, index, option):
530-
self._selected_ban = option.value
529+
self._selected_bans[index] = option.value
531530
clients[index].send_popup(self.reason_popup)
532531

533532
@self.reason_popup.register_build_callback
@@ -538,7 +537,7 @@ def build_callback(popup, index):
538537
popup.append(PagedOption(
539538
text=stock_ban_reason.translation,
540539
value=(
541-
self._selected_ban[0],
540+
self._selected_bans[index][0],
542541
stock_ban_reason.translation.get_string(
543542
language_manager.default),
544543
stock_ban_reason.duration,
@@ -547,26 +546,27 @@ def build_callback(popup, index):
547546

548547
@self.reason_popup.register_select_callback
549548
def select_callback(popup, index, option):
550-
self._selected_ban = option.value
549+
self._selected_bans[index] = option.value
551550
clients[index].send_popup(self.duration_popup)
552551

553552
@self.duration_popup.register_build_callback
554553
def build_callback(popup, index):
555554
popup.clear()
556555

557-
if self._selected_ban[2] is not None:
556+
if self._selected_bans[index][2] is not None:
558557
popup.append(PagedOption(
559558
text=plugin_strings['default_duration'].tokenized(
560-
default=format_ban_duration(self._selected_ban[2])),
561-
value=self._selected_ban
559+
default=format_ban_duration(
560+
self._selected_bans[index][2])),
561+
value=self._selected_bans[index]
562562
))
563563

564564
for stock_ban_duration in stock_ban_durations:
565565
popup.append(PagedOption(
566566
text=format_ban_duration(stock_ban_duration),
567567
value=(
568-
self._selected_ban[0],
569-
self._selected_ban[1],
568+
self._selected_bans[index][0],
569+
self._selected_bans[index][1],
570570
stock_ban_duration,
571571
)
572572
))
@@ -597,7 +597,7 @@ class SearchBadBansPopupFeature(Feature):
597597

598598
def __init__(self):
599599
# (_BannedPlayerInfo instance, whether to remove or not)
600-
self._selected_ban = None
600+
self._selected_bans = PlayerDictionary(lambda index: (None, False))
601601

602602
self.ban_popup = PagedMenu(title=self.popup_title)
603603
self.remove_popup = SimpleMenu()
@@ -620,38 +620,38 @@ def build_callback(popup, index):
620620

621621
@self.ban_popup.register_select_callback
622622
def select_callback(popup, index, option):
623-
self._selected_ban = option.value
623+
self._selected_bans[index] = option.value
624624
clients[index].send_popup(self.remove_popup)
625625

626626
@self.remove_popup.register_build_callback
627627
def build_callback(popup, index):
628628
popup.clear()
629629

630630
popup.append(Text(plugin_strings['ban_record'].tokenized(
631-
name=self._selected_ban[0].name,
632-
id=self._selected_ban[0].uniqueid
631+
name=self._selected_bans[index][0].name,
632+
id=self._selected_bans[index][0].uniqueid
633633
)))
634634

635635
popup.append(Text(
636636
plugin_strings['ban_record admin_steamid'].tokenized(
637-
admin_steamid=self._selected_ban[0].banned_by)))
637+
admin_steamid=self._selected_bans[index][0].banned_by)))
638638

639-
if self._selected_ban[0].notes:
639+
if self._selected_bans[index][0].notes:
640640
popup.append(Text(plugin_strings['ban_record notes'].tokenized(
641-
notes=self._selected_ban[0].notes)))
641+
notes=self._selected_bans[index][0].notes)))
642642

643643
popup.append(Text(
644644
plugin_strings['remove_bad_ban_confirmation']))
645645

646646
popup.append(SimpleOption(
647647
choice_index=1,
648648
text=plugin_strings['remove_bad_ban_confirmation no'],
649-
value=(self._selected_ban[0], False),
649+
value=(self._selected_bans[index][0], False),
650650
))
651651
popup.append(SimpleOption(
652652
choice_index=2,
653653
text=plugin_strings['remove_bad_ban_confirmation yes'],
654-
value=(self._selected_ban[0], True),
654+
value=(self._selected_bans[index][0], True),
655655
))
656656

657657
@self.remove_popup.register_select_callback

srcds/addons/source-python/plugins/admin/plugins/included/admin_tracking/admin_tracking.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class _TrackPopupFeature(PlayerBasedFeature):
162162
allow_execution_on_equal_priority = True
163163

164164
def __init__(self):
165-
self._selected_record = None
165+
self._selected_records = PlayerDictionary(lambda index: None)
166166
self._records_to_show = None
167167

168168
self.record_popup = PagedMenu(
@@ -199,36 +199,36 @@ def build_callback(popup, index):
199199
def select_callback(popup, index, option):
200200
client = clients[index]
201201

202-
self._selected_record = option.value
202+
self._selected_records[index] = option.value
203203
client.send_popup(self.track_popup)
204204

205205
@self.track_popup.register_build_callback
206206
def build_callback(popup, index):
207207
popup.title = plugin_strings['popup_title record_title'].tokenized(
208208
seen_at=strftime(
209209
"%d %b %Y %H:%M:%S", localtime(
210-
self._selected_record.seen_at)
210+
self._selected_records[index].seen_at)
211211
),
212-
name=format_player_name(self._selected_record.name)
212+
name=format_player_name(self._selected_records[index].name)
213213
)
214214

215215
popup.clear()
216216
popup.append(Text(plugin_strings['popup_text name'].tokenized(
217-
name=self._selected_record.name, # Non-formatted name
217+
name=self._selected_records[index].name, # Non-formatted name
218218
)))
219219
popup.append(Text(plugin_strings['popup_text steamid'].tokenized(
220-
steamid=self._selected_record.steamid,
220+
steamid=self._selected_records[index].steamid,
221221
)))
222222
popup.append(Text(
223223
plugin_strings['popup_text ip_address'].tokenized(
224-
ip_address=self._selected_record.ip_address,
224+
ip_address=self._selected_records[index].ip_address,
225225
)))
226226
popup.append(PagedOption(
227227
text=plugin_strings['popup_title search_for_ip'].tokenized(
228-
ip_address=self._selected_record.ip_address),
228+
ip_address=self._selected_records[index].ip_address),
229229
value=(
230230
_TrackPopupOption.SEARCH_BY_IP,
231-
self._selected_record.ip_address
231+
self._selected_records[index].ip_address
232232
)
233233
))
234234

0 commit comments

Comments
 (0)