mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-17 21:41:06 +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) {
|
||||
var res;
|
||||
for(var key in this.hash) {
|
||||
var space = this.hash[key].space(true);
|
||||
if(space) space += '?';
|
||||
|
||||
var ended = space + '(.*)';
|
||||
|
||||
var found = command.match(new RegExp('^' + key + ended));
|
||||
if(found) {
|
||||
res = [this.hash[key], found];
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
var parts=command.split(" ");
|
||||
var c=parts.shift();
|
||||
var pars=parts.join(" ");
|
||||
if(this.hash[c])
|
||||
return [this.hash[c], pars];
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async use(command, op=true) {
|
||||
var res = this.find(command);
|
||||
|
||||
if(res) {
|
||||
if (res[0].params.op && !op) return 'You do not have permission to use this command';
|
||||
var parse = res[0].params.parse;
|
||||
var [com,pars]=res;
|
||||
if (com.params.op && !op) return 'You do not have permission to use this command';
|
||||
var parse = com.params.parse;
|
||||
if(parse) {
|
||||
if(typeof parse == 'function') {
|
||||
res[1] = parse(res[1][1]);
|
||||
if(res[1] === false) {
|
||||
return res[0].params.usage ? 'Usage: ' + res[0].params.usage : 'Bad syntax';
|
||||
pars = parse(pars);
|
||||
if(pars === false) {
|
||||
return com.params.usage ? 'Usage: ' + com.params.usage : 'Bad syntax';
|
||||
}
|
||||
} 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;
|
||||
} else {
|
||||
return 'Command not found';
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ module.exports.server=function(serv)
|
|||
|
||||
serv.pardonIP = (IP) => {
|
||||
return serv.bannedIPs[IP] ? delete serv.bannedIPs[IP] : false
|
||||
}
|
||||
};
|
||||
|
||||
function pardon(uuid) {
|
||||
if (serv.bannedPlayers[uuid]) {
|
||||
|
|
@ -145,12 +145,12 @@ module.exports.player=function(player,serv)
|
|||
});
|
||||
|
||||
player.commands.add({
|
||||
base: 'ipban',
|
||||
base: 'ban-ip',
|
||||
info: 'bans a specific IP',
|
||||
usage: '/ban-ip <ip> [reason]',
|
||||
op: true,
|
||||
parse(str){
|
||||
var argv = str.split(' ')
|
||||
var argv = str.split(' ');
|
||||
if(argv.length < 1) return;
|
||||
|
||||
return {
|
||||
|
|
@ -159,10 +159,21 @@ module.exports.player=function(player,serv)
|
|||
}
|
||||
},
|
||||
action({IP, reason}){
|
||||
serv.banIP(IP, reason)
|
||||
serv.banIP(IP, reason);
|
||||
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({
|
||||
base: 'pardon',
|
||||
|
|
|
|||
Loading…
Reference in a new issue