|
|
@ -21,7 +21,7 @@ server.create = function create() { |
|
|
|
let splitted = data.toString("ascii").split("\r\n")[0].split(" ") |
|
|
|
let tokenized = [] |
|
|
|
let lastParam = -1 |
|
|
|
for(let i = 0; i < splitted.length; i++) { |
|
|
|
for (let i = 0; i < splitted.length; i++) { |
|
|
|
if (lastParam > 0) { |
|
|
|
tokenized[lastParam] = tokenized[lastParam] + " " + splitted[i] |
|
|
|
} else if (splitted[i].charAt(0) == ":" && i > 0) { |
|
|
@ -63,7 +63,8 @@ server.create = function create() { |
|
|
|
socket.write(`001 ${user.nickname} :Welcome to the example IRC Project ${user.nickname}!~${user.username}@${address}`) |
|
|
|
break; |
|
|
|
case "QUIT": |
|
|
|
server.closeConnection(user) |
|
|
|
server.closeConnection(user.nickname) |
|
|
|
break; |
|
|
|
default: |
|
|
|
console.error(`Unknown command: ${command}`); |
|
|
|
} |
|
|
@ -75,21 +76,14 @@ server.create = function create() { |
|
|
|
throw err; |
|
|
|
}); |
|
|
|
|
|
|
|
server.getUserlist = function() { |
|
|
|
server.getUserlist = function () { |
|
|
|
return userlist |
|
|
|
} |
|
|
|
|
|
|
|
server.getUserObjectFromNickName = function (nickname) { |
|
|
|
user_list = server.getUserlist() |
|
|
|
if (nickname in user_list) |
|
|
|
return user_list[nickname] |
|
|
|
} |
|
|
|
|
|
|
|
server.closeConnection = function (user_nickname) { |
|
|
|
console.log(user_nickname) |
|
|
|
userObject = server.getUserObjectFromNickName(user_nickname) |
|
|
|
userObject.closeConnection() |
|
|
|
delete server.getUserlist()[user_nickname] |
|
|
|
let user = userlist[user_nickname] |
|
|
|
user.closeConnection() |
|
|
|
delete userlist[user_nickname]; |
|
|
|
} |
|
|
|
|
|
|
|
return server |
|
|
|