From 73e5c5ccfe408e58eb4bb927c71a77e0fceb22c4 Mon Sep 17 00:00:00 2001 From: neelkamath Date: Fri, 11 May 2018 20:46:12 +0530 Subject: Remove forgettable, unused, occasionally harmful (w.r.t. ES6) directive --- server/src/commands/mod/ban.js | 2 -- server/src/commands/mod/kick.js | 2 -- server/src/commands/mod/unban.js | 2 -- 3 files changed, 6 deletions(-) (limited to 'server/src/commands/mod') diff --git a/server/src/commands/mod/ban.js b/server/src/commands/mod/ban.js index 409217a..e19efc2 100644 --- a/server/src/commands/mod/ban.js +++ b/server/src/commands/mod/ban.js @@ -2,8 +2,6 @@ Description: Adds the target socket's ip to the ratelimiter */ -'use strict'; - exports.run = async (core, server, socket, data) => { if (socket.uType == 'user') { // ignore if not mod or admin diff --git a/server/src/commands/mod/kick.js b/server/src/commands/mod/kick.js index f32eaf5..1797ba9 100644 --- a/server/src/commands/mod/kick.js +++ b/server/src/commands/mod/kick.js @@ -2,8 +2,6 @@ Description: Forces a change on the target socket's channel, then broadcasts event */ -'use strict'; - exports.run = async (core, server, socket, data) => { if (socket.uType === 'user') { // ignore if not mod or admin diff --git a/server/src/commands/mod/unban.js b/server/src/commands/mod/unban.js index 2406644..d63288e 100644 --- a/server/src/commands/mod/unban.js +++ b/server/src/commands/mod/unban.js @@ -2,8 +2,6 @@ Description: Removes a target ip from the ratelimiter */ -'use strict'; - exports.run = async (core, server, socket, data) => { if (socket.uType == 'user') { // ignore if not mod or admin -- cgit v1.2.1 From acbad15f2bc4a6733407bc17e1a5b4190ed3b287 Mon Sep 17 00:00:00 2001 From: neelkamath Date: Sat, 12 May 2018 14:13:12 +0530 Subject: Remove unused object fields --- server/src/commands/mod/ban.js | 6 +----- server/src/commands/mod/kick.js | 6 +----- server/src/commands/mod/unban.js | 6 +----- 3 files changed, 3 insertions(+), 15 deletions(-) (limited to 'server/src/commands/mod') diff --git a/server/src/commands/mod/ban.js b/server/src/commands/mod/ban.js index e19efc2..b2749ae 100644 --- a/server/src/commands/mod/ban.js +++ b/server/src/commands/mod/ban.js @@ -57,8 +57,4 @@ exports.run = async (core, server, socket, data) => { 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' -}; +exports.info = { name: 'ban' }; diff --git a/server/src/commands/mod/kick.js b/server/src/commands/mod/kick.js index 1797ba9..5c72160 100644 --- a/server/src/commands/mod/kick.js +++ b/server/src/commands/mod/kick.js @@ -71,8 +71,4 @@ exports.run = async (core, server, socket, data) => { 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' -}; +exports.info = { name: 'kick' }; diff --git a/server/src/commands/mod/unban.js b/server/src/commands/mod/unban.js index d63288e..5450858 100644 --- a/server/src/commands/mod/unban.js +++ b/server/src/commands/mod/unban.js @@ -48,8 +48,4 @@ exports.run = async (core, server, socket, data) => { core.managers.stats.decrement('users-banned'); }; -exports.info = { - name: 'unban', - usage: 'unban {[ip || hash]}', - description: 'Removes target ip from the ratelimiter' -}; +exports.info = { name: 'unban' }; -- cgit v1.2.1 From 343157350f627b9495184246a90033a1c41f1a2c Mon Sep 17 00:00:00 2001 From: Neel Kamath Date: Sun, 13 May 2018 16:03:22 +0530 Subject: Re-add module documentation --- server/src/commands/mod/ban.js | 6 +++++- server/src/commands/mod/kick.js | 6 +++++- server/src/commands/mod/unban.js | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) (limited to 'server/src/commands/mod') diff --git a/server/src/commands/mod/ban.js b/server/src/commands/mod/ban.js index b2749ae..e19efc2 100644 --- a/server/src/commands/mod/ban.js +++ b/server/src/commands/mod/ban.js @@ -57,4 +57,8 @@ exports.run = async (core, server, socket, data) => { exports.requiredData = ['nick']; -exports.info = { name: 'ban' }; +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/src/commands/mod/kick.js b/server/src/commands/mod/kick.js index 5c72160..157592d 100644 --- a/server/src/commands/mod/kick.js +++ b/server/src/commands/mod/kick.js @@ -71,4 +71,8 @@ exports.run = async (core, server, socket, data) => { exports.requiredData = ['nick']; -exports.info = { name: 'kick' }; +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/src/commands/mod/unban.js b/server/src/commands/mod/unban.js index 5450858..e82f0b9 100644 --- a/server/src/commands/mod/unban.js +++ b/server/src/commands/mod/unban.js @@ -48,4 +48,8 @@ exports.run = async (core, server, socket, data) => { core.managers.stats.decrement('users-banned'); }; -exports.info = { name: 'unban' }; +exports.info = { + name: 'unban', + usage: 'unban {[ip || hash]}', + description: 'Removes target ip from the ratelimiter' +}; \ No newline at end of file -- cgit v1.2.1 From 2bb5ced363b692a5696b176bc317fe525c0c05df Mon Sep 17 00:00:00 2001 From: Neel Kamath Date: Sun, 13 May 2018 16:09:55 +0530 Subject: Flatten --- server/src/commands/mod/ban.js | 64 --------------------------------- server/src/commands/mod/kick.js | 78 ---------------------------------------- server/src/commands/mod/unban.js | 55 ---------------------------- 3 files changed, 197 deletions(-) delete mode 100644 server/src/commands/mod/ban.js delete mode 100644 server/src/commands/mod/kick.js delete mode 100644 server/src/commands/mod/unban.js (limited to 'server/src/commands/mod') diff --git a/server/src/commands/mod/ban.js b/server/src/commands/mod/ban.js deleted file mode 100644 index e19efc2..0000000 --- a/server/src/commands/mod/ban.js +++ /dev/null @@ -1,64 +0,0 @@ -/* - 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/src/commands/mod/kick.js b/server/src/commands/mod/kick.js deleted file mode 100644 index 157592d..0000000 --- a/server/src/commands/mod/kick.js +++ /dev/null @@ -1,78 +0,0 @@ -/* - 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/src/commands/mod/unban.js b/server/src/commands/mod/unban.js deleted file mode 100644 index e82f0b9..0000000 --- a/server/src/commands/mod/unban.js +++ /dev/null @@ -1,55 +0,0 @@ -/* - 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 -- cgit v1.2.1 From 949404cd1aad8492ae0338130f16054adfa38ab7 Mon Sep 17 00:00:00 2001 From: Neel Kamath Date: Sun, 13 May 2018 16:37:56 +0530 Subject: Prevent fucking shit up --- server/src/commands/mod/ban.js | 64 +++++++++++++++++++++++++++++++++ server/src/commands/mod/kick.js | 78 ++++++++++++++++++++++++++++++++++++++++ server/src/commands/mod/unban.js | 55 ++++++++++++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 server/src/commands/mod/ban.js create mode 100644 server/src/commands/mod/kick.js create mode 100644 server/src/commands/mod/unban.js (limited to 'server/src/commands/mod') diff --git a/server/src/commands/mod/ban.js b/server/src/commands/mod/ban.js new file mode 100644 index 0000000..e19efc2 --- /dev/null +++ b/server/src/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/src/commands/mod/kick.js b/server/src/commands/mod/kick.js new file mode 100644 index 0000000..157592d --- /dev/null +++ b/server/src/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/src/commands/mod/unban.js b/server/src/commands/mod/unban.js new file mode 100644 index 0000000..e82f0b9 --- /dev/null +++ b/server/src/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 -- cgit v1.2.1