Minecraft-Console-Client icon indicating copy to clipboard operation
Minecraft-Console-Client copied to clipboard

[BUG] Crash after joining server

Open RainC7 opened this issue 1 year ago • 11 comments

Prerequisites

  • [X] I made sure I am running the latest development build
  • [X] I tried to look for similar issues before opening a new one
  • [X] I have set debugmessages=true in config to diagnose my issue
  • [X] I have redacted session tokens and passwords before attaching screenshots

Minecraft Version

1.20.1

Console Client Version

MinecraftClient-20240114-240-win-x64

Expected Behavior

Successfully Join Server

Actual Behavior

Crash after joining server.

Steps to Reproduce the bug

  1. Join Server
  2. Crash

Attach screenshot here (If applicable)

No response

Anythings that could help diagnosing the bug

[MCC] 已成功加入服务器。
输入 '/quit' 离开服务器。
> Unhandled exception. System.Collections.Generic.KeyNotFoundException: Packet ID of 0x4D4B doesn't exist!
   at MinecraftClient.Protocol.Handlers.PacketPalettes.PacketTypePalette.GetIncommingTypeById(Int32 packetId)
   at MinecraftClient.Protocol.Handlers.Protocol18Handler.HandlePacket(Int32 packetId, Queue`1 packetData)
   at MinecraftClient.Protocol.Handlers.Protocol18Handler.Updater(Object o)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

Device

Laptop

Operating System

Windows

Server Address (If applicable)

No response

RainC7 avatar Jan 21 '24 07:01 RainC7

Happens only on specific servers, tried all supported versions.

RainC7 avatar Jan 21 '24 07:01 RainC7

Hi @RainC7 , Are you using a Vanilla server or a Forge server?

Edit: I tested with the Vanilla server and didn't reproduce the issue.

oldkingOK avatar Jan 22 '24 12:01 oldkingOK

Hi @RainC7 , Are you using a Vanilla server or a Forge server?

Edit: I tested with the Vanilla server and didn't reproduce the issue.

PaperMC with Velocity

RainC7 avatar Jan 22 '24 13:01 RainC7

After testing, neither the chat machine nor the normal client will encounter problems.In MCC Client, the error is reported as above.

RainC7 avatar Jan 22 '24 13:01 RainC7

I think the Velocity may be causing this. Can this packet be blocked? :)

RainC7 avatar Jan 22 '24 14:01 RainC7

I used the latest version of PaperMC with Velocity and then joined the paper server as lobby and didn't reproduce the issue, maybe you need to specify the game version in the MinecraftClient.ini config file.

MinecraftVersion = "1.20.1"

image

oldkingOK avatar Jan 22 '24 17:01 oldkingOK

Would like to give more details about the tests. For example:

  • Exact Paper version and Velocity version (it would help more if you could include the relevant links)
  • Paper startup command line and Velocity startup command line
  • List of plugins installed on the server

oldkingOK avatar Jan 22 '24 18:01 oldkingOK

compression-threshold=0 I asked the server administrator and got this answer. This setting will cause MCC to be unable to connect. After adjusting this value, you can connect normally. What problem is causing this and can it be fixed?

RainC7 avatar Jan 24 '24 12:01 RainC7

compression-threshold=0 I asked the server administrator and got this answer. This setting will cause MCC to be unable to connect. After adjusting this value, you can connect normally. What problem is causing this and can it be fixed?

I think I know where the problem is.

/// <summary>
        /// Read the next packet from the network
        /// </summary>
        /// <param name="packetId">will contain packet ID</param>
        /// <param name="packetData">will contain raw packet Data</param>
        internal Tuple<int, Queue<byte>> ReadNextPacket()
        {
            var size = dataTypes.ReadNextVarIntRAW(socketWrapper); //Packet size
            Queue<byte> packetData = new(socketWrapper.ReadDataRAW(size)); //Packet contents

            //Handle packet decompression
            if (protocolVersion >= MC_1_8_Version
                && compression_treshold > 0)
            {
                var sizeUncompressed = dataTypes.ReadNextVarInt(packetData);
                if (sizeUncompressed != 0) // != 0 means compressed, let's decompress
                {
                    var toDecompress = packetData.ToArray();
                    var uncompressed = ZlibUtils.Decompress(toDecompress, sizeUncompressed);
                    packetData = new Queue<byte>(uncompressed);
                }
            }

            var packetId = dataTypes.ReadNextVarInt(packetData); // Packet ID
            if (handler.GetNetworkPacketCaptureEnabled())
                handler.OnNetworkPacket(packetId, packetData.ToList(), currentState == CurrentState.Login, true);

            return new(packetId, packetData);
        }

There is a missing check that checks the length of the raw packet against the compression treshold. This could be the cause of the issue, I'll make a separate branch with the changes, and then you can test it.

From the Wiki.vg:

If the size of the buffer containing the packet data and ID (as a VarInt) is smaller than the threshold specified in the packet Set Compression. It will be sent as uncompressed. This is done by setting the data length as 0. (Comparable to sending a non-compressed format with an extra 0 between the length, and packet data).

If it's larger than the threshold, then it follows the regular compressed protocol format.

Compression can be disabled by sending the packet Set Compression with a negative Threshold, or not sending the Set Compression packet at all

So something like

var packetDataRaw = socketWrapper.ReadDataRAW(size);
Queue<byte> packetData = new(packetDataRaw); //Packet contents

//Handle packet decompression
if (protocolVersion >= MC_1_8_Version && compression_treshold > 0 && packetDataRaw.Length >= compression_treshold)

Should fix it.

milutinke avatar Jan 27 '24 12:01 milutinke

compression-threshold=0 I asked the server administrator and got this answer. This setting will cause MCC to be unable to connect. After adjusting this value, you can connect normally. What problem is causing this and can it be fixed?

Is that a setting on Velocity or on the Paper MC if you could ask the server owner? Also, can you share the IP so I can debug it?

milutinke avatar Mar 09 '24 10:03 milutinke

compression-threshold=0 I asked the server administrator and got this answer. This setting will cause MCC to be unable to connect. After adjusting this value, you can connect normally. What problem is causing this and can it be fixed?

Is that a setting on Velocity or on the Paper MC if you could ask the server owner? Also, can you share the IP so I can debug it?

This setting is on Velocity. The server administrator has deprecated Velocity and updated it to Bungeecord. If necessary, you can adjust the Velocity settings to this, which will reproduce the problem. The server is private, sorry the IP cannot be shared.

RainC7 avatar Mar 11 '24 13:03 RainC7