mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Fix timeout on resolving SRV records (#1095)
This commit is contained in:
parent
8b208c5520
commit
c4647c35ef
1 changed files with 32 additions and 22 deletions
|
|
@ -29,12 +29,18 @@ namespace MinecraftClient.Protocol
|
|||
/// <returns>TRUE if a Minecraft Service was found.</returns>
|
||||
public static bool MinecraftServiceLookup(ref string domain, ref ushort port)
|
||||
{
|
||||
bool foundService = false;
|
||||
string domainVal = domain;
|
||||
ushort portVal = port;
|
||||
|
||||
if (!String.IsNullOrEmpty(domain) && domain.Any(c => char.IsLetter(c)))
|
||||
{
|
||||
AutoTimeout.Perform(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Resolving {0}...", domain);
|
||||
Heijden.DNS.Response response = new Heijden.DNS.Resolver().Query("_minecraft._tcp." + domain, Heijden.DNS.QType.SRV);
|
||||
Console.WriteLine("Resolving {0}...", domainVal);
|
||||
Heijden.DNS.Response response = new Heijden.DNS.Resolver().Query("_minecraft._tcp." + domainVal, Heijden.DNS.QType.SRV);
|
||||
Heijden.DNS.RecordSRV[] srvRecords = response.RecordsSRV;
|
||||
if (srvRecords != null && srvRecords.Any())
|
||||
{
|
||||
|
|
@ -45,18 +51,22 @@ namespace MinecraftClient.Protocol
|
|||
.ThenBy(record => Guid.NewGuid())
|
||||
.First();
|
||||
string target = result.TARGET.Trim('.');
|
||||
ConsoleIO.WriteLineFormatted(String.Format("§8Found server {0}:{1} for domain {2}", target, result.PORT, domain));
|
||||
domain = target;
|
||||
port = result.PORT;
|
||||
return true;
|
||||
ConsoleIO.WriteLineFormatted(String.Format("§8Found server {0}:{1} for domain {2}", target, result.PORT, domainVal));
|
||||
domainVal = target;
|
||||
portVal = result.PORT;
|
||||
foundService = true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted(String.Format("§8Failed to perform SRV lookup for {0}\n{1}: {2}", domain, e.GetType().FullName, e.Message));
|
||||
ConsoleIO.WriteLineFormatted(String.Format("§8Failed to perform SRV lookup for {0}\n{1}: {2}", domainVal, e.GetType().FullName, e.Message));
|
||||
}
|
||||
}, TimeSpan.FromSeconds(Settings.ResolveSrvRecordsShortTimeout ? 10 : 30));
|
||||
}
|
||||
return false;
|
||||
|
||||
domain = domainVal;
|
||||
port = portVal;
|
||||
return foundService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue