IW4M-Admin/Plugins/ScriptPlugins/VPNDetection.js

93 lines
3.0 KiB
JavaScript
Raw Permalink 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",
targetRequired: true,
arguments: [{
2022-03-30 23:15:29 -04:00
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',
2022-03-23 14:34:04 -04:00
version: 1.3,
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) {
if (id === origin.ClientId) {
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(element));
this.logger.WriteInfo(`Loaded ${vpnExceptionIds.length} ids into whitelist`);
},
onUnloadAsync: function () {
},
onTickAsync: function (server) {
}
2022-03-23 14:34:04 -04:00
};