2023-04-15 15:27:51 -04:00
|
|
|
const init = (registerEventCallback, serviceResolver, configWrapper) => {
|
|
|
|
plugin.onLoad(serviceResolver, configWrapper);
|
2023-02-11 22:01:47 -05:00
|
|
|
|
2023-04-04 19:24:13 -04:00
|
|
|
registerEventCallback('IManagementEventSubscriptions.ClientPenaltyAdministered', (penaltyEvent, _) => {
|
2023-02-11 22:01:47 -05:00
|
|
|
plugin.onPenalty(penaltyEvent);
|
|
|
|
});
|
|
|
|
|
|
|
|
return plugin;
|
|
|
|
};
|
|
|
|
|
|
|
|
const plugin = {
|
2020-07-25 22:15:46 -04:00
|
|
|
author: 'RaidMax',
|
2023-04-15 15:27:51 -04:00
|
|
|
version: '2.1',
|
2020-07-25 22:15:46 -04:00
|
|
|
name: 'Action on Report',
|
2023-04-15 15:27:51 -04:00
|
|
|
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
|
2023-02-11 22:01:47 -05:00
|
|
|
},
|
2020-07-25 22:15:46 -04:00
|
|
|
|
2023-04-04 19:24:13 -04:00
|
|
|
onPenalty: function (penaltyEvent) {
|
2023-04-15 15:27:51 -04:00
|
|
|
if (!this.config.enabled || penaltyEvent.penalty.type !== 'Report') {
|
2020-07-25 22:15:46 -04:00
|
|
|
return;
|
|
|
|
}
|
2023-04-15 15:27:51 -04:00
|
|
|
|
2023-02-11 22:01:47 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
let reportCount = this.reportCounts[penaltyEvent.client.networkId] === undefined ? 0 : this.reportCounts[penaltyEvent.Client.NetworkId];
|
|
|
|
reportCount++;
|
|
|
|
this.reportCounts[penaltyEvent.client.networkId] = reportCount;
|
2020-07-25 22:15:46 -04:00
|
|
|
|
2023-04-15 15:27:51 -04:00
|
|
|
if (reportCount >= this.config.maxReportCount) {
|
|
|
|
switch (this.config.reportAction) {
|
2023-02-11 22:01:47 -05:00
|
|
|
case 'TempBan':
|
|
|
|
this.logger.logInformation(`TempBanning client (id) ${penaltyEvent.client.clientId} because they received ${reportCount} reports`);
|
2023-04-15 15:27:51 -04:00
|
|
|
penaltyEvent.client.tempBan(this.translations['PLUGINS_REPORT_ACTION'], System.TimeSpan.FromMinutes(this.config.tempBanDurationMinutes), penaltyEvent.Client.CurrentServer.asConsoleClient());
|
2023-02-11 22:01:47 -05:00
|
|
|
break;
|
|
|
|
case 'Ban':
|
|
|
|
this.logger.logInformation(`Banning client (id) ${penaltyEvent.client.clientId} because they received ${reportCount} reports`);
|
|
|
|
penaltyEvent.client.ban(this.translations['PLUGINS_REPORT_ACTION'], penaltyEvent.client.currentServer.asConsoleClient(), false);
|
|
|
|
break;
|
2020-07-25 22:15:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2023-04-15 15:27:51 -04:00
|
|
|
onLoad: function (serviceResolver, configWrapper) {
|
2023-02-11 22:01:47 -05:00
|
|
|
this.translations = serviceResolver.resolveService('ITranslationLookup');
|
|
|
|
this.logger = serviceResolver.resolveService('ILogger', ['ScriptPluginV2']);
|
2023-04-15 15:27:51 -04:00
|
|
|
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);
|
2020-07-25 22:15:46 -04:00
|
|
|
this.reportCounts = {};
|
|
|
|
}
|
2020-07-27 17:22:07 -04:00
|
|
|
};
|