const cidrRegex = /^([0-9]{1,3}\.){3}[0-9]{1,3}(\/([0-9]|[1-2][0-9]|3[0-2]))?$/; const validCIDR = input => cidrRegex.test(input); const subnetBanlistKey = 'Webfront::Nav::Admin::SubnetBanlist'; let subnetList = []; const init = (registerNotify, serviceResolver, config) => { registerNotify('IManagementEventSubscriptions.ClientStateAuthorized', (authorizedEvent, _) => plugin.onClientAuthorized(authorizedEvent)); plugin.onLoad(serviceResolver, config); return plugin; }; const plugin = { author: 'RaidMax', version: '2.0', name: 'Subnet Banlist Plugin', manager: null, logger: null, config: null, serviceResolver: null, banMessage: '', commands: [{ name: 'bansubnet', description: 'bans an IPv4 subnet', alias: 'bs', permission: 'SeniorAdmin', targetRequired: false, arguments: [{ name: 'subnet in IPv4 CIDR notation', required: true }], execute: (gameEvent) => { const input = String(gameEvent.data).trim(); if (!validCIDR(input)) { gameEvent.origin.tell('Invalid CIDR input'); return; } subnetList.push(input); plugin.config.setValue('SubnetBanList', subnetList); gameEvent.origin.tell(`Added ${input} to subnet banlist`); } }, { name: 'unbansubnet', description: 'unbans an IPv4 subnet', alias: 'ubs', permission: 'SeniorAdmin', targetRequired: false, arguments: [{ name: 'subnet in IPv4 CIDR notation', required: true }], execute: (gameEvent) => { const input = String(gameEvent.data).trim(); if (!validCIDR(input)) { gameEvent.origin.tell('Invalid CIDR input'); return; } if (!subnetList.includes(input)) { gameEvent.origin.tell('Subnet is not banned'); return; } subnetList = subnetList.filter(item => item !== input); plugin.config.setValue('SubnetBanList', subnetList); gameEvent.origin.tell(`Removed ${input} from subnet banlist`); } } ], interactions: [{ name: subnetBanlistKey, action: function (_, __, ___) { const helpers = importNamespace('SharedLibraryCore.Helpers'); const interactionData = new helpers.InteractionData(); interactionData.name = 'Subnet Banlist'; // navigation link name interactionData.description = `List of banned subnets (${subnetList.length} Total)`; // alt and title interactionData.displayMeta = 'oi-circle-x'; // nav icon interactionData.interactionId = subnetBanlistKey; interactionData.minimumPermission = 3; interactionData.interactionType = 2; interactionData.source = plugin.name; interactionData.ScriptAction = (sourceId, targetId, game, meta, token) => { let table = '
${subnet} |
Unban Subnet
|