aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/internal/disconnect.js
blob: 520f8cb53a11e0f3f47454216d86474dfc7d838e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
  Description: This module will be directly called by the server event handler
               when a socket connection is closed or lost.
*/

// module main
exports.run = async (core, server, socket, data) => {
  if (data.cmdKey !== server.cmdKey) {
    // internal command attempt by client, increase rate limit chance and ignore
    return server.police.frisk(socket.remoteAddress, 20);
  }

  // send leave notice to client peers
  if (socket.channel) {
    server.broadcast({
      cmd: 'onlineRemove',
      nick: socket.nick
    }, { channel: socket.channel });
  }

  // commit close just in case
  socket.terminate();
};

// module meta
exports.requiredData = ['cmdKey'];
exports.info = {
  name: 'disconnect',
  usage: 'Internal Use Only',
  description: 'Internally used to relay `onlineRemove` event to clients'
};