|
@ -12,9 +12,9 @@ const ERR_NICKNAMEINUSE = '433' |
|
|
const ERR_NEEDMOREPARAMS = '461' |
|
|
const ERR_NEEDMOREPARAMS = '461' |
|
|
|
|
|
|
|
|
let server = {} |
|
|
let server = {} |
|
|
let registeredUserlist = require("../src/userlist.js") |
|
|
|
|
|
|
|
|
|
|
|
server.create = function create() { |
|
|
server.create = function create() { |
|
|
|
|
|
let userlist = {} |
|
|
let server = net.createServer((socket) => { |
|
|
let server = net.createServer((socket) => { |
|
|
const user = new User(socket) |
|
|
const user = new User(socket) |
|
|
socket.on('data', function (data) { |
|
|
socket.on('data', function (data) { |
|
@ -30,10 +30,10 @@ server.create = function create() { |
|
|
if (tokenized[1]) { |
|
|
if (tokenized[1]) { |
|
|
let nickname = tokenized[1] |
|
|
let nickname = tokenized[1] |
|
|
// nick collision test
|
|
|
// nick collision test
|
|
|
if (!Object.keys(registeredUserlist).includes(nickname)) { |
|
|
|
|
|
|
|
|
if (!Object.keys(userlist).includes(nickname)) { |
|
|
user.setNickname(nickname) |
|
|
user.setNickname(nickname) |
|
|
registeredUserlist[nickname] = user |
|
|
|
|
|
socket.write(RPL_WELCOME, " nick " + nickname + " succesfully added.") |
|
|
socket.write(RPL_WELCOME, " nick " + nickname + " succesfully added.") |
|
|
|
|
|
userlist[user.nickname] = user |
|
|
} else { |
|
|
} else { |
|
|
socket.write(ERR_NICKNAMEINUSE, " nickname in use") |
|
|
socket.write(ERR_NICKNAMEINUSE, " nickname in use") |
|
|
} |
|
|
} |
|
@ -56,7 +56,7 @@ server.create = function create() { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
server.getUserlist = function() { |
|
|
server.getUserlist = function() { |
|
|
return registeredUserlist |
|
|
|
|
|
|
|
|
return userlist |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return server |
|
|
return server |
|
|