Skip to content

Instantly share code, notes, and snippets.

@d0p3t
Created June 3, 2019 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d0p3t/226c9c255e192b7dbf45b2bb9ec456cb to your computer and use it in GitHub Desktop.
Save d0p3t/226c9c255e192b7dbf45b2bb9ec456cb to your computer and use it in GitHub Desktop.
import UserManager from '../classes/managers/userManager';
import { Ban } from '../models';
const utils = require('../utils');
on('playerConnecting', (playerName: string, setKickReason: any, deferrals: any) => {
const netId = (global as any).source;
const license = utils.GetPlayerIdentifier(netId);
const steam = utils.GetPlayerIdentifier(netId, 'steam');
const xbl = utils.GetPlayerIdentifier(netId, 'xbl');
const live = utils.GetPlayerIdentifier(netId, 'live');
const discord = utils.GetPlayerIdentifier(netId, 'discord');
deferrals.defer();
deferrals.update(`[${new Date().toLocaleString()}] Checking profile of [${playerName}]`);
const name = playerName;
const sanitized = utils.SanitizeUserName(name);
if (name !== sanitized) {
setImmediate(() => {
console.log(`[${new Date().toLocaleString()}] ${license} tried to connect with illegal characters.`);
deferrals.done(`[${new Date().toLocaleString()}] Illegal HTML tags found in name.`);
});
} else {
UserManager.CheckForBan(license, steam, xbl, live, discord)
.then((currentBan: Ban) => {
setImmediate(() => {
if (currentBan !== null) {
const options = {
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
};
console.log(`[${new Date().toLocaleString()}] Banned user ${license} tried to connect.`);
deferrals.done(
`[${new Date().toLocaleString()}] You're banned until ${currentBan.endDate.toLocaleString(
'default',
options,
)} (Reason: ${currentBan.reason})`,
);
} else {
// UserManager.BanUser(new Date(2019, 5, 1, 2, 59), "Nuub", license, steam, xbl, live, discord); // Ban for testing
deferrals.done();
}
});
})
.catch((reason: string) => {
console.log(reason);
deferrals.done();
}).finally(() => {
deferrals.done();
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment