mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-04 18:50:46 +00:00
fix commands to support /ban-ip , add /pardon-ip
This commit is contained in:
parent
e5ff8eae7e
commit
de202f5faa
2 changed files with 30 additions and 28 deletions
|
|
@ -8,42 +8,33 @@ class Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
find(command) {
|
find(command) {
|
||||||
var res;
|
var parts=command.split(" ");
|
||||||
for(var key in this.hash) {
|
var c=parts.shift();
|
||||||
var space = this.hash[key].space(true);
|
var pars=parts.join(" ");
|
||||||
if(space) space += '?';
|
if(this.hash[c])
|
||||||
|
return [this.hash[c], pars];
|
||||||
var ended = space + '(.*)';
|
return undefined;
|
||||||
|
|
||||||
var found = command.match(new RegExp('^' + key + ended));
|
|
||||||
if(found) {
|
|
||||||
res = [this.hash[key], found];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async use(command, op=true) {
|
async use(command, op=true) {
|
||||||
var res = this.find(command);
|
var res = this.find(command);
|
||||||
|
|
||||||
if(res) {
|
if(res) {
|
||||||
if (res[0].params.op && !op) return 'You do not have permission to use this command';
|
var [com,pars]=res;
|
||||||
var parse = res[0].params.parse;
|
if (com.params.op && !op) return 'You do not have permission to use this command';
|
||||||
|
var parse = com.params.parse;
|
||||||
if(parse) {
|
if(parse) {
|
||||||
if(typeof parse == 'function') {
|
if(typeof parse == 'function') {
|
||||||
res[1] = parse(res[1][1]);
|
pars = parse(pars);
|
||||||
if(res[1] === false) {
|
if(pars === false) {
|
||||||
return res[0].params.usage ? 'Usage: ' + res[0].params.usage : 'Bad syntax';
|
return com.params.usage ? 'Usage: ' + com.params.usage : 'Bad syntax';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
res[1] = res[1][1].match(parse);
|
pars = pars.match(parse);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
res[1].shift();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res = await res[0].params.action(res[1]);
|
res = await com.params.action(pars);
|
||||||
if(res) return '' + res;
|
if(res) return '' + res;
|
||||||
} else {
|
} else {
|
||||||
return 'Command not found';
|
return 'Command not found';
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ module.exports.server=function(serv)
|
||||||
|
|
||||||
serv.pardonIP = (IP) => {
|
serv.pardonIP = (IP) => {
|
||||||
return serv.bannedIPs[IP] ? delete serv.bannedIPs[IP] : false
|
return serv.bannedIPs[IP] ? delete serv.bannedIPs[IP] : false
|
||||||
}
|
};
|
||||||
|
|
||||||
function pardon(uuid) {
|
function pardon(uuid) {
|
||||||
if (serv.bannedPlayers[uuid]) {
|
if (serv.bannedPlayers[uuid]) {
|
||||||
|
|
@ -145,12 +145,12 @@ module.exports.player=function(player,serv)
|
||||||
});
|
});
|
||||||
|
|
||||||
player.commands.add({
|
player.commands.add({
|
||||||
base: 'ipban',
|
base: 'ban-ip',
|
||||||
info: 'bans a specific IP',
|
info: 'bans a specific IP',
|
||||||
usage: '/ban-ip <ip> [reason]',
|
usage: '/ban-ip <ip> [reason]',
|
||||||
op: true,
|
op: true,
|
||||||
parse(str){
|
parse(str){
|
||||||
var argv = str.split(' ')
|
var argv = str.split(' ');
|
||||||
if(argv.length < 1) return;
|
if(argv.length < 1) return;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -159,10 +159,21 @@ module.exports.player=function(player,serv)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
action({IP, reason}){
|
action({IP, reason}){
|
||||||
serv.banIP(IP, reason)
|
serv.banIP(IP, reason);
|
||||||
player.chat("" + IP + " was IP banned")
|
player.chat("" + IP + " was IP banned")
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
|
player.commands.add({
|
||||||
|
base: 'pardon-ip',
|
||||||
|
info: 'to pardon a player by ip',
|
||||||
|
usage: '/pardon-ip <ip>',
|
||||||
|
op: true,
|
||||||
|
action(IP) {
|
||||||
|
var result=serv.pardonIP(IP);
|
||||||
|
player.chat(result ? IP + " was IP pardonned" : IP+" is not banned");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
player.commands.add({
|
player.commands.add({
|
||||||
base: 'pardon',
|
base: 'pardon',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue