aboutsummaryrefslogtreecommitdiffstats
path: root/server/commands/mod
diff options
context:
space:
mode:
authorNeel Kamath <neelkamath@protonmail.com>2018-05-13 12:39:55 +0200
committerNeel Kamath <neelkamath@protonmail.com>2018-05-13 12:39:55 +0200
commit2bb5ced363b692a5696b176bc317fe525c0c05df (patch)
tree1532d9456c5f2b25ac05f7cec620a3af890eff83 /server/commands/mod
parentRe-add module documentation (diff)
downloadhackchat-2bb5ced363b692a5696b176bc317fe525c0c05df.tar.gz
hackchat-2bb5ced363b692a5696b176bc317fe525c0c05df.zip
Flatten
Diffstat (limited to 'server/commands/mod')
-rw-r--r--server/commands/mod/ban.js64
-rw-r--r--server/commands/mod/kick.js78
-rw-r--r--server/commands/mod/unban.js55
3 files changed, 197 insertions, 0 deletions
diff --git a/server/commands/mod/ban.js b/server/commands/mod/ban.js
new file mode 100644
index 0000000..e19efc2
--- /dev/null
+++ b/server/commands/mod/ban.js
@@ -0,0 +1,64 @@
+/*
+ Description: Adds the target socket's ip to the ratelimiter
+*/
+
+exports.run = async (core, server, socket, data) => {
+ if (socket.uType == 'user') {
+ // ignore if not mod or admin
+ return;
+ }
+
+ if (typeof data.nick !== 'string') {
+ return;
+ }
+
+ let targetNick = data.nick;
+ let badClient = server.findSockets({ channel: socket.channel, nick: targetNick });
+
+ if (badClient.length === 0) {
+ server.reply({
+ cmd: 'warn',
+ text: 'Could not find user in channel'
+ }, socket);
+
+ return;
+ }
+
+ badClient = badClient[0];
+
+ if (badClient.uType !== 'user') {
+ server.reply({
+ cmd: 'warn',
+ text: 'Cannot ban other mods, how rude'
+ }, socket);
+
+ return;
+ }
+
+ let clientHash = server.getSocketHash(badClient);
+ server._police.arrest(badClient.remoteAddress, clientHash);
+
+ console.log(`${socket.nick} [${socket.trip}] banned ${targetNick} in ${socket.channel}`);
+
+ server.broadcast({
+ cmd: 'info',
+ text: `Banned ${targetNick}`
+ }, { channel: socket.channel, uType: 'user' });
+
+ server.broadcast({
+ cmd: 'info',
+ text: `${socket.nick} banned ${targetNick} in ${socket.channel}, userhash: ${clientHash}`
+ }, { uType: 'mod' });
+
+ badClient.close();
+
+ core.managers.stats.increment('users-banned');
+};
+
+exports.requiredData = ['nick'];
+
+exports.info = {
+ name: 'ban',
+ usage: 'ban {nick}',
+ description: 'Disconnects the target nickname in the same channel as calling socket & adds to ratelimiter'
+};
diff --git a/server/commands/mod/kick.js b/server/commands/mod/kick.js
new file mode 100644
index 0000000..157592d
--- /dev/null
+++ b/server/commands/mod/kick.js
@@ -0,0 +1,78 @@
+/*
+ Description: Forces a change on the target socket's channel, then broadcasts event
+*/
+
+exports.run = async (core, server, socket, data) => {
+ if (socket.uType === 'user') {
+ // ignore if not mod or admin
+ return;
+ }
+
+ if (typeof data.nick !== 'string') {
+ if (typeof data.nick !== 'object' && !Array.isArray(data.nick)) {
+ return;
+ }
+ }
+
+ let badClients = server.findSockets({ channel: socket.channel, nick: data.nick });
+
+ if (badClients.length === 0) {
+ server.reply({
+ cmd: 'warn',
+ text: 'Could not find user(s) in channel'
+ }, socket);
+
+ return;
+ }
+
+ let newChannel = '';
+ let kicked = [];
+ for (let i = 0, j = badClients.length; i < j; i++) {
+ if (badClients[i].uType !== 'user') {
+ server.reply({
+ cmd: 'warn',
+ text: 'Cannot kick other mods, how rude'
+ }, socket);
+ } else {
+ newChannel = Math.random().toString(36).substr(2, 8);
+ badClients[i].channel = newChannel;
+
+ // inform mods with where they were sent
+ server.broadcast({
+ cmd: 'info',
+ text: `${badClients[i].nick} was banished to ?${newChannel}`
+ }, { channel: socket.channel, uType: 'mod' });
+
+ kicked.push(badClients[i].nick);
+ console.log(`${socket.nick} [${socket.trip}] kicked ${badClients[i].nick} in ${socket.channel}`);
+ }
+ }
+
+ if (kicked.length === 0) {
+ return;
+ }
+
+ // broadcast client leave event
+ for (let i = 0, j = kicked.length; i < j; i++) {
+ server.broadcast({
+ cmd: 'onlineRemove',
+ nick: kicked[i]
+ }, { channel: socket.channel });
+ }
+
+ // publicly broadcast kick event
+ server.broadcast({
+ cmd: 'info',
+ text: `Kicked ${kicked.join(', ')}`
+ }, { channel: socket.channel, uType: 'user' });
+
+ core.managers.stats.increment('users-kicked', kicked.length);
+};
+
+exports.requiredData = ['nick'];
+
+exports.info = {
+ name: 'kick',
+ usage: 'kick {nick}',
+ description: 'Silently forces target client(s) into another channel. `nick` may be string or array of strings'
+}; \ No newline at end of file
diff --git a/server/commands/mod/unban.js b/server/commands/mod/unban.js
new file mode 100644
index 0000000..e82f0b9
--- /dev/null
+++ b/server/commands/mod/unban.js
@@ -0,0 +1,55 @@
+/*
+ Description: Removes a target ip from the ratelimiter
+*/
+
+exports.run = async (core, server, socket, data) => {
+ if (socket.uType == 'user') {
+ // ignore if not mod or admin
+ return;
+ }
+
+ if (typeof data.ip !== 'string' && typeof data.hash !== 'string') {
+ server.reply({
+ cmd: 'warn',
+ text: "hash:'targethash' or ip:'1.2.3.4' is required"
+ }, socket);
+
+ return;
+ }
+
+ let mode, target;
+
+ if (typeof data.ip === 'string') {
+ mode = 'ip';
+ target = data.ip;
+ } else {
+ mode = 'hash';
+ target = data.hash;
+ }
+
+ server._police.pardon(target);
+
+ if (mode === 'ip') {
+ target = server.getSocketHash(target);
+ }
+
+ console.log(`${socket.nick} [${socket.trip}] unbanned ${target} in ${socket.channel}`);
+
+ server.reply({
+ cmd: 'info',
+ text: `Unbanned ${target}`
+ }, socket);
+
+ server.broadcast({
+ cmd: 'info',
+ text: `${socket.nick} unbanned: ${target}`
+ }, { uType: 'mod' });
+
+ core.managers.stats.decrement('users-banned');
+};
+
+exports.info = {
+ name: 'unban',
+ usage: 'unban {[ip || hash]}',
+ description: 'Removes target ip from the ratelimiter'
+}; \ No newline at end of file