diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index afd78df0..94420a56 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -2417,6 +2417,11 @@ namespace MinecraftClient /// public void OnGameJoined(bool isOnlineMode) { + if (protocolversion < Protocol18Handler.MC_1_19_3_Version || playerKeyPair == null || !isOnlineMode) + SetCanSendMessage(true); + else + SetCanSendMessage(false); + string? bandString = Config.Main.Advanced.BrandInfo.ToBrandString(); if (!String.IsNullOrWhiteSpace(bandString)) handler.SendBrandInfo(bandString.Trim()); @@ -2435,9 +2440,6 @@ namespace MinecraftClient && playerKeyPair != null && isOnlineMode) handler.SendPlayerSession(playerKeyPair); - if (protocolversion < Protocol18Handler.MC_1_19_3_Version) - CanSendMessage = true; - if (inventoryHandlingRequested) { inventoryHandlingRequested = false; @@ -3482,9 +3484,10 @@ namespace MinecraftClient ConsoleIO.OnAutoCompleteDone(transactionId, result); } - public void OnDeclareCommands() + public void SetCanSendMessage(bool canSendMessage) { - CanSendMessage = true; + CanSendMessage = canSendMessage; + Log.Debug("CanSendMessage = " + canSendMessage); } /// diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 022aa14b..35af0d8d 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -75,8 +75,9 @@ namespace MinecraftClient.Protocol.Handlers private readonly BlockingCollection>> packetQueue = new(); private float LastYaw, LastPitch; + private bool receiveDeclareCommands = false, receivePlayerInfo = false; private object MessageSigningLock = new(); - private Guid chatUuid = Guid.Empty; + private Guid chatUuid = Guid.NewGuid(); private int pendingAcknowledgments = 0, messageIndex = 0; private LastSeenMessagesCollector lastSeenMessagesCollector; private LastSeenMessageList.AcknowledgedMessage? lastReceivedMessage = null; @@ -367,7 +368,19 @@ namespace MinecraftClient.Protocol.Handlers SendPacket(PacketTypesOut.Pong, packetData); break; case PacketTypesIn.JoinGame: + { // Temporary fix + log.Debug("Receive JoinGame"); + + receiveDeclareCommands = receivePlayerInfo = false; + + messageIndex = 0; + pendingAcknowledgments = 0; + + lastReceivedMessage = null; + lastSeenMessagesCollector = protocolVersion >= MC_1_19_3_Version ? new(20) : new(5); + } handler.OnGameJoined(isOnlineMode); + int playerEntityID = dataTypes.ReadNextInt(packetData); handler.OnReceivePlayerEntityID(playerEntityID); @@ -467,8 +480,11 @@ namespace MinecraftClient.Protocol.Handlers case PacketTypesIn.DeclareCommands: if (protocolVersion >= MC_1_19_Version) { + log.Debug("Receive DeclareCommands"); DeclareCommands.Read(dataTypes, packetData, protocolVersion); - handler.OnDeclareCommands(); + receiveDeclareCommands = true; + if (receivePlayerInfo) + handler.SetCanSendMessage(true); } break; case PacketTypesIn.ChatMessage: @@ -1404,10 +1420,28 @@ namespace MinecraftClient.Protocol.Handlers byte[] encodedPublicKey = dataTypes.ReadNextByteArray(packetData); byte[] publicKeySignature = dataTypes.ReadNextByteArray(packetData); player.SetPublicKey(chatUuid, publicKeyExpiryTime, encodedPublicKey, publicKeySignature); + + if (playerUuid == handler.GetUserUuid()) + { + log.Debug("Receive ChatUuid = " + chatUuid); + this.chatUuid = chatUuid; + } } else { player.ClearPublicKey(); + + if (playerUuid == handler.GetUserUuid()) + { + log.Debug("Receive ChatUuid = Empty"); + } + } + + if (playerUuid == handler.GetUserUuid()) + { + receivePlayerInfo = true; + if (receiveDeclareCommands) + handler.SetCanSendMessage(true); } } if ((actionBitset & 1 << 2) > 0) // Actions bit 2: update gamemode @@ -3392,7 +3426,6 @@ namespace MinecraftClient.Protocol.Handlers { List packet = new(); - chatUuid = Guid.NewGuid(); packet.AddRange(DataTypes.GetUUID(chatUuid)); packet.AddRange(DataTypes.GetLong(playerKeyPair.GetExpirationMilliseconds())); packet.AddRange(DataTypes.GetVarInt(playerKeyPair.PublicKey.Key.Length)); @@ -3400,6 +3433,8 @@ namespace MinecraftClient.Protocol.Handlers packet.AddRange(DataTypes.GetVarInt(playerKeyPair.PublicKey.SignatureV2!.Length)); packet.AddRange(playerKeyPair.PublicKey.SignatureV2); + log.Debug($"SendPlayerSession MessageUUID = {chatUuid.ToString()}, len(PublicKey) = {playerKeyPair.PublicKey.Key.Length}, len(SignatureV2) = {playerKeyPair.PublicKey.SignatureV2!.Length}"); + SendPacket(PacketTypesOut.PlayerSession, packet); return true; } diff --git a/MinecraftClient/Protocol/IMinecraftComHandler.cs b/MinecraftClient/Protocol/IMinecraftComHandler.cs index 549d070d..58636d1c 100644 --- a/MinecraftClient/Protocol/IMinecraftComHandler.cs +++ b/MinecraftClient/Protocol/IMinecraftComHandler.cs @@ -466,7 +466,7 @@ namespace MinecraftClient.Protocol /// All commands. public void OnAutoCompleteDone(int transactionId, string[] result); - public void OnDeclareCommands(); + public void SetCanSendMessage(bool canSendMessage); /// /// Send a click container button packet to the server. diff --git a/MinecraftClient/Protocol/Message/ChatParser.cs b/MinecraftClient/Protocol/Message/ChatParser.cs index dad15d21..a1db8862 100644 --- a/MinecraftClient/Protocol/Message/ChatParser.cs +++ b/MinecraftClient/Protocol/Message/ChatParser.cs @@ -302,11 +302,9 @@ namespace MinecraftClient.Protocol.Message catch (Exception e) { ConsoleIO.WriteLineFormatted("ยง8" + Translations.chat_fail, acceptnewlines: true); - if (Config.Logging.DebugMessages) - { - ConsoleIO.WriteLine(e.Message); - ConsoleIO.WriteLine(e.StackTrace ?? ""); - } + ConsoleIO.WriteLine(e.Message); + if (Config.Logging.DebugMessages && !string.IsNullOrEmpty(e.StackTrace)) + ConsoleIO.WriteLine(e.StackTrace); } finally { diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 6b6bb5b9..af5f8bbf 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -705,7 +705,7 @@ namespace MinecraftClient public bool SignMessageInCommand = true; [TomlInlineComment("$Signature.MarkLegallySignedMsg$")] - public bool MarkLegallySignedMsg = false; + public bool MarkLegallySignedMsg = true; [TomlInlineComment("$Signature.MarkModifiedMsg$")] public bool MarkModifiedMsg = true; @@ -714,7 +714,7 @@ namespace MinecraftClient public bool MarkIllegallySignedMsg = true; [TomlInlineComment("$Signature.MarkSystemMessage$")] - public bool MarkSystemMessage = false; + public bool MarkSystemMessage = true; [TomlInlineComment("$Signature.ShowModifiedChat$")] public bool ShowModifiedChat = true;