aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/admin
diff options
context:
space:
mode:
authormarzavec <admin@marzavec.com>2018-03-10 08:47:00 +0100
committermarzavec <admin@marzavec.com>2018-03-10 08:47:00 +0100
commitfde6895720a4f417283b9e375583967b504de2f3 (patch)
treef5c8d9a188572d759456831d574bef9881d5c0be /server/src/commands/admin
downloadhackchat-fde6895720a4f417283b9e375583967b504de2f3.tar.gz
hackchat-fde6895720a4f417283b9e375583967b504de2f3.zip
initial commit
Diffstat (limited to 'server/src/commands/admin')
-rw-r--r--server/src/commands/admin/addmod.js47
-rw-r--r--server/src/commands/admin/listusers.js41
-rw-r--r--server/src/commands/admin/reload.js34
-rw-r--r--server/src/commands/admin/saveconfig.js34
-rw-r--r--server/src/commands/admin/shout.js25
5 files changed, 181 insertions, 0 deletions
diff --git a/server/src/commands/admin/addmod.js b/server/src/commands/admin/addmod.js
new file mode 100644
index 0000000..dba5aba
--- /dev/null
+++ b/server/src/commands/admin/addmod.js
@@ -0,0 +1,47 @@
+/*
+
+*/
+
+'use strict';
+
+exports.run = async (core, server, socket, data) => {
+ if (socket.uType != 'admin') {
+ // ignore if not admin
+ return;
+ }
+
+ let mod = {
+ trip: data.trip
+ }
+
+ core.config.mods.push(mod); // purposely not using `config.set()` to avoid auto-save
+
+ for (let client of server.clients) {
+ if (typeof client.trip !== 'undefined' && client.trip === data.trip) {
+ client.uType = 'mod';
+
+ server.reply({
+ cmd: 'info',
+ text: 'You are now a mod.'
+ }, client);
+ }
+ }
+
+ server.reply({
+ cmd: 'info',
+ text: `Added mod trip: ${data.trip}`
+ }, socket);
+
+ server.broadcast({
+ cmd: 'info',
+ text: `Added mod trip: ${data.trip}`
+ }, { uType: 'mod' });
+};
+
+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'
+};
diff --git a/server/src/commands/admin/listusers.js b/server/src/commands/admin/listusers.js
new file mode 100644
index 0000000..a853518
--- /dev/null
+++ b/server/src/commands/admin/listusers.js
@@ -0,0 +1,41 @@
+/*
+
+*/
+
+'use strict';
+
+exports.run = async (core, server, socket, data) => {
+ if (socket.uType != 'admin') {
+ // ignore if not admin
+ return;
+ }
+
+ let channels = {};
+ for (var client of server.clients) {
+ if (client.channel) {
+ if (!channels[client.channel]) {
+ channels[client.channel] = [];
+ }
+ channels[client.channel].push(client.nick);
+ }
+ }
+
+ let lines = [];
+ for (let channel in channels) {
+ lines.push(`?${channel} ${channels[channel].join(", ")}`);
+ }
+
+ let text = '';
+ text += lines.join("\n");
+
+ server.reply({
+ cmd: 'info',
+ text: text
+ }, socket);
+};
+
+exports.info = {
+ name: 'listusers',
+ usage: 'listusers',
+ description: 'Outputs all current channels and sockets in those channels'
+};
diff --git a/server/src/commands/admin/reload.js b/server/src/commands/admin/reload.js
new file mode 100644
index 0000000..7aefbcf
--- /dev/null
+++ b/server/src/commands/admin/reload.js
@@ -0,0 +1,34 @@
+/*
+
+*/
+
+'use strict';
+
+exports.run = async (core, server, socket, data) => {
+ if (socket.uType != 'admin') {
+ // ignore if not admin
+ return;
+ }
+
+ let loadResult = core.managers.dynamicImports.reloadDirCache('src/commands');
+ loadResult += core.commands.loadCommands();
+
+ if (loadResult == '')
+ loadResult = 'Commands reloaded without errors!';
+
+ server.reply({
+ cmd: 'info',
+ text: loadResult
+ }, socket);
+
+ server.broadcast({
+ cmd: 'info',
+ text: loadResult
+ }, { uType: 'mod' });
+};
+
+exports.info = {
+ name: 'reload',
+ usage: '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
new file mode 100644
index 0000000..e1a3ebe
--- /dev/null
+++ b/server/src/commands/admin/saveconfig.js
@@ -0,0 +1,34 @@
+/*
+
+*/
+
+'use strict';
+
+exports.run = async (core, server, socket, data) => {
+ if (socket.uType != 'admin') {
+ // ignore if not admin
+ return;
+ }
+
+ let saveResult = core.managers.config.save();
+
+ if (!saveResult) {
+ server.reply({
+ cmd: 'warn',
+ text: 'Failed to save config, check logs.'
+ }, client);
+
+ return;
+ }
+
+ server.broadcast({
+ cmd: 'info',
+ text: 'Config saved!'
+ }, { uType: 'mod' });
+};
+
+exports.info = {
+ name: 'saveconfig',
+ usage: 'saveconfig',
+ description: 'Saves current config'
+};
diff --git a/server/src/commands/admin/shout.js b/server/src/commands/admin/shout.js
new file mode 100644
index 0000000..c3cfded
--- /dev/null
+++ b/server/src/commands/admin/shout.js
@@ -0,0 +1,25 @@
+/*
+
+*/
+
+'use strict';
+
+exports.run = async (core, server, socket, data) => {
+ if (socket.uType != 'admin') {
+ // ignore if not admin
+ return;
+ }
+
+ server.broadcast( {
+ cmd: 'info',
+ text: `Server Notice: ${data.text}`
+ }, {});
+};
+
+exports.requiredData = ['text'];
+
+exports.info = {
+ name: 'shout',
+ usage: 'shout {text}',
+ description: 'Displays passed text to every client connected'
+};