TelnetNegotiationCore 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package TelnetNegotiationCore --version 1.0.2                
NuGet\Install-Package TelnetNegotiationCore -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TelnetNegotiationCore" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TelnetNegotiationCore --version 1.0.2                
#r "nuget: TelnetNegotiationCore, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TelnetNegotiationCore as a Cake Addin
#addin nuget:?package=TelnetNegotiationCore&version=1.0.2

// Install TelnetNegotiationCore as a Cake Tool
#tool nuget:?package=TelnetNegotiationCore&version=1.0.2                

Telnet Negotiation Core

Summary

This project is intended to be a library that implements basic telnet functionality. This is done with an eye on MUDs at this time, but may improve to support more terminal capabilities as time permits.

At this time, this repository is in a rough state and does not yet implement some common modern code standards.

State

This library is in a state where breaking changes to the interface are expected.

Support

RFC Description Supported Comments
http://www.faqs.org/rfcs/rfc855.html Telnet Option Specification Full
http://www.faqs.org/rfcs/rfc1091.html Terminal Type Negotiation Full
https://tintin.mudhalla.net/protocols/mtts MTTS Negotiation (Extends TTYPE) Full
http://www.faqs.org/rfcs/rfc1073.html Window Size Negotiation (NAWS) Full
https://tintin.mudhalla.net/protocols/gmcp Generic Mud Communication Protocol Full
https://tintin.mudhalla.net/protocols/mssp MSSP Negotiation Full Untested
http://www.faqs.org/rfcs/rfc885.html End Of Record Negotiation Full Untested
https://tintin.mudhalla.net/protocols/eor End Of Record Negotiation Full Untested
https://tintin.mudhalla.net/protocols/msdp Mud Server Data Protocol Partial Planned
http://www.faqs.org/rfcs/rfc2066.html Charset Negotiation Partial No TTABLE support
http://www.faqs.org/rfcs/rfc858.html Suppress GOAHEAD Negotiation No Planned
http://www.faqs.org/rfcs/rfc1572.html New Environment Negotiation No Planned
https://tintin.mudhalla.net/protocols/mnes Mud New Environment Negotiation No Planned
https://tintin.mudhalla.net/protocols/mccp Mud Client Compression Protocol No Rejects
https://tintin.mudhalla.net/rfc/rfc1950/ ZLIB Compression No Rejects
http://www.faqs.org/rfcs/rfc857.html Echo Negotiation No Rejects
http://www.faqs.org/rfcs/rfc1079.html Terminal Speed Negotiation No Rejects
http://www.faqs.org/rfcs/rfc1372.html Flow Control Negotiation No Rejects
http://www.faqs.org/rfcs/rfc1184.html Line Mode Negotiation No Rejects
http://www.faqs.org/rfcs/rfc1096.html X-Display Negotiation No Rejects
http://www.faqs.org/rfcs/rfc1408.html Environment Negotiation No Rejects
http://www.faqs.org/rfcs/rfc2941.html Authentication Negotiation No Rejects
http://www.faqs.org/rfcs/rfc2946.html Encryption Negotiation No Rejects

ANSI Support, ETC?

Being a Telnet Negotiation Library, this library doesn't give support for extensions like ANSI, Pueblo, MXP, etc at this time.

Use

Client

A messy example exists in the TestClient Project.

Initiate a logger. A Serilog logger is required by this library at this time.

	var log = new LoggerConfiguration()
		.Enrich.FromLogContext()
		.WriteTo.Console()
		.WriteTo.File(new CompactJsonFormatter(), "LogResult.log")
		.MinimumLevel.Debug()
		.CreateLogger();

	Log.Logger = log;

Create functions that implement your desired behavior on getting a signal.

	private async Task WriteToOutputStreamAsync(byte[] arg, StreamWriter writer)
	{
		try 
		{ 
			await writer.BaseStream.WriteAsync(arg, CancellationToken.None);
		}
		catch(ObjectDisposedException ode)
		{
			_Logger.Information("Stream has been closed", ode);
		}
	}

	public static Task WriteBackAsync(byte[] writeback, Encoding encoding) =>
		Task.Run(() => Console.WriteLine(encoding.GetString(writeback)));

	public Task SignalGMCPAsync((string module, string writeback) val, Encoding encoding) =>
		Task.Run(() => _Logger.Debug("GMCP Signal: {Module}: {WriteBack}", val.module, val.writeback));

	public Task SignalMSSPAsync(MSSPConfig val) =>
		Task.Run(() => _Logger.Debug("New MSSP: {@MSSP}", val));

	public Task SignalPromptAsync() =>
		Task.Run(() => _Logger.Debug("Prompt"));

	public Task SignalNAWSAsync(int height, int width) => 
		Task.Run(() => _Logger.Debug("Client Height and Width updated: {Height}x{Width}", height, width));

Initialize the Interpreter.

	var telnet = new TelnetInterpreter(TelnetInterpreter.TelnetMode.Client, _Logger.ForContext<TelnetInterpreter>())
	{
		CallbackOnSubmitAsync = WriteBackAsync,
		CallbackNegotiationAsync = (x) => WriteToOutputStreamAsync(x, output),
		SignalOnGMCPAsync = SignalGMCPAsync,
		SignalOnMSSPAsync = SignalMSSPAsync,
		SignalOnNAWSAsync = SignalNAWSAsync,
		SignalOnPromptingAsync = SignalPromptAsync,
		CharsetOrder = new[] { Encoding.GetEncoding("utf-8"), Encoding.GetEncoding("iso-8859-1") }
	}.BuildAsync();

Start interpreting.

	for (int currentByte = 0; currentByte != -1; currentByte = input.BaseStream.ReadByte())
	{
		telnet.InterpretAsync((byte)currentByte).GetAwaiter().GetResult();
	}

Server

A messy example exists in the TestServer Project.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.9 95 11/18/2024
1.0.7 971 3/19/2024
1.0.6 121 1/9/2024
1.0.4 114 1/9/2024
1.0.3 116 1/8/2024
1.0.2 126 1/7/2024
1.0.1 120 1/4/2024
1.0.0 129 1/3/2024

# Change Log
All notable changes to this project will be documented in this file.

## [1.0.2] - 2024-01-07
 
### Added
- Add MSDP support.
- Added a helper function to convert strings to safe byte arrays.

### Changed
- Altered EOR functionality.

## [1.0.1] - 2024-01-03
 
### Added
- Add callback function for MSSP.

### Changed
- Target .NET 8.0.
- Change Methods to be properly async.
- Modernized TestClient example to use Pipes.
- Modernized TestServer example to use Pipes and Kestrel.

## [1.0.0] - 2024-01-03
 
Initial version.

### Added
- Initial support for RFC855 (TELOPT)
- Initial support for RFC858 (GOAHEAD)
- Initial support for RFC1091 (TTERM)
- Initial support for MTTS
- Initial support for RFC885 (EOR)
- Initial support for RFC1073 (NAWS)
- Initial support for RFC2066 (CHARSET)
- Initial support for MSSP
- Initial support for GMCP