.NET 5+ Support (#1674)

Implement changes to support .NET 5 onwards.
Co-authored-by: ReinforceZwei <39955851+ReinforceZwei@users.noreply.github.com>
Co-authored-by: ORelio <ORelio@users.noreply.github.com>
This commit is contained in:
breadbyte 2022-07-03 22:34:07 +08:00 committed by GitHub
parent b3cc2351ee
commit d9f1a77ac2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
117 changed files with 1028 additions and 9058 deletions

View file

@ -23,7 +23,7 @@ namespace MinecraftClient.Protocol.Handlers
private string autocomplete_result = "";
private bool encrypted = false;
private int protocolversion;
private Thread netRead;
private Tuple<Thread, CancellationTokenSource>? netRead = null;
Crypto.IAesStream s;
TcpClient c;
@ -60,20 +60,28 @@ namespace MinecraftClient.Protocol.Handlers
this.c = Client;
}
private void Updater()
private void Updater(object? o)
{
if (((CancellationToken) o!).IsCancellationRequested)
return;
try
{
do
while (!((CancellationToken) o!).IsCancellationRequested)
{
Thread.Sleep(100);
do
{
Thread.Sleep(100);
} while (Update());
}
while (Update());
}
catch (System.IO.IOException) { }
catch (SocketException) { }
catch (ObjectDisposedException) { }
if (((CancellationToken) o!).IsCancellationRequested)
return;
handler.OnConnectionLost(ChatBot.DisconnectReason.ConnectionLost, "");
}
@ -194,11 +202,11 @@ namespace MinecraftClient.Protocol.Handlers
return true; //packet has been successfully skipped
}
private void StartUpdating()
private void StartUpdating()
{
netRead = new Thread(new ThreadStart(Updater));
netRead.Name = "ProtocolPacketHandler";
netRead.Start();
netRead = new(new Thread(new ParameterizedThreadStart(Updater)), new CancellationTokenSource());
netRead.Item1.Name = "ProtocolPacketHandler";
netRead.Item1.Start(netRead.Item2.Token);
}
/// <summary>
@ -207,7 +215,7 @@ namespace MinecraftClient.Protocol.Handlers
/// <returns>Net read thread ID</returns>
public int GetNetReadThreadId()
{
return netRead != null ? netRead.ManagedThreadId : -1;
return netRead != null ? netRead.Item1.ManagedThreadId : -1;
}
public void Dispose()
@ -216,7 +224,7 @@ namespace MinecraftClient.Protocol.Handlers
{
if (netRead != null)
{
netRead.Abort();
netRead.Item2.Cancel();
c.Close();
}
}