Skip to content

Commit bab87dc

Browse files
committed
feat(core): added server log for blocked joins of banned players
1 parent d7a260c commit bab87dc

3 files changed

Lines changed: 24 additions & 8 deletions

File tree

core/modules/Logger/handlers/server.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,13 @@ export default class ServerLogger extends LoggerBase {
153153
* @param {String} mutex
154154
*/
155155
processEvent(eventData, mutex) {
156-
//Get source + handle playerJoining
156+
//Get source
157157
let srcObject; //to be sent to the UI
158158
let srcString; //to ve saved to the log file
159159
if (eventData.src === 'tx') {
160160
srcObject = { id: false, name: 'txAdmin' };
161161
srcString = 'txAdmin';
162162

163-
} else if (typeof eventData.src === 0) {
164-
srcObject = { id: false, name: 'CONSOLE' };
165-
srcString = 'CONSOLE';
166-
167163
} else if (typeof eventData.src === 'number' && eventData.src > 0) {
168164
const player = globals.playerlistManager.getPlayerById(eventData.src);
169165
if (player) {
@@ -182,8 +178,7 @@ export default class ServerLogger extends LoggerBase {
182178
srcString = 'UNKNOWN';
183179
}
184180

185-
186-
//Process event types (except playerJoining)
181+
//Process event types
187182
//TODO: normalize/padronize actions
188183
let eventMessage; //to be sent to the UI + saved to the log
189184
if (eventData.type === 'playerJoining') {
@@ -194,6 +189,10 @@ export default class ServerLogger extends LoggerBase {
194189
const reason = eventData.data.reason || 'UNKNOWN REASON';
195190
eventMessage = `disconnected (${reason})`;
196191

192+
} else if (eventData.type === 'playerJoinDenied') {
193+
const reason = eventData.data.reason ?? 'UNKNOWN REASON';
194+
eventMessage = `player join denied due to ${reason}`;
195+
197196
} else if (eventData.type === 'ChatMessage') {
198197
const text = (typeof eventData.data.text === 'string') ? eventData.data.text.replace(/\^([0-9])/g, '') : 'unknown message';
199198
eventMessage = (typeof eventData.data.author === 'string' && eventData.data.author !== srcObject.name)

core/routes/player/checkJoin.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,23 @@ function checkBan(
228228
<span style="font-style: italic;">${note}</span>`
229229
);
230230

231+
//Send serverlog message
232+
const matchingIds = ban.ids.filter(id => validIdsArray.includes(id));
233+
const matchingHwids = ('hwids' in ban && ban.hwids)
234+
? ban.hwids.filter(hw => validHwidsArray.includes(hw))
235+
: [];
236+
const summarizedIds = [
237+
...matchingIds.map(shortenId),
238+
...matchingHwids.map(shortenId)
239+
];
240+
const loggerReason = `active ban (${ban.id}) for identifiers [${summarizedIds.join(', ')}]`;
241+
txAdmin.logger.server.write([{
242+
src: 'tx',
243+
type: 'playerJoinDenied',
244+
ts,
245+
data: { reason: loggerReason }
246+
}]);
247+
231248
return { allow: false, reason };
232249
} else {
233250
return { allow: true };

web/main/serverLog.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@
371371
const getShowTypes = () => Object.keys(eventFilters)
372372
.filter(fn => eventFilters[fn])
373373
.flatMap(fn => {
374-
if (fn === 'PlayerJoinLeave') return ['playerJoining', 'playerDropped'];
374+
if (fn === 'PlayerJoinLeave') return ['playerJoining', 'playerDropped', 'playerJoinDenied'];
375375
if(fn === 'System') return ['LoggerStarted', 'DebugMessage'];
376376
return fn;
377377
});

0 commit comments

Comments
 (0)