1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

add configuration update callback for script plugins & update plugins to utilize

This commit is contained in:
RaidMax
2023-04-15 14:27:51 -05:00
parent d3a2209f73
commit d3ac9d53a4
7 changed files with 120 additions and 35 deletions

View File

@ -1,5 +1,5 @@
const init = (registerEventCallback, serviceResolver, _) => {
plugin.onLoad(serviceResolver);
const init = (registerEventCallback, serviceResolver, configWrapper) => {
plugin.onLoad(serviceResolver, configWrapper);
registerEventCallback('IManagementEventSubscriptions.ClientPenaltyAdministered', (penaltyEvent, _) => {
plugin.onPenalty(penaltyEvent);
@ -10,21 +10,20 @@ const init = (registerEventCallback, serviceResolver, _) => {
const plugin = {
author: 'RaidMax',
version: '2.0',
version: '2.1',
name: 'Action on Report',
enabled: false, // indicates if the plugin is enabled
reportAction: 'TempBan', // can be TempBan or Ban
maxReportCount: 5, // how many reports before action is taken
tempBanDurationMinutes: 60, // how long to temporarily ban the player
penaltyType: {
'report': 0
config: {
enabled: false, // indicates if the plugin is enabled
reportAction: 'TempBan', // can be TempBan or Ban
maxReportCount: 5, // how many reports before action is taken
tempBanDurationMinutes: 60 // how long to temporarily ban the player
},
onPenalty: function (penaltyEvent) {
if (!this.enabled || penaltyEvent.penalty.type !== this.penaltyType['report']) {
if (!this.config.enabled || penaltyEvent.penalty.type !== 'Report') {
return;
}
if (!penaltyEvent.client.isIngame || (penaltyEvent.client.level !== 'User' && penaltyEvent.client.level !== 'Flagged')) {
this.logger.logInformation(`Ignoring report for client (id) ${penaltyEvent.client.clientId} because they are privileged or not in-game`);
return;
@ -34,11 +33,11 @@ const plugin = {
reportCount++;
this.reportCounts[penaltyEvent.client.networkId] = reportCount;
if (reportCount >= this.maxReportCount) {
switch (this.reportAction) {
if (reportCount >= this.config.maxReportCount) {
switch (this.config.reportAction) {
case 'TempBan':
this.logger.logInformation(`TempBanning client (id) ${penaltyEvent.client.clientId} because they received ${reportCount} reports`);
penaltyEvent.client.tempBan(this.translations['PLUGINS_REPORT_ACTION'], System.TimeSpan.FromMinutes(this.tempBanDurationMinutes), penaltyEvent.Client.CurrentServer.asConsoleClient());
penaltyEvent.client.tempBan(this.translations['PLUGINS_REPORT_ACTION'], System.TimeSpan.FromMinutes(this.config.tempBanDurationMinutes), penaltyEvent.Client.CurrentServer.asConsoleClient());
break;
case 'Ban':
this.logger.logInformation(`Banning client (id) ${penaltyEvent.client.clientId} because they received ${reportCount} reports`);
@ -48,10 +47,25 @@ const plugin = {
}
},
onLoad: function (serviceResolver) {
onLoad: function (serviceResolver, configWrapper) {
this.translations = serviceResolver.resolveService('ITranslationLookup');
this.logger = serviceResolver.resolveService('ILogger', ['ScriptPluginV2']);
this.logger.logInformation('ActionOnReport {version} by {author} loaded. Enabled={enabled}', this.version, this.author, this.enabled);
this.configWrapper = configWrapper;
const storedConfig = this.configWrapper.getValue('config', newConfig => {
if (newConfig) {
plugin.logger.logInformation('ActionOnReport config reloaded. Enabled={Enabled}', newConfig.enabled);
plugin.config = newConfig;
}
});
if (storedConfig != null) {
this.config = storedConfig
} else {
this.configWrapper.setValue('config', this.config);
}
this.logger.logInformation('ActionOnReport {version} by {author} loaded. Enabled={Enabled}', this.version, this.author, this.config.enabled);
this.reportCounts = {};
}
};

View File

@ -7,15 +7,16 @@ const init = (registerNotify, serviceResolver, config) => {
const plugin = {
author: 'Amos, RaidMax',
version: '2.0',
version: '2.1',
name: 'Broadcast Bans',
config: null,
logger: null,
translations: null,
manager: null,
enableBroadcastBans: false,
onClientPenalty: function (penaltyEvent) {
if (!this.enableBroadcastBans || penaltyEvent.penalty.type !== 5) {
if (!this.enableBroadcastBans || penaltyEvent.penalty.type !== 'Ban') {
return;
}
@ -43,7 +44,10 @@ const plugin = {
onLoad: function (serviceResolver, config) {
this.config = config;
this.config.setName(this.name);
this.enableBroadcastBans = this.config.getValue('EnableBroadcastBans');
this.enableBroadcastBans = this.config.getValue('EnableBroadcastBans', newConfig => {
plugin.logger.logInformation('{Name} config reloaded. Enabled={Enabled}', plugin.name, newConfig);
plugin.enableBroadcastBans = newConfig;
});
this.manager = serviceResolver.resolveService('IManager');
this.logger = serviceResolver.resolveService('ILogger', ['ScriptPluginV2']);
@ -54,7 +58,7 @@ const plugin = {
this.config.setValue('EnableBroadcastBans', this.enableBroadcastBans);
}
this.logger.logInformation('{Name} {Version} by {Author} loaded. Enabled={enabled}', this.name, this.version,
this.logger.logInformation('{Name} {Version} by {Author} loaded. Enabled={Enabled}', this.name, this.version,
this.author, this.enableBroadcastBans);
}
};

View File

@ -2,23 +2,24 @@ let vpnExceptionIds = [];
const vpnAllowListKey = 'Webfront::Nav::Admin::VPNAllowList';
const vpnWhitelistKey = 'Webfront::Profile::VPNWhitelist';
const init = (registerNotify, serviceResolver, config, pluginHelper) => {
const init = (registerNotify, serviceResolver, configWrapper, pluginHelper) => {
registerNotify('IManagementEventSubscriptions.ClientStateAuthorized', (authorizedEvent, token) => plugin.onClientAuthorized(authorizedEvent, token));
plugin.onLoad(serviceResolver, config, pluginHelper);
plugin.onLoad(serviceResolver, configWrapper, pluginHelper);
return plugin;
};
const plugin = {
author: 'RaidMax',
version: '2.0',
version: '2.1',
name: 'VPN Detection Plugin',
manager: null,
config: null,
configWrapper: null,
logger: null,
serviceResolver: null,
translations: null,
pluginHelper: null,
enabled: true,
commands: [{
name: 'whitelistvpn',
@ -32,7 +33,7 @@ const plugin = {
}],
execute: (gameEvent) => {
vpnExceptionIds.push(gameEvent.Target.ClientId);
plugin.config.setValue('vpnExceptionIds', vpnExceptionIds);
plugin.configWrapper.setValue('vpnExceptionIds', vpnExceptionIds);
gameEvent.origin.tell(`Successfully whitelisted ${gameEvent.target.name}`);
}
@ -49,7 +50,7 @@ const plugin = {
}],
execute: (gameEvent) => {
vpnExceptionIds = vpnExceptionIds.filter(exception => parseInt(exception) !== parseInt(gameEvent.Target.ClientId));
plugin.config.setValue('vpnExceptionIds', vpnExceptionIds);
plugin.configWrapper.setValue('vpnExceptionIds', vpnExceptionIds);
gameEvent.origin.tell(`Successfully disallowed ${gameEvent.target.name} from connecting with VPN`);
}
@ -148,30 +149,45 @@ const plugin = {
],
onClientAuthorized: async function (authorizeEvent, token) {
if (authorizeEvent.client.isBot) {
if (authorizeEvent.client.isBot || !this.enabled) {
return;
}
await this.checkForVpn(authorizeEvent.client, token);
},
onLoad: function (serviceResolver, config, pluginHelper) {
onLoad: function (serviceResolver, configWrapper, pluginHelper) {
this.serviceResolver = serviceResolver;
this.config = config;
this.configWrapper = configWrapper;
this.pluginHelper = pluginHelper;
this.manager = this.serviceResolver.resolveService('IManager');
this.logger = this.serviceResolver.resolveService('ILogger', ['ScriptPluginV2']);
this.translations = this.serviceResolver.resolveService('ITranslationLookup');
this.config.setName(this.name); // use legacy key
this.config.getValue('vpnExceptionIds').forEach(element => vpnExceptionIds.push(parseInt(element)));
this.configWrapper.setName(this.name); // use legacy key
this.configWrapper.getValue('vpnExceptionIds').forEach(element => vpnExceptionIds.push(parseInt(element)));
this.logger.logInformation(`Loaded ${vpnExceptionIds.length} ids into whitelist`);
this.enabled = this.configWrapper.getValue('enabled', newValue => {
if (newValue) {
plugin.logger.logInformation('{Name} configuration updated. Enabled={Enabled}', newValue);
plugin.enabled = newValue;
}
});
if (this.enabled === undefined) {
this.configWrapper.setValue('enabled', true);
this.enabled = true;
}
this.interactionRegistration = this.serviceResolver.resolveService('IInteractionRegistration');
this.interactionRegistration.unregisterInteraction(vpnWhitelistKey);
this.interactionRegistration.unregisterInteraction(vpnAllowListKey);
this.logger.logInformation('{Name} {Version} by {Author} loaded. Enabled={Enabled}', this.name, this.version,
this.author, this.enabled);
},
checkForVpn: async function (origin, token) {
checkForVpn: async function (origin, _) {
let exempt = false;
// prevent players that are exempt from being kicked
vpnExceptionIds.forEach(function (id) {