Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Michael on August 06, 2009, 04:29 PM

Title: [C#] Getting complete server lists
Post by: Michael on August 06, 2009, 04:29 PM
This is a bit off topic, but here is a great way to always have a complete up to date server list in C#.


   static class clsServers
   {
       public static List<clsServer> Servers = new List<clsServer>();
       /// <summary>
       /// Retrieve battle.net's server list.
       /// </summary>
       public static void Init()
       {

           //Populate server list
           GetServerList("USWest.battle.net", "@USWest", "@Lordaeron");
           GetServerList("USEast.battle.net", "@USEast", "@Azeroth");
           GetServerList("Europe.battle.net", "@Europe", "@Northrend");
           GetServerList("Asia.battle.net", "@Asia", "@Kalimdor");
       }

       private static void GetServerList(string server, string tag1, string tag2)
       {
           IPAddress[] result = Dns.GetHostEntry(server).AddressList;
           Servers.Add(new clsServer(server, tag1, tag2));
           foreach (IPAddress ip in result)
           {
               Servers.Add(new clsServer(ip.ToString(), tag1, tag2));
           }
       }
   }

   class clsServer
   {
       public string ServerIP;
       public string LegacyTag;
       public string WAR3Tag;

       public clsServer(string serverip, string legacytag, string war3tag)
       {
           ServerIP = serverip;
           LegacyTag = legacytag;
           WAR3Tag = war3tag;
       }
   }


This allows for both domain names and IP's to be used as an address for the battle.net server.


           IPAddress[] result = Dns.GetHostEntry(server).AddressList;

Gets all the IP's from the specified sub domain name that can be used to logon to battle.net

[MyndFyre edit: Split from the Regex for capturing topic /]
Title: Re: [C#] Getting complete server lists
Post by: Sixen on August 07, 2009, 02:43 AM
Do you want it to be 100% complete?

GetServerList("Beta.battle.net", "@ClassicBeta", "@Westfall");
GetServerList("demo.war3.battle.net", "", "");



The first is the PTR server on Battle.net, the second is the War3 Demo server, which has no namespace as far as i'm aware. Although, I haven't done much testing on it. It's basically a stripped down Battle.net server, but it is still a Battle.net server nonetheless.
Title: Re: [C#] Getting complete server lists
Post by: Michael on August 11, 2009, 07:33 PM
Do you think it's wise to include beta servers to a bot the average user is going to be using?
Title: Re: [C#] Getting complete server lists
Post by: Mystical on August 11, 2009, 07:47 PM
the point is to handle all aspects, what's one line to make it less limited?
Title: Re: [C#] Getting complete server lists
Post by: Michael on August 11, 2009, 08:30 PM
It may confuse the less educated.
Title: Re: [C#] Getting complete server lists
Post by: MyndFyre on August 11, 2009, 10:10 PM
Quote from: -MichaeL- on August 11, 2009, 08:30 PM
It may confuse the less educated.

Is that why you prefix a class name with "cls" (http://msdn.microsoft.com/en-us/library/ms229040.aspx)?
Title: Re: [C#] Getting complete server lists
Post by: Michael on August 11, 2009, 10:52 PM
Yes, it's a VB6 habit however it doesn't hurt.
Title: Re: [C#] Getting complete server lists
Post by: Sixen on August 12, 2009, 02:43 AM
Quote from: -MichaeL- on August 11, 2009, 07:33 PM
Do you think it's wise to include beta servers to a bot the average user is going to be using?

Yes, otherwise you shouldn't say "complete up to date server list".