Skip to content

Commit e63400b

Browse files
committed
CHANGES:
- Mission: better messages for ban avoidance
1 parent d63b970 commit e63400b

File tree

5 files changed

+84
-48
lines changed

5 files changed

+84
-48
lines changed

core/utils/os.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -313,30 +313,31 @@ def shouldRollover(self, record):
313313
return 0
314314

315315

316+
class SHELLEXECUTEINFO(ctypes.Structure):
317+
_fields_ = [
318+
("cbSize", ctypes.c_ulong),
319+
("fMask", ctypes.c_ulong),
320+
("hwnd", ctypes.c_void_p),
321+
("lpVerb", ctypes.c_wchar_p),
322+
("lpFile", ctypes.c_wchar_p),
323+
("lpParameters", ctypes.c_wchar_p),
324+
("lpDirectory", ctypes.c_wchar_p),
325+
("nShow", ctypes.c_int),
326+
("hInstApp", ctypes.c_void_p),
327+
("lpIDList", ctypes.c_void_p),
328+
("lpClass", ctypes.c_wchar_p),
329+
("hkeyClass", ctypes.c_void_p),
330+
("dwHotKey", ctypes.c_ulong),
331+
("hIcon", ctypes.c_void_p),
332+
("hProcess", ctypes.c_void_p),
333+
]
334+
335+
316336
def run_elevated(exe_path, cwd, *args):
317337
"""Start *exe_path* as Administrator and return the return code."""
318338
if sys.platform != 'win32':
319339
return -1
320340

321-
class SHELLEXECUTEINFO(ctypes.Structure):
322-
_fields_ = [
323-
("cbSize", ctypes.c_ulong),
324-
("fMask", ctypes.c_ulong),
325-
("hwnd", ctypes.c_void_p),
326-
("lpVerb", ctypes.c_wchar_p),
327-
("lpFile", ctypes.c_wchar_p),
328-
("lpParameters", ctypes.c_wchar_p),
329-
("lpDirectory", ctypes.c_wchar_p),
330-
("nShow", ctypes.c_int),
331-
("hInstApp", ctypes.c_void_p),
332-
("lpIDList", ctypes.c_void_p),
333-
("lpClass", ctypes.c_wchar_p),
334-
("hkeyClass", ctypes.c_void_p),
335-
("dwHotKey", ctypes.c_ulong),
336-
("hIcon", ctypes.c_void_p),
337-
("hProcess", ctypes.c_void_p),
338-
]
339-
340341
sei = SHELLEXECUTEINFO()
341342
sei.cbSize = ctypes.sizeof(sei)
342343
sei.fMask = SEE_MASK_NOCLOSEPROCESS

plugins/mission/commands.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,8 +2278,12 @@ async def on_interaction(self, interaction: discord.Interaction):
22782278
# noinspection PyUnresolvedReferences
22792279
await interaction.response.edit_message(view=None)
22802280
elif custom_id.startswith('ban_'):
2281-
ucid = custom_id[len('ban_'):]
2282-
await self.bus.ban(ucid, interaction.user.display_name, _("Inappropriate nickname"))
2281+
if custom_id.startswith('ban_profanity_'):
2282+
ucid = custom_id[len('ban_profanity_'):]
2283+
await self.bus.ban(ucid, interaction.user.display_name, _("Inappropriate nickname"))
2284+
elif custom_id.startswith('ban_evade_'):
2285+
ucid = custom_id[len('ban_evade_'):]
2286+
await self.bus.ban(ucid, interaction.user.display_name, _("Trying to evade a ban with a 2nd account."))
22832287
# noinspection PyUnresolvedReferences
22842288
await interaction.response.edit_message(view=None)
22852289
elif custom_id == 'cancel':

plugins/mission/listener.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
from core import utils, EventListener, PersistentReport, Plugin, Report, Status, Side, Player, Coalition, \
99
Channel, DataObjectFactory, event, chat_command, ServiceRegistry, ChatCommand, get_translation
1010
from datetime import datetime, timezone
11+
from discord import ButtonStyle
1112
from discord.ext import tasks
13+
from discord.ui import View, Button
1214
from pathlib import Path
1315
from psycopg.rows import dict_row
1416
from services.servicebus import ServiceBus
1517
from services.bot.dummy import DummyBot
1618
from typing import TYPE_CHECKING, Callable, Coroutine
1719

1820
from .menu import read_menu_config, filter_menu
19-
from .views import ProfanityView
2021

