Skip to content

Commit

Permalink
Fixed a crash
Browse files Browse the repository at this point in the history
Fixed a crash when a chat message was received on a server that uses protocol lib and viaversion.
  • Loading branch information
milutinke authored Jan 28, 2024
2 parents 6faddae + 88bca83 commit 3bfe5aa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions MinecraftClient/Protocol/Handlers/Protocol18.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ internal bool HandlePacket(int packetId, Queue<byte> packetData)

private bool HandlePlayPackets(int packetId, Queue<byte> packetData)
{
try{
switch (packetPalette.GetIncommingTypeById(packetId))
{
case PacketTypesIn.KeepAlive: // Keep Alive (Play)
Expand Down Expand Up @@ -797,7 +798,7 @@ private bool HandlePlayPackets(int packetId, Queue<byte> packetData)

var chatInfo = Json.ParseJson(chatName).Properties;
var senderDisplayName =
(chatInfo.ContainsKey("insertion") ? chatInfo["insertion"] : chatInfo["text"])
(chatInfo.ContainsKey("insertion") ? chatInfo["insertion"] : (chatInfo.ContainsKey("text") ? chatInfo["text"] : ""))
.StringValue;
string? senderTeamName = null;
var messageTypeEnum =
Expand Down Expand Up @@ -909,7 +910,7 @@ private bool HandlePlayPackets(int packetId, Queue<byte> packetData)
var chatInfo =
Json.ParseJson(targetName ?? chatName).Properties;
var senderDisplayName =
(chatInfo.ContainsKey("insertion") ? chatInfo["insertion"] : chatInfo["text"])
(chatInfo.ContainsKey("insertion") ? chatInfo["insertion"] : (chatInfo.ContainsKey("text") ? chatInfo["text"] : ""))
.StringValue;
string? senderTeamName = null;
if (targetName != null &&
Expand Down Expand Up @@ -2570,6 +2571,9 @@ private bool HandlePlayPackets(int packetId, Queue<byte> packetData)
}

return true; //Packet processed
}catch(Exception exception){
exception.printStackTrace();
}
}

/// <summary>
Expand Down

0 comments on commit 3bfe5aa

Please sign in to comment.