|
@ -18,7 +18,19 @@ server.create = function create() { |
|
|
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) { |
|
|
let tokenized = data.toString("ascii").split("\r\n")[0].split(" ") |
|
|
|
|
|
|
|
|
let splitted = data.toString("ascii").split("\r\n")[0].split(" ") |
|
|
|
|
|
let tokenized = [] |
|
|
|
|
|
let lastParam = -1 |
|
|
|
|
|
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) { |
|
|
|
|
|
lastParam = i |
|
|
|
|
|
tokenized[lastParam] = splitted[i] |
|
|
|
|
|
} else { |
|
|
|
|
|
tokenized[i] = splitted[i] |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
let command = tokenized[0].toUpperCase() |
|
|
let command = tokenized[0].toUpperCase() |
|
|
switch (command) { |
|
|
switch (command) { |
|
|
case "PING": |
|
|
case "PING": |
|
@ -43,6 +55,13 @@ server.create = function create() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case "USER": |
|
|
|
|
|
// ignoring servername and hostname, not useful these days
|
|
|
|
|
|
user.register(tokenized[1], tokenized[4]) |
|
|
|
|
|
let address = user.getAddress() |
|
|
|
|
|
socket.write(`001 ${user.nickname} :Welcome to the example IRC Project ${user.nickname}!~${user.username}@${address}`) |
|
|
|
|
|
break; |
|
|
default: |
|
|
default: |
|
|
console.error(`Unknown command: ${command}`); |
|
|
console.error(`Unknown command: ${command}`); |
|
|
} |
|
|
} |
|
|