Changeset 325 for binary-improvements/MapRendering/Web/API
- Timestamp:
- Sep 4, 2018, 1:00:48 PM (6 years ago)
- Location:
- binary-improvements/MapRendering/Web/API
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/API/ExecuteConsoleCommand.cs
r306 r325 1 using AllocsFixes.JSON;2 using AllocsFixes.PersistentData;3 1 using System; 4 using System.Collections.Generic;5 2 using System.Net; 6 3 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 public class ExecuteConsoleCommand : WebAPI 10 { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 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) { 12 8 if (string.IsNullOrEmpty (req.QueryString ["command"])) { 13 resp.StatusCode = (int) HttpStatusCode.BadRequest;9 resp.StatusCode = (int) HttpStatusCode.BadRequest; 14 10 Web.SetResponseTextContent (resp, "No command given"); 15 11 return; … … 17 13 18 14 WebCommandResult.ResultType responseType = 19 req.QueryString ["raw"] != null ? WebCommandResult.ResultType.Raw : 20 (req.QueryString ["simple"] != null ? WebCommandResult.ResultType.ResultOnly : 21 WebCommandResult.ResultType.Full); 15 req.QueryString ["raw"] != null 16 ? WebCommandResult.ResultType.Raw 17 : (req.QueryString ["simple"] != null 18 ? WebCommandResult.ResultType.ResultOnly 19 : WebCommandResult.ResultType.Full); 22 20 23 21 string commandline = req.QueryString ["command"]; … … 28 26 29 27 if (command == null) { 30 resp.StatusCode = (int) HttpStatusCode.NotImplemented;28 resp.StatusCode = (int) HttpStatusCode.NotImplemented; 31 29 Web.SetResponseTextContent (resp, "Unknown command"); 32 30 return; 33 31 } 34 32 35 AdminToolsCommandPermissions atcp = GameManager.Instance.adminTools.GetAdminToolsCommandPermission (command.GetCommands ()); 33 AdminToolsCommandPermissions atcp = 34 GameManager.Instance.adminTools.GetAdminToolsCommandPermission (command.GetCommands ()); 36 35 37 36 if (permissionLevel > atcp.PermissionLevel) { 38 resp.StatusCode = (int) HttpStatusCode.Forbidden;37 resp.StatusCode = (int) HttpStatusCode.Forbidden; 39 38 Web.SetResponseTextContent (resp, "You are not allowed to execute this command"); 40 39 return; … … 51 50 } 52 51 } 53 -
binary-improvements/MapRendering/Web/API/GetAllowedCommands.cs
r279 r325 1 using System.Net; 1 2 using AllocsFixes.JSON; 2 using AllocsFixes.PersistentData;3 using System;4 using System.Collections.Generic;5 using System.Net;6 3 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 4 namespace AllocsFixes.NetConnections.Servers.Web.API { 9 5 public class GetAllowedCommands : WebAPI { 10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 6 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 7 int permissionLevel) { 11 8 JSONObject result = new JSONObject (); 12 9 JSONArray entries = new JSONArray (); 13 10 foreach (IConsoleCommand cc in SdtdConsole.Instance.GetCommands ()) { 14 AdminToolsCommandPermissions atcp = GameManager.Instance.adminTools.GetAdminToolsCommandPermission (cc.GetCommands ()); 11 AdminToolsCommandPermissions atcp = 12 GameManager.Instance.adminTools.GetAdminToolsCommandPermission (cc.GetCommands ()); 15 13 if (permissionLevel <= atcp.PermissionLevel) { 16 14 string cmd = string.Empty; … … 20 18 } 21 19 } 20 22 21 JSONObject cmdObj = new JSONObject (); 23 22 cmdObj.Add ("command", new JSONString (cmd)); … … 38 37 } 39 38 } 40 -
binary-improvements/MapRendering/Web/API/GetAnimalsLocation.cs
r313 r325 1 using AllocsFixes.JSON; 1 using System.Collections.Generic; 2 using System.Net; 3 using AllocsFixes.JSON; 2 4 using AllocsFixes.LiveData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 5 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 class GetAnimalsLocation : WebAPI 10 { 11 private List<EntityAnimal> animals = new List<EntityAnimal> (); 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 internal class GetAnimalsLocation : WebAPI { 8 private readonly List<EntityAnimal> animals = new List<EntityAnimal> (); 12 9 13 public override void HandleRequest(HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 14 15 JSONArray animalsJsResult = new JSONArray();10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 11 int permissionLevel) { 12 JSONArray animalsJsResult = new JSONArray (); 16 13 17 14 Animals.Instance.Get (animals); 18 for (int i = 0; i < animals.Count; i++) 19 { 15 for (int i = 0; i < animals.Count; i++) { 20 16 EntityAnimal entity = animals [i]; 21 Vector3i position = new Vector3i(entity.GetPosition());17 Vector3i position = new Vector3i (entity.GetPosition ()); 22 18 23 JSONObject jsonPOS = new JSONObject();24 jsonPOS.Add("x", new JSONNumber(position.x));25 jsonPOS.Add("y", new JSONNumber(position.y));26 jsonPOS.Add("z", new JSONNumber(position.z));19 JSONObject jsonPOS = new JSONObject (); 20 jsonPOS.Add ("x", new JSONNumber (position.x)); 21 jsonPOS.Add ("y", new JSONNumber (position.y)); 22 jsonPOS.Add ("z", new JSONNumber (position.z)); 27 23 28 JSONObject pJson = new JSONObject();29 pJson.Add("id", new JSONNumber(entity.entityId));24 JSONObject pJson = new JSONObject (); 25 pJson.Add ("id", new JSONNumber (entity.entityId)); 30 26 31 if (!string.IsNullOrEmpty(entity.EntityName)) 32 pJson.Add("name", new JSONString(entity.EntityName)); 33 else 34 pJson.Add("name", new JSONString("animal class #" + entity.entityClass.ToString())); 27 if (!string.IsNullOrEmpty (entity.EntityName)) { 28 pJson.Add ("name", new JSONString (entity.EntityName)); 29 } else { 30 pJson.Add ("name", new JSONString ("animal class #" + entity.entityClass)); 31 } 35 32 36 pJson.Add("position", jsonPOS);33 pJson.Add ("position", jsonPOS); 37 34 38 animalsJsResult.Add(pJson);39 40 41 WriteJSON(resp, animalsJsResult);42 43 35 animalsJsResult.Add (pJson); 36 } 37 38 WriteJSON (resp, animalsJsResult); 39 } 40 } 44 41 } -
binary-improvements/MapRendering/Web/API/GetHostileLocation.cs
r313 r325 1 using AllocsFixes.JSON; 1 using System.Collections.Generic; 2 using System.Net; 3 using AllocsFixes.JSON; 2 4 using AllocsFixes.LiveData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 5 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 class GetHostileLocation : WebAPI 10 { 11 private List<EntityEnemy> enemies = new List<EntityEnemy> (); 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 7 internal class GetHostileLocation : WebAPI { 8 private readonly List<EntityEnemy> enemies = new List<EntityEnemy> (); 12 9 13 public override void HandleRequest(HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 14 15 JSONArray hostilesJsResult = new JSONArray();10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 11 int permissionLevel) { 12 JSONArray hostilesJsResult = new JSONArray (); 16 13 17 14 Hostiles.Instance.Get (enemies); 18 for (int i = 0; i < enemies.Count; i++) 19 { 15 for (int i = 0; i < enemies.Count; i++) { 20 16 EntityEnemy entity = enemies [i]; 21 Vector3i position = new Vector3i(entity.GetPosition());17 Vector3i position = new Vector3i (entity.GetPosition ()); 22 18 23 JSONObject jsonPOS = new JSONObject();24 jsonPOS.Add("x", new JSONNumber(position.x));25 jsonPOS.Add("y", new JSONNumber(position.y));26 jsonPOS.Add("z", new JSONNumber(position.z));19 JSONObject jsonPOS = new JSONObject (); 20 jsonPOS.Add ("x", new JSONNumber (position.x)); 21 jsonPOS.Add ("y", new JSONNumber (position.y)); 22 jsonPOS.Add ("z", new JSONNumber (position.z)); 27 23 28 JSONObject pJson = new JSONObject();29 pJson.Add("id", new JSONNumber(entity.entityId));24 JSONObject pJson = new JSONObject (); 25 pJson.Add ("id", new JSONNumber (entity.entityId)); 30 26 31 if (!string.IsNullOrEmpty(entity.EntityName)) 32 pJson.Add("name", new JSONString(entity.EntityName)); 33 else 34 pJson.Add("name", new JSONString("enemy class #" + entity.entityClass.ToString())); 27 if (!string.IsNullOrEmpty (entity.EntityName)) { 28 pJson.Add ("name", new JSONString (entity.EntityName)); 29 } else { 30 pJson.Add ("name", new JSONString ("enemy class #" + entity.entityClass)); 31 } 35 32 36 pJson.Add("position", jsonPOS);33 pJson.Add ("position", jsonPOS); 37 34 38 hostilesJsResult.Add(pJson);39 35 hostilesJsResult.Add (pJson); 36 } 40 37 41 WriteJSON(resp, hostilesJsResult);42 43 38 WriteJSON (resp, hostilesJsResult); 39 } 40 } 44 41 } -
binary-improvements/MapRendering/Web/API/GetLandClaims.cs
r253 r325 1 using System.Collections.Generic; 2 using System.Net; 1 3 using AllocsFixes.JSON; 2 4 using AllocsFixes.PersistentData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 5 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 9 7 public class GetLandClaims : WebAPI { 10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 8 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 9 int permissionLevel) { 11 10 string requestedSteamID = string.Empty; 12 11 … … 15 14 requestedSteamID = req.QueryString ["steamid"]; 16 15 if (requestedSteamID.Length != 17 || !ulong.TryParse (requestedSteamID, out lViewersSteamID)) { 17 resp.StatusCode = (int) HttpStatusCode.BadRequest;16 resp.StatusCode = (int) HttpStatusCode.BadRequest; 18 17 Web.SetResponseTextContent (resp, "Invalid SteamID given"); 19 18 return; … … 25 24 26 25 bool bViewAll = WebConnection.CanViewAllClaims (permissionLevel); 27 26 28 27 JSONObject result = new JSONObject (); 29 28 result.Add ("claimsize", new JSONNumber (GamePrefs.GetInt (EnumGamePrefs.LandClaimSize))); … … 35 34 if (!string.IsNullOrEmpty (requestedSteamID) || !bViewAll) { 36 35 if (!string.IsNullOrEmpty (requestedSteamID) && !bViewAll) { 37 ownerFilters = new LandClaimList.OwnerFilter[] {36 ownerFilters = new[] { 38 37 LandClaimList.SteamIdFilter (user.SteamID.ToString ()), 39 38 LandClaimList.SteamIdFilter (requestedSteamID) 40 39 }; 41 40 } else if (!bViewAll) { 42 ownerFilters = new LandClaimList.OwnerFilter[] { LandClaimList.SteamIdFilter (user.SteamID.ToString ())};41 ownerFilters = new[] {LandClaimList.SteamIdFilter (user.SteamID.ToString ())}; 43 42 } else { 44 ownerFilters = new LandClaimList.OwnerFilter[] { LandClaimList.SteamIdFilter (requestedSteamID)};43 ownerFilters = new[] {LandClaimList.SteamIdFilter (requestedSteamID)}; 45 44 } 46 45 } 46 47 47 LandClaimList.PositionFilter[] posFilters = null; 48 48 49 Dictionary<P ersistentData.Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters);49 Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters); 50 50 51 foreach (KeyValuePair<PersistentData.Player, List<Vector3i>> kvp in claims) { 52 51 foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) { 53 52 try { 54 53 JSONObject owner = new JSONObject (); … … 83 82 } 84 83 } 85 -
binary-improvements/MapRendering/Web/API/GetLog.cs
r253 r325 1 using AllocsFixes.JSON;2 using AllocsFixes.PersistentData;3 using System;4 1 using System.Collections.Generic; 5 2 using System.Net; 3 using AllocsFixes.JSON; 6 4 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 9 6 public class GetLog : WebAPI { 10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 8 int permissionLevel) { 11 9 int firstLine, lastLine; 12 10 … … 39 37 } 40 38 } 41 -
binary-improvements/MapRendering/Web/API/GetPlayerInventories.cs
r321 r325 1 using System.Net; 1 2 using AllocsFixes.JSON; 2 3 using AllocsFixes.PersistentData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 4 7 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 8 6 public class GetPlayerInventories : WebAPI { 7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 8 int permissionLevel) { 9 JSONArray AllInventoriesResult = new JSONArray (); 9 10 10 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) {11 JSONArray AllInventoriesResult = new JSONArray ();12 13 11 foreach (string sid in PersistentContainer.Instance.Players.SteamIDs) { 14 12 Player p = PersistentContainer.Instance.Players [sid, false]; … … 55 53 WriteJSON (resp, AllInventoriesResult); 56 54 } 57 58 55 } 59 56 } 60 -
binary-improvements/MapRendering/Web/API/GetPlayerInventory.cs
r321 r325 1 using System.Collections.Generic; 2 using System.Net; 1 3 using AllocsFixes.JSON; 2 4 using AllocsFixes.PersistentData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 5 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 6 namespace AllocsFixes.NetConnections.Servers.Web.API { 9 7 public class GetPlayerInventory : WebAPI { 10 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user,int permissionLevel) {8 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 9 int permissionLevel) { 12 10 if (req.QueryString ["steamid"] == null) { 13 resp.StatusCode = (int) HttpStatusCode.InternalServerError;11 resp.StatusCode = (int) HttpStatusCode.InternalServerError; 14 12 Web.SetResponseTextContent (resp, "No SteamID given"); 15 13 return; … … 18 16 Player p = PersistentContainer.Instance.Players [req.QueryString ["steamid"], false]; 19 17 if (p == null) { 20 resp.StatusCode = (int) HttpStatusCode.InternalServerError;18 resp.StatusCode = (int) HttpStatusCode.InternalServerError; 21 19 Web.SetResponseTextContent (resp, "Invalid or unknown SteamID given"); 22 20 return; … … 87 85 jsonItem.Add ("qualitycolor", new JSONString (QualityInfo.GetQualityColorHex (_item.quality))); 88 86 } 87 89 88 return jsonItem; 90 } else {91 return new JSONNull ();92 89 } 90 91 return new JSONNull (); 93 92 } 94 95 93 } 96 94 } 97 -
binary-improvements/MapRendering/Web/API/GetPlayerList.cs
r324 r325 1 using AllocsFixes.JSON;2 using AllocsFixes.PersistentData;3 1 using System; 4 2 using System.Collections.Generic; … … 6 4 using System.Net; 7 5 using System.Text.RegularExpressions; 8 9 namespace AllocsFixes.NetConnections.Servers.Web.API 10 { 11 public class GetPlayerList : WebAPI 12 { 13 private static Regex numberFilterMatcher = new Regex (@"^(>=|=>|>|<=|=<|<|==|=)?\s*([0-9]+(\.[0-9]*)?)$"); 14 private enum NumberMatchType { 15 Equal, 16 Greater, 17 GreaterEqual, 18 Lesser, 19 LesserEqual 20 } 21 22 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 23 { 24 AdminTools admTools = GameManager.Instance.adminTools; 25 user = user ?? new WebConnection ("", "", 0L); 26 27 bool bViewAll = WebConnection.CanViewAllPlayers (permissionLevel); 6 using AllocsFixes.JSON; 7 using AllocsFixes.PersistentData; 8 9 namespace AllocsFixes.NetConnections.Servers.Web.API { 10 public class GetPlayerList : WebAPI { 11 private static readonly Regex numberFilterMatcher = 12 new Regex (@"^(>=|=>|>|<=|=<|<|==|=)?\s*([0-9]+(\.[0-9]*)?)$"); 13 14 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 15 int permissionLevel) { 16 AdminTools admTools = GameManager.Instance.adminTools; 17 user = user ?? new WebConnection ("", "", 0L); 18 19 bool bViewAll = WebConnection.CanViewAllPlayers (permissionLevel); 28 20 29 21 // 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) … … 46 38 47 39 foreach (string sid in playersList.SteamIDs) { 48 Player p = playersList [sid, false]; 49 50 ulong player_steam_ID = 0L; 51 if (!ulong.TryParse (sid, out player_steam_ID)) 52 player_steam_ID = 0L; 53 54 if ((player_steam_ID == user.SteamID) || bViewAll) { 55 JSONObject pos = new JSONObject (); 56 pos.Add("x", new JSONNumber (p.LastPosition.x)); 57 pos.Add("y", new JSONNumber (p.LastPosition.y)); 58 pos.Add("z", new JSONNumber (p.LastPosition.z)); 59 60 JSONObject pJson = new JSONObject (); 61 pJson.Add("steamid", new JSONString (sid)); 62 pJson.Add("entityid", new JSONNumber (p.EntityID)); 63 pJson.Add("ip", new JSONString (p.IP)); 64 pJson.Add("name", new JSONString (p.Name)); 65 pJson.Add("online", new JSONBoolean (p.IsOnline)); 66 pJson.Add("position", pos); 40 Player p = playersList [sid, false]; 41 42 ulong player_steam_ID = 0L; 43 if (!ulong.TryParse (sid, out player_steam_ID)) { 44 player_steam_ID = 0L; 45 } 46 47 if (player_steam_ID == user.SteamID || bViewAll) { 48 JSONObject pos = new JSONObject (); 49 pos.Add ("x", new JSONNumber (p.LastPosition.x)); 50 pos.Add ("y", new JSONNumber (p.LastPosition.y)); 51 pos.Add ("z", new JSONNumber (p.LastPosition.z)); 52 53 JSONObject pJson = new JSONObject (); 54 pJson.Add ("steamid", new JSONString (sid)); 55 pJson.Add ("entityid", new JSONNumber (p.EntityID)); 56 pJson.Add ("ip", new JSONString (p.IP)); 57 pJson.Add ("name", new JSONString (p.Name)); 58 pJson.Add ("online", new JSONBoolean (p.IsOnline)); 59 pJson.Add ("position", pos); 67 60 68 61 pJson.Add ("totalplaytime", new JSONNumber (p.TotalPlayTime)); 69 pJson.Add ("lastonline", new JSONString (p.LastOnline.ToUniversalTime ().ToString ("yyyy-MM-ddTHH:mm:ssZ"))); 62 pJson.Add ("lastonline", 63 new JSONString (p.LastOnline.ToUniversalTime ().ToString ("yyyy-MM-ddTHH:mm:ssZ"))); 70 64 pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1)); 71 65 … … 76 70 banned = new JSONBoolean (false); 77 71 } 72 78 73 pJson.Add ("banned", banned); 79 74 80 75 playerList.Add (pJson); 81 82 76 } 77 } 83 78 84 79 IEnumerable<JSONObject> list = playerList; … … 124 119 } 125 120 126 private IEnumerable<JSONObject> ExecuteFilter (IEnumerable<JSONObject> _list, string _filterCol, string _filterVal) { 121 private IEnumerable<JSONObject> ExecuteFilter (IEnumerable<JSONObject> _list, string _filterCol, 122 string _filterVal) { 127 123 if (_list.Count () == 0) { 128 124 return _list; … … 131 127 if (_list.First ().ContainsKey (_filterCol)) { 132 128 Type colType = _list.First () [_filterCol].GetType (); 133 if (colType == typeof (JSONNumber)) {129 if (colType == typeof (JSONNumber)) { 134 130 return ExecuteNumberFilter (_list, _filterCol, _filterVal); 135 } else if (colType == typeof(JSONBoolean)) { 131 } 132 133 if (colType == typeof (JSONBoolean)) { 136 134 bool value = _filterVal.Trim ().ToLower () == "true"; 137 135 return _list.Where (line => (line [_filterCol] as JSONBoolean).GetBool () == value); 138 } else if (colType == typeof(JSONString)) { 136 } 137 138 if (colType == typeof (JSONString)) { 139 139 // regex-match whole ^string$, replace * by .*, ? by .?, + by .+ 140 140 _filterVal = _filterVal.Replace ("*", ".*").Replace ("?", ".?").Replace ("+", ".+"); 141 141 _filterVal = "^" + _filterVal + "$"; 142 142 143 //Log.Out ("GetPlayerList: Filter on String with Regex '" + _filterVal + "'"); 143 144 Regex matcher = new Regex (_filterVal, RegexOptions.IgnoreCase); … … 145 146 } 146 147 } 148 147 149 return _list; 148 150 } 149 151 150 152 151 private IEnumerable<JSONObject> ExecuteNumberFilter (IEnumerable<JSONObject> _list, string _filterCol, string _filterVal) { 153 private IEnumerable<JSONObject> ExecuteNumberFilter (IEnumerable<JSONObject> _list, string _filterCol, 154 string _filterVal) { 152 155 // allow value (exact match), =, ==, >=, >, <=, < 153 156 Match filterMatch = numberFilterMatcher.Match (_filterVal); … … 157 160 double epsilon = value / 100000; 158 161 switch (filterMatch.Groups [1].Value) { 159 case "": 160 case "=": 161 case "==": 162 matchType = NumberMatchType.Equal; 163 break; 164 case ">": 165 matchType = NumberMatchType.Greater; 166 break; 167 case ">=": 168 case "=>": 169 matchType = NumberMatchType.GreaterEqual; 170 break; 171 case "<": 172 matchType = NumberMatchType.Lesser; 173 break; 174 case "<=": 175 case "=<": 176 matchType = NumberMatchType.LesserEqual; 177 break; 178 default: 179 matchType = NumberMatchType.Equal; 180 break; 181 } 182 return _list.Where (delegate(JSONObject line) { 162 case "": 163 case "=": 164 case "==": 165 matchType = NumberMatchType.Equal; 166 break; 167 case ">": 168 matchType = NumberMatchType.Greater; 169 break; 170 case ">=": 171 case "=>": 172 matchType = NumberMatchType.GreaterEqual; 173 break; 174 case "<": 175 matchType = NumberMatchType.Lesser; 176 break; 177 case "<=": 178 case "=<": 179 matchType = NumberMatchType.LesserEqual; 180 break; 181 default: 182 matchType = NumberMatchType.Equal; 183 break; 184 } 185 186 return _list.Where (delegate (JSONObject line) { 183 187 double objVal = (line [_filterCol] as JSONNumber).GetDouble (); 184 188 switch (matchType) { 185 case NumberMatchType.Greater:186 return objVal > value;187 case NumberMatchType.GreaterEqual:188 return objVal >= value;189 case NumberMatchType.Lesser:190 return objVal < value;191 case NumberMatchType.LesserEqual:192 return objVal <= value;193 case NumberMatchType.Equal:194 default:195 return NearlyEqual (objVal, value, epsilon);189 case NumberMatchType.Greater: 190 return objVal > value; 191 case NumberMatchType.GreaterEqual: 192 return objVal >= value; 193 case NumberMatchType.Lesser: 194 return objVal < value; 195 case NumberMatchType.LesserEqual: 196 return objVal <= value; 197 case NumberMatchType.Equal: 198 default: 199 return NearlyEqual (objVal, value, epsilon); 196 200 } 197 201 }); 198 } else {199 Log.Out ("GetPlayerList: ignoring invalid filter for number-column '{0}': '{1}'", _filterCol, _filterVal); 200 }202 } 203 204 Log.Out ("GetPlayerList: ignoring invalid filter for number-column '{0}': '{1}'", _filterCol, _filterVal); 201 205 return _list; 202 206 } … … 210 214 if (_list.First ().ContainsKey (_sortCol)) { 211 215 Type colType = _list.First () [_sortCol].GetType (); 212 if (colType == typeof (JSONNumber)) {216 if (colType == typeof (JSONNumber)) { 213 217 if (_ascending) { 214 218 return _list.OrderBy (line => (line [_sortCol] as JSONNumber).GetDouble ()); 215 } else { 216 return _list.OrderByDescending (line => (line [_sortCol] as JSONNumber).GetDouble ()); 217 } 218 } else if (colType == typeof(JSONBoolean)) { 219 } 220 221 return _list.OrderByDescending (line => (line [_sortCol] as JSONNumber).GetDouble ()); 222 } 223 224 if (colType == typeof (JSONBoolean)) { 219 225 if (_ascending) { 220 226 return _list.OrderBy (line => (line [_sortCol] as JSONBoolean).GetBool ()); 221 } else { 222 return _list.OrderByDescending (line => (line [_sortCol] as JSONBoolean).GetBool ()); 223 } 224 } else { 225 if (_ascending) { 226 return _list.OrderBy (line => line [_sortCol].ToString ()); 227 } else { 228 return _list.OrderByDescending (line => line [_sortCol].ToString ()); 229 } 230 } 231 } 227 } 228 229 return _list.OrderByDescending (line => (line [_sortCol] as JSONBoolean).GetBool ()); 230 } 231 232 if (_ascending) { 233 return _list.OrderBy (line => line [_sortCol].ToString ()); 234 } 235 236 return _list.OrderByDescending (line => line [_sortCol].ToString ()); 237 } 238 232 239 return _list; 233 240 } 234 241 235 242 236 private bool NearlyEqual(double a, double b, double epsilon) 237 { 238 double absA = Math.Abs(a); 239 double absB = Math.Abs(b); 240 double diff = Math.Abs(a - b); 241 242 if (a == b) 243 { // shortcut, handles infinities 243 private bool NearlyEqual (double a, double b, double epsilon) { 244 double absA = Math.Abs (a); 245 double absB = Math.Abs (b); 246 double diff = Math.Abs (a - b); 247 248 if (a == b) { 244 249 return true; 245 } 246 else if (a == 0 || b == 0 || diff < Double.Epsilon) 247 { 248 // a or b is zero or both are extremely close to it 249 // relative error is less meaningful here 250 } 251 252 if (a == 0 || b == 0 || diff < double.Epsilon) { 250 253 return diff < epsilon; 251 254 } 252 else 253 { // use relative error 254 return diff / (absA + absB) < epsilon; 255 } 256 } 257 255 256 return diff / (absA + absB) < epsilon; 257 } 258 259 private enum NumberMatchType { 260 Equal, 261 Greater, 262 GreaterEqual, 263 Lesser, 264 LesserEqual 265 } 258 266 } 259 267 } 260 -
binary-improvements/MapRendering/Web/API/GetPlayersLocation.cs
r315 r325 1 using System.Net; 1 2 using AllocsFixes.JSON; 2 3 using AllocsFixes.PersistentData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 4 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 public class GetPlayersLocation : WebAPI 10 { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 { 13 AdminTools admTools = GameManager.Instance.adminTools; 14 user = user ?? new WebConnection ("", "", 0L); 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 6 public class GetPlayersLocation : WebAPI { 7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 8 int permissionLevel) { 9 AdminTools admTools = GameManager.Instance.adminTools; 10 user = user ?? new WebConnection ("", "", 0L); 15 11 16 12 bool listOffline = false; … … 19 15 } 20 16 21 17 bool bViewAll = WebConnection.CanViewAllPlayers (permissionLevel); 22 18 23 19 JSONArray playersJsResult = new JSONArray (); 24 20 25 21 Players playersList = PersistentContainer.Instance.Players; 26 22 27 23 foreach (string sid in playersList.SteamIDs) { 28 if (admTools != null) 29 if (admTools.IsBanned (sid)) 30 continue; 24 if (admTools != null) { 25 if (admTools.IsBanned (sid)) { 26 continue; 27 } 28 } 31 29 32 30 Player p = playersList [sid, false]; 33 31 34 32 if (listOffline || p.IsOnline) { 35 ulong player_steam_ID = 0L; 36 if (!ulong.TryParse (sid, out player_steam_ID)) 37 player_steam_ID = 0L; 33 ulong player_steam_ID = 0L; 34 if (!ulong.TryParse (sid, out player_steam_ID)) { 35 player_steam_ID = 0L; 36 } 38 37 39 if ((player_steam_ID == user.SteamID)|| bViewAll) {40 41 pos.Add("x", new JSONNumber (p.LastPosition.x));42 pos.Add("y", new JSONNumber (p.LastPosition.y));43 pos.Add("z", new JSONNumber (p.LastPosition.z));38 if (player_steam_ID == user.SteamID || bViewAll) { 39 JSONObject pos = new JSONObject (); 40 pos.Add ("x", new JSONNumber (p.LastPosition.x)); 41 pos.Add ("y", new JSONNumber (p.LastPosition.y)); 42 pos.Add ("z", new JSONNumber (p.LastPosition.z)); 44 43 45 JSONObject pJson = new JSONObject (); 46 pJson.Add("steamid", new JSONString (sid)); 47 // pJson.Add("entityid", new JSONNumber (p.EntityID)); 48 // pJson.Add("ip", new JSONString (p.IP)); 49 pJson.Add("name", new JSONString (p.Name)); 50 pJson.Add("online", new JSONBoolean (p.IsOnline)); 51 pJson.Add("position", pos); 44 JSONObject pJson = new JSONObject (); 45 pJson.Add ("steamid", new JSONString (sid)); 52 46 53 // pJson.Add ("totalplaytime", new JSONNumber (p.TotalPlayTime)); 54 // pJson.Add ("lastonline", new JSONString (p.LastOnline.ToString ("s"))); 55 // pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1)); 47 // pJson.Add("entityid", new JSONNumber (p.EntityID)); 48 // pJson.Add("ip", new JSONString (p.IP)); 49 pJson.Add ("name", new JSONString (p.Name)); 50 pJson.Add ("online", new JSONBoolean (p.IsOnline)); 51 pJson.Add ("position", pos); 52 53 // pJson.Add ("totalplaytime", new JSONNumber (p.TotalPlayTime)); 54 // pJson.Add ("lastonline", new JSONString (p.LastOnline.ToString ("s"))); 55 // pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1)); 56 56 57 57 playersJsResult.Add (pJson); 58 58 } 59 59 } 60 60 } 61 61 62 62 WriteJSON (resp, playersJsResult); … … 64 64 } 65 65 } 66 -
binary-improvements/MapRendering/Web/API/GetPlayersOnline.cs
r324 r325 1 using System.Collections.Generic; 2 using System.Net; 1 3 using AllocsFixes.JSON; 2 4 using AllocsFixes.PersistentData; 3 using System;4 using System.Collections.Generic;5 using System.Net;6 5 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 public class GetPlayersOnline : WebAPI 10 { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 { 13 JSONArray players = new JSONArray(); 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) { 10 JSONArray players = new JSONArray (); 14 11 15 12 World w = GameManager.Instance.World; … … 18 15 Player player = PersistentContainer.Instance.Players [ci.playerId, false]; 19 16 20 JSONObject pos = new JSONObject ();21 pos.Add ("x", new JSONNumber ((int) current.Value.GetPosition ().x));22 pos.Add ("y", new JSONNumber ((int) current.Value.GetPosition ().y));23 pos.Add ("z", new JSONNumber ((int) current.Value.GetPosition ().z));17 JSONObject pos = new JSONObject (); 18 pos.Add ("x", new JSONNumber ((int) current.Value.GetPosition ().x)); 19 pos.Add ("y", new JSONNumber ((int) current.Value.GetPosition ().y)); 20 pos.Add ("z", new JSONNumber ((int) current.Value.GetPosition ().z)); 24 21 25 JSONObject p = new JSONObject ();22 JSONObject p = new JSONObject (); 26 23 p.Add ("steamid", new JSONString (ci.playerId)); 27 24 p.Add ("entityid", new JSONNumber (ci.entityId)); … … 46 43 p.Add ("ping", new JSONNumber (ci != null ? ci.ping : -1)); 47 44 48 players.Add (p);45 players.Add (p); 49 46 } 50 47 51 WriteJSON (resp, players);48 WriteJSON (resp, players); 52 49 } 53 50 } 54 51 } 55 -
binary-improvements/MapRendering/Web/API/GetServerInfo.cs
r279 r325 1 using System; 2 using System.Net; 1 3 using AllocsFixes.JSON; 2 using AllocsFixes.PersistentData;3 using System;4 using System.Collections.Generic;5 using System.Net;6 4 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 public class GetServerInfo : WebAPI 10 { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 { 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) { 13 9 JSONObject serverInfo = new JSONObject (); 14 10 15 11 GameServerInfo gsi = Steam.Masterserver.Server.LocalGameInfo; 16 12 17 foreach (string stringGamePref in Enum.GetNames (typeof(GameInfoString))) {18 string value = gsi.GetValue ( (GameInfoString)Enum.Parse (typeof(GameInfoString), stringGamePref));13 foreach (string stringGamePref in Enum.GetNames (typeof (GameInfoString))) { 14 string value = gsi.GetValue ((GameInfoString) Enum.Parse (typeof (GameInfoString), stringGamePref)); 19 15 20 16 JSONObject singleStat = new JSONObject (); … … 25 21 } 26 22 27 foreach (string intGamePref in Enum.GetNames (typeof(GameInfoInt))) {28 int value = gsi.GetValue ( (GameInfoInt)Enum.Parse (typeof(GameInfoInt), intGamePref));23 foreach (string intGamePref in Enum.GetNames (typeof (GameInfoInt))) { 24 int value = gsi.GetValue ((GameInfoInt) Enum.Parse (typeof (GameInfoInt), intGamePref)); 29 25 30 26 JSONObject singleStat = new JSONObject (); … … 35 31 } 36 32 37 foreach (string boolGamePref in Enum.GetNames (typeof(GameInfoBool))) {38 bool value = gsi.GetValue ( (GameInfoBool)Enum.Parse (typeof(GameInfoBool), boolGamePref));33 foreach (string boolGamePref in Enum.GetNames (typeof (GameInfoBool))) { 34 bool value = gsi.GetValue ((GameInfoBool) Enum.Parse (typeof (GameInfoBool), boolGamePref)); 39 35 40 36 JSONObject singleStat = new JSONObject (); … … 46 42 47 43 48 WriteJSON (resp, serverInfo);44 WriteJSON (resp, serverInfo); 49 45 } 50 46 } 51 47 } 52 -
binary-improvements/MapRendering/Web/API/GetStats.cs
r313 r325 1 using System.Net; 1 2 using AllocsFixes.JSON; 2 3 using AllocsFixes.LiveData; 3 using AllocsFixes.PersistentData;4 using System;5 using System.Collections.Generic;6 using System.Net;7 4 8 namespace AllocsFixes.NetConnections.Servers.Web.API 9 { 10 public class GetStats : WebAPI 11 { 12 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 13 { 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) { 14 9 JSONObject result = new JSONObject (); 15 10 … … 32 27 } 33 28 } 34 -
binary-improvements/MapRendering/Web/API/GetWebUIUpdates.cs
r313 r325 1 using System.Net; 1 2 using AllocsFixes.JSON; 2 3 using AllocsFixes.LiveData; 3 using AllocsFixes.PersistentData;4 using System;5 using System.Collections.Generic;6 using System.Net;7 4 8 namespace AllocsFixes.NetConnections.Servers.Web.API 9 { 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 10 6 public class GetWebUIUpdates : WebAPI { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) { 7 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 8 int permissionLevel) { 12 9 int latestLine; 13 if (req.QueryString ["latestLine"] == null || !int.TryParse (req.QueryString ["latestLine"], out latestLine)) { 10 if (req.QueryString ["latestLine"] == null || 11 !int.TryParse (req.QueryString ["latestLine"], out latestLine)) { 14 12 latestLine = 0; 15 13 } … … 37 35 } 38 36 } 39 -
binary-improvements/MapRendering/Web/API/Null.cs
r251 r325 1 using AllocsFixes.JSON; 2 using System; 3 using System.Collections.Generic; 4 using System.Net; 1 using System.Net; 5 2 using System.Text; 6 3 7 namespace AllocsFixes.NetConnections.Servers.Web.API 8 { 9 public class Null : WebAPI 10 { 11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) 12 { 4 namespace AllocsFixes.NetConnections.Servers.Web.API { 5 public class Null : WebAPI { 6 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 7 int permissionLevel) { 13 8 resp.ContentLength64 = 0; 14 9 resp.ContentType = "text/plain"; 15 10 resp.ContentEncoding = Encoding.ASCII; 16 11 resp.OutputStream.Write (new byte[] { }, 0, 0); 17 18 12 } 13 } 19 14 } -
binary-improvements/MapRendering/Web/API/WebAPI.cs
r309 r325 1 using System;2 1 using System.Net; 3 2 using System.Text; 3 using AllocsFixes.JSON; 4 4 5 namespace AllocsFixes.NetConnections.Servers.Web.API 6 { 7 public abstract class WebAPI 8 { 9 public static void WriteJSON (HttpListenerResponse resp, JSON.JSONNode root) 10 { 5 namespace AllocsFixes.NetConnections.Servers.Web.API { 6 public abstract class WebAPI { 7 public static void WriteJSON (HttpListenerResponse resp, JSONNode root) { 11 8 StringBuilder sb = new StringBuilder (); 12 9 root.ToString (sb); … … 18 15 } 19 16 20 public static void WriteText (HttpListenerResponse _resp, string _text) 21 { 17 public static void WriteText (HttpListenerResponse _resp, string _text) { 22 18 byte[] buf = Encoding.UTF8.GetBytes (_text); 23 19 _resp.ContentLength64 = buf.Length; … … 27 23 } 28 24 29 public abstract void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel); 25 public abstract void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, 26 int permissionLevel); 30 27 31 28 public virtual int DefaultPermissionLevel () { … … 34 31 } 35 32 } 36
Note:
See TracChangeset
for help on using the changeset viewer.