2122
if TYPE_CHECKING:
2223
from core import Server
@@ -654,7 +655,49 @@ async def onCensoredPlayerName(self, server: Server, data: dict) -> None:
654655
else:
655656
message = _("User {} (ucid={})\nPotentially inappropriate nickname.").format(
656657
data['name'], data['ucid'])
657-
view = ProfanityView(ucid=data['ucid'], name=data['name'])
658+
659+
view = View(timeout=None)
660+
# noinspection PyTypeChecker
661+
button = Button(label="Whitelist", style=ButtonStyle.primary, custom_id=f"whitelist_{data['name']}")
662+
view.add_item(button)
663+
# noinspection PyTypeChecker
664+
button = Button(label="Ban", style=ButtonStyle.red, custom_id=f"ban_profanity_{data['ucid']}")
665+
view.add_item(button)
666+
# noinspection PyTypeChecker
667+
button = Button(label="Cancel", style=ButtonStyle.secondary, custom_id=f"cancel")
668+
view.add_item(button)
669+
await admin_channel.send(f"```{message}```", view=view)
670+
671+
@event(name="onBanReject")
672+
async def onBanReject(self, server: Server, data: dict) -> None:
673+
admin_channel = self.bot.get_admin_channel(server)
674+
if not admin_channel:
675+
return
676+
message = _('Banned user {name} (ucid={ucid}, ipaddr={ipaddr}) rejected. Reason: {reason}').format(
677+
name=data['name'], ucid=data['ucid'], ipaddr=data['ipaddr'], reason=data['reason'])
678+
await admin_channel.send(f"```{message}```")
679+
680+
@event(name="onBanEvade")
681+
async def onBanEvade(self, server: Server, data: dict) -> None:
682+
admin_channel = self.bot.get_admin_channel(server)
683+
if not admin_channel:
684+
return
685+
old_name = await self.bot.get_member_or_name_by_ucid(data['old_ucid'])
686+
if isinstance(old_name, discord.Member):
687+
old_name = old_name.display_name
688+
689+
message = _('Player {name} (ucid={ucid}) connected from the same IP (ipaddr={ipaddr}) '
690+
'as banned player {old_name} (ucid={old_ucid}), who was banned for {reason}!').format(
691+
name=data['name'], ucid=data['ucid'], ipaddr=data['ipaddr'], old_name=old_name,
692+
old_ucid=data['old_ucid'], reason=data['reason']
693+
)
694+
view = View(timeout=None)
695+
# noinspection PyTypeChecker
696+
button = Button(label="Ban", style=ButtonStyle.red, custom_id=f"ban_evade_{data['ucid']}")
697+
view.add_item(button)
698+
# noinspection PyTypeChecker
699+
button = Button(label="Cancel", style=ButtonStyle.secondary, custom_id=f"cancel")
700+
view.add_item(button)
658701
await admin_channel.send(f"```{message}```", view=view)
659702

660703
async def _stop_player(self, server: Server, player: Player):

plugins/mission/lua/callbacks.lua

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,21 @@ function mission.onPlayerTryConnect(addr, name, ucid, playerID)
125125
log.write('DCSServerBot', log.DEBUG, 'Mission: Smart Bans disabled')
126126
end
127127
local msg = {
128-
command = 'sendMessage',
129-
message = 'Banned user ' .. name .. ' (ucid=' .. ucid .. ', ipaddr=' .. ipaddr .. ') rejected. Reason: ' .. dcsbot.banList[ucid]
128+
command = 'onBanReject',
129+
ucid = ucid,
130+
ipaddr = ipaddr,
131+
reason = dcsbot.banList[ucid]
130132
}
131133
utils.sendBotTable(msg, config.channels.admin)
132134
return false, string.gsub(config['messages']['message_ban'], "{}", dcsbot.banList[ucid])
133135
elseif isBanned(ipaddr) and dcsbot.banList[dcsbot.banList[ipaddr]] then
134136
local old_ucid = dcsbot.banList[ipaddr]
135137
local msg = {
136-
command = 'sendMessage',
137-
message = 'Player ' .. name .. ' (ucid=' .. ucid .. ') connected from the same IP (ipaddr=' .. ipaddr .. ') as banned player (ucid=' .. old_ucid .. '), who was banned for ' .. dcsbot.banList[old_ucid] ..'!',
138-
mention = 'DCS Admin'
138+
command = 'onBanEvade',
139+
ucid = ucid,
140+
ipaddr = ipaddr,
141+
old_ucid = old_ucid,
142+
reason = dcsbot.banList[old_ucid]
139143
}
140144
utils.sendBotTable(msg, config.channels.admin)
141145
return false, string.gsub(config.messages.message_ban, "{}", dcsbot.banList[old_ucid])
@@ -152,7 +156,7 @@ function mission.onPlayerTryConnect(addr, name, ucid, playerID)
152156
ucid = ucid,
153157
name = name
154158
}
155-
utils.sendBotTable(msg, config.channels.admin)
159+
utils.sendBotTable(msg)
156160
if config.no_join_with_cursename then
157161
return false, config.messages.message_player_inappropriate_username
158162
end

plugins/mission/views.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
import os
44

55
from contextlib import suppress
6-
from core import Server, Report, Status, ReportEnv, Player, Member, DataObjectFactory, utils, ServiceRegistry, \
7-
get_translation
6+
from core import Server, Report, Status, ReportEnv, Player, Member, DataObjectFactory, utils, get_translation
87
from discord import SelectOption, ButtonStyle
9-
from discord.ui import View, Select, Button, Modal, TextInput
8+
from discord.ui import View, Select, Button
109
from io import StringIO
1110
from ruamel.yaml import YAML
1211
from typing import cast
1312

14-
from services.bot import DCSServerBot, BotService
15-
from services.servicebus import ServiceBus
13+
from services.bot import DCSServerBot
1614

1715
WARNING_ICON = "https://github.com/Special-K-s-Flightsim-Bots/DCSServerBot/blob/master/images/warning.png?raw=true"
1816
_ = get_translation(__name__.split('.')[1])
@@ -462,17 +460,3 @@ async def cancel(self, interaction: discord.Interaction):
462460
# noinspection PyUnresolvedReferences
463461
await interaction.response.defer()
464462
self.stop()
465-
466-
467-
class ProfanityView(View):
468-
def __init__(self, ucid: str, name: str):
469-
super().__init__(timeout=None)
470-
# noinspection PyTypeChecker
471-
button = Button(label="Whitelist", style=ButtonStyle.primary, custom_id=f"whitelist_{name}")
472-
self.add_item(button)
473-
# noinspection PyTypeChecker
474-
button = Button(label="Ban", style=ButtonStyle.red, custom_id=f"ban_{ucid}")
475-
self.add_item(button)
476-
# noinspection PyTypeChecker
477-
button = Button(label="Cancel", style=ButtonStyle.secondary, custom_id=f"cancel")
478-
self.add_item(button)

0 commit comments

Comments
 (0)