1
0
Fork 0
forked from svrjs/svrjs

Change blocklist-related commands to use .forEach() function instead of a for loop

This commit is contained in:
Dorian Niemiec 2024-08-29 19:05:02 +02:00
parent 7680bb8c27
commit 3b4fd9641c

View file

@ -23,14 +23,14 @@ module.exports.commands = {
if (ip == undefined || JSON.stringify(ip) == "[]") { if (ip == undefined || JSON.stringify(ip) == "[]") {
if (!cluster.isPrimary === false) log("Cannot block non-existent IP."); if (!cluster.isPrimary === false) log("Cannot block non-existent IP.");
} else { } else {
for (var i = 0; i < ip.length; i++) { ip.forEach((ipAddress) => {
if (ip[i] != "localhost" && ip[i].indexOf(":") == -1) { if (ipAddress !== "localhost" && ipAddress.indexOf(":") == -1) {
ip[i] = "::ffff:" + ip[i]; ipAddress = "::ffff:" + ipAddress;
}
if (!blocklist.check(ip[i])) {
blocklist.add(ip[i]);
} }
if (!blocklist.check(ipAddress)) {
blocklist.add(ipAddress);
} }
});
process.serverConfig.blacklist = blocklist.raw; process.serverConfig.blacklist = blocklist.raw;
if (!cluster.isPrimary === false) log("IPs successfully blocked."); if (!cluster.isPrimary === false) log("IPs successfully blocked.");
passCommand(ip, log); passCommand(ip, log);
@ -40,12 +40,12 @@ module.exports.commands = {
if (ip == undefined || JSON.stringify(ip) == "[]") { if (ip == undefined || JSON.stringify(ip) == "[]") {
if (!cluster.isPrimary === false) log("Cannot unblock non-existent IP."); if (!cluster.isPrimary === false) log("Cannot unblock non-existent IP.");
} else { } else {
for (var i = 0; i < ip.length; i++) { ip.forEach((ipAddress) => {
if (ip[i].indexOf(":") == -1) { if (ipAddress !== "localhost" && ipAddress.indexOf(":") == -1) {
ip[i] = "::ffff:" + ip[i]; ipAddress = "::ffff:" + ipAddress;
}
blocklist.remove(ip[i]);
} }
blocklist.remove(ipAddress);
});
process.serverConfig.blacklist = blocklist.raw; process.serverConfig.blacklist = blocklist.raw;
if (!cluster.isPrimary === false) log("IPs successfully unblocked."); if (!cluster.isPrimary === false) log("IPs successfully unblocked.");
passCommand(ip, log); passCommand(ip, log);