update action on report to script plugin v2
This commit is contained in:
parent
66c0561e7f
commit
59e3813fa7
@ -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',
|
||||
version: 1.1,
|
||||
version: '1.2',
|
||||
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
|
||||
eventTypes: { 'report': 103 },
|
||||
penaltyType: {
|
||||
'report': 0
|
||||
},
|
||||
|
||||
onEventAsync: function (gameEvent, server) {
|
||||
if (!this.enabled) {
|
||||
onPenalty: function(penaltyEvent) {
|
||||
if (!this.enabled || penaltyEvent.penalty.type !== this.penaltyType['report']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (gameEvent.Type === this.eventTypes['report']) {
|
||||
if (!gameEvent.Target.IsIngame || (gameEvent.Target.Level !== 'User' && gameEvent.Target.Level !== 'Flagged')) {
|
||||
server.Logger.WriteInfo(`Ignoring report for client (id) ${gameEvent.Target.ClientId} because they are privileged or not ingame`);
|
||||
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;
|
||||
}
|
||||
|
||||
let reportCount = this.reportCounts[gameEvent.Target.NetworkId] === undefined ? 0 : this.reportCounts[gameEvent.Target.NetworkId];
|
||||
reportCount++;
|
||||
this.reportCounts[gameEvent.Target.NetworkId] = reportCount;
|
||||
let reportCount = this.reportCounts[penaltyEvent.client.networkId] === undefined ? 0 : this.reportCounts[penaltyEvent.Client.NetworkId];
|
||||
reportCount++;
|
||||
this.reportCounts[penaltyEvent.client.networkId] = reportCount;
|
||||
|
||||
if (reportCount >= this.maxReportCount) {
|
||||
switch (this.reportAction) {
|
||||
case 'TempBan':
|
||||
server.Logger.WriteInfo(`TempBanning client (id) ${gameEvent.Target.ClientId} because they received ${reportCount} reports`);
|
||||
gameEvent.Target.TempBan(_localization.LocalizationIndex['PLUGINS_REPORT_ACTION'], System.TimeSpan.FromMinutes(this.tempBanDurationMinutes), _IW4MAdminClient);
|
||||
break;
|
||||
case 'Ban':
|
||||
server.Logger.WriteInfo(`Banning client (id) ${gameEvent.Target.ClientId} because they received ${reportCount} reports`);
|
||||
gameEvent.Target.Ban(_localization.LocalizationIndex['PLUGINS_REPORT_ACTION'], _IW4MAdminClient, false);
|
||||
break;
|
||||
}
|
||||
if (reportCount >= this.maxReportCount) {
|
||||
switch (this.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());
|
||||
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;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
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 = {};
|
||||
},
|
||||
|
||||
onUnloadAsync: function () {
|
||||
},
|
||||
|
||||
onTickAsync: function (server) {
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user