Browse Source

Refactor: Abstracted uppercase tokenized command

refactor/server
Sheogorath 5 years ago
parent
commit
26852d825b
No known key found for this signature in database GPG Key ID: 1F05CC3635CDDFFD
  1. 5
      src/server.js

5
src/server.js

@ -28,7 +28,8 @@ server.create = function create() {
return net.createServer((socket) => { return net.createServer((socket) => {
socket.on('data', function (data) { socket.on('data', function (data) {
let tokenized = data.toString("ascii").split("\r\n")[0].split(" ") let tokenized = data.toString("ascii").split("\r\n")[0].split(" ")
switch (tokenized[0].toUpperCase()) {
let command = tokenized[0].toUpperCase()
switch (command) {
case "PING": case "PING":
if (tokenized[1] && tokenized[1] === "irc.example.com") { if (tokenized[1] && tokenized[1] === "irc.example.com") {
socket.write("PONG irc.example.com\r\n") socket.write("PONG irc.example.com\r\n")
@ -62,7 +63,7 @@ server.create = function create() {
break; break;
default: default:
console.error(`Unknown command: ${tokenized[0].toUpperCase()}`);
console.error(`Unknown command: ${command}`);
} }
}).on('error', (err) => { }).on('error', (err) => {
console.error(err); console.error(err);

Loading…
Cancel
Save