aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/commands/core/changenick.js5
-rw-r--r--server/src/commands/core/invite.js5
-rw-r--r--server/src/commands/core/join.js4
-rw-r--r--server/src/commands/core/whisper.js5
-rw-r--r--server/src/commands/utility/UAC/_info.js18
5 files changed, 25 insertions, 12 deletions
diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js
index 6dbdfd2..9cfa929 100644
--- a/server/src/commands/core/changenick.js
+++ b/server/src/commands/core/changenick.js
@@ -2,8 +2,7 @@
Description: Allows calling client to change their current nickname
*/
-// module support functions
-const verifyNickname = (nick) => /^[a-zA-Z0-9_]{1,24}$/.test(nick);
+import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket, data) {
@@ -21,7 +20,7 @@ export async function run(core, server, socket, data) {
// make sure requested nickname meets standards
const newNick = data.nick.trim();
- if (!verifyNickname(newNick)) {
+ if (!UAC.verifyNickname(newNick)) {
return server.reply({
cmd: 'warn',
text: 'Nickname must consist of up to 24 letters, numbers, and underscores',
diff --git a/server/src/commands/core/invite.js b/server/src/commands/core/invite.js
index b594586..b98115b 100644
--- a/server/src/commands/core/invite.js
+++ b/server/src/commands/core/invite.js
@@ -2,8 +2,7 @@
Description: Generates a semi-unique channel name then broadcasts it to each client
*/
-// module support functions
-const verifyNickname = (nick) => /^[a-zA-Z0-9_]{1,24}$/.test(nick);
+import * as UAC from '../utility/UAC/_info';
// module main
export async function run(core, server, socket, data) {
@@ -16,7 +15,7 @@ export async function run(core, server, socket, data) {
}
// verify user input
- if (typeof data.nick !== 'string' || !verifyNickname(data.nick)) {
+ if (typeof data.nick !== 'string' || !UAC.verifyNickname(data.nick)) {
return true;
}
diff --git a/server/src/commands/core/join.js b/server/src/commands/core/join.js
index 3a59a6d..7e98721 100644
--- a/server/src/commands/core/join.js
+++ b/server/src/commands/core/join.js
@@ -13,8 +13,6 @@ const hash = (password) => {
return sha.digest('base64').substr(0, 6);
};
-const verifyNickname = (nick) => /^[a-zA-Z0-9_]{1,24}$/.test(nick);
-
// exposed "login" function to allow hooks to verify user join events
// returns object containing user info or string if error
export function parseNickname(core, data) {
@@ -29,7 +27,7 @@ export function parseNickname(core, data) {
const nickArray = data.nick.split('#', 2);
userInfo.nick = nickArray[0].trim();
- if (!verifyNickname(userInfo.nick)) {
+ if (!UAC.verifyNickname(userInfo.nick)) {
// return error as string
return 'Nickname must consist of up to 24 letters, numbers, and underscores';
}
diff --git a/server/src/commands/core/whisper.js b/server/src/commands/core/whisper.js
index decf765..0c2e2d3 100644
--- a/server/src/commands/core/whisper.js
+++ b/server/src/commands/core/whisper.js
@@ -2,8 +2,9 @@
Description: Display text on targets screen that only they can see
*/
+import * as UAC from '../utility/UAC/_info';
+
// module support functions
-const verifyNickname = (nick) => /^[a-zA-Z0-9_]{1,24}$/.test(nick);
const parseText = (text) => {
// verifies user input is text
@@ -41,7 +42,7 @@ export async function run(core, server, socket, payload) {
}
const targetNick = payload.nick;
- if (!verifyNickname(targetNick)) {
+ if (!UAC.verifyNickname(targetNick)) {
return true;
}
diff --git a/server/src/commands/utility/UAC/_info.js b/server/src/commands/utility/UAC/_info.js
index 6da85d5..c5010a6 100644
--- a/server/src/commands/utility/UAC/_info.js
+++ b/server/src/commands/utility/UAC/_info.js
@@ -1,6 +1,6 @@
/**
* User Account Control information containing level constants
- * and simple helper functions used to verify permissions
+ * and simple helper functions related to users
* @property {Object} levels - Defines labels for default permission ranges
* @author MinusGix ( https://github.com/MinusGix )
* @version v1.0.0
@@ -33,6 +33,7 @@ export const levels = {
/**
* Returns true if target level is equal or greater than the global admin level
* @public
+ * @param {number} level Level to verify
* @return {boolean}
*/
export function isAdmin(level) {
@@ -42,6 +43,7 @@ export function isAdmin(level) {
/**
* Returns true if target level is equal or greater than the global moderator level
* @public
+ * @param {number} level Level to verify
* @return {boolean}
*/
export function isModerator(level) {
@@ -51,6 +53,7 @@ export function isModerator(level) {
/**
* Returns true if target level is equal or greater than the channel owner level
* @public
+ * @param {number} level Level to verify
* @return {boolean}
*/
export function isChannelOwner(level) {
@@ -60,6 +63,7 @@ export function isChannelOwner(level) {
/**
* Returns true if target level is equal or greater than the channel moderator level
* @public
+ * @param {number} level Level to verify
* @return {boolean}
*/
export function isChannelModerator(level) {
@@ -69,6 +73,7 @@ export function isChannelModerator(level) {
/**
* Returns true if target level is equal or greater than the channel trust level
* @public
+ * @param {number} level Level to verify
* @return {boolean}
*/
export function isChannelTrusted(level) {
@@ -78,8 +83,19 @@ export function isChannelTrusted(level) {
/**
* Returns true if target level is equal or greater than a trusted user
* @public
+ * @param {number} level Level to verify
* @return {boolean}
*/
export function isTrustedUser(level) {
return level >= levels.trustedUser;
}
+
+/**
+ * Returns true if the nickname is valid
+ * @public
+ * @param {string} nick Nickname to verify
+ * @return {boolean}
+ */
+export function verifyNickname(nick) {
+ return /^[a-zA-Z0-9_]{1,24}$/.test(nick);
+}