Skip to content

Commit

Permalink
Improve EOR and add more TODO notes.
Browse files Browse the repository at this point in the history
  • Loading branch information
HarryCordewener committed Dec 27, 2023
1 parent d25aec3 commit 5ee84c6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ private async Task CompleteCharsetAsync(StateMachine<State, Trigger>.Transition

CurrentEncoding = chosenEncoding;

// TODO: The implementing Server or Client needs to be warned when CurrentEncoding is set!
// This would allow, for instance, the Console to ensure it displays Unicode correctly.

await CallbackNegotiation(preamble.Concat(charsetAscii).Concat(postamble).ToArray());
}

Expand Down
30 changes: 23 additions & 7 deletions TelnetNegotiationCore/Interpretors/TelnetEORInterpretor.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Stateless;
using TelnetNegotiationCore.Models;

namespace TelnetNegotiationCore.Interpretors
{
public partial class TelnetInterpretor
{
private bool _doEOR = false;
private bool? _doEOR = null;

/// <summary>
/// Character set Negotiation will set the Character Set and Character Page Server & Client have agreed to.
Expand All @@ -30,7 +29,7 @@ private StateMachine<State, Trigger> SetupEORNegotiation(StateMachine<State, Tri

tsm.Configure(State.DontEOR)
.SubstateOf(State.Accepting)
.OnEntry(() => _Logger.Debug("Connection: {connectionStatus}", "Client won't do EOR - do nothing"));
.OnEntryAsync(OnDontEORAsync);

RegisterInitialWilling(WillingEORAsync);
}
Expand All @@ -44,7 +43,7 @@ private StateMachine<State, Trigger> SetupEORNegotiation(StateMachine<State, Tri

tsm.Configure(State.WontEOR)
.SubstateOf(State.Accepting)
.OnEntry(() => _Logger.Debug("Connection: {connectionStatus}", "Server won't do EOR - do nothing"));
.OnEntryAsync(WontEORAsync);

tsm.Configure(State.WillEOR)
.SubstateOf(State.Accepting)
Expand All @@ -54,6 +53,20 @@ private StateMachine<State, Trigger> SetupEORNegotiation(StateMachine<State, Tri
return tsm;
}

private async Task OnDontEORAsync()
{
_Logger.Debug("Connection: {connectionStatus}", "Client won't do EOR - do nothing");
_doEOR = false;
await Task.CompletedTask;
}

private async Task WontEORAsync()
{
_Logger.Debug("Connection: {connectionStatus}", "Server won't do EOR - do nothing");
_doEOR = false;
await Task.CompletedTask;
}

/// <summary>
/// Announce we do EOR negotiation to the client.
/// </summary>
Expand Down Expand Up @@ -90,8 +103,11 @@ private async Task OnWillEORAsync(StateMachine<State, Trigger>.Transition _)
/// <returns>A completed Task</returns>
public async Task SendPromptAsync(byte[] send)
{
await CallbackNegotiation(send);
if (_doEOR)
if (_doEOR is null or false)
{
await CallbackNegotiation(send);
}
else
{
await CallbackNegotiation(new byte[] { (byte)Trigger.IAC, (byte)Trigger.EOR });
}
Expand Down

0 comments on commit 5ee84c6

Please sign in to comment.