IW4M-Admin/Plugins/ScriptPlugins/VPNDetection.js

118 lines
4.4 KiB
JavaScript
Raw Normal View History

let vpnExceptionIds = [];
2022-03-23 14:34:04 -04:00
const commands = [{
name: 'whitelistvpn',
description: 'whitelists a player\'s client id from VPN detection',
alias: 'wv',
permission: 'SeniorAdmin',
2022-03-23 14:34:04 -04:00
targetRequired: true,
arguments: [{
name: 'player',
2022-03-23 14:34:04 -04:00
required: true
}],
execute: (gameEvent) => {
vpnExceptionIds.push(gameEvent.Target.ClientId);
plugin.configHandler.SetValue('vpnExceptionIds', vpnExceptionIds);
2022-03-23 14:34:04 -04:00
gameEvent.Origin.Tell(`Successfully whitelisted ${gameEvent.Target.Name}`);
}
}];
const plugin = {
author: 'RaidMax',
version: 1.5,
name: 'VPN Detection Plugin',
manager: null,
logger: null,
checkForVpn: function (origin) {
2022-03-23 14:34:04 -04:00
let exempt = false;
// prevent players that are exempt from being kicked
vpnExceptionIds.forEach(function (id) {
2022-05-22 19:04:23 -04:00
if (id == origin.ClientId) { // when loaded from the config the "id" type is not the same as the ClientId type
exempt = true;
return false;
}
});
if (exempt) {
2022-03-23 14:34:04 -04:00
this.logger.WriteInfo(`${origin} is whitelisted, so we are not checking VPN status`);
return;
}
2022-03-23 14:34:04 -04:00
let usingVPN = false;
try {
2022-03-23 14:34:04 -04:00
const cl = new System.Net.Http.HttpClient();
const re = cl.GetAsync(`https://api.xdefcon.com/proxy/check/?ip=${origin.IPAddressString}`).Result;
const userAgent = `IW4MAdmin-${this.manager.GetApplicationSettings().Configuration().Id}`;
cl.DefaultRequestHeaders.Add('User-Agent', userAgent);
2022-03-23 14:34:04 -04:00
const co = re.Content;
const parsedJSON = JSON.parse(co.ReadAsStringAsync().Result);
co.Dispose();
re.Dispose();
cl.Dispose();
2021-04-07 10:53:32 -04:00
usingVPN = parsedJSON.success && parsedJSON.proxy;
} catch (e) {
2022-03-23 14:34:04 -04:00
this.logger.WriteWarning(`There was a problem checking client IP for VPN ${e.message}`);
}
if (usingVPN) {
this.logger.WriteInfo(origin + ' is using a VPN (' + origin.IPAddressString + ')');
2022-03-23 14:34:04 -04:00
const contactUrl = this.manager.GetApplicationSettings().Configuration().ContactUri;
let additionalInfo = '';
if (contactUrl) {
2022-03-23 14:34:04 -04:00
additionalInfo = _localization.LocalizationIndex['SERVER_KICK_VPNS_NOTALLOWED_INFO'] + ' ' + contactUrl;
}
2022-03-23 14:34:04 -04:00
origin.Kick(_localization.LocalizationIndex['SERVER_KICK_VPNS_NOTALLOWED'] + ' ' + additionalInfo, _IW4MAdminClient);
}
},
onEventAsync: function (gameEvent, server) {
// join event
2022-03-23 14:34:04 -04:00
if (gameEvent.TypeName === 'Join') {
this.checkForVpn(gameEvent.Origin);
}
},
onLoadAsync: function (manager) {
this.manager = manager;
this.logger = manager.GetLogger(0);
2022-03-23 14:34:04 -04:00
this.configHandler = _configHandler;
this.configHandler.GetValue('vpnExceptionIds').forEach(element => vpnExceptionIds.push(parseInt(element)));
this.logger.WriteInfo(`Loaded ${vpnExceptionIds.length} ids into whitelist`);
this.interactionRegistration = _serviceResolver.ResolveService('IInteractionRegistration');
this.interactionRegistration.RegisterScriptInteraction('WhitelistVPN', this.name, (originId, targetId, game, token) => {
if (vpnExceptionIds.includes(targetId)) {
return;
}
const helpers = importNamespace('SharedLibraryCore.Helpers');
const interactionData = new helpers.InteractionData();
interactionData.EntityId = targetId;
interactionData.Name = 'Whitelist VPN';
interactionData.DisplayMeta = 'oi-circle-check';
interactionData.ActionMeta.Add('InteractionId', 'command');
interactionData.ActionMeta.Add('Data', `whitelistvpn`);
interactionData.ActionMeta.Add('ActionButtonLabel', 'Allow');
interactionData.ActionMeta.Add('Name', 'Allow VPN Connection');
interactionData.ActionMeta.Add('ShouldRefresh', true.toString());
interactionData.ActionPath = 'DynamicAction';
interactionData.MinimumPermission = 3;
interactionData.Source = this.name;
return interactionData;
});
},
onUnloadAsync: function () {
this.interactionRegistration.UnregisterInteraction('WhitelistVPN');
},
onTickAsync: function (server) {
}
2022-03-23 14:34:04 -04:00
};