From 73e5c5ccfe408e58eb4bb927c71a77e0fceb22c4 Mon Sep 17 00:00:00 2001
From: neelkamath <neelkamath@protonmail.com>
Date: Fri, 11 May 2018 20:46:12 +0530
Subject: Remove forgettable, unused, occasionally harmful (w.r.t. ES6)
 directive

---
 server/src/commands/core/changenick.js | 2 --
 server/src/commands/core/chat.js       | 2 --
 server/src/commands/core/disconnect.js | 2 --
 server/src/commands/core/help.js       | 2 --
 server/src/commands/core/invite.js     | 2 --
 server/src/commands/core/join.js       | 2 --
 server/src/commands/core/morestats.js  | 2 --
 server/src/commands/core/move.js       | 2 --
 server/src/commands/core/showcase.js   | 2 --
 server/src/commands/core/stats.js      | 2 --
 10 files changed, 20 deletions(-)

(limited to 'server/src/commands/core')

diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js
index 6b2932c..4041bb0 100644
--- a/server/src/commands/core/changenick.js
+++ b/server/src/commands/core/changenick.js
@@ -2,8 +2,6 @@
   Description: Generates a semi-unique channel name then broadcasts it to each client
 */
 
-'use strict';
-
 const verifyNickname = (nick) => {
   return /^[a-zA-Z0-9_]{1,24}$/.test(nick);
 };
diff --git a/server/src/commands/core/chat.js b/server/src/commands/core/chat.js
index ee45425..4e95940 100644
--- a/server/src/commands/core/chat.js
+++ b/server/src/commands/core/chat.js
@@ -2,8 +2,6 @@
   Description: Rebroadcasts any `text` to all clients in a `channel`
 */
 
