update action on report to script plugin v2

This commit is contained in:
RaidMax 2023-02-11 21:01:47 -06:00
parent 66c0561e7f
commit 59e3813fa7

View File

@ -1,50 +1,57 @@
let plugin = { const init = (registerEventCallback, serviceResolver, _) => {
plugin.onLoad(serviceResolver);
registerEventCallback('IManagementEventSubscriptions.ClientPenaltyAdministered', (penaltyEvent, token) => {
plugin.onPenalty(penaltyEvent);
});
return plugin;
};
const plugin = {
author: 'RaidMax', author: 'RaidMax',
version: 1.1, version: '1.2',
name: 'Action on Report', name: 'Action on Report',
enabled: false, // indicates if the plugin is enabled enabled: false, // indicates if the plugin is enabled
reportAction: 'TempBan', // can be TempBan or Ban reportAction: 'TempBan', // can be TempBan or Ban
maxReportCount: 5, // how many reports before action is taken maxReportCount: 5, // how many reports before action is taken
tempBanDurationMinutes: 60, // how long to temporarily ban the player tempBanDurationMinutes: 60, // how long to temporarily ban the player
eventTypes: { 'report': 103 }, penaltyType: {
'report': 0
},
onEventAsync: function (gameEvent, server) { onPenalty: function(penaltyEvent) {
if (!this.enabled) { if (!this.enabled || penaltyEvent.penalty.type !== this.penaltyType['report']) {
return; return;
} }
if (gameEvent.Type === this.eventTypes['report']) { if (!penaltyEvent.client.isIngame || (penaltyEvent.client.level !== 'User' && penaltyEvent.client.level !== 'Flagged')) {
if (!gameEvent.Target.IsIngame || (gameEvent.Target.Level !== 'User' && gameEvent.Target.Level !== 'Flagged')) { this.logger.logInformation(`Ignoring report for client (id) ${penaltyEvent.client.clientId} because they are privileged or not in-game`);
server.Logger.WriteInfo(`Ignoring report for client (id) ${gameEvent.Target.ClientId} because they are privileged or not ingame`); return;
return; }
}
let reportCount = this.reportCounts[gameEvent.Target.NetworkId] === undefined ? 0 : this.reportCounts[gameEvent.Target.NetworkId]; let reportCount = this.reportCounts[penaltyEvent.client.networkId] === undefined ? 0 : this.reportCounts[penaltyEvent.Client.NetworkId];
reportCount++; reportCount++;
this.reportCounts[gameEvent.Target.NetworkId] = reportCount; this.reportCounts[penaltyEvent.client.networkId] = reportCount;
if (reportCount >= this.maxReportCount) { if (reportCount >= this.maxReportCount) {
switch (this.reportAction) { switch (this.reportAction) {
case 'TempBan': case 'TempBan':
server.Logger.WriteInfo(`TempBanning client (id) ${gameEvent.Target.ClientId} because they received ${reportCount} reports`); this.logger.logInformation(`TempBanning client (id) ${penaltyEvent.client.clientId} because they received ${reportCount} reports`);
gameEvent.Target.TempBan(_localization.LocalizationIndex['PLUGINS_REPORT_ACTION'], System.TimeSpan.FromMinutes(this.tempBanDurationMinutes), _IW4MAdminClient); penaltyEvent.client.tempBan(this.translations['PLUGINS_REPORT_ACTION'], System.TimeSpan.FromMinutes(this.tempBanDurationMinutes), penaltyEvent.Client.CurrentServer.asConsoleClient());
break; break;
case 'Ban': case 'Ban':
server.Logger.WriteInfo(`Banning client (id) ${gameEvent.Target.ClientId} because they received ${reportCount} reports`); this.logger.logInformation(`Banning client (id) ${penaltyEvent.client.clientId} because they received ${reportCount} reports`);
gameEvent.Target.Ban(_localization.LocalizationIndex['PLUGINS_REPORT_ACTION'], _IW4MAdminClient, false); penaltyEvent.client.ban(this.translations['PLUGINS_REPORT_ACTION'], penaltyEvent.client.currentServer.asConsoleClient(), false);
break; break;
}
} }
} }
}, },
onLoadAsync: function (manager) { onLoad: function(serviceResolver) {
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.reportCounts = {}; this.reportCounts = {};
},
onUnloadAsync: function () {
},
onTickAsync: function (server) {
} }
}; };