1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-13 00:28:10 -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 = {};
}
};