Fixes disconnect, and publishing to windows. (#114)

This commit is contained in:
Kamron Batman 2020-04-26 01:43:53 -07:00 committed by GitHub
parent cffb32d6ef
commit 63bf71ea47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 56 deletions

View file

@ -423,6 +423,12 @@ namespace Server.Network
ConnectedOn = DateTime.UtcNow;
connection.ConnectionClosed.Register(() =>
{
TcpServer.Instances.Remove(this);
Dispose();
});
CreatedCallback?.Invoke(this);
}
@ -482,6 +488,41 @@ namespace Server.Network
}
}
public async Task ProcessIncoming(IMessagePumpService messagePumpService)
{
var inPipe = Connection.Transport.Input;
while (true)
{
if (AsyncState.Paused)
continue;
try
{
var result = await inPipe.ReadAsync();
if (result.IsCanceled || result.IsCompleted)
return;
var seq = result.Buffer;
if (seq.IsEmpty)
break;
var pos = PacketHandlers.ProcessPacket(messagePumpService, this, seq);
if (pos <= 0)
break;
inPipe.AdvanceTo(seq.Slice(0, pos).End);
}
catch
{
// ignored
break;
}
}
}
public bool CheckEncrypted(int packetID)
{
if (!SentFirstPacket && packetID != 0xF0 && packetID != 0xF1 && packetID != 0xCF && packetID != 0x80 &&
@ -533,6 +574,8 @@ namespace Server.Network
try
{
Connection.Transport.Input.Complete();
Connection.Transport.Output.Complete();
Connection.Abort();
Task.Run(Connection.DisposeAsync).Wait();
}