1
0
mirror of https://github.com/hack-chat/main.git synced 2024-03-22 13:20:33 +08:00

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
This commit is contained in:
marzavec 2020-03-06 11:00:30 -06:00
parent 4e0e269007
commit da9cbe3dbb
18 changed files with 108 additions and 55 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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({

View File

@ -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) {

View File

@ -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) {

View File

@ -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)) {

View File

@ -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

View File

@ -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) {

View File

@ -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) {

View File

@ -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

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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;
}

View File

@ -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.',
};

View File

@ -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();