diff options
author | marzavec <admin@marzavec.com> | 2020-03-06 16:39:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-06 16:39:22 +0100 |
commit | 4e0e269007af349dee969724a8a0128c0ef22dae (patch) | |
tree | daf36b87a9863a798d201242d0bbc68d39cda56d | |
parent | Merge pull request #85 from MinusGix/add_channel_invite (diff) | |
parent | Move most uses of uType filtering to use UAC levels (diff) | |
download | hackchat-4e0e269007af349dee969724a8a0128c0ef22dae.tar.gz hackchat-4e0e269007af349dee969724a8a0128c0ef22dae.zip |
Merge pull request #89 from MinusGix/nul_initial2
Added UAC and numeric user levels
Diffstat (limited to '')
-rw-r--r-- | server/src/commands/admin/addmod.js | 7 | ||||
-rw-r--r-- | server/src/commands/admin/listusers.js | 4 | ||||
-rw-r--r-- | server/src/commands/admin/reload.js | 14 | ||||
-rw-r--r-- | server/src/commands/admin/removemod.js | 7 | ||||
-rw-r--r-- | server/src/commands/admin/saveconfig.js | 14 | ||||
-rw-r--r-- | server/src/commands/admin/shout.js | 4 | ||||
-rw-r--r-- | server/src/commands/core/chat.js | 7 | ||||
-rw-r--r-- | server/src/commands/core/join.js | 7 | ||||
-rw-r--r-- | server/src/commands/mod/ban.js | 10 | ||||
-rw-r--r-- | server/src/commands/mod/dumb.js | 8 | ||||
-rw-r--r-- | server/src/commands/mod/kick.js | 10 | ||||
-rw-r--r-- | server/src/commands/mod/moveuser.js | 6 | ||||
-rw-r--r-- | server/src/commands/mod/speak.js | 6 | ||||
-rw-r--r-- | server/src/commands/mod/unban.js | 6 | ||||
-rw-r--r-- | server/src/commands/mod/unbanall.js | 6 | ||||
-rw-r--r-- | server/src/commands/utility/UAC/info.js | 32 |
16 files changed, 103 insertions, 45 deletions
diff --git a/server/src/commands/admin/addmod.js b/server/src/commands/admin/addmod.js index 26cec40..e5d8495 100644 --- a/server/src/commands/admin/addmod.js +++ b/server/src/commands/admin/addmod.js @@ -2,10 +2,12 @@ Description: Adds the target trip to the mod list then elevates the uType */ +import * as UAC from "../utility/UAC/info"; + // module main export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin - if (socket.uType !== 'admin') { + if (!UAC.isAdmin(socket.level)) { return server.police.frisk(socket.address, 20); } @@ -18,6 +20,7 @@ export async function run(core, server, socket, data) { for (let i = 0, l = newMod.length; i < l; i += 1) { // upgrade privilages newMod[i].uType = 'mod'; + newMod[i].level = UAC.levels.moderator; // inform new mod server.send({ @@ -37,7 +40,7 @@ export async function run(core, server, socket, data) { server.broadcast({ cmd: 'info', text: `Added mod: ${data.trip}`, - }, { uType: 'mod' }); + }, { level: UAC.isModerator }); return true; } diff --git a/server/src/commands/admin/listusers.js b/server/src/commands/admin/listusers.js index 0b0199f..3ab6811 100644 --- a/server/src/commands/admin/listusers.js +++ b/server/src/commands/admin/listusers.js @@ -2,10 +2,12 @@ Description: Outputs all current channels and their user nicks */ +import * as UAC from "../utility/UAC/info"; + // module main export async function run(core, server, socket) { // increase rate limit chance and ignore if not admin - if (socket.uType !== 'admin') { + if (!UAC.isAdmin(socket.level)) { return server.police.frisk(socket.address, 20); } diff --git a/server/src/commands/admin/reload.js b/server/src/commands/admin/reload.js index 206e2ca..ccab805 100644 --- a/server/src/commands/admin/reload.js +++ b/server/src/commands/admin/reload.js @@ -2,10 +2,12 @@ Description: Clears and resets the command modules, outputting any errors */ +import * as UAC from "../utility/UAC/info"; + // module main export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin - if (socket.uType !== 'admin') { + if (!UAC.isAdmin(socket.level)) { return server.police.frisk(socket.address, 20); } @@ -28,17 +30,11 @@ export async function run(core, server, socket, data) { loadResult += `\nReason: ${data.reason}`; } - // reply with results + // send results to moderators (which the user using this command is higher than) server.reply({ cmd: 'info', text: loadResult, - }, socket); - - // notify mods of reload #transparency - server.broadcast({ - cmd: 'info', - text: loadResult, - }, { uType: 'mod' }); + }, { level: UAC.isModerator }); return true; } diff --git a/server/src/commands/admin/removemod.js b/server/src/commands/admin/removemod.js index 9190dd6..48e65fb 100644 --- a/server/src/commands/admin/removemod.js +++ b/server/src/commands/admin/removemod.js @@ -2,10 +2,12 @@ Description: Removes target trip from the config as a mod and downgrades the socket type */ +import * as UAC from "../utility/UAC/info"; + // module main export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin - if (socket.uType !== 'admin') { + if (!UAC.isAdmin(socket.level)) { return server.police.frisk(socket.address, 20); } @@ -18,6 +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; // inform ex-mod server.send({ @@ -39,7 +42,7 @@ export async function run(core, server, socket, data) { server.broadcast({ cmd: 'info', text: `Removed mod: ${data.trip}`, - }, { uType: 'mod' }); + }, { level: UAC.isModerator }); return true; } diff --git a/server/src/commands/admin/saveconfig.js b/server/src/commands/admin/saveconfig.js index 6c713b4..708f406 100644 --- a/server/src/commands/admin/saveconfig.js +++ b/server/src/commands/admin/saveconfig.js @@ -2,10 +2,12 @@ Description: Writes the current config to disk */ +import * as UAC from "../utility/UAC/info"; + // module main export async function run(core, server, socket) { // increase rate limit chance and ignore if not admin - if (socket.uType !== 'admin') { + if (!UAC.isAdmin(socket.level)) { return server.police.frisk(socket.address, 20); } @@ -17,17 +19,11 @@ export async function run(core, server, socket) { }, socket); } - // return success message + // return success message to moderators and admins server.reply({ cmd: 'info', text: 'Config saved!', - }, socket); - - // notify mods #transparency - server.broadcast({ - cmd: 'info', - text: 'Config saved!', - }, { uType: 'mod' }); + }, { level: UAC.isModerator }); return true; } diff --git a/server/src/commands/admin/shout.js b/server/src/commands/admin/shout.js index 73b0734..ee81e58 100644 --- a/server/src/commands/admin/shout.js +++ b/server/src/commands/admin/shout.js @@ -2,10 +2,12 @@ Description: Emmits a server-wide message as `info` */ +import * as UAC from "../utility/UAC/info"; + // module main export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin - if (socket.uType !== 'admin') { + if (!UAC.isAdmin(socket.level)) { return server.police.frisk(socket.address, 20); } diff --git a/server/src/commands/core/chat.js b/server/src/commands/core/chat.js index 6c491b1..01ee256 100644 --- a/server/src/commands/core/chat.js +++ b/server/src/commands/core/chat.js @@ -2,6 +2,8 @@ Description: Rebroadcasts any `text` to all clients in a `channel` */ +import * as UAC from "../utility/UAC/info"; + // module support functions const parseText = (text) => { // verifies user input is text @@ -43,11 +45,12 @@ export async function run(core, server, socket, data) { cmd: 'chat', nick: socket.nick, text, + level: socket.level }; - if (socket.uType === 'admin') { + if (UAC.isAdmin(socket.level)) { payload.admin = true; - } else if (socket.uType === 'mod') { + } else if (UAC.isModerator(socket.level)) { payload.mod = true; } diff --git a/server/src/commands/core/join.js b/server/src/commands/core/join.js index 644470e..eccac6e 100644 --- a/server/src/commands/core/join.js +++ b/server/src/commands/core/join.js @@ -2,6 +2,8 @@ Description: Initial entry point, applies `channel` and `nick` to the calling socket */ +import * as UAC from "../utility/UAC/info"; + // module support functions const crypto = require('crypto'); @@ -20,6 +22,7 @@ export function parseNickname(core, data) { nick: '', uType: 'user', trip: null, + level: UAC.levels.user, }; // seperate nick from password @@ -36,6 +39,7 @@ export function parseNickname(core, data) { if (hash(password + core.config.tripSalt) === core.config.adminTrip) { userInfo.uType = 'admin'; userInfo.trip = 'Admin'; + userInfo.level = UAC.levels.admin; } else if (userInfo.nick.toLowerCase() === core.config.adminName.toLowerCase()) { // they've got the main-admin name while not being an admin return 'You are not the admin, liar!'; @@ -48,6 +52,7 @@ export function parseNickname(core, data) { core.config.mods.forEach((mod) => { if (userInfo.trip === mod.trip) { userInfo.uType = 'mod'; + userInfo.level = UAC.levels.moderator; } }); @@ -113,6 +118,7 @@ export async function run(core, server, socket, data) { nick: userInfo.nick, trip: userInfo.trip || 'null', hash: userInfo.userHash, + level: userInfo.level, }; // send join announcement and prep online set @@ -126,6 +132,7 @@ export async function run(core, server, socket, data) { socket.nick = userInfo.nick; socket.channel = data.channel; socket.hash = userInfo.userHash; + socket.level = userInfo.level; if (userInfo.trip !== null) socket.trip = userInfo.trip; nicks.push(socket.nick); diff --git a/server/src/commands/mod/ban.js b/server/src/commands/mod/ban.js index dd5f01e..982c380 100644 --- a/server/src/commands/mod/ban.js +++ b/server/src/commands/mod/ban.js @@ -2,10 +2,12 @@ Description: Adds the target socket's ip to the ratelimiter */ +import * as UAC from "../utility/UAC/info"; + // module main export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin or mod - if (socket.uType === 'user') { + if (!UAC.isModerator(socket.level)) { return server.police.frisk(socket.address, 10); } @@ -28,7 +30,7 @@ export async function run(core, server, socket, data) { [badClient] = badClient; // i guess banning mods or admins isn't the best idea? - if (badClient.uType !== 'user') { + if (badClient.level >= socket.level) { return server.reply({ cmd: 'warn', text: 'Cannot ban other mods, how rude', @@ -44,13 +46,13 @@ export async function run(core, server, socket, data) { server.broadcast({ cmd: 'info', text: `Banned ${targetNick}`, - }, { channel: socket.channel, uType: 'user' }); + }, { channel: socket.channel, level: (level) => level < UAC.levels.moderator }); // notify mods server.broadcast({ cmd: 'info', text: `${socket.nick} banned ${targetNick} in ${socket.channel}, userhash: ${badClient.hash}`, - }, { uType: 'mod' }); + }, { level: UAC.isModerator }); // force connection closed badClient.terminate(); diff --git a/server/src/commands/mod/dumb.js b/server/src/commands/mod/dumb.js index 89aad4b..5693df2 100644 --- a/server/src/commands/mod/dumb.js +++ b/server/src/commands/mod/dumb.js @@ -3,6 +3,8 @@ * Author: simple */ +import * as UAC from "../utility/UAC/info"; + // module constructor export function init(core) { if (typeof core.muzzledHashes === 'undefined') { @@ -13,7 +15,7 @@ export function init(core) { // module main export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin or mod - if (socket.uType === 'user') { + if (!UAC.isModerator(socket.level)) { return server.police.frisk(socket.address, 10); } @@ -35,7 +37,7 @@ export async function run(core, server, socket, data) { [badClient] = badClient; // likely dont need this, muting mods and admins is fine - if (badClient.uType !== 'user') { + if (badClient.level >= socket.level) { return server.reply({ cmd: 'warn', text: 'This trick wont work on mods and admin', @@ -56,7 +58,7 @@ export async function run(core, server, socket, data) { server.broadcast({ cmd: 'info', text: `${socket.nick} muzzled ${data.nick} in ${socket.channel}, userhash: ${badClient.hash}`, - }, { uType: 'mod' }); + }, { level: UAC.isModerator }); return true; } diff --git a/server/src/commands/mod/kick.js b/server/src/commands/mod/kick.js index 3ba2f5c..0a94c6d 100644 --- a/server/src/commands/mod/kick.js +++ b/server/src/commands/mod/kick.js @@ -2,10 +2,12 @@ Description: Forces a change on the target(s) socket's channel, then broadcasts event */ +import * as UAC from "../utility/UAC/info"; + // module main export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin or mod - if (socket.uType === 'user') { + if (!UAC.isModerator(socket.level)) { return server.police.frisk(socket.address, 10); } @@ -36,7 +38,7 @@ export async function run(core, server, socket, data) { // check if found targets are kickable, add them to the list if they are const kicked = []; for (let i = 0, j = badClients.length; i < j; i += 1) { - if (badClients[i].uType !== 'user') { + if (badClients[i].level >= socket.level) { server.reply({ cmd: 'warn', text: 'Cannot kick other mods, how rude', @@ -68,7 +70,7 @@ export async function run(core, server, socket, data) { server.broadcast({ cmd: 'info', text: `${kicked[i].nick} was banished to ?${destChannel}`, - }, { channel: socket.channel, uType: 'mod' }); + }, { channel: socket.channel, level: UAC.isModerator }); console.log(`${socket.nick} [${socket.trip}] kicked ${kicked[i].nick} in ${socket.channel} to ${destChannel} `); } @@ -86,7 +88,7 @@ export async function run(core, server, socket, data) { server.broadcast({ cmd: 'info', text: `Kicked ${kicked.map(k => k.nick).join(', ')}`, - }, { channel: socket.channel, uType: 'user' }); + }, { channel: socket.channel, level: (level) => level < UAC.levels.moderator }); // stats are fun core.stats.increment('users-kicked', kicked.length); diff --git a/server/src/commands/mod/moveuser.js b/server/src/commands/mod/moveuser.js index b55c207..7eb6d83 100644 --- a/server/src/commands/mod/moveuser.js +++ b/server/src/commands/mod/moveuser.js @@ -2,10 +2,12 @@ Description: Removes the target socket from the current channel and forces a join event in another */ +import * as UAC from "../utility/UAC/info"; + // module main export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin or mod - if (socket.uType === 'user') { + if (!UAC.isModerator(socket.level)) { return server.police.frisk(socket.address, 10); } @@ -30,7 +32,7 @@ export async function run(core, server, socket, data) { const badClient = badClients[0]; - if (badClient.uType !== 'user') { + if (badClient.level >= socket.level) { return server.reply({ cmd: 'warn', text: 'Cannot move other mods, how rude', diff --git a/server/src/commands/mod/speak.js b/server/src/commands/mod/speak.js index 5514545..48d38c6 100644 --- a/server/src/commands/mod/speak.js +++ b/server/src/commands/mod/speak.js @@ -3,6 +3,8 @@ * Author: simple */ +import * as UAC from "../utility/UAC/info"; + // module constructor export function init(core) { if (typeof core.muzzledHashes === 'undefined') { @@ -13,7 +15,7 @@ export function init(core) { // module main export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin or mod - if (socket.uType === 'user') { + if (!UAC.isModerator(socket.level)) { return server.police.frisk(socket.address, 10); } @@ -39,7 +41,7 @@ export async function run(core, server, socket, data) { server.broadcast({ cmd: 'info', text: `${socket.nick} unmuzzled : ${target}`, - }, { uType: 'mod' }); + }, { level: UAC.isModerator }); return true; } diff --git a/server/src/commands/mod/unban.js b/server/src/commands/mod/unban.js index 0d1e469..b8506f3 100644 --- a/server/src/commands/mod/unban.js +++ b/server/src/commands/mod/unban.js @@ -2,10 +2,12 @@ Description: Removes a target ip from the ratelimiter */ +import * as UAC from "../utility/UAC/info"; + // module main export async function run(core, server, socket, data) { // increase rate limit chance and ignore if not admin or mod - if (socket.uType === 'user') { + if (!UAC.isModerator(socket.level)) { return server.police.frisk(socket.address, 10); } @@ -47,7 +49,7 @@ export async function run(core, server, socket, data) { server.broadcast({ cmd: 'info', text: `${socket.nick} unbanned: ${target}`, - }, { uType: 'mod' }); + }, { level: UAC.isModerator }); // stats are fun core.stats.decrement('users-banned'); diff --git a/server/src/commands/mod/unbanall.js b/server/src/commands/mod/unbanall.js index 49eeee5..e6affc4 100644 --- a/server/src/commands/mod/unbanall.js +++ b/server/src/commands/mod/unbanall.js @@ -2,10 +2,12 @@ Description: Clears all bans and ratelimits */ +import * as UAC from "../utility/UAC/info"; + // module main export async function run(core, server, socket) { // increase rate limit chance and ignore if not admin or mod - if (socket.uType === 'user') { + if (!UAC.isModerator(socket.level)) { return server.police.frisk(socket.address, 10); } @@ -24,7 +26,7 @@ export async function run(core, server, socket) { server.broadcast({ cmd: 'info', text: `${socket.nick} unbanned all ip addresses`, - }, { uType: 'mod' }); + }, { level: UAC.isModerator }); return true; } diff --git a/server/src/commands/utility/UAC/info.js b/server/src/commands/utility/UAC/info.js new file mode 100644 index 0000000..220e14d --- /dev/null +++ b/server/src/commands/utility/UAC/info.js @@ -0,0 +1,32 @@ +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 |