From fc30e38e78d2990d38d0cfa07258fa8b92193814 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Sat, 5 Nov 2022 21:15:16 +0800 Subject: [PATCH] Fix ServerList bug --- MinecraftClient/Settings.cs | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 445054f0..4fab7815 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -346,36 +346,32 @@ namespace MinecraftClient /// True if the server IP was valid and loaded, false otherwise public bool SetServerIP(ServerInfoConfig serverInfo, bool checkAlias) { - string serverStr = ToLowerIfNeed(serverInfo.Host); - string[] sip = serverStr.Split(new[] { ":", ":" }, StringSplitOptions.None); - string host = sip[0]; + string[] sip = serverInfo.Host.Split(new[] { ":", ":" }, StringSplitOptions.None); + string host = ToLowerIfNeed(sip[0]); ushort port = 25565; - if (sip.Length > 1) + if (serverInfo.Port.HasValue) { - if (serverInfo.Port != null) - { - port = (ushort)serverInfo.Port; - } - else - { - try { port = Convert.ToUInt16(sip[1]); } - catch (FormatException) { return false; } - } + port = serverInfo.Port.Value; + } + else if (sip.Length > 1) + { + try { port = Convert.ToUInt16(sip[1]); } + catch (FormatException) { return false; } } if (host == "localhost" || host.Contains('.')) { //Server IP (IP or domain names contains at least a dot) - if (sip.Length == 1 && serverInfo.Port == null && host.Contains('.') && host.Any(c => char.IsLetter(c)) && - Settings.Config.Main.Advanced.ResolveSrvRecords != MainConfigHealper.MainConfig.AdvancedConfig.ResolveSrvRecordType.no) + if (sip.Length == 1 && !serverInfo.Port.HasValue && host.Contains('.') && host.Any(c => char.IsLetter(c)) && + Settings.Config.Main.Advanced.ResolveSrvRecords != ResolveSrvRecordType.no) //Domain name without port may need Minecraft SRV Record lookup ProtocolHandler.MinecraftServiceLookup(ref host, ref port); InternalConfig.ServerIP = host; InternalConfig.ServerPort = port; return true; } - else if (checkAlias && Advanced.ServerList.TryGetValue(serverStr, out ServerInfoConfig serverStr2)) + else if (checkAlias && Advanced.ServerList.TryGetValue(sip[0], out ServerInfoConfig serverStr2)) { return SetServerIP(serverStr2, false); } @@ -428,7 +424,7 @@ namespace MinecraftClient if (!string.IsNullOrWhiteSpace(General.Server.Host)) { string[] sip = General.Server.Host.Split(new[] { ":", ":" }, StringSplitOptions.None); - General.Server.Host = sip[0]; + General.Server.Host = ToLowerIfNeed(sip[0]); InternalConfig.ServerIP = General.Server.Host; if (sip.Length > 1)