Browse Source

added command_quit command

feature/command_quit
Wayne 6 years ago
parent
commit
b9d4d6b2f3
  1. 15
      src/server.js
  2. 22
      src/user.js
  3. 2
      test/command_nick.js

15
src/server.js

@ -62,6 +62,8 @@ server.create = function create() {
let address = user.getAddress()
socket.write(`001 ${user.nickname} :Welcome to the example IRC Project ${user.nickname}!~${user.username}@${address}`)
break;
case "QUIT":
server.closeConnection(user)
default:
console.error(`Unknown command: ${command}`);
}
@ -77,6 +79,19 @@ server.create = function create() {
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]
}
return server
}

22
src/user.js

@ -22,6 +22,28 @@ function User(socket) {
this.getAddress = function() {
return this.connection.address().address
}
this.setNickname = function (nickname) {
this.nickname = nickname
}
this.setRealName = function (realname) {
this.realname = realname
}
this.quit = function (quit_message) {
if (quit_message === undefined)
this.sendMessage("QUIT")
else this.sendMessage(("QUIT :" + quit_message))
}
this.closeConnection = function () {
socket.close()
}
this.sendMessage = function (message) {
connection.write(message)
}
}
module.exports = User

2
test/command_nick.js

@ -56,8 +56,6 @@ describe("NICK no NICK given", function () {
done("Destroyed socket without answering")
}
console.log(server.getUserObjectFromNickName("some_nick"))
server.emit("connection", mockedSock)
mockedSock.emit('data', Buffer.from("NICK \r\n", "ascii"))
})

Loading…
Cancel
Save