aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/mod/unban.js
blob: 9115dbd4512ce439aebfe39ff76174bfe04505a8 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
  Description: Removes a target ip from the ratelimiter
*/

exports.run = async (core, server, socket, data) => {
  // increase rate limit chance and ignore if not admin or mod
  if (socket.uType == 'user') {
    server._police.frisk(socket.remoteAddress, 10);

    return;
  }

  // check user input
  if (typeof data.ip !== 'string' && typeof data.hash !== 'string') {
    server.reply({
      cmd: 'warn',
      text: "hash:'targethash' or ip:'1.2.3.4' is required"
    }, socket);

    return;
  }

  // find target
  let mode, target;
  if (typeof data.ip === 'string') {
    mode = 'ip';
    target = data.ip;
  } else {
    mode = 'hash';
    target = data.hash;
  }

  // remove arrest record
  server._police.pardon(target);

  // mask ip if used
  if (mode === 'ip') {
    target = server.getSocketHash(target);
  }
  console.log(`${socket.nick} [${socket.trip}] unbanned ${target} in ${socket.channel}`);

  // reply with success
  server.reply({
    cmd: 'info',
    text: `Unbanned ${target}`
  }, socket);

  // notify mods
  server.broadcast({
    cmd: 'info',
    text: `${socket.nick} unbanned: ${target}`
  }, { uType: 'mod' });

  // stats are fun
  core.managers.stats.decrement('users-banned');
};

exports.info = {
  name: 'unban',
  usage: 'unban {[ip || hash]}',
  description: 'Removes target ip from the ratelimiter'
};