Exemplo n.º 1
0
        public static ShardList Load()
        {
            XmlSerializer ser = new XmlSerializer(typeof(ShardList));
            ShardList     sl  = ser.Deserialize(new StreamReader("Shards.xml")) as ShardList;

            return(sl);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.Title = "Shard List Server";
            Console.WriteLine("Shard List Server");
            Console.WriteLine("");

            shardList = ShardList.Load();

            Console.WriteLine("Loaded " + shardList.ShardCount + " shards.");

            httpListener = new HttpListener();
            httpListener.Prefixes.Add("https://*:4444/");
            httpListener.Start();

            Console.WriteLine("Ready!");

            while (true)
            {
                HttpListenerContext  ctx  = httpListener.GetContext();
                HttpListenerRequest  req  = ctx.Request;
                HttpListenerResponse resp = ctx.Response;
                string response           = "";
                Console.WriteLine("Request = " + req.Url.AbsolutePath);
                switch (req.Url.AbsolutePath)
                {
                case "/gamepad/shardlist":
                    List <string> shardEntries = new List <string>();
                    foreach (ShardListEntry shardEntry in shardList.Shards)
                    {
                        string s = "{\"region\":" + (byte)shardEntry.Region + ",\"isup\":" + (shardEntry.Online ? "true" : "false");
                        s += ",\"timezone\":" + shardEntry.Timezone + ",\"weight\":100,\"host\":\"" + shardList.ProxyIP + ":" + shardList.ProxyPort + ":" + shardEntry.ServerID + "\"";
                        s += ",\"focusid\":0,\"name\":\"" + shardEntry.Name + "\",\"queuewait\":" + shardEntry.QueueWait + ",\"loadlevel\":" + (byte)shardEntry.LoadLevel + ",\"language\":\"" + shardEntry.Language + "\"}";
                        shardEntries.Add(s);
                    }
                    response = "{\"shards\":[";
                    bool first = true;
                    foreach (string shard in shardEntries)
                    {
                        if (!first)
                        {
                            response += ",";
                        }
                        response += shard;
                        first     = false;
                    }
                    response += "],\"environmentDisabled\":0, \"accountRegion\":1}";
                    break;

                case "/gamepad/lastshard":
                    response = "{\"region\":2,\"isup\":true,\"timezone\":-600,\"weight\":100,\"host\":\"127.0.0.1:7979:castlehilltest\",\"focusid\":0,\"name\":\"Sylar Testing Galaxy\",\"queuewait\":0,\"loadlevel\":1,\"language\":\"en\"}";
                    break;
                }
                byte[] buffer = Encoding.UTF8.GetBytes(response);
                resp.ContentLength64 = buffer.Length;
                resp.OutputStream.Write(buffer, 0, buffer.Length);
                resp.OutputStream.Close();
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.Title = "Shard List Server";
            Console.WriteLine("Shard List Server");
            Console.WriteLine("");

            shardList = ShardList.Load();

            Console.WriteLine("Loaded " + shardList.ShardCount + " shards.");

            httpListener = new HttpListener();
            httpListener.Prefixes.Add("https://*:4444/");
            httpListener.Start();

            Console.WriteLine("Ready!");

            while (true)
            {
                HttpListenerContext ctx = httpListener.GetContext();
                HttpListenerRequest req = ctx.Request;
                HttpListenerResponse resp = ctx.Response;
                string response = "";
                Console.WriteLine("Request = " + req.Url.AbsolutePath);
                switch (req.Url.AbsolutePath)
                {
                    case "/gamepad/shardlist":
                        List<string> shardEntries = new List<string>();
                        foreach (ShardListEntry shardEntry in shardList.Shards)
                        {
                            string s = "{\"region\":" + (byte)shardEntry.Region + ",\"isup\":" + (shardEntry.Online ? "true" : "false");
                            s += ",\"timezone\":" + shardEntry.Timezone + ",\"weight\":100,\"host\":\"" + shardList.ProxyIP + ":" + shardList.ProxyPort + ":" + shardEntry.ServerID + "\"";
                            s += ",\"focusid\":0,\"name\":\"" + shardEntry.Name + "\",\"queuewait\":" + shardEntry.QueueWait + ",\"loadlevel\":" + (byte)shardEntry.LoadLevel + ",\"language\":\"" + shardEntry.Language + "\"}";
                            shardEntries.Add(s);
                        }
                        response = "{\"shards\":[";
                        bool first = true;
                        foreach (string shard in shardEntries)
                        {
                            if (!first) response += ",";
                            response += shard;
                            first = false;
                        }
                        response += "],\"environmentDisabled\":0, \"accountRegion\":1}";
                        break;
                    case "/gamepad/lastshard":
                        response = "{\"region\":2,\"isup\":true,\"timezone\":-600,\"weight\":100,\"host\":\"127.0.0.1:7979:castlehilltest\",\"focusid\":0,\"name\":\"Sylar Testing Galaxy\",\"queuewait\":0,\"loadlevel\":1,\"language\":\"en\"}";
                        break;
                }
                byte[] buffer = Encoding.UTF8.GetBytes(response);
                resp.ContentLength64 = buffer.Length;
                resp.OutputStream.Write(buffer, 0, buffer.Length);
                resp.OutputStream.Close();
            }
        }