Changeset 387 for binary-improvements2/MapRendering/Web/API
- Timestamp:
- Aug 6, 2022, 11:32:32 PM (2 years ago)
- Location:
- binary-improvements2/MapRendering/Web/API
- Files:
-
- 16 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/MapRendering/Web/API/AbsWebAPI.cs
r386 r387 1 using System.Text;2 using AllocsFixes.JSON;3 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;4 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;5 6 1 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 public abstract class WebAPI {2 public abstract class AbsWebAPI { 8 3 public readonly string Name; 9 4 10 protected WebAPI (string _name = null) {5 protected AbsWebAPI (string _name = null) { 11 6 Name = _name ?? GetType ().Name; 12 7 } 13 8 14 #if ENABLE_PROFILER 15 private static readonly UnityEngine.Profiling.CustomSampler jsonSerializeSampler = UnityEngine.Profiling.CustomSampler.Create ("JSON_Serialize"); 16 private static readonly UnityEngine.Profiling.CustomSampler netWriteSampler = UnityEngine.Profiling.CustomSampler.Create ("JSON_Write"); 17 #endif 18 19 public static void WriteJSON (HttpListenerResponse _resp, JSONNode _root) { 20 #if ENABLE_PROFILER 21 jsonSerializeSampler.Begin (); 22 #endif 23 StringBuilder sb = new StringBuilder (); 24 _root.ToString (sb); 25 #if ENABLE_PROFILER 26 jsonSerializeSampler.End (); 27 netWriteSampler.Begin (); 28 #endif 29 byte[] buf = Encoding.UTF8.GetBytes (sb.ToString ()); 30 _resp.ContentLength64 = buf.Length; 31 _resp.ContentType = "application/json"; 32 _resp.ContentEncoding = Encoding.UTF8; 33 _resp.OutputStream.Write (buf, 0, buf.Length); 34 #if ENABLE_PROFILER 35 netWriteSampler.End (); 36 #endif 37 } 38 39 public static void WriteText (HttpListenerResponse _resp, string _text) { 40 byte[] buf = Encoding.UTF8.GetBytes (_text); 41 _resp.ContentLength64 = buf.Length; 42 _resp.ContentType = "text/plain"; 43 _resp.ContentEncoding = Encoding.UTF8; 44 _resp.OutputStream.Write (buf, 0, buf.Length); 45 } 46 47 public abstract void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, 48 WebConnection _user, int _permissionLevel); 9 public abstract void HandleRequest (RequestContext _context); 49 10 50 11 public virtual int DefaultPermissionLevel () { -
binary-improvements2/MapRendering/Web/API/ExecuteConsoleCommand.cs
r382 r387 1 1 using System; 2 2 using System.Net; 3 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;4 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;5 3 6 4 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 public class ExecuteConsoleCommand : WebAPI { 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 int _permissionLevel) { 10 if (string.IsNullOrEmpty (_req.QueryString ["command"])) { 11 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 12 Web.SetResponseTextContent (_resp, "No command given"); 5 public class ExecuteConsoleCommand : AbsWebAPI { 6 public override void HandleRequest (RequestContext _context) { 7 if (string.IsNullOrEmpty (_context.Request.QueryString ["command"])) { 8 WebUtils.WriteText (_context.Response, "No command given", HttpStatusCode.BadRequest); 13 9 return; 14 10 } 15 11 16 12 WebCommandResult.ResultType responseType = 17 _ req.QueryString ["raw"] != null13 _context.Request.QueryString ["raw"] != null 18 14 ? WebCommandResult.ResultType.Raw 19 : (_ req.QueryString ["simple"] != null15 : (_context.Request.QueryString ["simple"] != null 20 16 ? WebCommandResult.ResultType.ResultOnly 21 17 : WebCommandResult.ResultType.Full); 22 18 23 string commandline = _ req.QueryString ["command"];19 string commandline = _context.Request.QueryString ["command"]; 24 20 string commandPart = commandline.Split (' ') [0]; 25 21 string argumentsPart = commandline.Substring (Math.Min (commandline.Length, commandPart.Length + 1)); … … 28 24 29 25 if (command == null) { 30 _resp.StatusCode = (int) HttpStatusCode.NotFound; 31 Web.SetResponseTextContent (_resp, "Unknown command"); 26 WebUtils.WriteText (_context.Response, "Unknown command", HttpStatusCode.NotFound); 32 27 return; 33 28 } … … 35 30 int commandPermissionLevel = GameManager.Instance.adminTools.GetCommandPermissionLevel (command.GetCommands ()); 36 31 37 if (_permissionLevel > commandPermissionLevel) { 38 _resp.StatusCode = (int) HttpStatusCode.Forbidden; 39 Web.SetResponseTextContent (_resp, "You are not allowed to execute this command"); 32 if (_context.PermissionLevel > commandPermissionLevel) { 33 WebUtils.WriteText (_context.Response, "You are not allowed to execute this command", HttpStatusCode.Forbidden); 40 34 return; 41 35 } 42 36 43 _ resp.SendChunked = true;44 WebCommandResult wcr = new WebCommandResult (commandPart, argumentsPart, responseType, _ resp);37 _context.Response.SendChunked = true; 38 WebCommandResult wcr = new WebCommandResult (commandPart, argumentsPart, responseType, _context.Response); 45 39 SdtdConsole.Instance.ExecuteAsync (commandline, wcr); 46 40 } -
binary-improvements2/MapRendering/Web/API/GetAllowedCommands.cs
r383 r387 1 1 using AllocsFixes.JSON; 2 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;3 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;4 2 5 3 namespace AllocsFixes.NetConnections.Servers.Web.API { 6 public class GetAllowedCommands : WebAPI { 7 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 8 int _permissionLevel) { 4 public class GetAllowedCommands : AbsWebAPI { 5 public override void HandleRequest (RequestContext _context) { 9 6 JSONObject result = new JSONObject (); 10 7 JSONArray entries = new JSONArray (); 11 8 foreach (IConsoleCommand cc in SdtdConsole.Instance.GetCommands ()) { 12 9 int commandPermissionLevel = GameManager.Instance.adminTools.GetCommandPermissionLevel (cc.GetCommands ()); 13 if (_ permissionLevel <= commandPermissionLevel) {10 if (_context.PermissionLevel <= commandPermissionLevel) { 14 11 string cmd = string.Empty; 15 12 foreach (string s in cc.GetCommands ()) { … … 29 26 result.Add ("commands", entries); 30 27 31 W riteJSON (_resp, result);28 WebUtils.WriteJson (_context.Response, result); 32 29 } 33 30 -
binary-improvements2/MapRendering/Web/API/GetAnimalsLocation.cs
r383 r387 2 2 using AllocsFixes.JSON; 3 3 using AllocsFixes.LiveData; 4 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;5 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;6 4 7 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 8 internal class GetAnimalsLocation : WebAPI {6 internal class GetAnimalsLocation : AbsWebAPI { 9 7 private readonly List<EntityAnimal> animals = new List<EntityAnimal> (); 10 8 11 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 12 int _permissionLevel) { 9 public override void HandleRequest (RequestContext _context) { 13 10 JSONArray animalsJsResult = new JSONArray (); 14 11 … … 37 34 } 38 35 39 W riteJSON (_resp, animalsJsResult);36 WebUtils.WriteJson (_context.Response, animalsJsResult); 40 37 } 41 38 } -
binary-improvements2/MapRendering/Web/API/GetHostileLocation.cs
r383 r387 2 2 using AllocsFixes.JSON; 3 3 using AllocsFixes.LiveData; 4 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;5 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;6 4 7 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 8 internal class GetHostileLocation : WebAPI {6 internal class GetHostileLocation : AbsWebAPI { 9 7 private readonly List<EntityEnemy> enemies = new List<EntityEnemy> (); 10 8 11 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 12 int _permissionLevel) { 9 public override void HandleRequest (RequestContext _context) { 13 10 JSONArray hostilesJsResult = new JSONArray (); 14 11 … … 37 34 } 38 35 39 W riteJSON (_resp, hostilesJsResult);36 WebUtils.WriteJson (_context.Response, hostilesJsResult); 40 37 } 41 38 } -
binary-improvements2/MapRendering/Web/API/GetLandClaims.cs
r382 r387 3 3 using AllocsFixes.JSON; 4 4 using AllocsFixes.PersistentData; 5 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;6 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;7 5 8 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 9 public class GetLandClaims : WebAPI { 10 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 11 int _permissionLevel) { 7 public class GetLandClaims : AbsWebAPI { 8 public override void HandleRequest (RequestContext _context) { 12 9 PlatformUserIdentifierAbs requestedUserId = null; 13 if (_req.QueryString ["userid"] != null) { 14 if (!PlatformUserIdentifierAbs.TryFromCombinedString (_req.QueryString ["userid"], out requestedUserId)) { 15 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 16 Web.SetResponseTextContent (_resp, "Invalid user id given"); 10 if (_context.Request.QueryString ["userid"] != null) { 11 if (!PlatformUserIdentifierAbs.TryFromCombinedString (_context.Request.QueryString ["userid"], out requestedUserId)) { 12 WebUtils.WriteText (_context.Response, "Invalid user id given", HttpStatusCode.BadRequest); 17 13 return; 18 14 } … … 20 16 21 17 // default user, cheap way to avoid 'null reference exception' 22 PlatformUserIdentifierAbs userId = _ user?.UserId;18 PlatformUserIdentifierAbs userId = _context.Connection?.UserId; 23 19 24 bool bViewAll = WebConnection.CanViewAllClaims (_ permissionLevel);20 bool bViewAll = WebConnection.CanViewAllClaims (_context.PermissionLevel); 25 21 26 22 JSONObject result = new JSONObject (); … … 74 70 } 75 71 76 W riteJSON (_resp, result);72 WebUtils.WriteJson (_context.Response, result); 77 73 } 78 74 } -
binary-improvements2/MapRendering/Web/API/GetLog.cs
r383 r387 1 1 using System.Collections.Generic; 2 2 using AllocsFixes.JSON; 3 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;4 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;5 3 6 4 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 public class GetLog : WebAPI {5 public class GetLog : AbsWebAPI { 8 6 private const int MAX_COUNT = 1000; 9 7 10 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 11 int _permissionLevel) { 12 if (_req.QueryString ["count"] == null || !int.TryParse (_req.QueryString ["count"], out int count)) { 8 public override void HandleRequest (RequestContext _context) { 9 if (_context.Request.QueryString ["count"] == null || !int.TryParse (_context.Request.QueryString ["count"], out int count)) { 13 10 count = 50; 14 11 } … … 26 23 } 27 24 28 if (_ req.QueryString ["firstLine"] == null || !int.TryParse (_req.QueryString ["firstLine"], out int firstLine)) {25 if (_context.Request.QueryString ["firstLine"] == null || !int.TryParse (_context.Request.QueryString ["firstLine"], out int firstLine)) { 29 26 firstLine = count > 0 ? LogBuffer.Instance.OldestLine : LogBuffer.Instance.LatestLine; 30 27 } … … 37 34 foreach (LogBuffer.LogEntry logEntry in logEntries) { 38 35 JSONObject entry = new JSONObject (); 39 entry.Add ("date", new JSONString (logEntry.date));40 entry.Add ("time", new JSONString (logEntry.time));41 36 entry.Add ("isotime", new JSONString (logEntry.isoTime)); 42 37 entry.Add ("uptime", new JSONString (logEntry.uptime.ToString ())); … … 51 46 result.Add ("entries", entries); 52 47 53 W riteJSON (_resp, result);48 WebUtils.WriteJson (_context.Response, result); 54 49 } 55 50 } -
binary-improvements2/MapRendering/Web/API/GetPlayerInventories.cs
r383 r387 2 2 using AllocsFixes.JSON; 3 3 using AllocsFixes.PersistentData; 4 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;5 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;6 4 7 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 8 public class GetPlayerInventories : WebAPI { 9 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 10 int _permissionLevel) { 11 GetPlayerInventory.GetInventoryArguments (_req, out bool showIconColor, out bool showIconName); 6 public class GetPlayerInventories : AbsWebAPI { 7 public override void HandleRequest (RequestContext _context) { 8 GetPlayerInventory.GetInventoryArguments (_context.Request, out bool showIconColor, out bool showIconName); 12 9 13 10 JSONArray AllInventoriesResult = new JSONArray (); … … 25 22 } 26 23 27 W riteJSON (_resp, AllInventoriesResult);24 WebUtils.WriteJson (_context.Response, AllInventoriesResult); 28 25 } 29 26 } -
binary-improvements2/MapRendering/Web/API/GetPlayerInventory.cs
r382 r387 4 4 using AllocsFixes.PersistentData; 5 5 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest; 6 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;7 6 8 7 namespace AllocsFixes.NetConnections.Servers.Web.API { 9 public class GetPlayerInventory : WebAPI { 10 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, 11 WebConnection _user, int _permissionLevel) { 12 if (_req.QueryString ["userid"] == null) { 13 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 14 Web.SetResponseTextContent (_resp, "No user id given"); 8 public class GetPlayerInventory : AbsWebAPI { 9 public override void HandleRequest (RequestContext _context) { 10 if (_context.Request.QueryString ["userid"] == null) { 11 WebUtils.WriteText (_context.Response, "No user id given", HttpStatusCode.BadRequest); 15 12 return; 16 13 } 17 14 18 string userIdString = _ req.QueryString ["userid"];15 string userIdString = _context.Request.QueryString ["userid"]; 19 16 if (!PlatformUserIdentifierAbs.TryFromCombinedString (userIdString, out PlatformUserIdentifierAbs userId)) { 20 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 21 Web.SetResponseTextContent (_resp, "Invalid user id given"); 17 WebUtils.WriteText (_context.Response, "Invalid user id given", HttpStatusCode.BadRequest); 22 18 return; 23 19 } … … 25 21 Player p = PersistentContainer.Instance.Players [userId, false]; 26 22 if (p == null) { 27 _resp.StatusCode = (int) HttpStatusCode.NotFound; 28 Web.SetResponseTextContent (_resp, "Unknown user id given"); 23 WebUtils.WriteText (_context.Response, "Unknown user id given", HttpStatusCode.NotFound); 29 24 return; 30 25 } 31 26 32 GetInventoryArguments (_ req, out bool showIconColor, out bool showIconName);27 GetInventoryArguments (_context.Request, out bool showIconColor, out bool showIconName); 33 28 34 29 JSONObject result = DoPlayer (userIdString, p, showIconColor, showIconName); 35 30 36 W riteJSON (_resp, result);31 WebUtils.WriteJson (_context.Response, result); 37 32 } 38 33 -
binary-improvements2/MapRendering/Web/API/GetPlayerList.cs
r383 r387 5 5 using AllocsFixes.JSON; 6 6 using AllocsFixes.PersistentData; 7 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;8 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;9 7 10 8 namespace AllocsFixes.NetConnections.Servers.Web.API { 11 public class GetPlayerList : WebAPI {9 public class GetPlayerList : AbsWebAPI { 12 10 private static readonly Regex numberFilterMatcher = 13 11 new Regex (@"^(>=|=>|>|<=|=<|<|==|=)?\s*([0-9]+(\.[0-9]*)?)$"); … … 17 15 #endif 18 16 19 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 20 int _permissionLevel) { 17 public override void HandleRequest (RequestContext _context) { 21 18 AdminTools admTools = GameManager.Instance.adminTools; 22 PlatformUserIdentifierAbs userId = _ user?.UserId;23 24 bool bViewAll = WebConnection.CanViewAllPlayers (_ permissionLevel);19 PlatformUserIdentifierAbs userId = _context.Connection?.UserId; 20 21 bool bViewAll = WebConnection.CanViewAllPlayers (_context.PermissionLevel); 25 22 26 23 // TODO: Sort (and filter?) prior to converting to JSON ... hard as how to get the correct column's data? (i.e. column name matches JSON object field names, not source data) 27 24 28 25 int rowsPerPage = 25; 29 if (_ req.QueryString ["rowsperpage"] != null) {30 int.TryParse (_ req.QueryString ["rowsperpage"], out rowsPerPage);26 if (_context.Request.QueryString ["rowsperpage"] != null) { 27 int.TryParse (_context.Request.QueryString ["rowsperpage"], out rowsPerPage); 31 28 } 32 29 33 30 int page = 0; 34 if (_ req.QueryString ["page"] != null) {35 int.TryParse (_ req.QueryString ["page"], out page);31 if (_context.Request.QueryString ["page"] != null) { 32 int.TryParse (_context.Request.QueryString ["page"], out page); 36 33 } 37 34 … … 83 80 IEnumerable<JSONObject> list = playerList; 84 81 85 foreach (string key in _ req.QueryString.AllKeys) {82 foreach (string key in _context.Request.QueryString.AllKeys) { 86 83 if (!string.IsNullOrEmpty (key) && key.StartsWith ("filter[")) { 87 84 string filterCol = key.Substring (key.IndexOf ('[') + 1); 88 85 filterCol = filterCol.Substring (0, filterCol.Length - 1); 89 string filterVal = _ req.QueryString.Get (key).Trim ();86 string filterVal = _context.Request.QueryString.Get (key).Trim (); 90 87 91 88 list = ExecuteFilter (list, filterCol, filterVal); … … 95 92 int totalAfterFilter = list.Count (); 96 93 97 foreach (string key in _ req.QueryString.AllKeys) {94 foreach (string key in _context.Request.QueryString.AllKeys) { 98 95 if (!string.IsNullOrEmpty (key) && key.StartsWith ("sort[")) { 99 96 string sortCol = key.Substring (key.IndexOf ('[') + 1); 100 97 sortCol = sortCol.Substring (0, sortCol.Length - 1); 101 string sortVal = _ req.QueryString.Get (key);98 string sortVal = _context.Request.QueryString.Get (key); 102 99 103 100 list = ExecuteSort (list, sortCol, sortVal == "0"); … … 120 117 result.Add ("players", playersJsResult); 121 118 122 W riteJSON (_resp, result);119 WebUtils.WriteJson (_context.Response, result); 123 120 } 124 121 -
binary-improvements2/MapRendering/Web/API/GetPlayersLocation.cs
r383 r387 2 2 using AllocsFixes.JSON; 3 3 using AllocsFixes.PersistentData; 4 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;5 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;6 4 7 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 8 public class GetPlayersLocation : WebAPI { 9 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 10 int _permissionLevel) { 6 public class GetPlayersLocation : AbsWebAPI { 7 public override void HandleRequest (RequestContext _context) { 11 8 AdminTools admTools = GameManager.Instance.adminTools; 12 PlatformUserIdentifierAbs userId = _ user?.UserId;9 PlatformUserIdentifierAbs userId = _context.Connection?.UserId; 13 10 14 11 bool listOffline = false; 15 if (_ req.QueryString ["offline"] != null) {16 bool.TryParse (_ req.QueryString ["offline"], out listOffline);12 if (_context.Request.QueryString ["offline"] != null) { 13 bool.TryParse (_context.Request.QueryString ["offline"], out listOffline); 17 14 } 18 15 19 bool bViewAll = WebConnection.CanViewAllPlayers (_ permissionLevel);16 bool bViewAll = WebConnection.CanViewAllPlayers (_context.PermissionLevel); 20 17 21 18 JSONArray playersJsResult = new JSONArray (); … … 57 54 } 58 55 59 W riteJSON (_resp, playersJsResult);56 WebUtils.WriteJson (_context.Response, playersJsResult); 60 57 } 61 58 } -
binary-improvements2/MapRendering/Web/API/GetPlayersOnline.cs
r383 r387 2 2 using AllocsFixes.JSON; 3 3 using AllocsFixes.PersistentData; 4 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;5 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;6 4 7 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 8 public class GetPlayersOnline : WebAPI { 9 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 10 int _permissionLevel) { 6 public class GetPlayersOnline : AbsWebAPI { 7 public override void HandleRequest (RequestContext _context) { 11 8 JSONArray players = new JSONArray (); 12 9 … … 44 41 } 45 42 46 W riteJSON (_resp, players);43 WebUtils.WriteJson (_context.Response, players); 47 44 } 48 45 } -
binary-improvements2/MapRendering/Web/API/GetServerInfo.cs
r383 r387 1 1 using System; 2 2 using AllocsFixes.JSON; 3 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;4 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;5 3 6 4 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 public class GetServerInfo : WebAPI { 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 int _permissionLevel) { 5 public class GetServerInfo : AbsWebAPI { 6 public override void HandleRequest (RequestContext _context) { 10 7 JSONObject serverInfo = new JSONObject (); 11 8 … … 43 40 44 41 45 W riteJSON (_resp, serverInfo);42 WebUtils.WriteJson (_context.Response, serverInfo); 46 43 } 47 44 } -
binary-improvements2/MapRendering/Web/API/GetStats.cs
r383 r387 1 1 using AllocsFixes.JSON; 2 2 using AllocsFixes.LiveData; 3 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;4 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;5 3 6 4 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 public class GetStats : WebAPI { 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 int _permissionLevel) { 5 public class GetStats : AbsWebAPI { 6 public override void HandleRequest (RequestContext _context) { 10 7 JSONObject result = new JSONObject (); 11 8 … … 20 17 result.Add ("animals", new JSONNumber (Animals.Instance.GetCount ())); 21 18 22 W riteJSON (_resp, result);19 WebUtils.WriteJson (_context.Response, result); 23 20 } 24 21 -
binary-improvements2/MapRendering/Web/API/GetWebMods.cs
r384 r387 1 1 using AllocsFixes.JSON; 2 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;3 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;4 2 5 3 namespace AllocsFixes.NetConnections.Servers.Web.API { 6 public class GetWebMods : WebAPI {4 public class GetWebMods : AbsWebAPI { 7 5 private readonly JSONArray loadedWebMods = new JSONArray (); 8 6 … … 27 25 } 28 26 29 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 30 int _permissionLevel) { 31 32 WriteJSON (_resp, loadedWebMods); 27 public override void HandleRequest (RequestContext _context) { 28 WebUtils.WriteJson (_context.Response, loadedWebMods); 33 29 } 34 30 -
binary-improvements2/MapRendering/Web/API/GetWebUIUpdates.cs
r383 r387 1 1 using AllocsFixes.JSON; 2 2 using AllocsFixes.LiveData; 3 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;4 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;5 3 6 4 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 public class GetWebUIUpdates : WebAPI { 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 int _permissionLevel) { 5 public class GetWebUIUpdates : AbsWebAPI { 6 public override void HandleRequest (RequestContext _context) { 10 7 int latestLine; 11 if (_ req.QueryString ["latestLine"] == null ||12 !int.TryParse (_ req.QueryString ["latestLine"], out latestLine)) {8 if (_context.Request.QueryString ["latestLine"] == null || 9 !int.TryParse (_context.Request.QueryString ["latestLine"], out latestLine)) { 13 10 latestLine = 0; 14 11 } … … 28 25 result.Add ("newlogs", new JSONNumber (LogBuffer.Instance.LatestLine - latestLine)); 29 26 30 W riteJSON (_resp, result);27 WebUtils.WriteJson (_context.Response, result); 31 28 } 32 29 -
binary-improvements2/MapRendering/Web/API/Null.cs
r383 r387 1 1 using System.Text; 2 using HttpListenerRequest = SpaceWizards.HttpListener.HttpListenerRequest;3 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse;4 2 5 3 namespace AllocsFixes.NetConnections.Servers.Web.API { 6 public class Null : WebAPI {4 public class Null : AbsWebAPI { 7 5 public Null (string _name) : base(_name) { 8 6 } 9 7 10 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 11 int _permissionLevel) { 12 _resp.ContentLength64 = 0; 13 _resp.ContentType = "text/plain"; 14 _resp.ContentEncoding = Encoding.ASCII; 15 _resp.OutputStream.Write (new byte[] { }, 0, 0); 8 public override void HandleRequest (RequestContext _context) { 9 _context.Response.ContentLength64 = 0; 10 _context.Response.ContentType = "text/plain"; 11 _context.Response.ContentEncoding = Encoding.ASCII; 12 _context.Response.OutputStream.Write (new byte[] { }, 0, 0); 16 13 } 17 14 }
Note:
See TracChangeset
for help on using the changeset viewer.