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,34 +29,44 @@ namespace MinecraftClient.Protocol
|
||||||
/// <returns>TRUE if a Minecraft Service was found.</returns>
|
/// <returns>TRUE if a Minecraft Service was found.</returns>
|
||||||
public static bool MinecraftServiceLookup(ref string domain, ref ushort port)
|
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)))
|
if (!String.IsNullOrEmpty(domain) && domain.Any(c => char.IsLetter(c)))
|
||||||
{
|
{
|
||||||
try
|
AutoTimeout.Perform(() =>
|
||||||
{
|
{
|
||||||
Console.WriteLine("Resolving {0}...", domain);
|
try
|
||||||
Heijden.DNS.Response response = new Heijden.DNS.Resolver().Query("_minecraft._tcp." + domain, Heijden.DNS.QType.SRV);
|
|
||||||
Heijden.DNS.RecordSRV[] srvRecords = response.RecordsSRV;
|
|
||||||
if (srvRecords != null && srvRecords.Any())
|
|
||||||
{
|
{
|
||||||
//Order SRV records by priority and weight, then randomly
|
Console.WriteLine("Resolving {0}...", domainVal);
|
||||||
Heijden.DNS.RecordSRV result = srvRecords
|
Heijden.DNS.Response response = new Heijden.DNS.Resolver().Query("_minecraft._tcp." + domainVal, Heijden.DNS.QType.SRV);
|
||||||
.OrderBy(record => record.PRIORITY)
|
Heijden.DNS.RecordSRV[] srvRecords = response.RecordsSRV;
|
||||||
.ThenByDescending(record => record.WEIGHT)
|
if (srvRecords != null && srvRecords.Any())
|
||||||
.ThenBy(record => Guid.NewGuid())
|
{
|
||||||
.First();
|
//Order SRV records by priority and weight, then randomly
|
||||||
string target = result.TARGET.Trim('.');
|
Heijden.DNS.RecordSRV result = srvRecords
|
||||||
ConsoleIO.WriteLineFormatted(String.Format("§8Found server {0}:{1} for domain {2}", target, result.PORT, domain));
|
.OrderBy(record => record.PRIORITY)
|
||||||
domain = target;
|
.ThenByDescending(record => record.WEIGHT)
|
||||||
port = result.PORT;
|
.ThenBy(record => Guid.NewGuid())
|
||||||
return true;
|
.First();
|
||||||
|
string target = result.TARGET.Trim('.');
|
||||||
|
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)
|
||||||
catch (Exception e)
|
{
|
||||||
{
|
ConsoleIO.WriteLineFormatted(String.Format("§8Failed to perform SRV lookup for {0}\n{1}: {2}", domainVal, e.GetType().FullName, e.Message));
|
||||||
ConsoleIO.WriteLineFormatted(String.Format("§8Failed to perform SRV lookup for {0}\n{1}: {2}", domain, e.GetType().FullName, e.Message));
|
}
|
||||||
}
|
}, TimeSpan.FromSeconds(Settings.ResolveSrvRecordsShortTimeout ? 10 : 30));
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
domain = domainVal;
|
||||||
|
port = portVal;
|
||||||
|
return foundService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue