Browse Source

Refactor: Move userlist to server object

feature/user
Sheogorath 6 years ago
parent
commit
55b8e0dedd
No known key found for this signature in database GPG Key ID: 1F05CC3635CDDFFD
  1. 8
      src/server.js
  2. 3
      src/userlist.js

8
src/server.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

3
src/userlist.js

@ -1,3 +0,0 @@
let userlist = {}
module.exports = userlist
Loading…
Cancel
Save