aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/internal
diff options
context:
space:
mode:
authormarzavec <admin@marzavec.com>2018-06-03 20:08:35 +0200
committermarzavec <admin@marzavec.com>2018-06-03 20:08:35 +0200
commit62daa4893f374c1cbbecc63e4f1d4eec3fd29325 (patch)
treef5677c91c86efd60eb78d4c6b0258b17c1926074 /server/src/commands/internal
parentMerge pull request #16 from OpSimple/master (diff)
downloadhackchat-62daa4893f374c1cbbecc63e4f1d4eec3fd29325.tar.gz
hackchat-62daa4893f374c1cbbecc63e4f1d4eec3fd29325.zip
Completed protocol decoupling
Diffstat (limited to 'server/src/commands/internal')
-rw-r--r--server/src/commands/internal/disconnect.js30
-rw-r--r--server/src/commands/internal/socketreply.js22
2 files changed, 52 insertions, 0 deletions
diff --git a/server/src/commands/internal/disconnect.js b/server/src/commands/internal/disconnect.js
new file mode 100644
index 0000000..bb3981b
--- /dev/null
+++ b/server/src/commands/internal/disconnect.js
@@ -0,0 +1,30 @@
+/*
+ Description: This module will be directly called by the server event handler
+ when a socket connection is closed or lost.
+*/
+
+exports.run = async (core, server, socket, data) => {
+ if (data.cmdKey !== server._cmdKey) {
+ // internal command attempt by client, increase rate limit chance and ignore
+ server._police.frisk(socket.remoteAddress, 20);
+
+ return;
+ }
+
+ if (socket.channel) {
+ server.broadcast({
+ cmd: 'onlineRemove',
+ nick: socket.nick
+ }, { channel: socket.channel });
+ }
+
+ socket.terminate();
+};
+
+exports.requiredData = ['cmdKey'];
+
+exports.info = {
+ name: 'disconnect',
+ usage: 'Internal Use Only',
+ description: 'Internally used to relay `onlineRemove` event to clients'
+};
diff --git a/server/src/commands/internal/socketreply.js b/server/src/commands/internal/socketreply.js
new file mode 100644
index 0000000..82834b7
--- /dev/null
+++ b/server/src/commands/internal/socketreply.js
@@ -0,0 +1,22 @@
+/*
+ Description: Used to relay warnings to clients internally
+*/
+
+exports.run = async (core, server, socket, data) => {
+ if (data.cmdKey !== server._cmdKey) {
+ // internal command attempt by client, increase rate limit chance and ignore
+ server._police.frisk(socket.remoteAddress, 20);
+
+ return;
+ }
+
+ server.reply({ cmd: 'warn', text: data.text }, socket);
+};
+
+exports.requiredData = ['cmdKey', 'text'];
+
+exports.info = {
+ name: 'socketreply',
+ usage: 'Internal Use Only',
+ description: 'Internally used to relay warnings to clients'
+};