diff options
Diffstat (limited to 'server/src/commands/admin')
-rw-r--r-- | server/src/commands/admin/addmod.js | 20 | ||||
-rw-r--r-- | server/src/commands/admin/listusers.js | 10 | ||||
-rw-r--r-- | server/src/commands/admin/reload.js | 14 | ||||
-rw-r--r-- | server/src/commands/admin/removemod.js | 50 | ||||
-rw-r--r-- | server/src/commands/admin/saveconfig.js | 14 | ||||
-rw-r--r-- | server/src/commands/admin/shout.js | 12 |
6 files changed, 90 insertions, 30 deletions
diff --git a/server/src/commands/admin/addmod.js b/server/src/commands/admin/addmod.js index bde54a1..c4fcdd5 100644 --- a/server/src/commands/admin/addmod.js +++ b/server/src/commands/admin/addmod.js @@ -2,23 +2,24 @@ Description: Adds the target trip to the mod list then elevates the uType */ +// module main exports.run = async (core, server, socket, data) => { // increase rate limit chance and ignore if not admin if (socket.uType != 'admin') { - server._police.frisk(socket.remoteAddress, 20); - - return; + return server._police.frisk(socket.remoteAddress, 20); } // add new trip to config core.config.mods.push({ trip: data.trip }); // purposely not using `config.set()` to avoid auto-save - // upgarde existing connections & notify user + // find targets current connections let newMod = server.findSockets({ trip: data.trip }); if (newMod.length !== 0) { for (let i = 0, l = newMod.length; i < l; i++) { + // upgrade privilages newMod[i].uType = 'mod'; + // inform new mod server.send({ cmd: 'info', text: 'You are now a mod.' @@ -29,20 +30,21 @@ exports.run = async (core, server, socket, data) => { // return success message server.reply({ cmd: 'info', - text: `Added mod trip: ${data.trip}` + text: `Added mod trip: ${data.trip}, remember to run 'saveconfig' to make it permanent` }, socket); // notify all mods server.broadcast({ cmd: 'info', - text: `Added mod trip: ${data.trip}` + text: `Added mod: ${data.trip}` }, { uType: 'mod' }); }; +// module meta exports.requiredData = ['trip']; - exports.info = { name: 'addmod', - usage: 'addmod {trip}', - description: 'Adds target trip to the config as a mod and upgrades the socket type' + description: 'Adds target trip to the config as a mod and upgrades the socket type', + usage: ` + API: { cmd: 'addmod', trip: '<target trip>' }` }; diff --git a/server/src/commands/admin/listusers.js b/server/src/commands/admin/listusers.js index d3dddc2..85fc078 100644 --- a/server/src/commands/admin/listusers.js +++ b/server/src/commands/admin/listusers.js @@ -2,12 +2,11 @@ Description: Outputs all current channels and their user nicks */ +// module main exports.run = async (core, server, socket, data) => { // increase rate limit chance and ignore if not admin if (socket.uType != 'admin') { - server._police.frisk(socket.remoteAddress, 20); - - return; + return server._police.frisk(socket.remoteAddress, 20); } // find all users currently in a channel @@ -37,7 +36,10 @@ exports.run = async (core, server, socket, data) => { }, socket); }; +// module meta exports.info = { name: 'listusers', - description: 'Outputs all current channels and sockets in those channels' + description: 'Outputs all current channels and sockets in those channels', + usage: ` + API: { cmd: 'listusers' }` }; diff --git a/server/src/commands/admin/reload.js b/server/src/commands/admin/reload.js index 7a0ffdc..f7f7464 100644 --- a/server/src/commands/admin/reload.js +++ b/server/src/commands/admin/reload.js @@ -2,18 +2,21 @@ Description: Clears and resets the command modules, outputting any errors */ +// module main exports.run = async (core, server, socket, data) => { // increase rate limit chance and ignore if not admin if (socket.uType != 'admin') { - server._police.frisk(socket.remoteAddress, 20); - - return; + return server._police.frisk(socket.remoteAddress, 20); } // do command reloads and store results let loadResult = core.managers.dynamicImports.reloadDirCache('src/commands'); loadResult += core.commands.loadCommands(); + // clear and rebuild all module hooks + server.clearHooks(); + core.commands.initCommandHooks(server); + // build reply based on reload results if (loadResult == '') { loadResult = `Loaded ${core.commands._commands.length} commands, 0 errors`; @@ -34,7 +37,10 @@ exports.run = async (core, server, socket, data) => { }, { uType: 'mod' }); }; +// module meta exports.info = { name: 'reload', - description: '(Re)loads any new commands into memory, outputs errors if any' + description: '(Re)loads any new commands into memory, outputs errors if any', + usage: ` + API: { cmd: 'reload' }` }; diff --git a/server/src/commands/admin/removemod.js b/server/src/commands/admin/removemod.js new file mode 100644 index 0000000..dda822c --- /dev/null +++ b/server/src/commands/admin/removemod.js @@ -0,0 +1,50 @@ +/* + Description: Removes target trip from the config as a mod and downgrades the socket type +*/ + +// module main +exports.run = async (core, server, socket, data) => { + // increase rate limit chance and ignore if not admin + if (socket.uType != 'admin') { + return server._police.frisk(socket.remoteAddress, 20); + } + + // remove trip from config + core.config.mods = core.config.mods.filter(mod => mod.trip !== data.trip); + + // find targets current connections + let targetMod = server.findSockets({ trip: data.trip }); + if (newMod.length !== 0) { + for (let i = 0, l = newMod.length; i < l; i++) { + // downgrade privilages + targetMod[i].uType = 'user'; + + // inform ex-mod + server.send({ + cmd: 'info', + text: 'You are now a user.' + }, targetMod[i]); + } + } + + // return success message + server.reply({ + cmd: 'info', + text: `Removed mod trip: ${data.trip}, remember to run 'saveconfig' to make it permanent` + }, socket); + + // notify all mods + server.broadcast({ + cmd: 'info', + text: `Removed mod: ${data.trip}` + }, { uType: 'mod' }); +}; + +// module meta +exports.requiredData = ['trip']; +exports.info = { + name: 'removemod', + description: 'Removes target trip from the config as a mod and downgrades the socket type', + usage: ` + API: { cmd: 'removemod', trip: '<target trip>' }` +}; diff --git a/server/src/commands/admin/saveconfig.js b/server/src/commands/admin/saveconfig.js index 20927e7..b8a769b 100644 --- a/server/src/commands/admin/saveconfig.js +++ b/server/src/commands/admin/saveconfig.js @@ -2,22 +2,19 @@ Description: Writes the current config to disk */ +// module main exports.run = async (core, server, socket, data) => { // increase rate limit chance and ignore if not admin if (socket.uType != 'admin') { - server._police.frisk(socket.remoteAddress, 20); - - return; + return server._police.frisk(socket.remoteAddress, 20); } // attempt save, notify of failure if (!core.managers.config.save()) { - server.reply({ + return server.reply({ cmd: 'warn', text: 'Failed to save config, check logs.' }, client); - - return; } // return success message @@ -33,7 +30,10 @@ exports.run = async (core, server, socket, data) => { }, { uType: 'mod' }); }; +// module meta exports.info = { name: 'saveconfig', - description: 'Writes the current config to disk' + description: 'Writes the current config to disk', + usage: ` + API: { cmd: 'saveconfig' }` }; diff --git a/server/src/commands/admin/shout.js b/server/src/commands/admin/shout.js index 80a6470..e9c69e0 100644 --- a/server/src/commands/admin/shout.js +++ b/server/src/commands/admin/shout.js @@ -2,12 +2,11 @@ Description: Emmits a server-wide message as `info` */ +// module main exports.run = async (core, server, socket, data) => { // increase rate limit chance and ignore if not admin if (socket.uType != 'admin') { - server._police.frisk(socket.remoteAddress, 20); - - return; + return server._police.frisk(socket.remoteAddress, 20); } // send text to all channels @@ -17,10 +16,11 @@ exports.run = async (core, server, socket, data) => { }, {}); }; +// module meta exports.requiredData = ['text']; - exports.info = { name: 'shout', - usage: 'shout {text}', - description: 'Displays passed text to every client connected' + description: 'Displays passed text to every client connected', + usage: ` + API: { cmd: 'shout', text: '<shout text>' }` }; |