Skip to content

Commit

Permalink
feat(backend): implemented MSSP telnet option
Browse files Browse the repository at this point in the history
  • Loading branch information
mystiker committed Nov 4, 2024
1 parent 1aa74dc commit b887bcb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/src/features/telnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ The TelnetClient class handles these negotiation commands, regardless of their o
| SGA (Suppress Go Ahead) | Full | DO | WONT | We offer a DO at startup and can handle changes on the fly. However, Unitopia WONT accept this option for unknown reasons. | https://github.com/unitopia-de/webmud3/issues/115 |
| TTYPE | Full | WILL | DO | Allows the client to send its name (originally the terminal type but it looks abused nowadays) to the server. | https://github.com/unitopia-de/webmud3/issues/126 |
| STATUS | Full | DO | WILL | Allows for comparisson of the status of the server and the client. Allows for comparison of the negotiated options | https://github.com/unitopia-de/webmud3/issues/130 |
| MSSP (Mud Server Status Protocol) | Full | DO | WILL | Allows our client to retrieve basic information about the mud, like the current player count or the server name. | https://github.com/unitopia-de/webmud3/issues/131 |
| NAWS (Negotiate About Window Size) | Partial | WILL (+ Sub) | DO | We support this option to subnegotiate the window size. However, we send static values for the window size (80x25) and it does look like Unitopia is ignoring these values. | https://github.com/unitopia-de/webmud3/issues/108 |
| CHARSET | Partial | DO / WILL (+ Sub) | WILL (+ Sub) / DO | We support this option to subnegotiate the character set with the server. However, we only accept UTF-8. If the server does not subnogitiate for UTF-8, an error will be thrown and the connection will be closed. | https://github.com/unitopia-de/webmud3/issues/111 |
| LINEMODE | Partial | WILL | DO | We support the LINEMODE option. However, the server wants us to send our input buffer whenever ANY ASCII control character is entered (FORWARDMASK), which is unsupported. On the other side, we do support SOFT_TAB and EDIT MODES | https://github.com/unitopia-de/webmud3/issues/114 |
| EOR (End of Record) | Todo | DONT | WILL | Allows for the server to signal the end of a record which is not needed for our client. | https://github.com/unitopia-de/webmud3/issues/112 |
| MSSP (Mud Server Status Protocol) | Todo | DO | WILL | Allows our client to retrieve basic information about the mud, like the current player count or the server name. | |
| STARTTLS | Unsupported | WONT | DO | This option allows to upgrade any existing connection to a secure one. However, we don't support this intentionally and recommend you to initialize a secure connection from the beginning. | https://github.com/unitopia-de/webmud3/issues/113 |
| XDISPLOC | Unsupported | WONT | DO | Crazy option to redirect graphical output directly to a X display. Probably not used by Unitopia. | |
| TSPEED (Terminal Speed) | Unsupported | WONT | DO | Allows the client to report its connection speed (in baud) to the server, which can adjust data transmission rates accordingly. Although we do not support this option now, it could be valuable, especially for managing data flow over unstable or mobile connections. | |
Expand Down
6 changes: 4 additions & 2 deletions backend/src/features/telnet/telnet-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { TelnetOptionHandler } from './types/telnet-option-handler.js';
import { handleCharsetOption } from './utils/handle-charset-option.js';
import { handleEchoOption } from './utils/handle-echo-option.js';
import { handleLinemodeOption } from './utils/handle-linemode-option.js';
import { handleMSSPOption } from './utils/handle-mssp-option.js';
import { handleNawsOption } from './utils/handle-naws-option.js';
import { handleSGAOption } from './utils/handle-sga-option.js';
import { handleStatusOption } from './utils/handle-status-option.js';
Expand Down Expand Up @@ -78,6 +79,7 @@ export class TelnetClient extends EventEmitter<TelnetClientEvents> {
[TelnetOptions.TELOPT_LINEMODE, handleLinemodeOption(this.telnetSocket)],
[TelnetOptions.TELOPT_TTYPE, handleTTypeOption(this.telnetSocket)],
[TelnetOptions.TELOPT_STATUS, handleStatusOption(this.telnetSocket)],
[TelnetOptions.TELOPT_MSSP, handleMSSPOption(this.telnetSocket)],
]);

this.telnetSocket.on('connect', () => this.handleConnect());
Expand Down Expand Up @@ -313,7 +315,7 @@ export class TelnetClient extends EventEmitter<TelnetClientEvents> {
serverChunks: [
...(existing.subnegotiation?.serverChunks || []),
...(negotiations.serverChunk
? [`0x${negotiations.serverChunk.toString('hex')}`]
? [`0x${negotiations.serverChunk.toString()}`]
: []),
],
}
Expand All @@ -324,7 +326,7 @@ export class TelnetClient extends EventEmitter<TelnetClientEvents> {
clientChunks: [
...(existing.subnegotiation?.clientChunks || []),
...(negotiations.clientChunk
? [`0x${negotiations.clientChunk.toString('hex')}`]
? [`0x${negotiations.clientChunk.toString()}`]
: []),
],
}
Expand Down
39 changes: 39 additions & 0 deletions backend/src/features/telnet/utils/handle-mssp-option.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { TelnetSocket } from 'telnet-stream';

import { TelnetOptions } from '../models/telnet-options.js';
import { TelnetControlSequences } from '../types/telnet-control-sequences.js';
import { TelnetOptionHandler } from '../types/telnet-option-handler.js';
import { TelnetOptionResult } from '../types/telnet-option-result.js';

const handleMSSPDo = (socket: TelnetSocket) => (): TelnetOptionResult => {
socket.writeWill(TelnetOptions.TELOPT_MSSP);

return { controlSequence: TelnetControlSequences.WILL };
};

const handleMSSPDont = (socket: TelnetSocket) => (): TelnetOptionResult => {
socket.writeWont(TelnetOptions.TELOPT_MSSP);

return { controlSequence: TelnetControlSequences.WONT };
};

const handleMSSPWill = (socket: TelnetSocket) => (): TelnetOptionResult => {
socket.writeDo(TelnetOptions.TELOPT_MSSP);

return { controlSequence: TelnetControlSequences.DO };
};

const handleMSSPWont = (socket: TelnetSocket) => (): TelnetOptionResult => {
socket.writeDont(TelnetOptions.TELOPT_MSSP);

return { controlSequence: TelnetControlSequences.DONT };
};

export const handleMSSPOption = (socket: TelnetSocket): TelnetOptionHandler => {
return {
handleDo: handleMSSPDo(socket),
handleDont: handleMSSPDont(socket),
handleWill: handleMSSPWill(socket),
handleWont: handleMSSPWont(socket),
};
};

0 comments on commit b887bcb

Please sign in to comment.