diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 10c471dd..4c8c280e 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -408,12 +408,12 @@ namespace MinecraftClient } } InternalConfig.Username = InternalConfig.Login; - if (string.IsNullOrEmpty(Config.Main.General.Account.Password) && !useBrowser && + if (string.IsNullOrEmpty(Config.Main.General.Account.Password) && string.IsNullOrEmpty(InternalConfig.Password) && !useBrowser && (Config.Main.Advanced.SessionCache == CacheType.none || !SessionCache.Contains(Settings.ToLowerIfNeed(InternalConfig.Login)))) { RequestPassword(); } - else + else if (string.IsNullOrEmpty(InternalConfig.Password)) { InternalConfig.Password = Config.Main.General.Account.Password; } diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index f7ddda15..70670e4b 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -2236,7 +2236,7 @@ namespace MinecraftClient.Protocol.Handlers { try { - byte[] fields = dataTypes.GetAcknowledgment(acknowledgment, isOnlineMode); + byte[] fields = dataTypes.GetAcknowledgment(acknowledgment, isOnlineMode && Config.Signature.LoginWithSecureProfile); SendPacket(PacketTypesOut.MessageAcknowledgment, fields); @@ -2298,7 +2298,8 @@ namespace MinecraftClient.Protocol.Handlers fields.AddRange(dataTypes.GetLong(timeNow.ToUnixTimeMilliseconds())); List>? needSigned = null; // List< Argument Name, Argument Value > - if (playerKeyPair != null && isOnlineMode && Config.Signature.SignMessageInCommand && protocolVersion >= MC_1_19_Version) + if (playerKeyPair != null && isOnlineMode && protocolVersion >= MC_1_19_Version + && Config.Signature.LoginWithSecureProfile && Config.Signature.SignMessageInCommand) needSigned = DeclareCommands.CollectSignArguments(command); if (needSigned == null || needSigned!.Count == 0) @@ -2329,7 +2330,7 @@ namespace MinecraftClient.Protocol.Handlers if (protocolVersion >= MC_1_19_2_Version) { // Message Acknowledgment - fields.AddRange(dataTypes.GetAcknowledgment(acknowledgment!, isOnlineMode)); + fields.AddRange(dataTypes.GetAcknowledgment(acknowledgment!, isOnlineMode && Config.Signature.LoginWithSecureProfile)); } SendPacket(PacketTypesOut.ChatCommand, fields); @@ -2371,7 +2372,7 @@ namespace MinecraftClient.Protocol.Handlers DateTimeOffset timeNow = DateTimeOffset.UtcNow; fields.AddRange(dataTypes.GetLong(timeNow.ToUnixTimeMilliseconds())); - if (!isOnlineMode || playerKeyPair == null || !Config.Signature.SignChat) + if (!isOnlineMode || playerKeyPair == null || !Config.Signature.LoginWithSecureProfile || !Config.Signature.SignChat) { fields.AddRange(dataTypes.GetLong(0)); // Salt: Long fields.AddRange(dataTypes.GetVarInt(0)); // Signature Length: VarInt @@ -2397,7 +2398,7 @@ namespace MinecraftClient.Protocol.Handlers if (protocolVersion >= MC_1_19_2_Version) { // Message Acknowledgment - fields.AddRange(dataTypes.GetAcknowledgment(acknowledgment!, isOnlineMode)); + fields.AddRange(dataTypes.GetAcknowledgment(acknowledgment!, isOnlineMode && Config.Signature.LoginWithSecureProfile)); } } SendPacket(PacketTypesOut.ChatMessage, fields); diff --git a/MinecraftClient/Scripting/ChatBot.cs b/MinecraftClient/Scripting/ChatBot.cs index 9570fe25..bd171234 100644 --- a/MinecraftClient/Scripting/ChatBot.cs +++ b/MinecraftClient/Scripting/ChatBot.cs @@ -568,7 +568,7 @@ namespace MinecraftClient //User-defined regex for private chat messages if (Config.ChatFormat.UserDefined && !string.IsNullOrWhiteSpace(Config.ChatFormat.Private)) { - Match regexMatch = new Regex(Config.ChatFormat.Private).Match(text); + Match regexMatch = Regex.Match(text, Config.ChatFormat.Private); if (regexMatch.Success && regexMatch.Groups.Count >= 3) { sender = regexMatch.Groups[1].Value; @@ -679,7 +679,7 @@ namespace MinecraftClient //User-defined regex for public chat messages if (Config.ChatFormat.UserDefined && !string.IsNullOrWhiteSpace(Config.ChatFormat.Public)) { - Match regexMatch = new Regex(Config.ChatFormat.Public).Match(text); + Match regexMatch = Regex.Match(text, Config.ChatFormat.Public); if (regexMatch.Success && regexMatch.Groups.Count >= 3) { sender = regexMatch.Groups[1].Value; @@ -782,7 +782,7 @@ namespace MinecraftClient //User-defined regex for teleport requests if (Config.ChatFormat.UserDefined && !string.IsNullOrWhiteSpace(Config.ChatFormat.TeleportRequest)) { - Match regexMatch = new Regex(Config.ChatFormat.TeleportRequest).Match(text); + Match regexMatch = Regex.Match(text, Config.ChatFormat.TeleportRequest); if (regexMatch.Success && regexMatch.Groups.Count >= 2) { sender = regexMatch.Groups[1].Value; diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index ee680ea2..7880ead0 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -969,7 +969,40 @@ namespace MinecraftClient public string TeleportRequest = @"^([a-zA-Z0-9_]+) has requested (?:to|that you) teleport to (?:you|them)\.$"; - public void OnSettingUpdate() { } + public void OnSettingUpdate() + { + if (UserDefined) + { + bool checkResult = true; + + try { _ = new Regex(Public); } + catch (ArgumentException) + { + checkResult = false; + ConsoleIO.WriteLineFormatted("§cIllegal regular expression: ChatFormat.Public = " + Public); + } + + try { _ = new Regex(Private); } + catch (ArgumentException) + { + checkResult = false; + ConsoleIO.WriteLineFormatted("§cIllegal regular expression: ChatFormat.Private = " + Private); + } + + try { _ = new Regex(TeleportRequest); } + catch (ArgumentException) + { + checkResult = false; + ConsoleIO.WriteLineFormatted("§cIllegal regular expression: ChatFormat.TeleportRequest = " + TeleportRequest); + } + + if (!checkResult) + { + UserDefined = false; + ConsoleIO.WriteLineFormatted("§cChatFormat: User-defined regular expressions are disabled."); + } + } + } } }