aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/admin
diff options
context:
space:
mode:
authormarzavec <admin@marzavec.com>2018-06-04 09:07:24 +0200
committermarzavec <admin@marzavec.com>2018-06-04 09:07:24 +0200
commite35fff59ba30e78046c9212e74fce9aef56c6e93 (patch)
treec7d3e0cd75f5a6063d629d4295952488907e9562 /server/src/commands/admin
parentCompleted protocol decoupling (diff)
downloadhackchat-e35fff59ba30e78046c9212e74fce9aef56c6e93.tar.gz
hackchat-e35fff59ba30e78046c9212e74fce9aef56c6e93.zip
cleaned up and commented modules
Diffstat (limited to '')
-rw-r--r--server/src/commands/admin/addmod.js15
-rw-r--r--server/src/commands/admin/listusers.js27
-rw-r--r--server/src/commands/admin/reload.js9
-rw-r--r--server/src/commands/admin/saveconfig.js15
-rw-r--r--server/src/commands/admin/shout.js9
5 files changed, 46 insertions, 29 deletions
diff --git a/server/src/commands/admin/addmod.js b/server/src/commands/admin/addmod.js
index 4c13b22..bde54a1 100644
--- a/server/src/commands/admin/addmod.js
+++ b/server/src/commands/admin/addmod.js
@@ -3,19 +3,18 @@
*/
exports.run = async (core, server, socket, data) => {
+ // increase rate limit chance and ignore if not admin
if (socket.uType != 'admin') {
- // ignore if not admin
- return;
- }
+ server._police.frisk(socket.remoteAddress, 20);
- let mod = {
- trip: data.trip
+ return;
}
- core.config.mods.push(mod); // purposely not using `config.set()` to avoid auto-save
+ // 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
let newMod = server.findSockets({ trip: data.trip });
-
if (newMod.length !== 0) {
for (let i = 0, l = newMod.length; i < l; i++) {
newMod[i].uType = 'mod';
@@ -27,11 +26,13 @@ exports.run = async (core, server, socket, data) => {
}
}
+ // return success message
server.reply({
cmd: 'info',
text: `Added mod trip: ${data.trip}`
}, socket);
+ // notify all mods
server.broadcast({
cmd: 'info',
text: `Added mod trip: ${data.trip}`
diff --git a/server/src/commands/admin/listusers.js b/server/src/commands/admin/listusers.js
index a539a3c..d3dddc2 100644
--- a/server/src/commands/admin/listusers.js
+++ b/server/src/commands/admin/listusers.js
@@ -3,32 +3,37 @@
*/
exports.run = async (core, server, socket, data) => {
+ // increase rate limit chance and ignore if not admin
if (socket.uType != 'admin') {
- // ignore if not admin
+ server._police.frisk(socket.remoteAddress, 20);
+
return;
}
+ // find all users currently in a channel
+ let currentUsers = server.findSockets({
+ channel: (channel) => true
+ });
+
+ // compile channel and user list
let channels = {};
- for (var client of server.clients) {
- if (client.channel) {
- if (!channels[client.channel]) {
- channels[client.channel] = [];
- }
- channels[client.channel].push(client.nick);
+ for (let i = 0, j = currentUsers.length; i < j; i++) {
+ if (typeof channels[currentUsers[i].channel] === 'undefined') {
+ channels[currentUsers[i].channel] = [];
}
+ channels[currentUsers[i].channel].push(currentUsers[i].nick);
}
+ // build output
let lines = [];
for (let channel in channels) {
lines.push(`?${channel} ${channels[channel].join(", ")}`);
}
- let text = '';
- text += lines.join("\n");
-
+ // send reply
server.reply({
cmd: 'info',
- text: text
+ text: lines.join("\n")
}, socket);
};
diff --git a/server/src/commands/admin/reload.js b/server/src/commands/admin/reload.js
index e2cfbe6..7a0ffdc 100644
--- a/server/src/commands/admin/reload.js
+++ b/server/src/commands/admin/reload.js
@@ -3,25 +3,31 @@
*/
exports.run = async (core, server, socket, data) => {
+ // increase rate limit chance and ignore if not admin
if (socket.uType != 'admin') {
- // ignore if not admin
+ server._police.frisk(socket.remoteAddress, 20);
+
return;
}
+ // do command reloads and store results
let loadResult = core.managers.dynamicImports.reloadDirCache('src/commands');
loadResult += core.commands.loadCommands();
+ // build reply based on reload results
if (loadResult == '') {
loadResult = `Loaded ${core.commands._commands.length} commands, 0 errors`;
} else {
loadResult = `Loaded ${core.commands._commands.length} commands, error(s): ${loadResult}`;
}
+ // reply with results
server.reply({
cmd: 'info',
text: loadResult
}, socket);
+ // notify mods of reload #transparency
server.broadcast({
cmd: 'info',
text: loadResult
@@ -32,4 +38,3 @@ exports.info = {
name: 'reload',
description: '(Re)loads any new commands into memory, outputs errors if any'
};
-
diff --git a/server/src/commands/admin/saveconfig.js b/server/src/commands/admin/saveconfig.js
index ed3a312..20927e7 100644
--- a/server/src/commands/admin/saveconfig.js
+++ b/server/src/commands/admin/saveconfig.js
@@ -1,16 +1,17 @@
/*
- Description: Writes any changes to the config to the disk
+ Description: Writes the current config to disk
*/
exports.run = async (core, server, socket, data) => {
+ // increase rate limit chance and ignore if not admin
if (socket.uType != 'admin') {
- // ignore if not admin
+ server._police.frisk(socket.remoteAddress, 20);
+
return;
}
- let saveResult = core.managers.config.save();
-
- if (!saveResult) {
+ // attempt save, notify of failure
+ if (!core.managers.config.save()) {
server.reply({
cmd: 'warn',
text: 'Failed to save config, check logs.'
@@ -19,11 +20,13 @@ exports.run = async (core, server, socket, data) => {
return;
}
+ // return success message
server.reply({
cmd: 'info',
text: 'Config saved!'
}, socket);
+ // notify mods #transparency
server.broadcast({
cmd: 'info',
text: 'Config saved!'
@@ -32,5 +35,5 @@ exports.run = async (core, server, socket, data) => {
exports.info = {
name: 'saveconfig',
- description: 'Saves current config'
+ description: 'Writes the current config to disk'
};
diff --git a/server/src/commands/admin/shout.js b/server/src/commands/admin/shout.js
index 1358dd9..80a6470 100644
--- a/server/src/commands/admin/shout.js
+++ b/server/src/commands/admin/shout.js
@@ -3,12 +3,15 @@
*/
exports.run = async (core, server, socket, data) => {
+ // increase rate limit chance and ignore if not admin
if (socket.uType != 'admin') {
- // ignore if not admin
+ server._police.frisk(socket.remoteAddress, 20);
+
return;
}
- server.broadcast( {
+ // send text to all channels
+ server.broadcast({
cmd: 'info',
text: `Server Notice: ${data.text}`
}, {});
@@ -20,4 +23,4 @@ exports.info = {
name: 'shout',
usage: 'shout {text}',
description: 'Displays passed text to every client connected'
-}; \ No newline at end of file
+};