aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/admin/saveconfig.js
blob: b8a769b6efd1f2659f6cef2fb93e4887c50a3fa2 (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
/*
  Description: Writes the current config to disk
*/

// module main
exports.run = async (core, server, socket, data) => {
  // increase rate limit chance and ignore if not admin
  if (socket.uType != 'admin') {
    return server._police.frisk(socket.remoteAddress, 20);
  }

  // attempt save, notify of failure
  if (!core.managers.config.save()) {
    return server.reply({
      cmd: 'warn',
      text: 'Failed to save config, check logs.'
    }, client);
  }

  // return success message
  server.reply({
    cmd: 'info',
    text: 'Config saved!'
  }, socket);

  // notify mods #transparency
  server.broadcast({
    cmd: 'info',
    text: 'Config saved!'
  }, { uType: 'mod' });
};

// module meta
exports.info = {
  name: 'saveconfig',
  description: 'Writes the current config to disk',
  usage: `
    API: { cmd: 'saveconfig' }`
};