RanvierMUD / ranvier-telnet

Telnet server and socket with GMCP support
https://npmjs.com/package/ranvier-telnet
MIT License
9 stars 11 forks source link

Ranvier telnet is an event-based telnet server and socket package with GMCP support. Telnet commands are issued as events that you can handle as you please.

Requirements

Node >= 7

Usage

const Telnet = require('ranvier-telnet');
const server = new Telnet.TelnetServer(rawSocket => {
  const telnetSocket = new Telnet.TelnetSocket();
  telnetSocket.attach(rawSocket);

  telnetSocket.on('data', data => {
    // do stuff with input
  });
}).netServer;

server.listen(4000);

Events

<event name>(arguments)

GMCP

As shown above you can receive GMCP data with the GMCP event. To send GMCP data you can use the sendGMCP method:

telnetSocket.sendGMCP('foo.bar', { some: "data" });

Executing other Telnet commands

If you want to execute other telnet commands, perhaps in response to a DO or DONT you can use the telnetCommand method:

// inside some class somewhere
this.useGMCP = false;

telnetSocket.on('DO', option => {
  switch (option) {
    case Telnet.Options.GMCP:
      this.useGMCP = true;
      break;
  }
});

telnetSocket.telnetCommand(Telnet.Sequences.WILL, Telnet.Options.GMCP);