diff options
author | marzavec <admin@marzavec.com> | 2018-06-03 20:08:35 +0200 |
---|---|---|
committer | marzavec <admin@marzavec.com> | 2018-06-03 20:08:35 +0200 |
commit | 62daa4893f374c1cbbecc63e4f1d4eec3fd29325 (patch) | |
tree | f5677c91c86efd60eb78d4c6b0258b17c1926074 /server/src/commands/internal | |
parent | Merge pull request #16 from OpSimple/master (diff) | |
download | hackchat-62daa4893f374c1cbbecc63e4f1d4eec3fd29325.tar.gz hackchat-62daa4893f374c1cbbecc63e4f1d4eec3fd29325.zip |
Completed protocol decoupling
Diffstat (limited to 'server/src/commands/internal')
-rw-r--r-- | server/src/commands/internal/disconnect.js | 30 | ||||
-rw-r--r-- | server/src/commands/internal/socketreply.js | 22 |
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' +}; |