diff --git a/README.md b/README.md index 56c7388..08c0206 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Discord](https://img.shields.io/discord/1193672869104861195?style=for-the-badge)](https://discord.gg/SK2cWERJF7) [![Build Status](https://img.shields.io/github/actions/workflow/status/HarryCordewener/TelnetNegotiationCore/dotnet.yml?style=for-the-badge)](https://github.com/HarryCordewener/TelnetNegotiationCore/actions/workflows/dotnet.yml) [![Nuget](https://img.shields.io/nuget/dt/TelnetNegotiationCore?style=for-the-badge&color=blue)](https://www.nuget.org/packages/TelnetNegotiationCore) +[![Discord](https://img.shields.io/discord/1193672869104861195?style=for-the-badge)](https://discord.gg/SK2cWERJF7) [![Build Status](https://img.shields.io/github/actions/workflow/status/HarryCordewener/TelnetNegotiationCore/dotnet.yml?style=for-the-badge)](https://github.com/HarryCordewener/TelnetNegotiationCore/actions/workflows/dotnet.yml) [![NuGet](https://img.shields.io/nuget/dt/TelnetNegotiationCore?style=for-the-badge&color=blue)](https://www.nuget.org/packages/TelnetNegotiationCore) ![Larger Logo](LargerLogo.png) # Telnet Negotiation Core diff --git a/TelnetNegotiationCore.UnitTests/CHARSETTests.cs b/TelnetNegotiationCore.UnitTests/CHARSETTests.cs index 25b1319..1eb0d00 100644 --- a/TelnetNegotiationCore.UnitTests/CHARSETTests.cs +++ b/TelnetNegotiationCore.UnitTests/CHARSETTests.cs @@ -11,7 +11,7 @@ namespace TelnetNegotiationCore.UnitTests { [TestFixture] - public class CHARSETTests: BaseTest + public class CHARSETTests : BaseTest { private byte[] _negotiationOutput; @@ -19,9 +19,9 @@ public class CHARSETTests: BaseTest private Task WriteBackToGMCP((string module, string writeback) arg1) => throw new NotImplementedException(); - private Task ClientWriteBackToNegotiate(byte[] arg1) => Task.Run(() => _negotiationOutput = arg1); + private Task ClientWriteBackToNegotiate(byte[] arg1) { _negotiationOutput = arg1; return Task.CompletedTask; } - private Task ServerWriteBackToNegotiate(byte[] arg1) => Task.Run(() => _negotiationOutput = arg1); + private Task ServerWriteBackToNegotiate(byte[] arg1) => ServerWriteBackToNegotiate(arg1); [SetUp] public void Setup() diff --git a/TelnetNegotiationCore/Handlers/MSDPClientHandler.cs b/TelnetNegotiationCore/Handlers/MSDPClientHandler.cs new file mode 100644 index 0000000..4d14f68 --- /dev/null +++ b/TelnetNegotiationCore/Handlers/MSDPClientHandler.cs @@ -0,0 +1,20 @@ +using System; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TelnetNegotiationCore.Handlers +{ + /// + /// A simple handler for MSDP that creates a workflow for requesting MSDP information, and storing returned information. + /// + public class MSDPClientHandler + { + public MSDPClientHandler() { } + + public Task HandleAsync(string serverJson) + { + throw new NotImplementedException(); + } + } +} diff --git a/TelnetNegotiationCore/Handlers/MSDPServerHandler.cs b/TelnetNegotiationCore/Handlers/MSDPServerHandler.cs new file mode 100644 index 0000000..cc0f88b --- /dev/null +++ b/TelnetNegotiationCore/Handlers/MSDPServerHandler.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TelnetNegotiationCore.Handlers +{ + /// + /// A simple handler for MSDP that creates a workflow for responding with MSDP information. + /// + public class MSDPServerHandler + { + public MSDPServerHandler() { } + + public Task HandleAsync(string clientJson) + { + throw new NotImplementedException(); + } + } +} diff --git a/TelnetNegotiationCore/Interpreters/TelnetMSDPInterpreter.cs b/TelnetNegotiationCore/Interpreters/TelnetMSDPInterpreter.cs index b2c8ae8..a7c0148 100644 --- a/TelnetNegotiationCore/Interpreters/TelnetMSDPInterpreter.cs +++ b/TelnetNegotiationCore/Interpreters/TelnetMSDPInterpreter.cs @@ -63,10 +63,7 @@ private StateMachine SetupMSDPNegotiation(StateMachine - { - _currentMSDPInfo = []; - }); + .OnEntry(() => _currentMSDPInfo = []); tsm.Configure(State.AlmostNegotiatingMSDP) .Permit(Trigger.MSDP_VAR, State.EvaluatingMSDP) @@ -85,23 +82,18 @@ private StateMachine SetupMSDPNegotiation(StateMachine + TriggerHelper.ForAllTriggersButIAC(t => tsm.Configure(State.EvaluatingMSDP).OnEntryFrom(ParameterizedTrigger(t), CaptureMSDPValue).PermitReentry(t)); } return tsm; } - private void CaptureMSDPValue(OneOf b) => - _currentMSDPInfo.Add(b.AsT0); + private void CaptureMSDPValue(OneOf b) => _currentMSDPInfo.Add(b.AsT0); - private Task ReadMSDPValues() - { - Functional.MSDPLibrary.MSDPScan(_currentMSDPInfo.Skip(1), CurrentEncoding); - return Task.CompletedTask; - } + private void ReadMSDPValues() => Functional.MSDPLibrary.MSDPScan(_currentMSDPInfo.Skip(1), CurrentEncoding); /// /// Announce we do MSDP negotiation to the client. diff --git a/TelnetNegotiationCore/Interpreters/TelnetSafeInterpreter.cs b/TelnetNegotiationCore/Interpreters/TelnetSafeInterpreter.cs index 4a14705..e80cc75 100644 --- a/TelnetNegotiationCore/Interpreters/TelnetSafeInterpreter.cs +++ b/TelnetNegotiationCore/Interpreters/TelnetSafeInterpreter.cs @@ -104,13 +104,12 @@ private StateMachine SetupSafeNegotiation(StateMachine (State)x.UnderlyingState == State.SubNegotiation).Transitions - .Select(x => (Trigger)x.Trigger.UnderlyingTrigger))) - { - tsm.Configure(State.SubNegotiation) - .Permit(trigger, State.BadSubNegotiation); - } + var underlyingTriggers = info.States.First(x => (State)x.UnderlyingState == State.SubNegotiation).Transitions + .Select(x => (Trigger)x.Trigger.UnderlyingTrigger); + + triggers + .Except(underlyingTriggers) + .ForEach(trigger => tsm.Configure(State.SubNegotiation).Permit(trigger, State.BadSubNegotiation)); TriggerHelper.ForAllTriggersButIAC(t => tsm.Configure(State.BadSubNegotiation).Permit(t, State.BadSubNegotiationEvaluating)); TriggerHelper.ForAllTriggersButIAC(t => tsm.Configure(State.BadSubNegotiationEvaluating).PermitReentry(t)); @@ -131,11 +130,7 @@ private StateMachine SetupSafeNegotiation(StateMachine tsm.Configure((State)state.UnderlyingState).Permit(Trigger.Error, State.Accepting)); tsm.OnUnhandledTrigger(async (state, trigger, unmetguards) => {