-'use strict';
-
 const parseText = (text) => {
   if (typeof text !== 'string') {
     return false;
diff --git a/server/src/commands/core/disconnect.js b/server/src/commands/core/disconnect.js
index 1a9c635..41ca380 100644
--- a/server/src/commands/core/disconnect.js
+++ b/server/src/commands/core/disconnect.js
@@ -4,8 +4,6 @@
                by a client to have the connection severed.
 */
 
-'use strict';
-
 exports.run = async (core, server, socket, data) => {
   if (socket.channel) {
     server.broadcast({
diff --git a/server/src/commands/core/help.js b/server/src/commands/core/help.js
index 71cc745..331e13f 100644
--- a/server/src/commands/core/help.js
+++ b/server/src/commands/core/help.js
@@ -2,8 +2,6 @@
   Description: Outputs the current command module list or command categories
 */
 
-'use strict';
-
 const stripIndents = require('common-tags').stripIndents;
 
 exports.run = async (core, server, socket, data) => {
diff --git a/server/src/commands/core/invite.js b/server/src/commands/core/invite.js
index bd85812..735dace 100644
--- a/server/src/commands/core/invite.js
+++ b/server/src/commands/core/invite.js
@@ -2,8 +2,6 @@
   Description: Generates a semi-unique channel name then broadcasts it to each client
 */
 
-'use strict';
-
 const verifyNickname = (nick) => {
   return /^[a-zA-Z0-9_]{1,24}$/.test(nick);
 };
diff --git a/server/src/commands/core/join.js b/server/src/commands/core/join.js
index 82b48d2..b385b89 100644
--- a/server/src/commands/core/join.js
+++ b/server/src/commands/core/join.js
@@ -2,8 +2,6 @@
   Description: Initial entry point, applies `channel` and `nick` to the calling socket
 */
 
-'use strict';
-
 const crypto = require('crypto');
 
 const hash = (password) => {
diff --git a/server/src/commands/core/morestats.js b/server/src/commands/core/morestats.js
index d8bc23d..c1105f1 100644
--- a/server/src/commands/core/morestats.js
+++ b/server/src/commands/core/morestats.js
@@ -2,8 +2,6 @@
   Description: Outputs more info than the legacy stats command
 */
 
-'use strict';
-
 const stripIndents = require('common-tags').stripIndents;
 
 const formatTime = (time) => {
diff --git a/server/src/commands/core/move.js b/server/src/commands/core/move.js
index 862025c..9e50f4f 100644
--- a/server/src/commands/core/move.js
+++ b/server/src/commands/core/move.js
@@ -2,8 +2,6 @@
   Description: Generates a semi-unique channel name then broadcasts it to each client
 */
 
-'use strict';
-
 exports.run = async (core, server, socket, data) => {
   if (server._police.frisk(socket.remoteAddress, 6)) {
     server.reply({
diff --git a/server/src/commands/core/showcase.js b/server/src/commands/core/showcase.js
index 5eca4a2..35d811a 100644
--- a/server/src/commands/core/showcase.js
+++ b/server/src/commands/core/showcase.js
@@ -2,8 +2,6 @@
   Description: This is a template module that should not be on prod
 */
 
-'use strict';
-
 // you can require() modules here
 
 // this function will only be only in the scope of the module
diff --git a/server/src/commands/core/stats.js b/server/src/commands/core/stats.js
index a1abddb..3a96381 100644
--- a/server/src/commands/core/stats.js
+++ b/server/src/commands/core/stats.js
@@ -2,8 +2,6 @@
   Description: Legacy stats output, kept for compatibility, outputs user and channel count
 */
 
-'use strict';
-
 exports.run = async (core, server, socket, data) => {
   let ips = {};
   let channels = {};
-- 
cgit v1.2.1


From 4b30736929e65ec7ad664b2ffb2d1eca10b0636a Mon Sep 17 00:00:00 2001
From: neelkamath <neelkamath@protonmail.com>
Date: Sat, 12 May 2018 13:52:19 +0530
Subject: Remove help.js as we need human, not programmatic documentation for
 this

---
 server/src/commands/core/help.js | 49 ----------------------------------------
 1 file changed, 49 deletions(-)
 delete mode 100644 server/src/commands/core/help.js

(limited to 'server/src/commands/core')

diff --git a/server/src/commands/core/help.js b/server/src/commands/core/help.js
deleted file mode 100644
index 331e13f..0000000
--- a/server/src/commands/core/help.js
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-  Description: Outputs the current command module list or command categories
-*/
-
-const stripIndents = require('common-tags').stripIndents;
-
-exports.run = async (core, server, socket, data) => {
-  // verify passed arguments
-  let typeDt = typeof data.type;
-  let catDt = typeof data.category;
-  let cmdDt = typeof data.command;
-  if (typeDt !== 'undefined' && typeDt !== 'string' ) {
-    return;
-  } else if (catDt !== 'undefined' && catDt !== 'string' ) {
-    return;
-  } else if (cmdDt !== 'undefined' && cmdDt !== 'string' ) {
-    return;
-  }
-
-  // set default reply
-  let reply = stripIndents`Help usage:
-    Show all categories -> { cmd: 'help', type: 'categories' }
-    Show all commands in category -> { cmd: 'help', category: '<category name>' }
-    Show specific command -> { cmd: 'help', command: '<command name>' }`;
-
-  if (typeDt !== 'undefined') {
-    let categories = core.commands.categories().sort();
-    reply = `Command Categories:\n${categories.map(c => `- ${c.replace('../src/commands/', '')}`).join('\n')}`;
-  } else if (catDt !== 'undefined') {
-    let catCommands = core.commands.all('../src/commands/' + data.category).sort((a, b) => a.info.name.localeCompare(b.info.name));
-    reply = `${data.category} commands:\n${catCommands.map(c => `- ${c.info.name}`).join('\n')}`;
-  } else if (cmdDt !== 'undefined') {
-    let command = core.commands.get(data.command);
-    reply = stripIndents`
-      Usage: ${command.info.usage || command.info.name}
-      Description: ${command.info.description || '¯\_(ツ)_/¯'}`;
-  }
-
-  server.reply({
-    cmd: 'info',
-    text: reply
-  }, socket);
-};
-
-exports.info = {
-  name: 'help',
-  usage: 'help ([ type:categories] | [category:<category name> | command:<command name> ])',
-  description: 'Outputs information about the servers current protocol'
-};
-- 
cgit v1.2.1


From acbad15f2bc4a6733407bc17e1a5b4190ed3b287 Mon Sep 17 00:00:00 2001
From: neelkamath <neelkamath@protonmail.com>
Date: Sat, 12 May 2018 14:13:12 +0530
Subject: Remove unused object fields

---
 server/src/commands/core/changenick.js | 6 +-----
 server/src/commands/core/chat.js       | 6 +-----
 server/src/commands/core/disconnect.js | 5 +----
 server/src/commands/core/invite.js     | 6 +-----
 server/src/commands/core/join.js       | 6 +-----
 server/src/commands/core/morestats.js  | 5 +----
 server/src/commands/core/move.js       | 6 +-----
 server/src/commands/core/showcase.js   | 6 ++----
 server/src/commands/core/stats.js      | 5 +----
 9 files changed, 10 insertions(+), 41 deletions(-)

(limited to 'server/src/commands/core')

diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js
index 4041bb0..94ae4d4 100644
--- a/server/src/commands/core/changenick.js
+++ b/server/src/commands/core/changenick.js
@@ -81,8 +81,4 @@ exports.run = async (core, server, socket, data) => {
 
 exports.requiredData = ['nick'];
 
-exports.info = {
-  name: 'changenick',
-  usage: 'changenick {nick}',
-  description: 'This will change your current connections nickname'
-};
+exports.info = { name: 'changenick' };
diff --git a/server/src/commands/core/chat.js b/server/src/commands/core/chat.js
index 4e95940..36a98e8 100644
--- a/server/src/commands/core/chat.js
+++ b/server/src/commands/core/chat.js
@@ -55,8 +55,4 @@ exports.run = async (core, server, socket, data) => {
 
 exports.requiredData = ['text'];
 
-exports.info = {
-  name: 'chat',
-  usage: 'chat {text}',
-  description: 'Broadcasts passed `text` field to the calling users channel'
-};
+exports.info = { name: 'chat' };
diff --git a/server/src/commands/core/disconnect.js b/server/src/commands/core/disconnect.js
index 41ca380..9e733fa 100644
--- a/server/src/commands/core/disconnect.js
+++ b/server/src/commands/core/disconnect.js
@@ -15,7 +15,4 @@ exports.run = async (core, server, socket, data) => {
   socket.terminate();
 };
 
-exports.info = {
-  name: 'disconnect',
-  description: 'Event handler or force disconnect (if your into that kind of thing)'
-};
+exports.info = { name: 'disconnect' };
diff --git a/server/src/commands/core/invite.js b/server/src/commands/core/invite.js
index 735dace..3fbbe6e 100644
--- a/server/src/commands/core/invite.js
+++ b/server/src/commands/core/invite.js
@@ -58,8 +58,4 @@ exports.run = async (core, server, socket, data) => {
 
 exports.requiredData = ['nick'];
 
-exports.info = {
-  name: 'invite',
-  usage: 'invite {nick}',
-  description: 'Generates a unique (more or less) room name and passes it to two clients'
-};
+exports.info = { name: 'invite' };
diff --git a/server/src/commands/core/join.js b/server/src/commands/core/join.js
index b385b89..b72824b 100644
--- a/server/src/commands/core/join.js
+++ b/server/src/commands/core/join.js
@@ -128,8 +128,4 @@ exports.run = async (core, server, socket, data) => {
 
 exports.requiredData = ['channel', 'nick'];
 
-exports.info = {
-  name: 'join',
-  usage: 'join {channel} {nick}',
-  description: 'Place calling socket into target channel with target nick & broadcast event to channel'
-};
+exports.info = { name: 'join' };
diff --git a/server/src/commands/core/morestats.js b/server/src/commands/core/morestats.js
index c1105f1..ce0e87d 100644
--- a/server/src/commands/core/morestats.js
+++ b/server/src/commands/core/morestats.js
@@ -47,7 +47,4 @@ exports.run = async (core, server, socket, data) => {
   core.managers.stats.increment('stats-requested');
 };
 
-exports.info = {
-  name: 'morestats',
-  description: 'Sends back current server stats to the calling client'
-};
+exports.info = { name: 'morestats' };
diff --git a/server/src/commands/core/move.js b/server/src/commands/core/move.js
index 9e50f4f..9462468 100644
--- a/server/src/commands/core/move.js
+++ b/server/src/commands/core/move.js
@@ -76,8 +76,4 @@ exports.run = async (core, server, socket, data) => {
 
 exports.requiredData = ['channel'];
 
-exports.info = {
-  name: 'move',
-  usage: 'move {channel}',
-  description: 'This will change the current channel to the new one provided'
-};
+exports.info = { name: 'move' };
diff --git a/server/src/commands/core/showcase.js b/server/src/commands/core/showcase.js
index 35d811a..1f2cdd9 100644
--- a/server/src/commands/core/showcase.js
+++ b/server/src/commands/core/showcase.js
@@ -43,9 +43,7 @@ exports.init = (core) => {
 exports.requiredData = ['echo'];
 
 // optional parameters are marked, all others are required
-exports.info = {
+exports.info = { 
   name: 'showcase', // actual command name
-  aliases: ['templateModule'], // optional, an array of other names this module can be executed by
-  usage: 'showcase {echo}', // used for help output, can be ommited if no parameters are required
-  description: 'Simple command module template & info' // used for help output
+  aliases: ['templateModule']
 };
diff --git a/server/src/commands/core/stats.js b/server/src/commands/core/stats.js
index 3a96381..2802579 100644
--- a/server/src/commands/core/stats.js
+++ b/server/src/commands/core/stats.js
@@ -26,7 +26,4 @@ exports.run = async (core, server, socket, data) => {
   core.managers.stats.increment('stats-requested');
 };
 
-exports.info = {
-  name: 'stats',
-  description: 'Sends back legacy server stats to the calling client'
-};
+exports.info = { name: 'stats' };
-- 
cgit v1.2.1


From 5b3322ebba246c3d3581e3e51e3c29671d506a20 Mon Sep 17 00:00:00 2001
From: neelkamath <neelkamath@protonmail.com>
Date: Sat, 12 May 2018 14:49:56 +0530
Subject: Enhance READM.md

---
 server/src/commands/core/showcase.js | 49 ------------------------------------
 1 file changed, 49 deletions(-)
 delete mode 100644 server/src/commands/core/showcase.js

(limited to 'server/src/commands/core')

diff --git a/server/src/commands/core/showcase.js b/server/src/commands/core/showcase.js
deleted file mode 100644
index 1f2cdd9..0000000
--- a/server/src/commands/core/showcase.js
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-  Description: This is a template module that should not be on prod
-*/
-
-// you can require() modules here
-
-// this function will only be only in the scope of the module
-const createReply = (echoInput) => {
-  if (echoInput.length > 100)
-    echoInput = 'HOW ABOUT NO?';
-
-  return `You want me to echo: ${echoInput}?`
-};
-
-/*
-  `exports.run()` is required and will always be passed (core, server, socket, data)
-
-  be sure it's async too
-  this is the main function that will run when called
-*/
-exports.run = async (core, server, socket, data) => {
-
-  server.reply({
-    cmd: 'info',
-    text: `SHOWCASE MODULE: ${core.showcase} - ${createReply(data.echo)}`
-  }, socket);
-
-};
-
-/*
-  `exports.init()` is optional, and will only be run when the module is loaded into memory
-  it will always be passed a reference to the global core class
-  note: this will fire again if a reload is issued, keep that in mind
-*/
-exports.init = (core) => {
-  if (typeof core.showcase === 'undefined') {
-    core.showcase = 'init is a handy place to put global data by assigning it to `core`';
-  }
-}
-
-// optional, if `data.echo` is missing `exports.run()` will never be called & the user will be alerted
-// remember; this will only verify that the data is not undefined, not the type of data
-exports.requiredData = ['echo'];
-
-// optional parameters are marked, all others are required
-exports.info = { 
-  name: 'showcase', // actual command name
-  aliases: ['templateModule']
-};
-- 
cgit v1.2.1


From 343157350f627b9495184246a90033a1c41f1a2c Mon Sep 17 00:00:00 2001
From: Neel Kamath <neelkamath@protonmail.com>
Date: Sun, 13 May 2018 16:03:22 +0530
Subject: Re-add module documentation

---
 server/src/commands/core/changenick.js |  6 ++++-
 server/src/commands/core/chat.js       |  6 ++++-
 server/src/commands/core/disconnect.js |  5 +++-
 server/src/commands/core/help.js       | 49 ++++++++++++++++++++++++++++++++++
 server/src/commands/core/invite.js     |  6 ++++-
 server/src/commands/core/join.js       |  6 ++++-
 server/src/commands/core/morestats.js  |  5 +++-
 server/src/commands/core/move.js       |  6 ++++-
 server/src/commands/core/stats.js      |  5 +++-
 9 files changed, 86 insertions(+), 8 deletions(-)
 create mode 100644 server/src/commands/core/help.js

(limited to 'server/src/commands/core')

diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js
index 94ae4d4..4041bb0 100644
--- a/server/src/commands/core/changenick.js
+++ b/server/src/commands/core/changenick.js
@@ -81,4 +81,8 @@ exports.run = async (core, server, socket, data) => {
 
 exports.requiredData = ['nick'];
 
-exports.info = { name: 'changenick' };
+exports.info = {
+  name: 'changenick',
+  usage: 'changenick {nick}',
+  description: 'This will change your current connections nickname'
+};
diff --git a/server/src/commands/core/chat.js b/server/src/commands/core/chat.js
index 36a98e8..bce6adb 100644
--- a/server/src/commands/core/chat.js
+++ b/server/src/commands/core/chat.js
@@ -55,4 +55,8 @@ exports.run = async (core, server, socket, data) => {
 
 exports.requiredData = ['text'];
 
-exports.info = { name: 'chat' };
+exports.info = {
+  name: 'chat',
+  usage: 'chat {text}',
+  description: 'Broadcasts passed `text` field to the calling users channel'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/disconnect.js b/server/src/commands/core/disconnect.js
index 9e733fa..9b54214 100644
--- a/server/src/commands/core/disconnect.js
+++ b/server/src/commands/core/disconnect.js
@@ -15,4 +15,7 @@ exports.run = async (core, server, socket, data) => {
   socket.terminate();
 };
 
-exports.info = { name: 'disconnect' };
+exports.info = {
+  name: 'disconnect',
+  description: 'Event handler or force disconnect (if your into that kind of thing)'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/help.js b/server/src/commands/core/help.js
new file mode 100644
index 0000000..7f63d3d
--- /dev/null
+++ b/server/src/commands/core/help.js
@@ -0,0 +1,49 @@
+/*
+  Description: Outputs the current command module list or command categories
+*/
+
+const stripIndents = require('common-tags').stripIndents;
+
+exports.run = async (core, server, socket, data) => {
+  // verify passed arguments
+  let typeDt = typeof data.type;
+  let catDt = typeof data.category;
+  let cmdDt = typeof data.command;
+  if (typeDt !== 'undefined' && typeDt !== 'string' ) {
+    return;
+  } else if (catDt !== 'undefined' && catDt !== 'string' ) {
+    return;
+  } else if (cmdDt !== 'undefined' && cmdDt !== 'string' ) {
+    return;
+  }
+
+  // set default reply
+  let reply = stripIndents`Help usage:
+    Show all categories -> { cmd: 'help', type: 'categories' }
+    Show all commands in category -> { cmd: 'help', category: '<category name>' }
+    Show specific command -> { cmd: 'help', command: '<command name>' }`;
+
+  if (typeDt !== 'undefined') {
+    let categories = core.commands.categories().sort();
+    reply = `Command Categories:\n${categories.map(c => `- ${c.replace('../src/commands/', '')}`).join('\n')}`;
+  } else if (catDt !== 'undefined') {
+    let catCommands = core.commands.all('../src/commands/' + data.category).sort((a, b) => a.info.name.localeCompare(b.info.name));
+    reply = `${data.category} commands:\n${catCommands.map(c => `- ${c.info.name}`).join('\n')}`;
+  } else if (cmdDt !== 'undefined') {
+    let command = core.commands.get(data.command);
+    reply = stripIndents`
+      Usage: ${command.info.usage || command.info.name}
+      Description: ${command.info.description || '¯\_(ツ)_/¯'}`;
+  }
+
+  server.reply({
+    cmd: 'info',
+    text: reply
+  }, socket);
+};
+
+exports.info = {
+  name: 'help',
+  usage: 'help ([ type:categories] | [category:<category name> | command:<command name> ])',
+  description: 'Outputs information about the servers current protocol'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/invite.js b/server/src/commands/core/invite.js
index 3fbbe6e..bcf9097 100644
--- a/server/src/commands/core/invite.js
+++ b/server/src/commands/core/invite.js
@@ -58,4 +58,8 @@ exports.run = async (core, server, socket, data) => {
 
 exports.requiredData = ['nick'];
 
-exports.info = { name: 'invite' };
+exports.info = {
+  name: 'invite',
+  usage: 'invite {nick}',
+  description: 'Generates a unique (more or less) room name and passes it to two clients'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/join.js b/server/src/commands/core/join.js
index b72824b..f2b2c9d 100644
--- a/server/src/commands/core/join.js
+++ b/server/src/commands/core/join.js
@@ -128,4 +128,8 @@ exports.run = async (core, server, socket, data) => {
 
 exports.requiredData = ['channel', 'nick'];
 
-exports.info = { name: 'join' };
+exports.info = {
+  name: 'join',
+  usage: 'join {channel} {nick}',
+  description: 'Place calling socket into target channel with target nick & broadcast event to channel'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/morestats.js b/server/src/commands/core/morestats.js
index ce0e87d..5510cb1 100644
--- a/server/src/commands/core/morestats.js
+++ b/server/src/commands/core/morestats.js
@@ -47,4 +47,7 @@ exports.run = async (core, server, socket, data) => {
   core.managers.stats.increment('stats-requested');
 };
 
-exports.info = { name: 'morestats' };
+exports.info = {
+  name: 'morestats',
+  description: 'Sends back current server stats to the calling client'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/move.js b/server/src/commands/core/move.js
index 9462468..c5efafd 100644
--- a/server/src/commands/core/move.js
+++ b/server/src/commands/core/move.js
@@ -76,4 +76,8 @@ exports.run = async (core, server, socket, data) => {
 
 exports.requiredData = ['channel'];
 
-exports.info = { name: 'move' };
+exports.info = {
+  name: 'move',
+  usage: 'move {channel}',
+  description: 'This will change the current channel to the new one provided'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/stats.js b/server/src/commands/core/stats.js
index 2802579..b9dc002 100644
--- a/server/src/commands/core/stats.js
+++ b/server/src/commands/core/stats.js
@@ -26,4 +26,7 @@ exports.run = async (core, server, socket, data) => {
   core.managers.stats.increment('stats-requested');
 };
 
-exports.info = { name: 'stats' };
+exports.info = {
+  name: 'stats',
+  description: 'Sends back legacy server stats to the calling client'
+};
\ No newline at end of file
-- 
cgit v1.2.1


From 2bb5ced363b692a5696b176bc317fe525c0c05df Mon Sep 17 00:00:00 2001
From: Neel Kamath <neelkamath@protonmail.com>
Date: Sun, 13 May 2018 16:09:55 +0530
Subject: Flatten

---
 server/src/commands/core/changenick.js |  88 ---------------------
 server/src/commands/core/chat.js       |  62 ---------------
 server/src/commands/core/disconnect.js |  21 -----
 server/src/commands/core/help.js       |  49 ------------
 server/src/commands/core/invite.js     |  65 ----------------
 server/src/commands/core/join.js       | 135 ---------------------------------
 server/src/commands/core/morestats.js  |  53 -------------
 server/src/commands/core/move.js       |  83 --------------------
 server/src/commands/core/stats.js      |  32 --------
 9 files changed, 588 deletions(-)
 delete mode 100644 server/src/commands/core/changenick.js
 delete mode 100644 server/src/commands/core/chat.js
 delete mode 100644 server/src/commands/core/disconnect.js
 delete mode 100644 server/src/commands/core/help.js
 delete mode 100644 server/src/commands/core/invite.js
 delete mode 100644 server/src/commands/core/join.js
 delete mode 100644 server/src/commands/core/morestats.js
 delete mode 100644 server/src/commands/core/move.js
 delete mode 100644 server/src/commands/core/stats.js

(limited to 'server/src/commands/core')

diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js
deleted file mode 100644
index 4041bb0..0000000
--- a/server/src/commands/core/changenick.js
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
-  Description: Generates a semi-unique channel name then broadcasts it to each client
-*/
-
-const verifyNickname = (nick) => {
-  return /^[a-zA-Z0-9_]{1,24}$/.test(nick);
-};
-
-exports.run = async (core, server, socket, data) => {
-  if (server._police.frisk(socket.remoteAddress, 6)) {
-    server.reply({
-      cmd: 'warn',
-      text: 'You are changing nicknames too fast. Wait a moment before trying again.'
-    }, socket);
-
-    return;
-  }
-
-  if (typeof data.nick !== 'string') {
-    return;
-  }
-
-  let newNick = data.nick.trim();
-
-  if (!verifyNickname(newNick)) {
-    server.reply({
-      cmd: 'warn',
-      text: 'Nickname must consist of up to 24 letters, numbers, and underscores'
-    }, socket);
-
-    return;
-  }
-
-  if (newNick.toLowerCase() == core.config.adminName.toLowerCase()) {
-    server._police.frisk(socket.remoteAddress, 4);
-
-    server.reply({
-      cmd: 'warn',
-      text: 'Gtfo'
-    }, socket);
-
-    return;
-  }
-
-  let userExists = server.findSockets({
-    channel: socket.channel,
-    nick: (targetNick) => targetNick.toLowerCase() === newNick.toLowerCase()
-  });
-
-  if (userExists.length > 0) {
-    // That nickname is already in that channel
-    server.reply({
-      cmd: 'warn',
-      text: 'Nickname taken'
-    }, socket);
-
-    return;
-  }
-
-  let peerList = server.findSockets({ channel: socket.channel });
-  let leaveNotice = {
-    cmd: 'onlineRemove',
-    nick: socket.nick
-  };
-  let joinNotice = {
-    cmd: 'onlineAdd',
-    nick: newNick,
-    trip: socket.trip || 'null',
-    hash: server.getSocketHash(socket)
-  };
-
-  server.broadcast( leaveNotice, { channel: socket.channel });
-  server.broadcast( joinNotice, { channel: socket.channel });
-  server.broadcast( {
-    cmd: 'info',
-    text: `${socket.nick} is now ${newNick}`
-  }, { channel: socket.channel });
-
-  socket.nick = newNick;
-};
-
-exports.requiredData = ['nick'];
-
-exports.info = {
-  name: 'changenick',
-  usage: 'changenick {nick}',
-  description: 'This will change your current connections nickname'
-};
diff --git a/server/src/commands/core/chat.js b/server/src/commands/core/chat.js
deleted file mode 100644
index bce6adb..0000000
--- a/server/src/commands/core/chat.js
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
-  Description: Rebroadcasts any `text` to all clients in a `channel`
-*/
-
-const parseText = (text) => {
-  if (typeof text !== 'string') {
-    return false;
-  }
-
-  // strip newlines from beginning and end
-  text = text.replace(/^\s*\n|^\s+$|\n\s*$/g, '');
-  // replace 3+ newlines with just 2 newlines
-  text = text.replace(/\n{3,}/g, "\n\n");
-
-  return text;
-};
-
-exports.run = async (core, server, socket, data) => {
-  let text = parseText(data.text);
-  if (!text) {
-    // lets not send objects or empty text, yea?
-    return;
-  }
-
-  let score = text.length / 83 / 4;
-  if (server._police.frisk(socket.remoteAddress, score)) {
-    server.reply({
-      cmd: 'warn',
-      text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.'
-    }, socket);
-
-    return;
-  }
-
-  let payload = {
-    cmd: 'chat',
-    nick: socket.nick,
-    text: text
-  };
-
-  if (socket.uType == 'admin') {
-    payload.admin = true;
-  } else if (socket.uType == 'mod') {
-    payload.mod = true;
-  }
-
-  if (socket.trip) {
-    payload.trip = socket.trip;
-  }
-
-  server.broadcast( payload, { channel: socket.channel });
-
-  core.managers.stats.increment('messages-sent');
-};
-
-exports.requiredData = ['text'];
-
-exports.info = {
-  name: 'chat',
-  usage: 'chat {text}',
-  description: 'Broadcasts passed `text` field to the calling users channel'
-};
\ No newline at end of file
diff --git a/server/src/commands/core/disconnect.js b/server/src/commands/core/disconnect.js
deleted file mode 100644
index 9b54214..0000000
--- a/server/src/commands/core/disconnect.js
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
-  Description: This module will be directly called by the server event handler
-               when a socket connection is closed or lost. It can calso be called
-               by a client to have the connection severed.
-*/
-
-exports.run = async (core, server, socket, data) => {
-  if (socket.channel) {
-    server.broadcast({
-      cmd: 'onlineRemove',
-      nick: socket.nick
-    }, { channel: socket.channel });
-  }
-
-  socket.terminate();
-};
-
-exports.info = {
-  name: 'disconnect',
-  description: 'Event handler or force disconnect (if your into that kind of thing)'
-};
\ No newline at end of file
diff --git a/server/src/commands/core/help.js b/server/src/commands/core/help.js
deleted file mode 100644
index 7f63d3d..0000000
--- a/server/src/commands/core/help.js
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-  Description: Outputs the current command module list or command categories
-*/
-
-const stripIndents = require('common-tags').stripIndents;
-
-exports.run = async (core, server, socket, data) => {
-  // verify passed arguments
-  let typeDt = typeof data.type;
-  let catDt = typeof data.category;
-  let cmdDt = typeof data.command;
-  if (typeDt !== 'undefined' && typeDt !== 'string' ) {
-    return;
-  } else if (catDt !== 'undefined' && catDt !== 'string' ) {
-    return;
-  } else if (cmdDt !== 'undefined' && cmdDt !== 'string' ) {
-    return;
-  }
-
-  // set default reply
-  let reply = stripIndents`Help usage:
-    Show all categories -> { cmd: 'help', type: 'categories' }
-    Show all commands in category -> { cmd: 'help', category: '<category name>' }
-    Show specific command -> { cmd: 'help', command: '<command name>' }`;
-
-  if (typeDt !== 'undefined') {
-    let categories = core.commands.categories().sort();
-    reply = `Command Categories:\n${categories.map(c => `- ${c.replace('../src/commands/', '')}`).join('\n')}`;
-  } else if (catDt !== 'undefined') {
-    let catCommands = core.commands.all('../src/commands/' + data.category).sort((a, b) => a.info.name.localeCompare(b.info.name));
-    reply = `${data.category} commands:\n${catCommands.map(c => `- ${c.info.name}`).join('\n')}`;
-  } else if (cmdDt !== 'undefined') {
-    let command = core.commands.get(data.command);
-    reply = stripIndents`
-      Usage: ${command.info.usage || command.info.name}
-      Description: ${command.info.description || '¯\_(ツ)_/¯'}`;
-  }
-
-  server.reply({
-    cmd: 'info',
-    text: reply
-  }, socket);
-};
-
-exports.info = {
-  name: 'help',
-  usage: 'help ([ type:categories] | [category:<category name> | command:<command name> ])',
-  description: 'Outputs information about the servers current protocol'
-};
\ No newline at end of file
diff --git a/server/src/commands/core/invite.js b/server/src/commands/core/invite.js
deleted file mode 100644
index bcf9097..0000000
--- a/server/src/commands/core/invite.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-  Description: Generates a semi-unique channel name then broadcasts it to each client
-*/
-
-const verifyNickname = (nick) => {
-  return /^[a-zA-Z0-9_]{1,24}$/.test(nick);
-};
-
-exports.run = async (core, server, socket, data) => {
-  if (server._police.frisk(socket.remoteAddress, 2)) {
-    server.reply({
-      cmd: 'warn',
-      text: 'You are sending invites too fast. Wait a moment before trying again.'
-    }, socket);
-
-    return;
-  }
-
-  if (typeof data.nick !== 'string') {
-    return;
-  }
-
-  if (!verifyNickname(data.nick)) {
-    // Not a valid nickname? Chances are we won't find them
-    return;
-  }
-
-  if (data.nick == socket.nick) {
-    // They invited themself
-    return;
-  }
-  
-  let channel = Math.random().toString(36).substr(2, 8);
-
-  let payload = {
-    cmd: 'info',
-    invite: channel,
-    text: `${socket.nick} invited you to ?${channel}`
-  };
-  let inviteSent = server.broadcast( payload, { channel: socket.channel, nick: data.nick });
-
-  if (!inviteSent) {
-    server.reply({
-      cmd: 'warn',
-      text: 'Could not find user in channel'
-    }, socket);
-
-    return;
-  }
-
-  server.reply({
-    cmd: 'info',
-    text: `You invited ${data.nick} to ?${channel}`
-  }, socket);
-
-  core.managers.stats.increment('invites-sent');
-};
-
-exports.requiredData = ['nick'];
-
-exports.info = {
-  name: 'invite',
-  usage: 'invite {nick}',
-  description: 'Generates a unique (more or less) room name and passes it to two clients'
-};
\ No newline at end of file
diff --git a/server/src/commands/core/join.js b/server/src/commands/core/join.js
deleted file mode 100644
index f2b2c9d..0000000
--- a/server/src/commands/core/join.js
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
-  Description: Initial entry point, applies `channel` and `nick` to the calling socket
-*/
-
-const crypto = require('crypto');
-
-const hash = (password) => {
-  let sha = crypto.createHash('sha256');
-  sha.update(password);
-  return sha.digest('base64').substr(0, 6);
-};
-
-const verifyNickname = (nick) => {
-  return /^[a-zA-Z0-9_]{1,24}$/.test(nick);
-};
-
-exports.run = async (core, server, socket, data) => {
-  if (server._police.frisk(socket.remoteAddress, 3)) {
-    server.reply({
-      cmd: 'warn',
-      text: 'You are joining channels too fast. Wait a moment and try again.'
-    }, socket);
-
-    return;
-  }
-
-  if (typeof socket.channel !== 'undefined') {
-    // Calling socket already in a channel
-    return;
-  }
-
-  if (typeof data.channel !== 'string' || typeof data.nick !== 'string') {
-    return;
-  }
-
-  let channel = data.channel.trim();
-  if (!channel) {
-    // Must join a non-blank channel
-    return;
-  }
-
-  // Process nickname
-  let nick = data.nick;
-  let nickArray = nick.split('#', 2);
-  nick = nickArray[0].trim();
-
-  if (!verifyNickname(nick)) {
-    server.reply({
-      cmd: 'warn',
-      text: 'Nickname must consist of up to 24 letters, numbers, and underscores'
-    }, socket);
-
-    return;
-  }
-
-  let userExists = server.findSockets({
-    channel: data.channel,
-    nick: (targetNick) => targetNick.toLowerCase() === nick.toLowerCase()
-  });
-
-  if (userExists.length > 0) {
-    // That nickname is already in that channel
-    server.reply({
-      cmd: 'warn',
-      text: 'Nickname taken'
-    }, socket);
-
-    return;
-  }
-
-  // TODO: Should we check for mod status first to prevent overwriting of admin status somehow? Meh, w/e, cba.
-  let uType = 'user';
-  let trip = null;
-  let password = nickArray[1];
-  if (nick.toLowerCase() == core.config.adminName.toLowerCase()) {
-    if (password != core.config.adminPass) {
-      server._police.frisk(socket.remoteAddress, 4);
-
-      server.reply({
-        cmd: 'warn',
-        text: 'Gtfo'
-      }, socket);
-
-      return;
-    } else {
-      uType = 'admin';
-      trip = 'Admin';
-    }
-  } else if (password) {
-    trip = hash(password + core.config.tripSalt);
-  }
-
-  // TODO: Disallow moderator impersonation
-  for (let mod of core.config.mods) {
-    if (trip === mod.trip) {
-      uType = 'mod';
-    }
-  }
-
-  // Reply with online user list
-  let newPeerList = server.findSockets({ channel: data.channel });
-  let joinAnnouncement = {
-    cmd: 'onlineAdd',
-    nick: nick,
-    trip: trip || 'null',
-    hash: server.getSocketHash(socket)
-  };
-  let nicks = [];
-
-  for (let i = 0, l = newPeerList.length; i < l; i++) {
-    server.reply(joinAnnouncement, newPeerList[i]);
-    nicks.push(newPeerList[i].nick);
-  }
-
-  socket.uType = uType;
-  socket.nick = nick;
-  socket.channel = channel;
-  if (trip !== null) socket.trip = trip;
-  nicks.push(socket.nick);
-
-  server.reply({
-    cmd: 'onlineSet',
-    nicks: nicks
-  }, socket);
-
-  core.managers.stats.increment('users-joined');
-};
-
-exports.requiredData = ['channel', 'nick'];
-
-exports.info = {
-  name: 'join',
-  usage: 'join {channel} {nick}',
-  description: 'Place calling socket into target channel with target nick & broadcast event to channel'
-};
\ No newline at end of file
diff --git a/server/src/commands/core/morestats.js b/server/src/commands/core/morestats.js
deleted file mode 100644
index 5510cb1..0000000
--- a/server/src/commands/core/morestats.js
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
-  Description: Outputs more info than the legacy stats command
-*/
-
-const stripIndents = require('common-tags').stripIndents;
-
-const formatTime = (time) => {
-  let seconds = time[0] + time[1] / 1e9;
-
-  let minutes = Math.floor(seconds / 60);
-  seconds = seconds % 60;
-
-  let hours = Math.floor(minutes / 60);
-  minutes = minutes % 60;
-  return `${hours.toFixed(0)}h ${minutes.toFixed(0)}m ${seconds.toFixed(0)}s`;
-};
-
-exports.run = async (core, server, socket, data) => {
-  let ips = {};
-  let channels = {};
-  for (let client of server.clients) {
-    if (client.channel) {
-      channels[client.channel] = true;
-      ips[client.remoteAddress] = true;
-    }
-  }
-
-  let uniqueClientCount = Object.keys(ips).length;
-  let uniqueChannels = Object.keys(channels).length;
-
-  ips = null;
-  channels = null;
-
-  server.reply({
-    cmd: 'info',
-    text: stripIndents`current-connections: ${uniqueClientCount}
-                       current-channels: ${uniqueChannels}
-                       users-joined: ${(core.managers.stats.get('users-joined') || 0)}
-                       invites-sent: ${(core.managers.stats.get('invites-sent') || 0)}
-                       messages-sent: ${(core.managers.stats.get('messages-sent') || 0)}
-                       users-banned: ${(core.managers.stats.get('users-banned') || 0)}
-                       users-kicked: ${(core.managers.stats.get('users-kicked') || 0)}
-                       stats-requested: ${(core.managers.stats.get('stats-requested') || 0)}
-                       server-uptime: ${formatTime(process.hrtime(core.managers.stats.get('start-time')))}`
-  }, socket);
-
-  core.managers.stats.increment('stats-requested');
-};
-
-exports.info = {
-  name: 'morestats',
-  description: 'Sends back current server stats to the calling client'
-};
\ No newline at end of file
diff --git a/server/src/commands/core/move.js b/server/src/commands/core/move.js
deleted file mode 100644
index c5efafd..0000000
--- a/server/src/commands/core/move.js
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
-  Description: Generates a semi-unique channel name then broadcasts it to each client
-*/
-
-exports.run = async (core, server, socket, data) => {
-  if (server._police.frisk(socket.remoteAddress, 6)) {
-    server.reply({
-      cmd: 'warn',
-      text: 'You are changing channels too fast. Wait a moment before trying again.'
-    }, socket);
-
-    return;
-  }
-
-  if (typeof data.channel !== 'string') {
-    return;
-  }
-
-  if (data.channel === socket.channel) {
-    // They are trying to rejoin the channel
-    return;
-  }
-
-  const currentNick = socket.nick.toLowerCase();
-  let userExists = server.findSockets({
-    channel: data.channel,
-    nick: (targetNick) => targetNick.toLowerCase() === currentNick
-  });
-
-  if (userExists.length > 0) {
-    // That nickname is already in that channel
-    return;
-  }
-
-  let peerList = server.findSockets({ channel: socket.channel });
-
-  if (peerList.length > 1) {
-    for (let i = 0, l = peerList.length; i < l; i++) {
-      server.reply({
-        cmd: 'onlineRemove',
-        nick: peerList[i].nick
-      }, socket);
-
-      if (socket.nick !== peerList[i].nick){
-        server.reply({
-          cmd: 'onlineRemove',
-          nick: socket.nick
-        }, peerList[i]);
-      }
-    }
-  }
-
-  let newPeerList = server.findSockets({ channel: data.channel });
-  let moveAnnouncement = {
-    cmd: 'onlineAdd',
-    nick: socket.nick,
-    trip: socket.trip || 'null',
-    hash: server.getSocketHash(socket)
-  };
-  let nicks = [];
-
-  for (let i = 0, l = newPeerList.length; i < l; i++) {
-    server.reply(moveAnnouncement, newPeerList[i]);
-    nicks.push(newPeerList[i].nick);
-  }
-
-  nicks.push(socket.nick);
-
-  server.reply({
-    cmd: 'onlineSet',
-    nicks: nicks
-  }, socket);
-
-  socket.channel = data.channel;
-};
-
-exports.requiredData = ['channel'];
-
-exports.info = {
-  name: 'move',
-  usage: 'move {channel}',
-  description: 'This will change the current channel to the new one provided'
-};
\ No newline at end of file
diff --git a/server/src/commands/core/stats.js b/server/src/commands/core/stats.js
deleted file mode 100644
index b9dc002..0000000
--- a/server/src/commands/core/stats.js
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-  Description: Legacy stats output, kept for compatibility, outputs user and channel count
-*/
-
-exports.run = async (core, server, socket, data) => {
-  let ips = {};
-  let channels = {};
-  for (let client of server.clients) {
-    if (client.channel) {
-      channels[client.channel] = true;
-      ips[client.remoteAddress] = true;
-    }
-  }
-
-  let uniqueClientCount = Object.keys(ips).length;
-  let uniqueChannels = Object.keys(channels).length;
-
-  ips = null;
-  channels = null;
-
-  server.reply({
-    cmd: 'info',
-    text: `${uniqueClientCount} unique IPs in ${uniqueChannels} channels`
-  }, socket);
-
-  core.managers.stats.increment('stats-requested');
-};
-
-exports.info = {
-  name: 'stats',
-  description: 'Sends back legacy server stats to the calling client'
-};
\ No newline at end of file
-- 
cgit v1.2.1


From 949404cd1aad8492ae0338130f16054adfa38ab7 Mon Sep 17 00:00:00 2001
From: Neel Kamath <neelkamath@protonmail.com>
Date: Sun, 13 May 2018 16:37:56 +0530
Subject: Prevent fucking shit up

---
 server/src/commands/core/changenick.js |  88 +++++++++++++++++++++
 server/src/commands/core/chat.js       |  62 +++++++++++++++
 server/src/commands/core/disconnect.js |  21 +++++
 server/src/commands/core/help.js       |  49 ++++++++++++
 server/src/commands/core/invite.js     |  65 ++++++++++++++++
 server/src/commands/core/join.js       | 135 +++++++++++++++++++++++++++++++++
 server/src/commands/core/morestats.js  |  53 +++++++++++++
 server/src/commands/core/move.js       |  83 ++++++++++++++++++++
 server/src/commands/core/stats.js      |  32 ++++++++
 9 files changed, 588 insertions(+)
 create mode 100644 server/src/commands/core/changenick.js
 create mode 100644 server/src/commands/core/chat.js
 create mode 100644 server/src/commands/core/disconnect.js
 create mode 100644 server/src/commands/core/help.js
 create mode 100644 server/src/commands/core/invite.js
 create mode 100644 server/src/commands/core/join.js
 create mode 100644 server/src/commands/core/morestats.js
 create mode 100644 server/src/commands/core/move.js
 create mode 100644 server/src/commands/core/stats.js

(limited to 'server/src/commands/core')

diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js
new file mode 100644
index 0000000..4041bb0
--- /dev/null
+++ b/server/src/commands/core/changenick.js
@@ -0,0 +1,88 @@
+/*
+  Description: Generates a semi-unique channel name then broadcasts it to each client
+*/
+
+const verifyNickname = (nick) => {
+  return /^[a-zA-Z0-9_]{1,24}$/.test(nick);
+};
+
+exports.run = async (core, server, socket, data) => {
+  if (server._police.frisk(socket.remoteAddress, 6)) {
+    server.reply({
+      cmd: 'warn',
+      text: 'You are changing nicknames too fast. Wait a moment before trying again.'
+    }, socket);
+
+    return;
+  }
+
+  if (typeof data.nick !== 'string') {
+    return;
+  }
+
+  let newNick = data.nick.trim();
+
+  if (!verifyNickname(newNick)) {
+    server.reply({
+      cmd: 'warn',
+      text: 'Nickname must consist of up to 24 letters, numbers, and underscores'
+    }, socket);
+
+    return;
+  }
+
+  if (newNick.toLowerCase() == core.config.adminName.toLowerCase()) {
+    server._police.frisk(socket.remoteAddress, 4);
+
+    server.reply({
+      cmd: 'warn',
+      text: 'Gtfo'
+    }, socket);
+
+    return;
+  }
+
+  let userExists = server.findSockets({
+    channel: socket.channel,
+    nick: (targetNick) => targetNick.toLowerCase() === newNick.toLowerCase()
+  });
+
+  if (userExists.length > 0) {
+    // That nickname is already in that channel
+    server.reply({
+      cmd: 'warn',
+      text: 'Nickname taken'
+    }, socket);
+
+    return;
+  }
+
+  let peerList = server.findSockets({ channel: socket.channel });
+  let leaveNotice = {
+    cmd: 'onlineRemove',
+    nick: socket.nick
+  };
+  let joinNotice = {
+    cmd: 'onlineAdd',
+    nick: newNick,
+    trip: socket.trip || 'null',
+    hash: server.getSocketHash(socket)
+  };
+
+  server.broadcast( leaveNotice, { channel: socket.channel });
+  server.broadcast( joinNotice, { channel: socket.channel });
+  server.broadcast( {
+    cmd: 'info',
+    text: `${socket.nick} is now ${newNick}`
+  }, { channel: socket.channel });
+
+  socket.nick = newNick;
+};
+
+exports.requiredData = ['nick'];
+
+exports.info = {
+  name: 'changenick',
+  usage: 'changenick {nick}',
+  description: 'This will change your current connections nickname'
+};
diff --git a/server/src/commands/core/chat.js b/server/src/commands/core/chat.js
new file mode 100644
index 0000000..bce6adb
--- /dev/null
+++ b/server/src/commands/core/chat.js
@@ -0,0 +1,62 @@
+/*
+  Description: Rebroadcasts any `text` to all clients in a `channel`
+*/
+
+const parseText = (text) => {
+  if (typeof text !== 'string') {
+    return false;
+  }
+
+  // strip newlines from beginning and end
+  text = text.replace(/^\s*\n|^\s+$|\n\s*$/g, '');
+  // replace 3+ newlines with just 2 newlines
+  text = text.replace(/\n{3,}/g, "\n\n");
+
+  return text;
+};
+
+exports.run = async (core, server, socket, data) => {
+  let text = parseText(data.text);
+  if (!text) {
+    // lets not send objects or empty text, yea?
+    return;
+  }
+
+  let score = text.length / 83 / 4;
+  if (server._police.frisk(socket.remoteAddress, score)) {
+    server.reply({
+      cmd: 'warn',
+      text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.'
+    }, socket);
+
+    return;
+  }
+
+  let payload = {
+    cmd: 'chat',
+    nick: socket.nick,
+    text: text
+  };
+
+  if (socket.uType == 'admin') {
+    payload.admin = true;
+  } else if (socket.uType == 'mod') {
+    payload.mod = true;
+  }
+
+  if (socket.trip) {
+    payload.trip = socket.trip;
+  }
+
+  server.broadcast( payload, { channel: socket.channel });
+
+  core.managers.stats.increment('messages-sent');
+};
+
+exports.requiredData = ['text'];
+
+exports.info = {
+  name: 'chat',
+  usage: 'chat {text}',
+  description: 'Broadcasts passed `text` field to the calling users channel'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/disconnect.js b/server/src/commands/core/disconnect.js
new file mode 100644
index 0000000..9b54214
--- /dev/null
+++ b/server/src/commands/core/disconnect.js
@@ -0,0 +1,21 @@
+/*
+  Description: This module will be directly called by the server event handler
+               when a socket connection is closed or lost. It can calso be called
+               by a client to have the connection severed.
+*/
+
+exports.run = async (core, server, socket, data) => {
+  if (socket.channel) {
+    server.broadcast({
+      cmd: 'onlineRemove',
+      nick: socket.nick
+    }, { channel: socket.channel });
+  }
+
+  socket.terminate();
+};
+
+exports.info = {
+  name: 'disconnect',
+  description: 'Event handler or force disconnect (if your into that kind of thing)'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/help.js b/server/src/commands/core/help.js
new file mode 100644
index 0000000..7f63d3d
--- /dev/null
+++ b/server/src/commands/core/help.js
@@ -0,0 +1,49 @@
+/*
+  Description: Outputs the current command module list or command categories
+*/
+
+const stripIndents = require('common-tags').stripIndents;
+
+exports.run = async (core, server, socket, data) => {
+  // verify passed arguments
+  let typeDt = typeof data.type;
+  let catDt = typeof data.category;
+  let cmdDt = typeof data.command;
+  if (typeDt !== 'undefined' && typeDt !== 'string' ) {
+    return;
+  } else if (catDt !== 'undefined' && catDt !== 'string' ) {
+    return;
+  } else if (cmdDt !== 'undefined' && cmdDt !== 'string' ) {
+    return;
+  }
+
+  // set default reply
+  let reply = stripIndents`Help usage:
+    Show all categories -> { cmd: 'help', type: 'categories' }
+    Show all commands in category -> { cmd: 'help', category: '<category name>' }
+    Show specific command -> { cmd: 'help', command: '<command name>' }`;
+
+  if (typeDt !== 'undefined') {
+    let categories = core.commands.categories().sort();
+    reply = `Command Categories:\n${categories.map(c => `- ${c.replace('../src/commands/', '')}`).join('\n')}`;
+  } else if (catDt !== 'undefined') {
+    let catCommands = core.commands.all('../src/commands/' + data.category).sort((a, b) => a.info.name.localeCompare(b.info.name));
+    reply = `${data.category} commands:\n${catCommands.map(c => `- ${c.info.name}`).join('\n')}`;
+  } else if (cmdDt !== 'undefined') {
+    let command = core.commands.get(data.command);
+    reply = stripIndents`
+      Usage: ${command.info.usage || command.info.name}
+      Description: ${command.info.description || '¯\_(ツ)_/¯'}`;
+  }
+
+  server.reply({
+    cmd: 'info',
+    text: reply
+  }, socket);
+};
+
+exports.info = {
+  name: 'help',
+  usage: 'help ([ type:categories] | [category:<category name> | command:<command name> ])',
+  description: 'Outputs information about the servers current protocol'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/invite.js b/server/src/commands/core/invite.js
new file mode 100644
index 0000000..bcf9097
--- /dev/null
+++ b/server/src/commands/core/invite.js
@@ -0,0 +1,65 @@
+/*
+  Description: Generates a semi-unique channel name then broadcasts it to each client
+*/
+
+const verifyNickname = (nick) => {
+  return /^[a-zA-Z0-9_]{1,24}$/.test(nick);
+};
+
+exports.run = async (core, server, socket, data) => {
+  if (server._police.frisk(socket.remoteAddress, 2)) {
+    server.reply({
+      cmd: 'warn',
+      text: 'You are sending invites too fast. Wait a moment before trying again.'
+    }, socket);
+
+    return;
+  }
+
+  if (typeof data.nick !== 'string') {
+    return;
+  }
+
+  if (!verifyNickname(data.nick)) {
+    // Not a valid nickname? Chances are we won't find them
+    return;
+  }
+
+  if (data.nick == socket.nick) {
+    // They invited themself
+    return;
+  }
+  
+  let channel = Math.random().toString(36).substr(2, 8);
+
+  let payload = {
+    cmd: 'info',
+    invite: channel,
+    text: `${socket.nick} invited you to ?${channel}`
+  };
+  let inviteSent = server.broadcast( payload, { channel: socket.channel, nick: data.nick });
+
+  if (!inviteSent) {
+    server.reply({
+      cmd: 'warn',
+      text: 'Could not find user in channel'
+    }, socket);
+
+    return;
+  }
+
+  server.reply({
+    cmd: 'info',
+    text: `You invited ${data.nick} to ?${channel}`
+  }, socket);
+
+  core.managers.stats.increment('invites-sent');
+};
+
+exports.requiredData = ['nick'];
+
+exports.info = {
+  name: 'invite',
+  usage: 'invite {nick}',
+  description: 'Generates a unique (more or less) room name and passes it to two clients'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/join.js b/server/src/commands/core/join.js
new file mode 100644
index 0000000..f2b2c9d
--- /dev/null
+++ b/server/src/commands/core/join.js
@@ -0,0 +1,135 @@
+/*
+  Description: Initial entry point, applies `channel` and `nick` to the calling socket
+*/
+
+const crypto = require('crypto');
+
+const hash = (password) => {
+  let sha = crypto.createHash('sha256');
+  sha.update(password);
+  return sha.digest('base64').substr(0, 6);
+};
+
+const verifyNickname = (nick) => {
+  return /^[a-zA-Z0-9_]{1,24}$/.test(nick);
+};
+
+exports.run = async (core, server, socket, data) => {
+  if (server._police.frisk(socket.remoteAddress, 3)) {
+    server.reply({
+      cmd: 'warn',
+      text: 'You are joining channels too fast. Wait a moment and try again.'
+    }, socket);
+
+    return;
+  }
+
+  if (typeof socket.channel !== 'undefined') {
+    // Calling socket already in a channel
+    return;
+  }
+
+  if (typeof data.channel !== 'string' || typeof data.nick !== 'string') {
+    return;
+  }
+
+  let channel = data.channel.trim();
+  if (!channel) {
+    // Must join a non-blank channel
+    return;
+  }
+
+  // Process nickname
+  let nick = data.nick;
+  let nickArray = nick.split('#', 2);
+  nick = nickArray[0].trim();
+
+  if (!verifyNickname(nick)) {
+    server.reply({
+      cmd: 'warn',
+      text: 'Nickname must consist of up to 24 letters, numbers, and underscores'
+    }, socket);
+
+    return;
+  }
+
+  let userExists = server.findSockets({
+    channel: data.channel,
+    nick: (targetNick) => targetNick.toLowerCase() === nick.toLowerCase()
+  });
+
+  if (userExists.length > 0) {
+    // That nickname is already in that channel
+    server.reply({
+      cmd: 'warn',
+      text: 'Nickname taken'
+    }, socket);
+
+    return;
+  }
+
+  // TODO: Should we check for mod status first to prevent overwriting of admin status somehow? Meh, w/e, cba.
+  let uType = 'user';
+  let trip = null;
+  let password = nickArray[1];
+  if (nick.toLowerCase() == core.config.adminName.toLowerCase()) {
+    if (password != core.config.adminPass) {
+      server._police.frisk(socket.remoteAddress, 4);
+
+      server.reply({
+        cmd: 'warn',
+        text: 'Gtfo'
+      }, socket);
+
+      return;
+    } else {
+      uType = 'admin';
+      trip = 'Admin';
+    }
+  } else if (password) {
+    trip = hash(password + core.config.tripSalt);
+  }
+
+  // TODO: Disallow moderator impersonation
+  for (let mod of core.config.mods) {
+    if (trip === mod.trip) {
+      uType = 'mod';
+    }
+  }
+
+  // Reply with online user list
+  let newPeerList = server.findSockets({ channel: data.channel });
+  let joinAnnouncement = {
+    cmd: 'onlineAdd',
+    nick: nick,
+    trip: trip || 'null',
+    hash: server.getSocketHash(socket)
+  };
+  let nicks = [];
+
+  for (let i = 0, l = newPeerList.length; i < l; i++) {
+    server.reply(joinAnnouncement, newPeerList[i]);
+    nicks.push(newPeerList[i].nick);
+  }
+
+  socket.uType = uType;
+  socket.nick = nick;
+  socket.channel = channel;
+  if (trip !== null) socket.trip = trip;
+  nicks.push(socket.nick);
+
+  server.reply({
+    cmd: 'onlineSet',
+    nicks: nicks
+  }, socket);
+
+  core.managers.stats.increment('users-joined');
+};
+
+exports.requiredData = ['channel', 'nick'];
+
+exports.info = {
+  name: 'join',
+  usage: 'join {channel} {nick}',
+  description: 'Place calling socket into target channel with target nick & broadcast event to channel'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/morestats.js b/server/src/commands/core/morestats.js
new file mode 100644
index 0000000..5510cb1
--- /dev/null
+++ b/server/src/commands/core/morestats.js
@@ -0,0 +1,53 @@
+/*
+  Description: Outputs more info than the legacy stats command
+*/
+
+const stripIndents = require('common-tags').stripIndents;
+
+const formatTime = (time) => {
+  let seconds = time[0] + time[1] / 1e9;
+
+  let minutes = Math.floor(seconds / 60);
+  seconds = seconds % 60;
+
+  let hours = Math.floor(minutes / 60);
+  minutes = minutes % 60;
+  return `${hours.toFixed(0)}h ${minutes.toFixed(0)}m ${seconds.toFixed(0)}s`;
+};
+
+exports.run = async (core, server, socket, data) => {
+  let ips = {};
+  let channels = {};
+  for (let client of server.clients) {
+    if (client.channel) {
+      channels[client.channel] = true;
+      ips[client.remoteAddress] = true;
+    }
+  }
+
+  let uniqueClientCount = Object.keys(ips).length;
+  let uniqueChannels = Object.keys(channels).length;
+
+  ips = null;
+  channels = null;
+
+  server.reply({
+    cmd: 'info',
+    text: stripIndents`current-connections: ${uniqueClientCount}
+                       current-channels: ${uniqueChannels}
+                       users-joined: ${(core.managers.stats.get('users-joined') || 0)}
+                       invites-sent: ${(core.managers.stats.get('invites-sent') || 0)}
+                       messages-sent: ${(core.managers.stats.get('messages-sent') || 0)}
+                       users-banned: ${(core.managers.stats.get('users-banned') || 0)}
+                       users-kicked: ${(core.managers.stats.get('users-kicked') || 0)}
+                       stats-requested: ${(core.managers.stats.get('stats-requested') || 0)}
+                       server-uptime: ${formatTime(process.hrtime(core.managers.stats.get('start-time')))}`
+  }, socket);
+
+  core.managers.stats.increment('stats-requested');
+};
+
+exports.info = {
+  name: 'morestats',
+  description: 'Sends back current server stats to the calling client'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/move.js b/server/src/commands/core/move.js
new file mode 100644
index 0000000..c5efafd
--- /dev/null
+++ b/server/src/commands/core/move.js
@@ -0,0 +1,83 @@
+/*
+  Description: Generates a semi-unique channel name then broadcasts it to each client
+*/
+
+exports.run = async (core, server, socket, data) => {
+  if (server._police.frisk(socket.remoteAddress, 6)) {
+    server.reply({
+      cmd: 'warn',
+      text: 'You are changing channels too fast. Wait a moment before trying again.'
+    }, socket);
+
+    return;
+  }
+
+  if (typeof data.channel !== 'string') {
+    return;
+  }
+
+  if (data.channel === socket.channel) {
+    // They are trying to rejoin the channel
+    return;
+  }
+
+  const currentNick = socket.nick.toLowerCase();
+  let userExists = server.findSockets({
+    channel: data.channel,
+    nick: (targetNick) => targetNick.toLowerCase() === currentNick
+  });
+
+  if (userExists.length > 0) {
+    // That nickname is already in that channel
+    return;
+  }
+
+  let peerList = server.findSockets({ channel: socket.channel });
+
+  if (peerList.length > 1) {
+    for (let i = 0, l = peerList.length; i < l; i++) {
+      server.reply({
+        cmd: 'onlineRemove',
+        nick: peerList[i].nick
+      }, socket);
+
+      if (socket.nick !== peerList[i].nick){
+        server.reply({
+          cmd: 'onlineRemove',
+          nick: socket.nick
+        }, peerList[i]);
+      }
+    }
+  }
+
+  let newPeerList = server.findSockets({ channel: data.channel });
+  let moveAnnouncement = {
+    cmd: 'onlineAdd',
+    nick: socket.nick,
+    trip: socket.trip || 'null',
+    hash: server.getSocketHash(socket)
+  };
+  let nicks = [];
+
+  for (let i = 0, l = newPeerList.length; i < l; i++) {
+    server.reply(moveAnnouncement, newPeerList[i]);
+    nicks.push(newPeerList[i].nick);
+  }
+
+  nicks.push(socket.nick);
+
+  server.reply({
+    cmd: 'onlineSet',
+    nicks: nicks
+  }, socket);
+
+  socket.channel = data.channel;
+};
+
+exports.requiredData = ['channel'];
+
+exports.info = {
+  name: 'move',
+  usage: 'move {channel}',
+  description: 'This will change the current channel to the new one provided'
+};
\ No newline at end of file
diff --git a/server/src/commands/core/stats.js b/server/src/commands/core/stats.js
new file mode 100644
index 0000000..b9dc002
--- /dev/null
+++ b/server/src/commands/core/stats.js
@@ -0,0 +1,32 @@
+/*
+  Description: Legacy stats output, kept for compatibility, outputs user and channel count
+*/
+
+exports.run = async (core, server, socket, data) => {
+  let ips = {};
+  let channels = {};
+  for (let client of server.clients) {
+    if (client.channel) {
+      channels[client.channel] = true;
+      ips[client.remoteAddress] = true;
+    }
+  }
+
+  let uniqueClientCount = Object.keys(ips).length;
+  let uniqueChannels = Object.keys(channels).length;
+
+  ips = null;
+  channels = null;
+
+  server.reply({
+    cmd: 'info',
+    text: `${uniqueClientCount} unique IPs in ${uniqueChannels} channels`
+  }, socket);
+
+  core.managers.stats.increment('stats-requested');
+};
+
+exports.info = {
+  name: 'stats',
+  description: 'Sends back legacy server stats to the calling client'
+};
\ No newline at end of file
-- 
cgit v1.2.1