aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/core/changenick.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/commands/core/changenick.js')
-rw-r--r--server/src/commands/core/changenick.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js
index 4041bb0..5a8b5c2 100644
--- a/server/src/commands/core/changenick.js
+++ b/server/src/commands/core/changenick.js
@@ -2,9 +2,7 @@
Description: Generates a semi-unique channel name then broadcasts it to each client
*/
-const verifyNickname = (nick) => {
- return /^[a-zA-Z0-9_]{1,24}$/.test(nick);
-};
+const verifyNickname = (nick) => /^[a-zA-Z0-9_]{1,24}$/.test(nick);
exports.run = async (core, server, socket, data) => {
if (server._police.frisk(socket.remoteAddress, 6)) {
@@ -16,12 +14,13 @@ exports.run = async (core, server, socket, data) => {
return;
}
+ // verify user data is string
if (typeof data.nick !== 'string') {
return;
}
+ // make sure requested nickname meets standards
let newNick = data.nick.trim();
-
if (!verifyNickname(newNick)) {
server.reply({
cmd: 'warn',
@@ -31,6 +30,8 @@ exports.run = async (core, server, socket, data) => {
return;
}
+ // prevent admin impersonation
+ // TODO: prevent mod impersonation
if (newNick.toLowerCase() == core.config.adminName.toLowerCase()) {
server._police.frisk(socket.remoteAddress, 4);
@@ -42,11 +43,13 @@ exports.run = async (core, server, socket, data) => {
return;
}
+ // find any sockets that have the same nickname
let userExists = server.findSockets({
channel: socket.channel,
nick: (targetNick) => targetNick.toLowerCase() === newNick.toLowerCase()
});
+ // return error if found
if (userExists.length > 0) {
// That nickname is already in that channel
server.reply({
@@ -57,7 +60,7 @@ exports.run = async (core, server, socket, data) => {
return;
}
- let peerList = server.findSockets({ channel: socket.channel });
+ // build join and leave notices
let leaveNotice = {
cmd: 'onlineRemove',
nick: socket.nick
@@ -66,16 +69,20 @@ exports.run = async (core, server, socket, data) => {
cmd: 'onlineAdd',
nick: newNick,
trip: socket.trip || 'null',
- hash: server.getSocketHash(socket)
+ hash: socket.hash
};
+ // broadcast remove event and join event with new name, this is to support legacy clients and bots
server.broadcast( leaveNotice, { channel: socket.channel });
server.broadcast( joinNotice, { channel: socket.channel });
+
+ // notify channel that the user has changed their name
server.broadcast( {
cmd: 'info',
text: `${socket.nick} is now ${newNick}`
}, { channel: socket.channel });
+ // commit change to nickname
socket.nick = newNick;
};