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.js12
5 files changed, 19 insertions, 12 deletions
diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js
index 6dbdfd2..6e9e59f 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..6d7c2af 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..e574e1f 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..d34a384 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
@@ -83,3 +83,13 @@ export function isChannelTrusted(level) {
export function isTrustedUser(level) {
return level >= levels.trustedUser;
}
+
+/**
+ * Returns true if the nickname is valid
+ * @public
+ * @param {String} nick
+ * @return {boolean}
+ */
+export function verifyNickname (nick) {
+ return /^[a-zA-Z0-9_]{1,24}$/.test(nick);
+} \ No newline at end of file