Skip to content

Commit a0e9a9a

Browse files
committed
CHANGES:
- Profanity filter will block bad nicknames also now (if enabled) BUGFIXES: - Profanity filter could be overwritten with different configurations for different servers.
1 parent b176ea1 commit a0e9a9a

File tree

7 files changed

+102
-91
lines changed

7 files changed

+102
-91
lines changed

core/data/impl/instanceimpl.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import luadata
21
import os
32
import psycopg
4-
import shutil
53

64
from core import Instance, InstanceBusyError, Status, utils, DataObjectFactory
75
from dataclasses import dataclass
@@ -125,24 +123,3 @@ def prepare(self):
125123
if os.path.exists(filename):
126124
utils.desanitize(self, filename)
127125
break
128-
# Profanity filter
129-
if self.server and self.server.locals.get('profanity_filter', False):
130-
language = self.node.config.get('language', 'en')
131-
wordlist = os.path.join(self.node.config_dir, 'profanity.txt')
132-
if not os.path.exists(wordlist):
133-
shutil.copy2(os.path.join('samples', 'wordlists', f"{language}.txt"), wordlist)
134-
with open(wordlist, mode='r', encoding='utf-8') as wl:
135-
words = [x.strip() for x in wl.readlines() if not x.startswith('#')]
136-
targetfile = os.path.join(os.path.expandvars(self.node.locals['DCS']['installation']), 'Data', 'censor.lua')
137-
bakfile = targetfile.replace('.lua', '.bak')
138-
if not os.path.exists(bakfile):
139-
shutil.copy2(targetfile, bakfile)
140-
with open(targetfile, mode='wb') as outfile:
141-
outfile.write((f"{language.upper()} = " + luadata.serialize(
142-
words, indent='\t', indent_level=0)).encode('utf-8'))
143-
else:
144-
targetfile = os.path.join(os.path.expandvars(self.node.locals['DCS']['installation']), 'Data', 'censor.lua')
145-
bakfile = targetfile.replace('.lua', '.bak')
146-
if os.path.exists(bakfile):
147-
shutil.copy2(bakfile, targetfile)
148-
os.remove(bakfile)

core/data/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def read_locals(self) -> dict:
8787
"message_server_locked": "This server is currently locked and cannot be joined.",
8888
"message_player_default_username": "Please change your default player name at the top right of the multiplayer selection list to an individual one!",
8989
"message_player_username": "Your player name contains invalid characters. Please change your name to join our server.",
90+
"message_player_inappropriate_username": "Your username is inappropriate and needs to be changed to join this server.",
9091
"message_ban": "You are banned from this server. Reason: {}",
9192
"message_reserved": "This server is locked for specific users.\nPlease contact a server admin.",
9293
"message_no_voice": 'You need to be in voice channel "{}" to use this server!',

core/utils/dcs.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"create_writable_mission",
2424
"get_orig_file",
2525
"lua_pattern_to_python_regex",
26-
"format_frequency"
26+
"format_frequency",
27+
"init_profanity_filter"
2728
]
2829

2930

@@ -71,6 +72,7 @@ def desanitize(self, _filename: str = None) -> None:
7172
except PermissionError:
7273
self.log.error(f"Can't desanitize {filename}, no write permissions!")
7374
raise
75+
7476
backup = filename.replace('.lua', '.bak')
7577
if os.path.exists(os.path.join(self.node.config_dir, 'MissionScripting.lua')):
7678
if _filename:
@@ -155,17 +157,15 @@ def create_writable_mission(filename: str) -> str:
155157
filename = filename[:-5]
156158
try:
157159
with open(filename, mode='a'):
158-
new_filename = filename
160+
return filename
159161
except PermissionError:
160162
if '.dcssb' in filename:
161-
new_filename = os.path.join(os.path.dirname(filename).replace('.dcssb', ''),
162-
os.path.basename(filename))
163+
return os.path.join(os.path.dirname(filename).replace('.dcssb', ''),
164+
os.path.basename(filename))
163165
else:
164166
dirname = os.path.join(os.path.dirname(filename), '.dcssb')
165167
os.makedirs(dirname, exist_ok=True)
166-
new_filename = os.path.join(dirname, os.path.basename(filename))
167-
return new_filename
168-
168+
return os.path.join(dirname, os.path.basename(filename))
169169

170170
def get_orig_file(filename: str, *, create_file: bool = True) -> Optional[str]:
171171
if filename.endswith('.orig'):
@@ -225,3 +225,20 @@ def format_frequency(frequency_hz: int, *, band: bool = True) -> str:
225225
return f"{frequency_mhz:.1f} MHz ({_band})"
226226
else:
227227
return f"{frequency_mhz:.1f} MHz"
228+
229+
230+
def init_profanity_filter(node: Node):
231+
# Profanity filter
232+
language = node.config.get('language', 'en')
233+
wordlist = os.path.join(node.config_dir, 'profanity.txt')
234+
if not os.path.exists(wordlist):
235+
shutil.copy2(os.path.join('samples', 'wordlists', f"{language}.txt"), wordlist)
236+
with open(wordlist, mode='r', encoding='utf-8') as wl:
237+
words = [x.strip() for x in wl.readlines() if not x.startswith('#')]
238+
targetfile = os.path.join(os.path.expandvars(node.locals['DCS']['installation']), 'Data', 'censor.lua')
239+
bakfile = targetfile.replace('.lua', '.bak')
240+
if not os.path.exists(bakfile):
241+
shutil.copy2(targetfile, bakfile)
242+
with open(targetfile, mode='wb') as outfile:
243+
outfile.write((f"{language.upper()} = " + luadata.serialize(
244+
words, indent='\t', indent_level=0)).encode('utf-8'))

0 commit comments

Comments
 (0)