Browse Source
Refactor: Move userlist to server object
feature/user
Sheogorath
6 years ago
No known key found for this signature in database
GPG Key ID: 1F05CC3635CDDFFD
2 changed files with
4 additions and
7 deletions
-
src/server.js
-
src/userlist.js
|
|
@ -12,9 +12,9 @@ const ERR_NICKNAMEINUSE = '433' |
|
|
|
const ERR_NEEDMOREPARAMS = '461' |
|
|
|
|
|
|
|
let server = {} |
|
|
|
let registeredUserlist = require("../src/userlist.js") |
|
|
|
|
|
|
|
server.create = function create() { |
|
|
|
let userlist = {} |
|
|
|
let server = net.createServer((socket) => { |
|
|
|
const user = new User(socket) |
|
|
|
socket.on('data', function (data) { |
|
|
@ -30,10 +30,10 @@ server.create = function create() { |
|
|
|
if (tokenized[1]) { |
|
|
|
let nickname = tokenized[1] |
|
|
|
// nick collision test
|
|
|
|
if (!Object.keys(registeredUserlist).includes(nickname)) { |
|
|
|
if (!Object.keys(userlist).includes(nickname)) { |
|
|
|
user.setNickname(nickname) |
|
|
|
registeredUserlist[nickname] = user |
|
|
|
socket.write(RPL_WELCOME, " nick " + nickname + " succesfully added.") |
|
|
|
userlist[user.nickname] = user |
|
|
|
} else { |
|
|
|
socket.write(ERR_NICKNAMEINUSE, " nickname in use") |
|
|
|
} |
|
|
@ -56,7 +56,7 @@ server.create = function create() { |
|
|
|
}); |
|
|
|
|
|
|
|
server.getUserlist = function() { |
|
|
|
return registeredUserlist |
|
|
|
return userlist |
|
|
|
} |
|
|
|
|
|
|
|
return server |
|
|
|
|
|
@ -1,3 +0,0 @@ |
|
|
|
let userlist = {} |
|
|
|
|
|
|
|
module.exports = userlist |