mirror of
https://gitlab.acidiclight.dev/sociallydistant/sociallydistant.git
synced 2025-01-22 17:41:49 -05:00
Add support for disconnecting transport connections
This commit is contained in:
parent
e860084825
commit
92346f13f7
4 changed files with 33 additions and 10 deletions
|
@ -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: []
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue