Changeset 454 for binary-improvements/MapRendering
- Timestamp:
- Jul 28, 2023, 8:42:10 PM (16 months ago)
- Location:
- binary-improvements/MapRendering
- Files:
-
- 3 added
- 14 deleted
- 3 edited
- 15 moved
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/API.cs
r420 r454 1 using AllocsFixes.NetConnections.Servers.Web; 2 using AllocsFixes.NetConnections.Servers.Web.Handlers; 1 using System; 2 using System.IO; 3 using Webserver; 4 using Webserver.FileCache; 5 using Webserver.UrlHandlers; 3 6 4 7 namespace AllocsFixes { 5 8 public class API : IModApi { 6 private Web webInstance;9 private Mod modInstance; 7 10 8 11 public void InitMod (Mod _modInstance) { 9 ModEvents.GameStartDone.RegisterHandler (GameStartDone); 10 ModEvents.GameShutdown.RegisterHandler (GameShutdown); 12 modInstance = _modInstance; 13 14 Web.ServerInitialized += _web => { 15 try { 16 const string legacyModUrl = "/legacymap"; 17 const string legacyFilesFoldername = "webserver_legacy"; 18 string legacyFilePath = $"{modInstance.Path}/{legacyFilesFoldername}"; 19 20 if (!Directory.Exists (legacyFilePath)) { 21 Log.Out ($"Legacy webmod feature not started (folder \"{legacyFilesFoldername}\" not found in Allocs_WebAndMapRendering mod folder)"); 22 return; 23 } 24 25 // TODO: Read from config 26 bool useStaticCache = false; 27 28 _web.RegisterPathHandler ("/legacymap.htm", new SimpleRedirectHandler ($"{legacyModUrl}/index.html")); 29 _web.RegisterPathHandler ($"{legacyModUrl}/", new StaticHandler (legacyFilePath, useStaticCache ? (AbstractCache) new SimpleCache () : new DirectAccess (), false)); 30 31 int webPort = GamePrefs.GetInt (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.WebDashboardPort))); 32 Log.Out ($"Started legacy webmod feature on port {webPort}, local adress {legacyModUrl}"); 33 } catch (Exception e) { 34 Log.Out ("Error in Web.ctor: " + e); 35 } 36 }; 11 37 } 12 38 13 private void GameStartDone () { 14 // ReSharper disable once ObjectCreationAsStatement 15 if (!ConnectionManager.Instance.IsServer) { 16 return; 17 } 18 19 webInstance = new Web (); 20 LogBuffer.Init (); 39 // public static void SetResponseTextContent (HttpListenerResponse _context.Response, string _text) { 40 // byte[] buf = Encoding.UTF8.GetBytes (_text); 41 // _context.Response.ContentLength64 = buf.Length; 42 // _context.Response.ContentType = "text/html"; 43 // _context.Response.ContentEncoding = Encoding.UTF8; 44 // _context.Response.OutputStream.Write (buf, 0, buf.Length); 45 // } 21 46 22 if (ItemIconHandler.Instance != null) { 23 ItemIconHandler.Instance.LoadIcons (); 24 } 25 } 26 27 private void GameShutdown () { 28 webInstance?.Shutdown (); 29 } 47 30 48 } 31 49 } -
binary-improvements/MapRendering/API/ExecuteConsoleCommand.cs
r453 r454 1 1 using System; 2 2 using System.Net; 3 using Webserver; 4 using Webserver.WebAPI; 5 using WebCommandResult = AllocsFixes.NetConnections.Servers.Web.WebCommandResult; 3 6 4 namespace AllocsFixes.NetConnections.Servers.Web.API { 5 public class ExecuteConsoleCommand : WebAPI { 6 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 7 int _permissionLevel) { 8 if (string.IsNullOrEmpty (_req.QueryString ["command"])) { 9 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 10 Web.SetResponseTextContent (_resp, "No command given"); 7 namespace AllocsFixes.WebAPIs { 8 public class ExecuteConsoleCommand : AbsWebAPI { 9 public override void HandleRequest (RequestContext _context) { 10 if (string.IsNullOrEmpty (_context.Request.QueryString ["command"])) { 11 WebUtils.WriteText (_context.Response, "No command given", HttpStatusCode.BadRequest); 11 12 return; 12 13 } 13 14 14 15 WebCommandResult.ResultType responseType = 15 _ req.QueryString ["raw"] != null16 _context.Request.QueryString ["raw"] != null 16 17 ? WebCommandResult.ResultType.Raw 17 : (_ req.QueryString ["simple"] != null18 : (_context.Request.QueryString ["simple"] != null 18 19 ? WebCommandResult.ResultType.ResultOnly 19 20 : WebCommandResult.ResultType.Full); 20 21 21 string commandline = _ req.QueryString ["command"];22 string commandline = _context.Request.QueryString ["command"]; 22 23 string commandPart = commandline.Split (' ') [0]; 23 24 string argumentsPart = commandline.Substring (Math.Min (commandline.Length, commandPart.Length + 1)); … … 26 27 27 28 if (command == null) { 28 _resp.StatusCode = (int) HttpStatusCode.NotFound; 29 Web.SetResponseTextContent (_resp, "Unknown command"); 29 WebUtils.WriteText (_context.Response, "Unknown command", HttpStatusCode.NotFound); 30 30 return; 31 31 } … … 33 33 int commandPermissionLevel = GameManager.Instance.adminTools.Commands.GetCommandPermissionLevel (command.GetCommands ()); 34 34 35 if (_permissionLevel > commandPermissionLevel) { 36 _resp.StatusCode = (int) HttpStatusCode.Forbidden; 37 Web.SetResponseTextContent (_resp, "You are not allowed to execute this command"); 35 if (_context.PermissionLevel > commandPermissionLevel) { 36 WebUtils.WriteText (_context.Response, "You are not allowed to execute this command", HttpStatusCode.Forbidden); 38 37 return; 39 38 } 40 39 41 _ resp.SendChunked = true;42 WebCommandResult wcr = new WebCommandResult (commandPart, argumentsPart, responseType, _ resp);40 _context.Response.SendChunked = true; 41 WebCommandResult wcr = new WebCommandResult (commandPart, argumentsPart, responseType, _context); 43 42 SdtdConsole.Instance.ExecuteAsync (commandline, wcr); 44 43 } -
binary-improvements/MapRendering/API/GetAllowedCommands.cs
r453 r454 1 using System.Net;2 1 using AllocsFixes.JSON; 2 using Webserver; 3 using Webserver.WebAPI; 3 4 4 namespace AllocsFixes.NetConnections.Servers.Web.API { 5 public class GetAllowedCommands : WebAPI { 6 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 7 int _permissionLevel) { 5 namespace AllocsFixes.WebAPIs { 6 public class GetAllowedCommands : AbsWebAPI { 7 public override void HandleRequest (RequestContext _context) { 8 8 JSONObject result = new JSONObject (); 9 9 JSONArray entries = new JSONArray (); 10 10 foreach (IConsoleCommand cc in SdtdConsole.Instance.GetCommands ()) { 11 11 int commandPermissionLevel = GameManager.Instance.adminTools.Commands.GetCommandPermissionLevel (cc.GetCommands ()); 12 if (_ permissionLevel <= commandPermissionLevel) {12 if (_context.PermissionLevel <= commandPermissionLevel) { 13 13 string cmd = string.Empty; 14 14 foreach (string s in cc.GetCommands ()) { … … 28 28 result.Add ("commands", entries); 29 29 30 WriteJSON (_resp, result);30 LegacyApiHelper.WriteJSON (_context.Response, result); 31 31 } 32 32 -
binary-improvements/MapRendering/API/GetAnimalsLocation.cs
r453 r454 1 1 using System.Collections.Generic; 2 using System.Net;3 2 using AllocsFixes.JSON; 4 3 using AllocsFixes.LiveData; 4 using Webserver; 5 using Webserver.WebAPI; 5 6 6 namespace AllocsFixes. NetConnections.Servers.Web.API{7 internal class GetAnimalsLocation : WebAPI {7 namespace AllocsFixes.WebAPIs { 8 internal class GetAnimalsLocation : AbsWebAPI { 8 9 private readonly List<EntityAnimal> animals = new List<EntityAnimal> (); 9 10 10 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 11 int _permissionLevel) { 11 public override void HandleRequest (RequestContext _context) { 12 12 JSONArray animalsJsResult = new JSONArray (); 13 13 … … 36 36 } 37 37 38 WriteJSON (_resp, animalsJsResult);38 LegacyApiHelper.WriteJSON (_context.Response, animalsJsResult); 39 39 } 40 40 } -
binary-improvements/MapRendering/API/GetHostileLocation.cs
r453 r454 1 1 using System.Collections.Generic; 2 using System.Net;3 2 using AllocsFixes.JSON; 4 3 using AllocsFixes.LiveData; 4 using Webserver; 5 using Webserver.WebAPI; 5 6 6 namespace AllocsFixes. NetConnections.Servers.Web.API{7 internal class GetHostileLocation : WebAPI {7 namespace AllocsFixes.WebAPIs { 8 internal class GetHostileLocation : AbsWebAPI { 8 9 private readonly List<EntityEnemy> enemies = new List<EntityEnemy> (); 9 10 10 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 11 int _permissionLevel) { 11 public override void HandleRequest (RequestContext _context) { 12 12 JSONArray hostilesJsResult = new JSONArray (); 13 13 … … 36 36 } 37 37 38 WriteJSON (_resp, hostilesJsResult);38 LegacyApiHelper.WriteJSON (_context.Response, hostilesJsResult); 39 39 } 40 40 } -
binary-improvements/MapRendering/API/GetLandClaims.cs
r453 r454 3 3 using AllocsFixes.JSON; 4 4 using AllocsFixes.PersistentData; 5 using Webserver; 6 using Webserver.Permissions; 7 using Webserver.WebAPI; 5 8 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 public class GetLandClaims : WebAPI { 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 int _permissionLevel) { 9 namespace AllocsFixes.WebAPIs { 10 public class GetLandClaims : AbsWebAPI { 11 public override void HandleRequest (RequestContext _context) { 10 12 PlatformUserIdentifierAbs requestedUserId = null; 11 if (_req.QueryString ["userid"] != null) { 12 if (!PlatformUserIdentifierAbs.TryFromCombinedString (_req.QueryString ["userid"], out requestedUserId)) { 13 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 14 Web.SetResponseTextContent (_resp, "Invalid user id given"); 13 if (_context.Request.QueryString ["userid"] != null) { 14 if (!PlatformUserIdentifierAbs.TryFromCombinedString (_context.Request.QueryString ["userid"], out requestedUserId)) { 15 WebUtils.WriteText (_context.Response, "Invalid user id given", HttpStatusCode.BadRequest); 15 16 return; 16 17 } … … 18 19 19 20 // default user, cheap way to avoid 'null reference exception' 20 PlatformUserIdentifierAbs userId = _ user?.UserId;21 PlatformUserIdentifierAbs userId = _context.Connection?.UserId; 21 22 22 bool bViewAll = WebConnection.CanViewAllClaims (_permissionLevel);23 bool bViewAll = PermissionUtils.CanViewAllClaims (_context.PermissionLevel); 23 24 24 25 JSONObject result = new JSONObject (); … … 73 74 } 74 75 75 WriteJSON (_resp, result);76 LegacyApiHelper.WriteJSON (_context.Response, result); 76 77 } 77 78 } -
binary-improvements/MapRendering/API/GetLog.cs
r453 r454 1 1 using System.Collections.Generic; 2 using System.Net;3 2 using AllocsFixes.JSON; 3 using Webserver; 4 using Webserver.WebAPI; 4 5 5 namespace AllocsFixes. NetConnections.Servers.Web.API{6 public class GetLog : WebAPI {6 namespace AllocsFixes.WebAPIs { 7 public class GetLog : AbsWebAPI { 7 8 private const int MAX_COUNT = 1000; 8 9 9 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 10 int _permissionLevel) { 11 int count, firstLine, lastLine; 12 13 if (_req.QueryString ["count"] == null || !int.TryParse (_req.QueryString ["count"], out count)) { 10 public override void HandleRequest (RequestContext _context) { 11 if (_context.Request.QueryString ["count"] == null || !int.TryParse (_context.Request.QueryString ["count"], out var count)) { 14 12 count = 50; 15 13 } … … 27 25 } 28 26 29 if (_ req.QueryString ["firstLine"] == null || !int.TryParse (_req.QueryString ["firstLine"], outfirstLine)) {27 if (_context.Request.QueryString ["firstLine"] == null || !int.TryParse (_context.Request.QueryString ["firstLine"], out var firstLine)) { 30 28 if (count > 0) { 31 29 firstLine = LogBuffer.Instance.OldestLine; … … 37 35 JSONObject result = new JSONObject (); 38 36 39 List<LogBuffer.LogEntry> logEntries = LogBuffer.Instance.GetRange (ref firstLine, count, out lastLine);37 List<LogBuffer.LogEntry> logEntries = LogBuffer.Instance.GetRange (ref firstLine, count, out var lastLine); 40 38 41 39 JSONArray entries = new JSONArray (); 42 40 foreach (LogBuffer.LogEntry logEntry in logEntries) { 43 41 JSONObject entry = new JSONObject (); 44 entry.Add ("date", new JSONString (logEntry.date)); 45 entry.Add ("time", new JSONString (logEntry.time)); 46 entry.Add ("uptime", new JSONString (logEntry.uptime)); 47 entry.Add ("msg", new JSONString (logEntry.message)); 48 entry.Add ("trace", new JSONString (logEntry.trace)); 49 entry.Add ("type", new JSONString (logEntry.type.ToStringCached ())); 42 var logEntryTimestamp = logEntry.Timestamp; 43 entry.Add ("date", new JSONString ($"{logEntryTimestamp.Year:0000}-{logEntryTimestamp.Month:00}-{logEntryTimestamp.Day:00}")); 44 entry.Add ("time", new JSONString ($"{logEntryTimestamp.Hour:00}:{logEntryTimestamp.Minute:00}:{logEntryTimestamp.Second:00}")); 45 entry.Add ("uptime", new JSONString (logEntry.Uptime.ToString())); 46 entry.Add ("msg", new JSONString (logEntry.Message)); 47 entry.Add ("trace", new JSONString (logEntry.Trace)); 48 entry.Add ("type", new JSONString (logEntry.Type.ToStringCached ())); 50 49 entries.Add (entry); 51 50 } … … 55 54 result.Add ("entries", entries); 56 55 57 WriteJSON (_resp, result);56 LegacyApiHelper.WriteJSON (_context.Response, result); 58 57 } 59 58 } -
binary-improvements/MapRendering/API/GetPlayerInventories.cs
r453 r454 1 1 using System.Collections.Generic; 2 using System.Net;3 2 using AllocsFixes.JSON; 4 3 using AllocsFixes.PersistentData; 4 using Webserver; 5 using Webserver.WebAPI; 5 6 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 public class GetPlayerInventories : WebAPI { 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 int _permissionLevel) { 10 GetPlayerInventory.GetInventoryArguments (_req, out bool showIconColor, out bool showIconName); 7 namespace AllocsFixes.WebAPIs { 8 public class GetPlayerInventories : AbsWebAPI { 9 public override void HandleRequest (RequestContext _context) { 10 GetPlayerInventory.GetInventoryArguments (_context, out bool showIconColor, out bool showIconName); 11 11 12 12 JSONArray AllInventoriesResult = new JSONArray (); … … 24 24 } 25 25 26 WriteJSON (_resp, AllInventoriesResult);26 LegacyApiHelper.WriteJSON (_context.Response, AllInventoriesResult); 27 27 } 28 28 } -
binary-improvements/MapRendering/API/GetPlayerInventory.cs
r453 r454 3 3 using AllocsFixes.JSON; 4 4 using AllocsFixes.PersistentData; 5 using Webserver; 6 using Webserver.WebAPI; 5 7 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 public class GetPlayerInventory : WebAPI { 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 int _permissionLevel) { 10 if (_req.QueryString ["userid"] == null) { 11 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 12 Web.SetResponseTextContent (_resp, "No user id given"); 8 namespace AllocsFixes.WebAPIs { 9 public class GetPlayerInventory : AbsWebAPI { 10 public override void HandleRequest (RequestContext _context) { 11 if (_context.Request.QueryString ["userid"] == null) { 12 WebUtils.WriteText (_context.Response, "No user id given", HttpStatusCode.BadRequest); 13 13 return; 14 14 } 15 15 16 string userIdString = _ req.QueryString ["userid"];16 string userIdString = _context.Request.QueryString ["userid"]; 17 17 if (!PlatformUserIdentifierAbs.TryFromCombinedString (userIdString, out PlatformUserIdentifierAbs userId)) { 18 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 19 Web.SetResponseTextContent (_resp, "Invalid user id given"); 18 WebUtils.WriteText (_context.Response, "Invalid user id given", HttpStatusCode.BadRequest); 20 19 return; 21 20 } … … 23 22 Player p = PersistentContainer.Instance.Players.GetByUserId (userId); 24 23 if (p == null) { 25 _resp.StatusCode = (int) HttpStatusCode.NotFound; 26 Web.SetResponseTextContent (_resp, "Unknown user id given"); 24 WebUtils.WriteText (_context.Response, "Unknown user id given", HttpStatusCode.NotFound); 27 25 return; 28 26 } 29 27 30 GetInventoryArguments (_ req, out bool showIconColor, out bool showIconName);28 GetInventoryArguments (_context, out bool showIconColor, out bool showIconName); 31 29 32 30 JSONObject result = DoPlayer (p, showIconColor, showIconName); 33 31 34 WriteJSON (_resp, result);32 LegacyApiHelper.WriteJSON (_context.Response, result); 35 33 } 36 34 37 internal static void GetInventoryArguments ( HttpListenerRequest _req, out bool _showIconColor, out bool _showIconName) {38 if (_ req.QueryString ["showiconcolor"] == null || !bool.TryParse (_req.QueryString ["showiconcolor"], out _showIconColor)) {35 internal static void GetInventoryArguments (RequestContext _context, out bool _showIconColor, out bool _showIconName) { 36 if (_context.Request.QueryString ["showiconcolor"] == null || !bool.TryParse (_context.Request.QueryString ["showiconcolor"], out _showIconColor)) { 39 37 _showIconColor = true; 40 38 } 41 39 42 if (_ req.QueryString ["showiconname"] == null || !bool.TryParse (_req.QueryString ["showiconname"], out _showIconName)) {40 if (_context.Request.QueryString ["showiconname"] == null || !bool.TryParse (_context.Request.QueryString ["showiconname"], out _showIconName)) { 43 41 _showIconName = true; 44 42 } -
binary-improvements/MapRendering/API/GetPlayerList.cs
r453 r454 2 2 using System.Collections.Generic; 3 3 using System.Linq; 4 using System.Net;5 4 using System.Text.RegularExpressions; 6 5 using AllocsFixes.JSON; 7 6 using AllocsFixes.PersistentData; 8 9 namespace AllocsFixes.NetConnections.Servers.Web.API { 10 public class GetPlayerList : WebAPI { 7 using Webserver; 8 using Webserver.Permissions; 9 using Webserver.WebAPI; 10 11 namespace AllocsFixes.WebAPIs { 12 public class GetPlayerList : AbsWebAPI { 11 13 private static readonly Regex numberFilterMatcher = 12 14 new Regex (@"^(>=|=>|>|<=|=<|<|==|=)?\s*([0-9]+(\.[0-9]*)?)$"); … … 16 18 #endif 17 19 18 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 19 int _permissionLevel) { 20 public override void HandleRequest (RequestContext _context) { 20 21 AdminTools admTools = GameManager.Instance.adminTools; 21 PlatformUserIdentifierAbs userId = _ user?.UserId;22 23 bool bViewAll = WebConnection.CanViewAllPlayers (_permissionLevel);22 PlatformUserIdentifierAbs userId = _context.Connection?.UserId; 23 24 bool bViewAll = PermissionUtils.CanViewAllPlayers (_context.PermissionLevel); 24 25 25 26 // 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) 26 27 27 28 int rowsPerPage = 25; 28 if (_ req.QueryString ["rowsperpage"] != null) {29 int.TryParse (_ req.QueryString ["rowsperpage"], out rowsPerPage);29 if (_context.Request.QueryString ["rowsperpage"] != null) { 30 int.TryParse (_context.Request.QueryString ["rowsperpage"], out rowsPerPage); 30 31 } 31 32 32 33 int page = 0; 33 if (_ req.QueryString ["page"] != null) {34 int.TryParse (_ req.QueryString ["page"], out page);34 if (_context.Request.QueryString ["page"] != null) { 35 int.TryParse (_context.Request.QueryString ["page"], out page); 35 36 } 36 37 … … 83 84 IEnumerable<JSONObject> list = playerList; 84 85 85 foreach (string key in _ req.QueryString.AllKeys) {86 foreach (string key in _context.Request.QueryString.AllKeys) { 86 87 if (!string.IsNullOrEmpty (key) && key.StartsWith ("filter[")) { 87 88 string filterCol = key.Substring (key.IndexOf ('[') + 1); 88 89 filterCol = filterCol.Substring (0, filterCol.Length - 1); 89 string filterVal = _ req.QueryString.Get (key).Trim ();90 string filterVal = _context.Request.QueryString.Get (key).Trim (); 90 91 91 92 list = ExecuteFilter (list, filterCol, filterVal); … … 95 96 int totalAfterFilter = list.Count (); 96 97 97 foreach (string key in _ req.QueryString.AllKeys) {98 foreach (string key in _context.Request.QueryString.AllKeys) { 98 99 if (!string.IsNullOrEmpty (key) && key.StartsWith ("sort[")) { 99 100 string sortCol = key.Substring (key.IndexOf ('[') + 1); 100 101 sortCol = sortCol.Substring (0, sortCol.Length - 1); 101 string sortVal = _ req.QueryString.Get (key);102 string sortVal = _context.Request.QueryString.Get (key); 102 103 103 104 list = ExecuteSort (list, sortCol, sortVal == "0"); … … 120 121 result.Add ("players", playersJsResult); 121 122 122 WriteJSON (_resp, result);123 LegacyApiHelper.WriteJSON (_context.Response, result); 123 124 } 124 125 -
binary-improvements/MapRendering/API/GetPlayersLocation.cs
r453 r454 1 1 using System.Collections.Generic; 2 using System.Net;3 2 using AllocsFixes.JSON; 4 3 using AllocsFixes.PersistentData; 4 using Webserver; 5 using Webserver.Permissions; 6 using Webserver.WebAPI; 5 7 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 public class GetPlayersLocation : WebAPI { 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 int _permissionLevel) { 8 namespace AllocsFixes.WebAPIs { 9 public class GetPlayersLocation : AbsWebAPI { 10 public override void HandleRequest (RequestContext _context) { 10 11 AdminTools admTools = GameManager.Instance.adminTools; 11 PlatformUserIdentifierAbs userId = _ user?.UserId;12 PlatformUserIdentifierAbs userId = _context.Connection?.UserId; 12 13 13 14 bool listOffline = false; 14 if (_ req.QueryString ["offline"] != null) {15 bool.TryParse (_ req.QueryString ["offline"], out listOffline);15 if (_context.Request.QueryString ["offline"] != null) { 16 bool.TryParse (_context.Request.QueryString ["offline"], out listOffline); 16 17 } 17 18 18 bool bViewAll = WebConnection.CanViewAllPlayers (_permissionLevel);19 bool bViewAll = PermissionUtils.CanViewAllPlayers (_context.PermissionLevel); 19 20 20 21 JSONArray playersJsResult = new JSONArray (); … … 57 58 } 58 59 59 WriteJSON (_resp, playersJsResult);60 LegacyApiHelper.WriteJSON (_context.Response, playersJsResult); 60 61 } 61 62 } -
binary-improvements/MapRendering/API/GetPlayersOnline.cs
r453 r454 1 1 using System.Collections.Generic; 2 using System.Net;3 2 using AllocsFixes.JSON; 4 3 using AllocsFixes.PersistentData; 4 using Webserver; 5 using Webserver.WebAPI; 5 6 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 public class GetPlayersOnline : WebAPI { 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 int _permissionLevel) { 7 namespace AllocsFixes.WebAPIs { 8 public class GetPlayersOnline : AbsWebAPI { 9 public override void HandleRequest (RequestContext _context) { 10 10 JSONArray players = new JSONArray (); 11 11 … … 44 44 } 45 45 46 WriteJSON (_resp, players);46 LegacyApiHelper.WriteJSON (_context.Response, players); 47 47 } 48 48 } -
binary-improvements/MapRendering/API/GetServerInfo.cs
r453 r454 1 1 using System; 2 using System.Net;3 2 using AllocsFixes.JSON; 3 using Webserver; 4 using Webserver.WebAPI; 4 5 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 6 public class GetServerInfo : WebAPI { 7 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 8 int _permissionLevel) { 6 namespace AllocsFixes.WebAPIs { 7 public class GetServerInfo : AbsWebAPI { 8 public override void HandleRequest (RequestContext _context) { 9 9 JSONObject serverInfo = new JSONObject (); 10 10 … … 42 42 43 43 44 WriteJSON (_resp, serverInfo);44 LegacyApiHelper.WriteJSON (_context.Response, serverInfo); 45 45 } 46 46 } -
binary-improvements/MapRendering/API/GetStats.cs
r453 r454 1 using System.Net;2 1 using AllocsFixes.JSON; 3 2 using AllocsFixes.LiveData; 3 using Webserver; 4 using Webserver.WebAPI; 4 5 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 6 public class GetStats : WebAPI { 7 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 8 int _permissionLevel) { 6 namespace AllocsFixes.WebAPIs { 7 public class GetStats : AbsWebAPI { 8 public override void HandleRequest (RequestContext _context) { 9 9 JSONObject result = new JSONObject (); 10 10 … … 19 19 result.Add ("animals", new JSONNumber (Animals.Instance.GetCount ())); 20 20 21 WriteJSON (_resp, result);21 LegacyApiHelper.WriteJSON (_context.Response, result); 22 22 } 23 23 -
binary-improvements/MapRendering/API/GetWebUIUpdates.cs
r453 r454 1 using System.Net;2 1 using AllocsFixes.JSON; 3 2 using AllocsFixes.LiveData; 3 using Webserver; 4 using Webserver.WebAPI; 4 5 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 6 public class GetWebUIUpdates : WebAPI { 7 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 8 int _permissionLevel) { 6 namespace AllocsFixes.WebAPIs { 7 public class GetWebUIUpdates : AbsWebAPI { 8 public override void HandleRequest (RequestContext _context) { 9 9 int latestLine; 10 if (_ req.QueryString ["latestLine"] == null ||11 !int.TryParse (_ req.QueryString ["latestLine"], out latestLine)) {10 if (_context.Request.QueryString ["latestLine"] == null || 11 !int.TryParse (_context.Request.QueryString ["latestLine"], out latestLine)) { 12 12 latestLine = 0; 13 13 } … … 27 27 result.Add ("newlogs", new JSONNumber (LogBuffer.Instance.LatestLine - latestLine)); 28 28 29 WriteJSON (_resp, result);29 LegacyApiHelper.WriteJSON (_context.Response, result); 30 30 } 31 31 -
binary-improvements/MapRendering/ModInfo.xml
r448 r454 5 5 <Description value="Render the game map to image map tiles as it is uncovered" /> 6 6 <Author value="Christian 'Alloc' Illy" /> 7 <Version value="4 2" />7 <Version value="43" /> 8 8 <Website value="http://7dtd.illy.bz" /> 9 9 </ModInfo> -
binary-improvements/MapRendering/WebAndMapRendering.csproj
r450 r454 11 11 <AssemblyName>AllocsWeb</AssemblyName> 12 12 <TargetFrameworkVersion>v4.8</TargetFrameworkVersion> 13 <Nullable>warnings</Nullable> 14 <LangVersion>9</LangVersion> 13 15 </PropertyGroup> 14 16 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> … … 55 57 <Private>False</Private> 56 58 </Reference> 59 <Reference Include="SpaceWizards.HttpListener"> 60 <HintPath>..\7dtd-binaries\SpaceWizards.HttpListener.dll</HintPath> 61 <Private>False</Private> 62 </Reference> 57 63 <Reference Include="UnityEngine"> 58 64 <HintPath>..\7dtd-binaries\UnityEngine.dll</HintPath> … … 89 95 </ItemGroup> 90 96 <ItemGroup> 97 <Compile Include="API\ExecuteConsoleCommand.cs" /> 98 <Compile Include="API\GetAllowedCommands.cs" /> 99 <Compile Include="API\GetAnimalsLocation.cs" /> 100 <Compile Include="API\GetHostileLocation.cs" /> 101 <Compile Include="API\GetLandClaims.cs" /> 102 <Compile Include="API\GetLog.cs" /> 103 <Compile Include="API\GetPlayerInventories.cs" /> 104 <Compile Include="API\GetPlayerInventory.cs" /> 105 <Compile Include="API\GetPlayerList.cs" /> 106 <Compile Include="API\GetPlayersLocation.cs" /> 107 <Compile Include="API\GetPlayersOnline.cs" /> 108 <Compile Include="API\GetServerInfo.cs" /> 109 <Compile Include="API\GetStats.cs" /> 110 <Compile Include="API\GetWebUIUpdates.cs" /> 91 111 <Compile Include="AssemblyInfo.cs" /> 92 112 <Compile Include="API.cs" /> 93 <Compile Include="Web\API\GetAnimalsLocation.cs" /> 94 <Compile Include="Web\API\GetHostileLocation.cs" /> 95 <Compile Include="Web\API\Null.cs" /> 96 <Compile Include="Web\SSE\EventLog.cs" /> 97 <Compile Include="Web\SSE\SseHandler.cs" /> 98 <Compile Include="Web\SSE\EventBase.cs" /> 99 <Compile Include="Web\Web.cs" /> 100 <Compile Include="Web\MimeType.cs" /> 101 <Compile Include="Web\API\GetPlayersOnline.cs" /> 102 <Compile Include="Web\API\WebAPI.cs" /> 103 <Compile Include="Web\API\GetPlayersLocation.cs" /> 104 <Compile Include="Web\API\GetPlayerInventory.cs" /> 105 <Compile Include="Web\API\GetLandClaims.cs" /> 106 <Compile Include="Commands\webstat.cs" /> 107 <Compile Include="Web\API\GetStats.cs" /> 108 <Compile Include="Web\WebConnection.cs" /> 109 <Compile Include="Web\OpenID.cs" /> 110 <Compile Include="Web\ConnectionHandler.cs" /> 111 <Compile Include="Web\WebPermissions.cs" /> 112 <Compile Include="Web\Handlers\ApiHandler.cs" /> 113 <Compile Include="Web\Handlers\ItemIconHandler.cs" /> 114 <Compile Include="Web\Handlers\PathHandler.cs" /> 115 <Compile Include="Web\Handlers\SimpleRedirectHandler.cs" /> 116 <Compile Include="Web\Handlers\StaticHandler.cs" /> 117 <Compile Include="Web\Handlers\SessionHandler.cs" /> 118 <Compile Include="Web\API\ExecuteConsoleCommand.cs" /> 119 <Compile Include="Commands\ReloadWebPermissions.cs" /> 120 <Compile Include="Web\Handlers\UserStatusHandler.cs" /> 121 <Compile Include="Commands\WebTokens.cs" /> 122 <Compile Include="Commands\WebPermissionsCmd.cs" /> 123 <Compile Include="Web\LogBuffer.cs" /> 124 <Compile Include="Web\API\GetLog.cs" /> 125 <Compile Include="Web\API\GetWebUIUpdates.cs" /> 126 <Compile Include="Web\API\GetServerInfo.cs" /> 127 <Compile Include="Web\API\GetPlayerList.cs" /> 128 <Compile Include="Web\WebCommandResult.cs" /> 129 <Compile Include="Web\API\GetAllowedCommands.cs" /> 130 <Compile Include="Web\API\GetPlayerInventories.cs" /> 113 <Compile Include="LegacyApiHelper.cs" /> 114 <Compile Include="SteamLoginApi.cs" /> 115 <Compile Include="WebCommandResult.cs" /> 131 116 </ItemGroup> 132 117 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> … … 142 127 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 143 128 </None> 144 <None Include="steam-intermediate.cer">145 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>146 </None>147 <None Include="steam-rootca.cer">148 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>149 </None>150 129 </ItemGroup> 151 130 </Project> -
binary-improvements/MapRendering/WebCommandResult.cs
r453 r454 2 2 using System.Collections.Generic; 3 3 using System.IO; 4 using System.Net;5 4 using System.Net.Sockets; 6 5 using System.Text; 7 6 using System.Threading; 8 7 using AllocsFixes.JSON; 9 using AllocsFixes.NetConnections.Servers.Web.API;10 8 using UnityEngine; 9 using Webserver; 11 10 12 11 namespace AllocsFixes.NetConnections.Servers.Web { … … 24 23 private readonly string parameters; 25 24 26 private readonly HttpListenerResponse response;25 private readonly RequestContext context; 27 26 private readonly ResultType responseType; 28 27 29 public WebCommandResult (string _command, string _parameters, ResultType _responseType, 30 HttpListenerResponse _response) { 28 public WebCommandResult (string _command, string _parameters, ResultType _resultType, RequestContext _context) { 31 29 Interlocked.Increment (ref handlingCount); 32 30 Interlocked.Increment (ref currentHandlers); 33 31 34 response = _response;32 context = _context; 35 33 command = _command; 36 34 parameters = _parameters; 37 responseType = _res ponseType;35 responseType = _resultType; 38 36 } 39 37 … … 47 45 48 46 try { 49 response.SendChunked = false;47 context.Response.SendChunked = false; 50 48 51 49 if (responseType == ResultType.Raw) { 52 Web API.WriteText (response, sb.ToString ());50 WebUtils.WriteText (context.Response, sb.ToString ()); 53 51 } else { 54 52 JSONNode result; … … 65 63 } 66 64 67 WebAPI.WriteJSON (response, result);65 LegacyApiHelper.WriteJSON (context.Response, result); 68 66 } 69 67 } catch (IOException e) { 70 68 if (e.InnerException is SocketException) { 71 Log.Out ("Error in WebCommandResult.SendLines(): Remote host closed connection: " + 72 e.InnerException.Message); 69 Log.Out ("Error in WebCommandResult.SendLines(): Remote host closed connection: " + e.InnerException.Message); 73 70 } else { 74 71 Log.Out ("Error (IO) in WebCommandResult.SendLines(): " + e); … … 77 74 Log.Out ("Error in WebCommandResult.SendLines(): " + e); 78 75 } finally { 79 if (response != null) { 80 response.Close (); 81 } 76 context.Response?.Close (); 82 77 83 // msw.Stop ();78 // msw.Stop (); 84 79 // if (GamePrefs.GetInt (EnumGamePrefs.HideCommandExecutionLog) < 1) { 85 80 // totalHandlingTime += msw.ElapsedMicroseconds;
Note:
See TracChangeset
for help on using the changeset viewer.