Skip to content

Commit c50b360

Browse files
authored
Fix minor bugs (#2759)
* add miscellaneous fixes * Fixed connecting to server when compression threshold is set to 0 The client assumes that 0 means disabled, when on a notchian (vanilla) server, it is possible to set the compression threshold to 0 (compress all packets). * Try to capture all exceptions through Sentry No exceptions are being logged through Sentry, so be more aggressive when sending exceptions (cherry picked from commit eb1c2f5) * Call OnSpawnPlayer packet when a player is spawned using the SpawnEntity packet references #2721 (cherry picked from commit ef28ae0)
1 parent 2f9cf7b commit c50b360

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

MinecraftClient/Program.cs

+5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ static void Main(string[] args)
7474
options.EnableTracing = true;
7575
options.SendDefaultPii = false;
7676
});
77+
78+
AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) =>
79+
{
80+
SentrySdk.CaptureException((Exception)eventArgs.ExceptionObject);
81+
};
7782
}
7883

7984
Task.Run(() =>

MinecraftClient/Protocol/Handlers/Protocol18.cs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Diagnostics;
@@ -72,7 +72,7 @@ class Protocol18Handler : IMinecraftCom
7272
internal const int MC_1_20_2_Version = 764;
7373
internal const int MC_1_20_4_Version = 765;
7474

75-
private int compression_treshold = 0;
75+
private int compression_treshold = -1;
7676
private int autocomplete_transaction_id = 0;
7777
private readonly Dictionary<int, short> window_actions = new();
7878
private CurrentState currentState = CurrentState.Login;
@@ -345,7 +345,7 @@ internal Tuple<int, Queue<byte>> ReadNextPacket()
345345

346346
//Handle packet decompression
347347
if (protocolVersion >= MC_1_8_Version
348-
&& compression_treshold > 0)
348+
&& compression_treshold >= 0)
349349
{
350350
var sizeUncompressed = dataTypes.ReadNextVarInt(packetData);
351351
if (sizeUncompressed != 0) // != 0 means compressed, let's decompress
@@ -2196,6 +2196,14 @@ private bool HandlePlayPackets(int packetId, Queue<byte> packetData)
21962196
if (handler.GetEntityHandlingEnabled())
21972197
{
21982198
var entity = dataTypes.ReadNextEntity(packetData, entityPalette, false);
2199+
2200+
if (protocolVersion >= MC_1_20_2_Version)
2201+
{
2202+
if (entity.Type == EntityType.Player)
2203+
handler.OnSpawnPlayer(entity.ID, entity.UUID, entity.Location, (byte)entity.Yaw, (byte)entity.Pitch);
2204+
break;
2205+
}
2206+
21992207
handler.OnSpawnEntity(entity);
22002208
}
22012209

@@ -2759,7 +2767,7 @@ private void SendPacket(int packetId, IEnumerable<byte> packetData)
27592767
//The inner packet
27602768
var thePacket = dataTypes.ConcatBytes(DataTypes.GetVarInt(packetId), packetData.ToArray());
27612769

2762-
if (compression_treshold > 0) //Compression enabled?
2770+
if (compression_treshold >= 0) //Compression enabled?
27632771
{
27642772
thePacket = thePacket.Length >= compression_treshold
27652773
? dataTypes.ConcatBytes(DataTypes.GetVarInt(thePacket.Length), ZlibUtils.Compress(thePacket))

0 commit comments

Comments
 (0)