Changeset 306 for binary-improvements/MapRendering
- Timestamp:
- Aug 2, 2017, 6:46:15 PM (7 years ago)
- Location:
- binary-improvements/MapRendering
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/ModInfo.xml
r299 r306 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=" 19" />7 <Version value="20" /> 8 8 <Website value="http://7dtd.illy.bz" /> 9 9 </ModInfo> -
binary-improvements/MapRendering/Web/API/ExecuteConsoleCommand.cs
r279 r306 15 15 return; 16 16 } 17 18 WebCommandResult.ResultType responseType = 19 req.QueryString ["raw"] != null ? WebCommandResult.ResultType.Raw : 20 (req.QueryString ["simple"] != null ? WebCommandResult.ResultType.ResultOnly : 21 WebCommandResult.ResultType.Full); 17 22 18 23 string commandline = req.QueryString ["command"]; … … 36 41 } 37 42 38 // TODO: Execute command (store resp as IConsoleConnection instance to deliver response to the single client?)39 40 43 resp.SendChunked = true; 41 WebCommandResult wcr = new WebCommandResult (commandPart, argumentsPart, resp );44 WebCommandResult wcr = new WebCommandResult (commandPart, argumentsPart, responseType, resp); 42 45 SdtdConsole.Instance.ExecuteAsync (commandline, wcr); 43 46 } -
binary-improvements/MapRendering/Web/API/GetAnimalsLocation.cs
r251 r306 9 9 class GetAnimalsLocation : WebAPI 10 10 { 11 private List<EntityAnimal> animals = new List<EntityAnimal> (); 12 11 13 public override void HandleRequest(HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 14 { 13 15 JSONArray animalsJsResult = new JSONArray(); 14 16 15 foreach (EntityAnimal entity in Animals.List) 16 { 17 Animals.Get (animals); 18 for (int i = 0; i < animals.Count; i++) 19 { 20 EntityAnimal entity = animals [i]; 17 21 Vector3i position = new Vector3i(entity.GetPosition()); 18 22 -
binary-improvements/MapRendering/Web/API/GetHostileLocation.cs
r251 r306 9 9 class GetHostileLocation : WebAPI 10 10 { 11 private List<EntityEnemy> enemies = new List<EntityEnemy> (); 12 11 13 public override void HandleRequest(HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 14 { 13 15 JSONArray hostilesJsResult = new JSONArray(); 14 16 15 foreach (EntityEnemy entity in Hostiles.List) 17 Hostiles.Get (enemies); 18 for (int i = 0; i < enemies.Count; i++) 16 19 { 20 EntityEnemy entity = enemies [i]; 17 21 Vector3i position = new Vector3i(entity.GetPosition()); 18 22 -
binary-improvements/MapRendering/Web/API/GetStats.cs
r279 r306 21 21 22 22 result.Add ("players", new JSONNumber (GameManager.Instance.World.Players.Count)); 23 result.Add ("hostiles", new JSONNumber (Hostiles.Count));24 result.Add ("animals", new JSONNumber (Animals.Count));23 result.Add ("hostiles", new JSONNumber (Hostiles.GetCount ())); 24 result.Add ("animals", new JSONNumber (Animals.GetCount ())); 25 25 26 26 WriteJSON (resp, result); -
binary-improvements/MapRendering/Web/API/GetWebUIUpdates.cs
r279 r306 24 24 25 25 result.Add ("players", new JSONNumber (GameManager.Instance.World.Players.Count)); 26 result.Add ("hostiles", new JSONNumber (Hostiles.Count));27 result.Add ("animals", new JSONNumber (Animals.Count));26 result.Add ("hostiles", new JSONNumber (Hostiles.GetCount ())); 27 result.Add ("animals", new JSONNumber (Animals.GetCount ())); 28 28 29 29 result.Add ("newlogs", new JSONNumber (LogBuffer.Instance.LatestLine - latestLine)); -
binary-improvements/MapRendering/Web/API/WebAPI.cs
r279 r306 7 7 public abstract class WebAPI 8 8 { 9 public void WriteJSON (HttpListenerResponse resp, JSON.JSONNode root)9 public static void WriteJSON (HttpListenerResponse resp, JSON.JSONNode root) 10 10 { 11 11 byte[] buf = Encoding.UTF8.GetBytes (root.ToString()); … … 14 14 resp.ContentEncoding = Encoding.UTF8; 15 15 resp.OutputStream.Write (buf, 0, buf.Length); 16 } 17 18 public static void WriteText (HttpListenerResponse _resp, string _text) 19 { 20 byte[] buf = Encoding.UTF8.GetBytes (_text); 21 _resp.ContentLength64 = buf.Length; 22 _resp.ContentType = "text/plain"; 23 _resp.ContentEncoding = Encoding.UTF8; 24 _resp.OutputStream.Write (buf, 0, buf.Length); 16 25 } 17 26 -
binary-improvements/MapRendering/Web/Handlers/ItemIconHandler.cs
r292 r306 152 152 153 153 private void AddIcon (string _name, Texture2D _tex, Dictionary<string, List<Color>> _tintedIcons) { 154 icons .Add (_name + "__FFFFFF", _tex.EncodeToPNG ());154 icons [_name + "__FFFFFF"] = _tex.EncodeToPNG (); 155 155 156 156 if (_tintedIcons.ContainsKey (_name)) { … … 166 166 } 167 167 168 icons .Add (tintedName, tintedTex.EncodeToPNG ());168 icons [tintedName] = tintedTex.EncodeToPNG (); 169 169 170 170 UnityEngine.Object.Destroy (tintedTex); -
binary-improvements/MapRendering/Web/WebCommandResult.cs
r279 r306 8 8 using System.Net.Sockets; 9 9 using System.Threading; 10 using AllocsFixes.NetConnections.Servers.Web.API; 10 11 11 12 namespace AllocsFixes.NetConnections.Servers.Web … … 13 14 public class WebCommandResult : IConsoleConnection 14 15 { 16 public enum ResultType { 17 Full, 18 ResultOnly, 19 Raw 20 } 21 15 22 public static int handlingCount = 0; 16 23 public static int currentHandlers = 0; … … 20 27 private string command; 21 28 private string parameters; 29 private ResultType responseType; 22 30 23 public WebCommandResult (string _command, string _parameters, HttpListenerResponse _response) {31 public WebCommandResult (string _command, string _parameters, ResultType _responseType, HttpListenerResponse _response) { 24 32 Interlocked.Increment (ref handlingCount); 25 33 Interlocked.Increment (ref currentHandlers); … … 28 36 command = _command; 29 37 parameters = _parameters; 38 responseType = _responseType; 30 39 } 31 40 … … 38 47 } 39 48 40 JSONObject result = new JSONObject ();41 42 result.Add ("command", new JSONString (command));43 result.Add ("parameters", new JSONString (parameters));44 result.Add ("result", new JSONString (sb.ToString ()));45 46 49 response.SendChunked = false; 47 50 48 51 try { 49 WriteJSON (response, result); 52 if (responseType == ResultType.Raw) { 53 WebAPI.WriteText (response, sb.ToString ()); 54 } else { 55 JSONNode result; 56 if (responseType == ResultType.ResultOnly) { 57 result = new JSONString (sb.ToString ()); 58 } else { 59 JSONObject resultObj = new JSONObject (); 60 61 resultObj.Add ("command", new JSONString (command)); 62 resultObj.Add ("parameters", new JSONString (parameters)); 63 resultObj.Add ("result", new JSONString (sb.ToString ())); 64 65 result = resultObj; 66 } 67 WebAPI.WriteJSON (response, result); 68 } 50 69 } catch (IOException e) { 51 70 if (e.InnerException is SocketException) { … … 62 81 63 82 msw.Stop (); 64 totalHandlingTime += msw.ElapsedMicroseconds; 65 Log.Out ("WebCommandResult.SendLines(): Took {0} µs", msw.ElapsedMicroseconds); 83 if (GamePrefs.GetInt (EnumGamePrefs.HideCommandExecutionLog) < 1) { 84 totalHandlingTime += msw.ElapsedMicroseconds; 85 Log.Out ("WebCommandResult.SendLines(): Took {0} µs", msw.ElapsedMicroseconds); 86 } 66 87 Interlocked.Decrement (ref currentHandlers); 67 88 } 68 }69 70 public void WriteJSON (HttpListenerResponse resp, JSON.JSONNode root)71 {72 byte[] buf = Encoding.UTF8.GetBytes (root.ToString());73 resp.ContentLength64 = buf.Length;74 resp.ContentType = "application/json";75 resp.ContentEncoding = Encoding.UTF8;76 resp.OutputStream.Write (buf, 0, buf.Length);77 89 } 78 90
Note:
See TracChangeset
for help on using the changeset viewer.