• Welcome to Valhalla Legends Archive.
 

[C#] Getting complete server lists

Started by Michael, August 06, 2009, 04:29 PM

Previous topic - Next topic

Michael

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 /]

Sixen

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.
Blizzard Tech Support/Op W@R - FallenArms
The Chat Gem Lives!
http://www.diablofans.com
http://www.sixen.org

Michael

Do you think it's wise to include beta servers to a bot the average user is going to be using?

Mystical

the point is to handle all aspects, what's one line to make it less limited?

Michael


MyndFyre

QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Michael

Yes, it's a VB6 habit however it doesn't hurt.

Sixen

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".
Blizzard Tech Support/Op W@R - FallenArms
The Chat Gem Lives!
http://www.diablofans.com
http://www.sixen.org