aboutsummaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authormarzavec <admin@marzavec.com>2020-03-06 18:00:30 +0100
committermarzavec <admin@marzavec.com>2020-03-06 18:00:30 +0100
commitda9cbe3dbb799b7b668c895367c7d3778f1d0e16 (patch)
tree026aebaf1c24e82043c658d29afc8cc9b0bce121 /server/src
parentMerge pull request #89 from MinusGix/nul_initial2 (diff)
downloadhackchat-da9cbe3dbb799b7b668c895367c7d3778f1d0e16.tar.gz
hackchat-da9cbe3dbb799b7b668c895367c7d3778f1d0e16.zip
Minor UAC tweaks
Added an underscore to the uac info lib which prevents the server from attempting to use the file as a command module, allowing removal of the 'info' property and empty 'run' command
Diffstat (limited to '')
-rw-r--r--server/src/commands/admin/addmod.js2
-rw-r--r--server/src/commands/admin/listusers.js2
-rw-r--r--server/src/commands/admin/reload.js2
-rw-r--r--server/src/commands/admin/removemod.js4
-rw-r--r--server/src/commands/admin/saveconfig.js2
-rw-r--r--server/src/commands/admin/shout.js2
-rw-r--r--server/src/commands/core/chat.js4
-rw-r--r--server/src/commands/core/join.js4
-rw-r--r--server/src/commands/mod/ban.js2
-rw-r--r--server/src/commands/mod/dumb.js2
-rw-r--r--server/src/commands/mod/kick.js10
-rw-r--r--server/src/commands/mod/moveuser.js2
-rw-r--r--server/src/commands/mod/speak.js2
-rw-r--r--server/src/commands/mod/unban.js2
-rw-r--r--server/src/commands/mod/unbanall.js2
-rw-r--r--server/src/commands/utility/UAC/_info.js85
-rw-r--r--server/src/commands/utility/UAC/info.js32
-rw-r--r--server/src/serverLib/RateLimiter.js2
18 files changed, 108 insertions, 55 deletions
diff --git a/server/src/commands/admin/addmod.js b/server/src/commands/admin/addmod.js
index e5d8495..8f934ce 100644
--- a/server/src/commands/admin/addmod.js
+++ b/server/src/commands/admin/addmod.js
@@ -2,7 +2,7 @@
Description: Adds the target trip to the mod list then elevates the uType
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket, data) {
diff --git a/server/src/commands/admin/listusers.js b/server/src/commands/admin/listusers.js
index 3ab6811..54c93dc 100644
--- a/server/src/commands/admin/listusers.js
+++ b/server/src/commands/admin/listusers.js
@@ -2,7 +2,7 @@
Description: Outputs all current channels and their user nicks
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket) {
diff --git a/server/src/commands/admin/reload.js b/server/src/commands/admin/reload.js
index ccab805..f74624e 100644
--- a/server/src/commands/admin/reload.js
+++ b/server/src/commands/admin/reload.js
@@ -2,7 +2,7 @@
Description: Clears and resets the command modules, outputting any errors
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket, data) {
diff --git a/server/src/commands/admin/removemod.js b/server/src/commands/admin/removemod.js
index 48e65fb..f76ff13 100644
--- a/server/src/commands/admin/removemod.js
+++ b/server/src/commands/admin/removemod.js
@@ -2,7 +2,7 @@
Description: Removes target trip from the config as a mod and downgrades the socket type
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket, data) {
@@ -20,7 +20,7 @@ export async function run(core, server, socket, data) {
for (let i = 0, l = targetMod.length; i < l; i += 1) {
// downgrade privilages
targetMod[i].uType = 'user';
- targetMod[i].level = UAC.levels.user;
+ targetMod[i].level = UAC.levels.default;
// inform ex-mod
server.send({
diff --git a/server/src/commands/admin/saveconfig.js b/server/src/commands/admin/saveconfig.js
index 708f406..b9411af 100644
--- a/server/src/commands/admin/saveconfig.js
+++ b/server/src/commands/admin/saveconfig.js
@@ -2,7 +2,7 @@
Description: Writes the current config to disk
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket) {
diff --git a/server/src/commands/admin/shout.js b/server/src/commands/admin/shout.js
index ee81e58..65695b3 100644
--- a/server/src/commands/admin/shout.js
+++ b/server/src/commands/admin/shout.js
@@ -2,7 +2,7 @@
Description: Emmits a server-wide message as `info`
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket, data) {
diff --git a/server/src/commands/core/chat.js b/server/src/commands/core/chat.js
index 01ee256..908c205 100644
--- a/server/src/commands/core/chat.js
+++ b/server/src/commands/core/chat.js
@@ -2,7 +2,7 @@
Description: Rebroadcasts any `text` to all clients in a `channel`
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module support functions
const parseText = (text) => {
@@ -45,7 +45,7 @@ export async function run(core, server, socket, data) {
cmd: 'chat',
nick: socket.nick,
text,
- level: socket.level
+ level: socket.level,
};
if (UAC.isAdmin(socket.level)) {
diff --git a/server/src/commands/core/join.js b/server/src/commands/core/join.js
index eccac6e..3a59a6d 100644
--- a/server/src/commands/core/join.js
+++ b/server/src/commands/core/join.js
@@ -2,7 +2,7 @@
Description: Initial entry point, applies `channel` and `nick` to the calling socket
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module support functions
const crypto = require('crypto');
@@ -22,7 +22,7 @@ export function parseNickname(core, data) {
nick: '',
uType: 'user',
trip: null,
- level: UAC.levels.user,
+ level: UAC.levels.default,
};
// seperate nick from password
diff --git a/server/src/commands/mod/ban.js b/server/src/commands/mod/ban.js
index 982c380..abc02d7 100644
--- a/server/src/commands/mod/ban.js
+++ b/server/src/commands/mod/ban.js
@@ -2,7 +2,7 @@
Description: Adds the target socket's ip to the ratelimiter
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket, data) {
diff --git a/server/src/commands/mod/dumb.js b/server/src/commands/mod/dumb.js
index 5693df2..125660c 100644
--- a/server/src/commands/mod/dumb.js
+++ b/server/src/commands/mod/dumb.js
@@ -3,7 +3,7 @@
* Author: simple
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module constructor
export function init(core) {
diff --git a/server/src/commands/mod/kick.js b/server/src/commands/mod/kick.js
index 0a94c6d..ec5696b 100644
--- a/server/src/commands/mod/kick.js
+++ b/server/src/commands/mod/kick.js
@@ -2,7 +2,7 @@
Description: Forces a change on the target(s) socket's channel, then broadcasts event
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket, data) {
@@ -54,17 +54,17 @@ export async function run(core, server, socket, data) {
// Announce the kicked clients arrival in destChannel and that they were kicked
// Before they arrive, so they don't see they got moved
- for (let i = 0; i < kicked.length; i++) {
+ for (let i = 0; i < kicked.length; i += 1) {
server.broadcast({
cmd: 'onlineAdd',
nick: kicked[i].nick,
trip: kicked[i].trip || 'null',
- hash: kicked[i].userHash
+ hash: kicked[i].userHash,
}, { channel: destChannel });
}
// Move all kicked clients to the new channel
- for (let i = 0; i < kicked.length; i++) {
+ for (let i = 0; i < kicked.length; i += 1) {
kicked[i].channel = destChannel;
server.broadcast({
@@ -87,7 +87,7 @@ export async function run(core, server, socket, data) {
// publicly broadcast kick event
server.broadcast({
cmd: 'info',
- text: `Kicked ${kicked.map(k => k.nick).join(', ')}`,
+ text: `Kicked ${kicked.map((k) => k.nick).join(', ')}`,
}, { channel: socket.channel, level: (level) => level < UAC.levels.moderator });
// stats are fun
diff --git a/server/src/commands/mod/moveuser.js b/server/src/commands/mod/moveuser.js
index 7eb6d83..6b25d07 100644
--- a/server/src/commands/mod/moveuser.js
+++ b/server/src/commands/mod/moveuser.js
@@ -2,7 +2,7 @@
Description: Removes the target socket from the current channel and forces a join event in another
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket, data) {
diff --git a/server/src/commands/mod/speak.js b/server/src/commands/mod/speak.js
index 48d38c6..7dada13 100644
--- a/server/src/commands/mod/speak.js
+++ b/server/src/commands/mod/speak.js
@@ -3,7 +3,7 @@
* Author: simple
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module constructor
export function init(core) {
diff --git a/server/src/commands/mod/unban.js b/server/src/commands/mod/unban.js
index b8506f3..dd14a3a 100644
--- a/server/src/commands/mod/unban.js
+++ b/server/src/commands/mod/unban.js
@@ -2,7 +2,7 @@
Description: Removes a target ip from the ratelimiter
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket, data) {
diff --git a/server/src/commands/mod/unbanall.js b/server/src/commands/mod/unbanall.js
index e6affc4..750c322 100644
--- a/server/src/commands/mod/unbanall.js
+++ b/server/src/commands/mod/unbanall.js
@@ -2,7 +2,7 @@
Description: Clears all bans and ratelimits
*/
-import * as UAC from "../utility/UAC/info";
+import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket) {
diff --git a/server/src/commands/utility/UAC/_info.js b/server/src/commands/utility/UAC/_info.js
new file mode 100644
index 0000000..6da85d5
--- /dev/null
+++ b/server/src/commands/utility/UAC/_info.js
@@ -0,0 +1,85 @@
+/**
+ * User Account Control information containing level constants
+ * and simple helper functions used to verify permissions
+ * @property {Object} levels - Defines labels for default permission ranges
+ * @author MinusGix ( https://github.com/MinusGix )
+ * @version v1.0.0
+ * @license WTFPL ( http://www.wtfpl.net/txt/copying/ )
+ */
+
+/**
+ * Object defining labels for default permission ranges
+ * @typedef {Object} levels
+ * @property {number} admin Global administrator range
+ * @property {number} moderator Global moderator range
+ * @property {number} channelOwner Local administrator range
+ * @property {number} channelModerator Local moderator range
+ * @property {number} channelTrusted Local (non-public) channel trusted
+ * @property {number} trustedUser Public channel trusted
+ * @property {number} default Default user level
+ */
+export const levels = {
+ admin: 9999999,
+ moderator: 999999,
+
+ channelOwner: 99999,
+ channelModerator: 9999,
+ channelTrusted: 8999,
+
+ trustedUser: 500,
+ default: 100,
+};
+
+/**
+ * Returns true if target level is equal or greater than the global admin level
+ * @public
+ * @return {boolean}
+ */
+export function isAdmin(level) {
+ return level >= levels.admin;
+}
+
+/**
+ * Returns true if target level is equal or greater than the global moderator level
+ * @public
+ * @return {boolean}
+ */
+export function isModerator(level) {
+ return level >= levels.moderator;
+}
+
+/**
+ * Returns true if target level is equal or greater than the channel owner level
+ * @public
+ * @return {boolean}
+ */
+export function isChannelOwner(level) {
+ return level >= levels.channelOwner;
+}
+
+/**
+ * Returns true if target level is equal or greater than the channel moderator level
+ * @public
+ * @return {boolean}
+ */
+export function isChannelModerator(level) {
+ return level >= levels.channelModerator;
+}
+
+/**
+ * Returns true if target level is equal or greater than the channel trust level
+ * @public
+ * @return {boolean}
+ */
+export function isChannelTrusted(level) {
+ return level >= levels.channelTrusted;
+}
+
+/**
+ * Returns true if target level is equal or greater than a trusted user
+ * @public
+ * @return {boolean}
+ */
+export function isTrustedUser(level) {
+ return level >= levels.trustedUser;
+}
diff --git a/server/src/commands/utility/UAC/info.js b/server/src/commands/utility/UAC/info.js
deleted file mode 100644
index 220e14d..0000000
--- a/server/src/commands/utility/UAC/info.js
+++ /dev/null
@@ -1,32 +0,0 @@
-export const levels = {
- admin : 9999999,
- moderator : 999999,
-
- channelOwner : 99999,
- channelModerator : 9999,
-
- user : 100,
-};
-
-export function isAdmin (level) {
- return level >= levels.admin;
-}
-
-export function isModerator (level) {
- return level >= levels.moderator;
-}
-
-export function isChannelOwner (level) {
- return level >= levels.channelOwner;
-}
-
-export function isChannelModerator (level) {
- return level >= levels.channelModerator;
-}
-
-export async function run (core, server, socket, data) {}
-
-export const info = {
- name: 'uac_info',
- description: 'This module contains information about UAC levels, and minor utility functions.',
-}; \ No newline at end of file
diff --git a/server/src/serverLib/RateLimiter.js b/server/src/serverLib/RateLimiter.js
index a4a0cd8..de91e5e 100644
--- a/server/src/serverLib/RateLimiter.js
+++ b/server/src/serverLib/RateLimiter.js
@@ -77,7 +77,7 @@ class RateLimiter {
return true;
}
- record.score *= Math.pow(2, -(Date.now() - record.time ) / this.halflife);
+ record.score *= Math.pow(2, -(Date.now() - record.time) / this.halflife);
record.score += deltaScore;
record.time = Date.now();