From 73e5c5ccfe408e58eb4bb927c71a77e0fceb22c4 Mon Sep 17 00:00:00 2001 From: neelkamath Date: Fri, 11 May 2018 20:46:12 +0530 Subject: Remove forgettable, unused, occasionally harmful (w.r.t. ES6) directive --- server/src/commands/core/changenick.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'server/src/commands/core/changenick.js') diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js index 6b2932c..4041bb0 100644 --- a/server/src/commands/core/changenick.js +++ b/server/src/commands/core/changenick.js @@ -2,8 +2,6 @@ Description: Generates a semi-unique channel name then broadcasts it to each client */ -'use strict'; - const verifyNickname = (nick) => { return /^[a-zA-Z0-9_]{1,24}$/.test(nick); }; -- cgit v1.2.1 From acbad15f2bc4a6733407bc17e1a5b4190ed3b287 Mon Sep 17 00:00:00 2001 From: neelkamath Date: Sat, 12 May 2018 14:13:12 +0530 Subject: Remove unused object fields --- server/src/commands/core/changenick.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'server/src/commands/core/changenick.js') diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js index 4041bb0..94ae4d4 100644 --- a/server/src/commands/core/changenick.js +++ b/server/src/commands/core/changenick.js @@ -81,8 +81,4 @@ exports.run = async (core, server, socket, data) => { exports.requiredData = ['nick']; -exports.info = { - name: 'changenick', - usage: 'changenick {nick}', - description: 'This will change your current connections nickname' -}; +exports.info = { name: 'changenick' }; -- cgit v1.2.1 From 343157350f627b9495184246a90033a1c41f1a2c Mon Sep 17 00:00:00 2001 From: Neel Kamath Date: Sun, 13 May 2018 16:03:22 +0530 Subject: Re-add module documentation --- server/src/commands/core/changenick.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'server/src/commands/core/changenick.js') diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js index 94ae4d4..4041bb0 100644 --- a/server/src/commands/core/changenick.js +++ b/server/src/commands/core/changenick.js @@ -81,4 +81,8 @@ exports.run = async (core, server, socket, data) => { exports.requiredData = ['nick']; -exports.info = { name: 'changenick' }; +exports.info = { + name: 'changenick', + usage: 'changenick {nick}', + description: 'This will change your current connections nickname' +}; -- cgit v1.2.1 From 2bb5ced363b692a5696b176bc317fe525c0c05df Mon Sep 17 00:00:00 2001 From: Neel Kamath Date: Sun, 13 May 2018 16:09:55 +0530 Subject: Flatten --- server/src/commands/core/changenick.js | 88 ---------------------------------- 1 file changed, 88 deletions(-) delete mode 100644 server/src/commands/core/changenick.js (limited to 'server/src/commands/core/changenick.js') diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js deleted file mode 100644 index 4041bb0..0000000 --- a/server/src/commands/core/changenick.js +++ /dev/null @@ -1,88 +0,0 @@ -/* - 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); -}; - -exports.run = async (core, server, socket, data) => { - if (server._police.frisk(socket.remoteAddress, 6)) { - server.reply({ - cmd: 'warn', - text: 'You are changing nicknames too fast. Wait a moment before trying again.' - }, socket); - - return; - } - - if (typeof data.nick !== 'string') { - return; - } - - let newNick = data.nick.trim(); - - if (!verifyNickname(newNick)) { - server.reply({ - cmd: 'warn', - text: 'Nickname must consist of up to 24 letters, numbers, and underscores' - }, socket); - - return; - } - - if (newNick.toLowerCase() == core.config.adminName.toLowerCase()) { - server._police.frisk(socket.remoteAddress, 4); - - server.reply({ - cmd: 'warn', - text: 'Gtfo' - }, socket); - - return; - } - - let userExists = server.findSockets({ - channel: socket.channel, - nick: (targetNick) => targetNick.toLowerCase() === newNick.toLowerCase() - }); - - if (userExists.length > 0) { - // That nickname is already in that channel - server.reply({ - cmd: 'warn', - text: 'Nickname taken' - }, socket); - - return; - } - - let peerList = server.findSockets({ channel: socket.channel }); - let leaveNotice = { - cmd: 'onlineRemove', - nick: socket.nick - }; - let joinNotice = { - cmd: 'onlineAdd', - nick: newNick, - trip: socket.trip || 'null', - hash: server.getSocketHash(socket) - }; - - server.broadcast( leaveNotice, { channel: socket.channel }); - server.broadcast( joinNotice, { channel: socket.channel }); - server.broadcast( { - cmd: 'info', - text: `${socket.nick} is now ${newNick}` - }, { channel: socket.channel }); - - socket.nick = newNick; -}; - -exports.requiredData = ['nick']; - -exports.info = { - name: 'changenick', - usage: 'changenick {nick}', - description: 'This will change your current connections nickname' -}; -- cgit v1.2.1 From 949404cd1aad8492ae0338130f16054adfa38ab7 Mon Sep 17 00:00:00 2001 From: Neel Kamath Date: Sun, 13 May 2018 16:37:56 +0530 Subject: Prevent fucking shit up --- server/src/commands/core/changenick.js | 88 ++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 server/src/commands/core/changenick.js (limited to 'server/src/commands/core/changenick.js') diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js new file mode 100644 index 0000000..4041bb0 --- /dev/null +++ b/server/src/commands/core/changenick.js @@ -0,0 +1,88 @@ +/* + 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); +}; + +exports.run = async (core, server, socket, data) => { + if (server._police.frisk(socket.remoteAddress, 6)) { + server.reply({ + cmd: 'warn', + text: 'You are changing nicknames too fast. Wait a moment before trying again.' + }, socket); + + return; + } + + if (typeof data.nick !== 'string') { + return; + } + + let newNick = data.nick.trim(); + + if (!verifyNickname(newNick)) { + server.reply({ + cmd: 'warn', + text: 'Nickname must consist of up to 24 letters, numbers, and underscores' + }, socket); + + return; + } + + if (newNick.toLowerCase() == core.config.adminName.toLowerCase()) { + server._police.frisk(socket.remoteAddress, 4); + + server.reply({ + cmd: 'warn', + text: 'Gtfo' + }, socket); + + return; + } + + let userExists = server.findSockets({ + channel: socket.channel, + nick: (targetNick) => targetNick.toLowerCase() === newNick.toLowerCase() + }); + + if (userExists.length > 0) { + // That nickname is already in that channel + server.reply({ + cmd: 'warn', + text: 'Nickname taken' + }, socket); + + return; + } + + let peerList = server.findSockets({ channel: socket.channel }); + let leaveNotice = { + cmd: 'onlineRemove', + nick: socket.nick + }; + let joinNotice = { + cmd: 'onlineAdd', + nick: newNick, + trip: socket.trip || 'null', + hash: server.getSocketHash(socket) + }; + + server.broadcast( leaveNotice, { channel: socket.channel }); + server.broadcast( joinNotice, { channel: socket.channel }); + server.broadcast( { + cmd: 'info', + text: `${socket.nick} is now ${newNick}` + }, { channel: socket.channel }); + + socket.nick = newNick; +}; + +exports.requiredData = ['nick']; + +exports.info = { + name: 'changenick', + usage: 'changenick {nick}', + description: 'This will change your current connections nickname' +}; -- cgit v1.2.1