Add support for disconnecting transport connections

This commit is contained in:
Ritchie Frodomar 2024-06-04 21:19:08 -04:00
parent e860084825
commit 92346f13f7
4 changed files with 33 additions and 10 deletions

View file

@ -84,5 +84,5 @@ Material:
m_Colors:
- _Color: {r: 0, g: 0, b: 0, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _ForegroundColor: {r: 1, g: 0.92156863, b: 0.015686275, a: 1}
- _ForegroundColor: {r: 0, g: 0, b: 1, a: 1}
m_BuildTextureStacks: []

View file

@ -132,6 +132,24 @@ namespace GameplaySystems.Networld
break;
}
case PacketType.Disconnect:
{
using var ms = new MemoryStream(packetEvent.Packet.Data);
using var binaryReader = new BinaryReader(ms, Encoding.UTF8);
using var dataReader = new BinaryDataReader(binaryReader);
var transmissionPacket = new TransmissionProtocolMessage();
transmissionPacket.Read(dataReader);
if (!connections.TryGetValue(transmissionPacket.ConnectionId, out ConnectionHandle connection))
{
packetEvent.Handle();
return;
}
connection.Close();
break;
}
case PacketType.Transmission:
{
using var ms = new MemoryStream(packetEvent.Packet.Data);

View file

@ -42,6 +42,9 @@ namespace NetworkServices.Ssh
for (var i = 0; i < activeConnections.Count; i++)
{
activeConnections[i].Update();
if (this.activeConnections[i].IsDone)
this.activeConnections.RemoveAt(i);
}
}

View file

@ -15,11 +15,9 @@ namespace NetworkServices.Ssh
{
private readonly SshServer server;
private readonly SimulatedNetworkStream stream;
private readonly IDataWriter writer;
private readonly IDataReader reader;
private readonly Task thread;
public bool IsDone => thread.IsCanceled;
public bool IsDone => thread.IsCompleted;
@ -27,19 +25,25 @@ namespace NetworkServices.Ssh
{
this.server = server;
stream = new SimulatedNetworkStream(connection);
writer = new BinaryDataWriter(new BinaryWriter(stream, Encoding.UTF8, true));
reader = new BinaryDataReader(new BinaryReader(stream, Encoding.UTF8, true));
thread = Task.Run(ThreadUpdate);
}
public void Update()
{
if (IsDone)
{
Dispose();
return;
}
}
private async void ThreadUpdate()
{
using var writer = new BinaryDataWriter(new BinaryWriter(stream, Encoding.UTF8, true));
using var reader = new BinaryDataReader(new BinaryReader(stream, Encoding.UTF8, true));
var state = State.Username;
var willFail = false;
var attemptsLeft = 4;
@ -177,8 +181,6 @@ namespace NetworkServices.Ssh
/// <inheritdoc />
public void Dispose()
{
writer.Dispose();
reader.Dispose();
stream?.Dispose();
}