Browse Source
Refactor: Abstracted uppercase tokenized command
refactor/server
Sheogorath
5 years ago
No known key found for this signature in database
GPG Key ID: 1F05CC3635CDDFFD
1 changed files with
3 additions and
2 deletions
-
src/server.js
|
|
@ -28,7 +28,8 @@ server.create = function create() { |
|
|
|
return net.createServer((socket) => { |
|
|
|
socket.on('data', function (data) { |
|
|
|
let tokenized = data.toString("ascii").split("\r\n")[0].split(" ") |
|
|
|
switch (tokenized[0].toUpperCase()) { |
|
|
|
let command = tokenized[0].toUpperCase() |
|
|
|
switch (command) { |
|
|
|
case "PING": |
|
|
|
if (tokenized[1] && tokenized[1] === "irc.example.com") { |
|
|
|
socket.write("PONG irc.example.com\r\n") |
|
|
@ -62,7 +63,7 @@ server.create = function create() { |
|
|
|
|
|
|
|
break; |
|
|
|
default: |
|
|
|
console.error(`Unknown command: ${tokenized[0].toUpperCase()}`); |
|
|
|
console.error(`Unknown command: ${command}`); |
|
|
|
} |
|
|
|
}).on('error', (err) => { |
|
|
|
console.error(err); |
|
|
|