Sheogorath
5 years ago
No known key found for this signature in database
GPG Key ID: 1F05CC3635CDDFFD
3 changed files with 64 additions and 13 deletions
-
21src/server.js
-
32src/user.js
-
24test/command_user.js
@ -1,19 +1,27 @@ |
|||||
const userlist = require("../src/userlist.js") |
|
||||
|
|
||||
function User(socket) { |
function User(socket) { |
||||
|
this.registered = false |
||||
|
this.nickname = "" |
||||
|
this.connection = socket |
||||
|
this.realname = "" |
||||
|
this.username = "" |
||||
|
|
||||
|
this.setNickname = function(nickname) { |
||||
|
this.nickname = nickname |
||||
|
} |
||||
|
|
||||
this.nickname = "" |
|
||||
this.user = "" |
|
||||
this.realname = "" |
|
||||
|
this.getNickname = function(nickname) { |
||||
|
return this.nickname |
||||
|
} |
||||
|
|
||||
this.connection = socket |
|
||||
|
this.register = function(username, realname) { |
||||
|
this.username = username |
||||
|
this.realname = realname |
||||
|
this.registered = true |
||||
|
} |
||||
|
|
||||
this.setNickname = function (nickname) { |
|
||||
this.nickname = nickname |
|
||||
} |
|
||||
this.setRealName = function (realname) { |
|
||||
this.realname = realname |
|
||||
} |
|
||||
|
this.getAddress = function() { |
||||
|
return this.connection.address().address |
||||
|
} |
||||
} |
} |
||||
|
|
||||
module.exports = User |
module.exports = User |
@ -0,0 +1,24 @@ |
|||||
|
const assert = require('assert'); |
||||
|
const EventEmitter = require('events'); |
||||
|
const IRCServer = require("../src/server.js"); |
||||
|
|
||||
|
describe("USER OK", function () { |
||||
|
it("should handle a USER command -> USER guest tolmoon tolsun :Ronnie Reagan", function (done) { |
||||
|
const server = IRCServer.create() |
||||
|
let mockedSock = new EventEmitter() |
||||
|
mockedSock.address = function() { |
||||
|
return { port: 12346, family: 'IPv4', address: '127.0.0.1' } |
||||
|
} |
||||
|
mockedSock.write = function (data) { |
||||
|
assert.equal(data.toString("ascii"), "001 some_nick :Welcome to the example IRC Project some_nick!~guest@127.0.0.1") |
||||
|
done() |
||||
|
} |
||||
|
mockedSock.destroy = function () { |
||||
|
done("Destroyed socket without answering") |
||||
|
} |
||||
|
|
||||
|
server.emit("connection", mockedSock) |
||||
|
mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii")) |
||||
|
mockedSock.emit('data', Buffer.from("USER guest tolmoon tolsun :Ronnie Reagan\r\n", "ascii")) |
||||
|
}) |
||||
|
}) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue