Esempio n. 1
0
 public void GetPage()
 {
     // TODO: FIX ME!
     string pageLow = http_request_page.ToLowerFast();
     #if PAGE_MAGIC
     if (pageLow.StartsWith("/map/region/"))
     {
         string after;
         string region = pageLow.Substring("/map/region/".Length).BeforeAndAfter("/", out after);
         for (int i = 0; i < TheServer.LoadedRegions.Count; i++)
         {
             if (TheServer.LoadedRegions[i].Name == region)
             {
                 string[] dat = after.SplitFast('/');
                 if (dat[0] == "img" && dat.Length >= 4)
                 {
                     int x = Utilities.StringToInt(dat[1]);
                     int y = Utilities.StringToInt(dat[2]);
                     int z = Utilities.StringToInt(dat[3].Before("."));
                     byte[] data = TheServer.LoadedRegions[i].ChunkManager.GetImage(x, y, z);
                     if (data != null)
                     {
                         http_response_contenttype = "image/png";
                         http_response_content = data;
                         return;
                     }
                 }
                 else if (dat[0] == "full_img" && dat.Length >= 3)
                 {
                     int x = Utilities.StringToInt(dat[1]);
                     int y = Utilities.StringToInt(dat[2].Before("."));
                     KeyValuePair<int, int> maxes = TheServer.LoadedRegions[i].ChunkManager.GetMaxes(x, y);
                     List<byte[]> datums = new List<byte[]>();
                     for (int z = maxes.Key; z <= maxes.Value; z++)
                     {
                         byte[] dt = TheServer.LoadedRegions[i].ChunkManager.GetImage(x, y, z);
                         if (dt != null)
                         {
                             datums.Add(dt);
                         }
                     }
                     http_response_contenttype = "image/png";
                     if (datums.Count > 1)
                     {
                         http_response_content = TheServer.BlockImages.Combine(datums, false);
                     }
                     else if (datums.Count == 1)
                     {
                         http_response_content = datums[0];
                     }
                     else
                     {
                         Bitmap bmp = new Bitmap(1, 1);
                         bmp.SetPixel(0, 0, Color.Black);
                         DataStream ds = new DataStream();
                         bmp.Save(ds, ImageFormat.Png);
                         http_response_content = ds.ToArray();
                         ds.Dispose();
                         bmp.Dispose();
                     }
                     return;
                 }
                 else if (dat[0] == "full_img_angle" && dat.Length >= 4)
                 {
                     int x = Utilities.StringToInt(dat[1]);
                     int y = Utilities.StringToInt(dat[2]);
                     int z = Utilities.StringToInt(dat[3].Before("."));
                     byte[] dt = TheServer.LoadedRegions[i].ChunkManager.GetImageAngle(x, y, z);
                     http_response_contenttype = "image/png";
                     if (dt != null)
                     {
                         http_response_content = dt;
                     }
                     else
                     {
                         Bitmap bmp = new Bitmap(1, 1);
                         bmp.SetPixel(0, 0, Color.Transparent);
                         DataStream ds = new DataStream();
                         bmp.Save(ds, ImageFormat.Png);
                         http_response_content = ds.ToArray();
                         ds.Dispose();
                         bmp.Dispose();
                     }
                     return;
                 }
                 else if (dat[0] == "maxes" && dat.Length >= 3)
                 {
                     int x = Utilities.StringToInt(dat[1]);
                     int y = Utilities.StringToInt(dat[2]);
                     KeyValuePair<int, int> maxes = TheServer.LoadedRegions[i].ChunkManager.GetMaxes(x, y);
                     http_response_content = FileHandler.encoding.GetBytes(maxes.Key + "," + maxes.Value);
                     return;
                 }
                 else if (dat[0] == "expquick" && dat.Length >= 3)
                 {
                     int bx = Utilities.StringToInt(dat[1]);
                     int by = Utilities.StringToInt(dat[2]);
                     int sz = Chunk.CHUNK_SIZE * BlockImageManager.TexWidth;
                     StringBuilder content = new StringBuilder();
                     content.Append("<!doctype html>\n<html>\n<head>\n<title>Voxalia EXP-QUICK</title>\n</head>\n<body>\n");
                     const int SIZE = 6;
                     for (int x = -SIZE; x <= SIZE; x++)
                     {
                         for (int y = -SIZE; y <= SIZE; y++)
                         {
                             content.Append("<img style=\"position:absolute;top:" + (y + SIZE) * sz + "px;left:" + (x + SIZE) * sz + "px;\" src=\"/map/region/"
                                 + region + "/full_img/" + (bx + x) + "/" + (by + y) + ".png\" width=\"" + sz + "\" height=\"" + sz + "\" />");
                         }
                     }
                     content.Append("\n</body>\n</html>\n");
                     http_response_content = FileHandler.encoding.GetBytes(content.ToString());
                     return;
                 }
                 else if (dat[0] == "expquick_angle" && dat.Length >= 4)
                 {
                     int bx = Utilities.StringToInt(dat[1]);
                     int by = Utilities.StringToInt(dat[2]);
                     int bz = Utilities.StringToInt(dat[3]);
                     int sz = Chunk.CHUNK_SIZE * BlockImageManager.TexWidth;
                     int sz2 = Chunk.CHUNK_SIZE * BlockImageManager.TexWidth2;
                     StringBuilder content = new StringBuilder();
                     content.Append("<!doctype html>\n<html>\n<head>\n<title>Voxalia EXP-QUICK (Angled)</title>\n</head>\n<body>\n");
                     const int SIZE = 3;
                     for (int x = -SIZE; x <= SIZE; x++)
                     {
                         for (int y = -SIZE; y <= SIZE; y++)
                         {
                             for (int z = -SIZE; z <= SIZE; z++)
                             {
                                 int x1 = (x) * sz;
                                 int y1 = (y) * sz;
                                 int z1 = (bz + z) * sz;
                                 int xw = (SIZE * 2 * sz) + (x1 - y1);
                                 int yw = ((SIZE * 2 * sz) + ((x1 + y1) - (z1))) / 2;
                                 content.Append("<img style=\"position:absolute;top:" + yw + "px;left:" + xw + "px;z-index:" + z + ";\" src=\"/map/region/"
                                     + region + "/full_img_angle/" + (bx + x) + "/" + (by + y) + "/" + (bz + z) + ".png\" width=\"" + sz2 + "\" height=\"" + sz2 + "\" />");
                             }
                         }
                     }
                     content.Append("\n</body>\n</html>\n");
                     http_response_content = FileHandler.encoding.GetBytes(content.ToString());
                     return;
                 }
                 break;
             }
         }
     }
     else
     #endif
     if (pageLow.StartsWith("/log_view/"))
     {
         string[] dat = pageLow.Substring("/log_view/".Length).SplitFast('/');
         string username = dat[0];
         string passcode = dat.Length < 2 ? "" : dat[1];
         bool valid = false;
         StringBuilder content = new StringBuilder();
         content.Append("<!doctype html>\n<html>\n<head>\n<title>Voxalia Log View</title>\n</head>\n<body>\n");
         lock (TheServer.TickLock)
         {
             FDSSection cfg = TheServer.GetPlayerConfig(username);
             valid = cfg != null
                 && cfg.GetString("web.is_admin", "false").ToLowerFast() == "true"
                 && cfg.GetString("web.passcode", "") == Utilities.HashQuick(username.ToLowerFast(), passcode);
         }
         if (valid)
         {
             content.Append("Logs follow:\n<pre><code>\n");
             lock (TheServer.RecentMessagesLock)
             {
                 foreach (string str in TheServer.RecentMessages)
                 {
                     foreach (string substr in str.SplitFast('\n'))
                     {
                         string trimmedsubstr = substr.Trim();
                         if (trimmedsubstr.Length > 0)
                         {
                             content.Append(trimmedsubstr.Replace("&", "&amp;").Replace("<", "&lt;").Replace(">", "&gt;")).Append("\n");
                         }
                     }
                 }
             }
             content.Append("\n</code></pre>");
         }
         else
         {
             content.Append("Not a valid login!");
         }
         content.Append("\n</body>\n</html>\n");
         http_response_content = FileHandler.encoding.GetBytes(content.ToString());
         return;
     }
     Do404();
 }