mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Fix not calling "handler.OnUpdate()" on time
This commit is contained in:
parent
1a90b6d942
commit
a6b98de43f
1 changed files with 27 additions and 37 deletions
|
|
@ -172,27 +172,44 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Updater(object? o)
|
private void Updater(object? o)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (((CancellationToken)o!).IsCancellationRequested)
|
if (((CancellationToken)o!).IsCancellationRequested)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Stopwatch stopWatch = new();
|
||||||
bool keepUpdating = true;
|
while (!packetQueue.IsAddingCompleted)
|
||||||
Stopwatch stopWatch = new Stopwatch();
|
|
||||||
while (keepUpdating)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
((CancellationToken)o!).ThrowIfCancellationRequested();
|
((CancellationToken)o!).ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
handler.OnUpdate();
|
||||||
|
|
||||||
stopWatch.Start();
|
stopWatch.Start();
|
||||||
keepUpdating = Update();
|
while (packetQueue.TryTake(out Tuple<int, Queue<byte>>? packetInfo))
|
||||||
|
{
|
||||||
|
(int packetID, Queue<byte> packetData) = packetInfo;
|
||||||
|
|
||||||
|
HandlePacket(packetID, packetData);
|
||||||
|
|
||||||
|
if (handler.GetNetworkPacketCaptureEnabled())
|
||||||
|
{
|
||||||
|
List<byte> clone = packetData.ToList();
|
||||||
|
handler.OnNetworkPacket(packetID, clone, login_phase, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
stopWatch.Stop();
|
||||||
|
if (stopWatch.Elapsed.Milliseconds >= 100)
|
||||||
|
{
|
||||||
|
stopWatch.Reset();
|
||||||
|
handler.OnUpdate();
|
||||||
|
}
|
||||||
|
stopWatch.Start();
|
||||||
|
}
|
||||||
stopWatch.Stop();
|
stopWatch.Stop();
|
||||||
int elapsed = stopWatch.Elapsed.Milliseconds;
|
|
||||||
|
if (stopWatch.Elapsed.Milliseconds < 100)
|
||||||
|
Thread.Sleep(100 - stopWatch.Elapsed.Milliseconds);
|
||||||
stopWatch.Reset();
|
stopWatch.Reset();
|
||||||
if (elapsed < 100)
|
|
||||||
Thread.Sleep(100 - elapsed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (System.IO.IOException) { }
|
catch (System.IO.IOException) { }
|
||||||
|
|
@ -206,33 +223,6 @@ namespace MinecraftClient.Protocol.Handlers
|
||||||
handler.OnConnectionLost(ChatBot.DisconnectReason.ConnectionLost, "");
|
handler.OnConnectionLost(ChatBot.DisconnectReason.ConnectionLost, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Read data from the network. Should be called on a separate thread.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>FALSE if an error occured, TRUE otherwise.</returns>
|
|
||||||
private bool Update()
|
|
||||||
{
|
|
||||||
handler.OnUpdate();
|
|
||||||
|
|
||||||
if (packetQueue.IsAddingCompleted)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
while (packetQueue.TryTake(out Tuple<int, Queue<byte>>? packetInfo))
|
|
||||||
{
|
|
||||||
(int packetID, Queue<byte> packetData) = packetInfo;
|
|
||||||
|
|
||||||
HandlePacket(packetID, packetData);
|
|
||||||
|
|
||||||
if (handler.GetNetworkPacketCaptureEnabled())
|
|
||||||
{
|
|
||||||
List<byte> clone = packetData.ToList();
|
|
||||||
handler.OnNetworkPacket(packetID, clone, login_phase, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read and decompress packets.
|
/// Read and decompress packets.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue