fix subnet ban and vpn detection persistence

This commit is contained in:
RaidMax 2022-04-20 10:45:30 -05:00
parent 5e12bf60b5
commit 0175425708
2 changed files with 12 additions and 10 deletions

View File

@ -1,5 +1,6 @@
const cidrRegex = /^([0-9]{1,3}\.){3}[0-9]{1,3}(\/([0-9]|[1-2][0-9]|3[0-2]))?$/; const cidrRegex = /^([0-9]{1,3}\.){3}[0-9]{1,3}(\/([0-9]|[1-2][0-9]|3[0-2]))?$/;
const validCIDR = input => cidrRegex.test(input); const validCIDR = input => cidrRegex.test(input);
let subnetList = [];
const commands = [{ const commands = [{
name: "bansubnet", name: "bansubnet",
@ -20,8 +21,8 @@ const commands = [{
return; return;
} }
plugin.subnetList.push(input); subnetList.push(input);
_configHandler.SetValue('SubnetBanList', plugin.subnetList); _configHandler.SetValue('SubnetBanList', subnetList);
gameEvent.Origin.Tell(`Added ${input} to subnet banlist`); gameEvent.Origin.Tell(`Added ${input} to subnet banlist`);
} }
@ -73,7 +74,7 @@ const plugin = {
onEventAsync: (gameEvent, server) => { onEventAsync: (gameEvent, server) => {
if (gameEvent.TypeName === 'Join') { if (gameEvent.TypeName === 'Join') {
if (!isSubnetBanned(gameEvent.Origin.IPAddressString, this.subnetList, this.logger)) { if (!isSubnetBanned(gameEvent.Origin.IPAddressString, subnetList, this.logger)) {
return; return;
} }
@ -91,7 +92,7 @@ const plugin = {
if (list !== undefined) { if (list !== undefined) {
list.forEach(element => { list.forEach(element => {
const ban = String(element); const ban = String(element);
this.subnetList.push(ban) subnetList.push(ban)
}); });
this.logger.WriteInfo(`Loaded ${list.length} banned subnets`); this.logger.WriteInfo(`Loaded ${list.length} banned subnets`);
} else { } else {

View File

@ -1,3 +1,4 @@
let vpnExceptionIds = [];
const commands = [{ const commands = [{
name: "whitelistvpn", name: "whitelistvpn",
description: "whitelists a player's client id from VPN detection", description: "whitelists a player's client id from VPN detection",
@ -9,8 +10,8 @@ const commands = [{
required: true required: true
}], }],
execute: (gameEvent) => { execute: (gameEvent) => {
plugin.vpnExceptionIds.push(gameEvent.Target.ClientId); vpnExceptionIds.push(gameEvent.Target.ClientId);
plugin.configHandler.SetValue('vpnExceptionIds', plugin.vpnExceptionIds); plugin.configHandler.SetValue('vpnExceptionIds', vpnExceptionIds);
gameEvent.Origin.Tell(`Successfully whitelisted ${gameEvent.Target.Name}`); gameEvent.Origin.Tell(`Successfully whitelisted ${gameEvent.Target.Name}`);
} }
@ -22,12 +23,12 @@ const plugin = {
name: 'VPN Detection Plugin', name: 'VPN Detection Plugin',
manager: null, manager: null,
logger: null, logger: null,
vpnExceptionIds: [],
checkForVpn: function (origin) { checkForVpn: function (origin) {
let exempt = false; let exempt = false;
// prevent players that are exempt from being kicked // prevent players that are exempt from being kicked
this.vpnExceptionIds.forEach(function (id) { vpnExceptionIds.forEach(function (id) {
if (id === origin.ClientId) { if (id === origin.ClientId) {
exempt = true; exempt = true;
return false; return false;
@ -79,8 +80,8 @@ const plugin = {
this.logger = manager.GetLogger(0); this.logger = manager.GetLogger(0);
this.configHandler = _configHandler; this.configHandler = _configHandler;
this.configHandler.GetValue('vpnExceptionIds').forEach(element => this.vpnExceptionIds.push(element)); this.configHandler.GetValue('vpnExceptionIds').forEach(element => vpnExceptionIds.push(element));
this.logger.WriteInfo(`Loaded ${this.vpnExceptionIds.length} ids into whitelist`); this.logger.WriteInfo(`Loaded ${vpnExceptionIds.length} ids into whitelist`);
}, },
onUnloadAsync: function () { onUnloadAsync: function () {