From 62daa4893f374c1cbbecc63e4f1d4eec3fd29325 Mon Sep 17 00:00:00 2001 From: marzavec Date: Sun, 3 Jun 2018 11:08:35 -0700 Subject: Completed protocol decoupling --- server/src/commands/internal/disconnect.js | 30 +++++++++++++++++++++++++++++ server/src/commands/internal/socketreply.js | 22 +++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 server/src/commands/internal/disconnect.js create mode 100644 server/src/commands/internal/socketreply.js (limited to 'server/src/commands/internal') 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' +}; -- cgit v1.2.1