Changeset 351 for binary-improvements/MapRendering/Web/API/GetPlayerList.cs
- Timestamp:
- Jan 19, 2019, 6:12:21 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/API/GetPlayerList.cs
r332 r351 17 17 #endif 18 18 19 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnectionuser,20 int permissionLevel) {19 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 20 int _permissionLevel) { 21 21 AdminTools admTools = GameManager.Instance.adminTools; 22 user =user ?? new WebConnection ("", IPAddress.None, 0L);23 24 bool bViewAll = WebConnection.CanViewAllPlayers ( permissionLevel);22 _user = _user ?? new WebConnection ("", IPAddress.None, 0L); 23 24 bool bViewAll = WebConnection.CanViewAllPlayers (_permissionLevel); 25 25 26 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) 27 27 28 28 int rowsPerPage = 25; 29 if ( req.QueryString ["rowsperpage"] != null) {30 int.TryParse ( req.QueryString ["rowsperpage"], out rowsPerPage);29 if (_req.QueryString ["rowsperpage"] != null) { 30 int.TryParse (_req.QueryString ["rowsperpage"], out rowsPerPage); 31 31 } 32 32 33 33 int page = 0; 34 if ( req.QueryString ["page"] != null) {35 int.TryParse ( req.QueryString ["page"], out page);34 if (_req.QueryString ["page"] != null) { 35 int.TryParse (_req.QueryString ["page"], out page); 36 36 } 37 37 … … 55 55 } 56 56 57 if (player_steam_ID == user.SteamID || bViewAll) {57 if (player_steam_ID == _user.SteamID || bViewAll) { 58 58 JSONObject pos = new JSONObject (); 59 59 pos.Add ("x", new JSONNumber (p.LastPosition.x)); … … 93 93 IEnumerable<JSONObject> list = playerList; 94 94 95 foreach (string key in req.QueryString.AllKeys) {95 foreach (string key in _req.QueryString.AllKeys) { 96 96 if (!string.IsNullOrEmpty (key) && key.StartsWith ("filter[")) { 97 97 string filterCol = key.Substring (key.IndexOf ('[') + 1); 98 98 filterCol = filterCol.Substring (0, filterCol.Length - 1); 99 string filterVal = req.QueryString.Get (key).Trim ();99 string filterVal = _req.QueryString.Get (key).Trim (); 100 100 101 101 list = ExecuteFilter (list, filterCol, filterVal); … … 105 105 int totalAfterFilter = list.Count (); 106 106 107 foreach (string key in req.QueryString.AllKeys) {107 foreach (string key in _req.QueryString.AllKeys) { 108 108 if (!string.IsNullOrEmpty (key) && key.StartsWith ("sort[")) { 109 109 string sortCol = key.Substring (key.IndexOf ('[') + 1); 110 110 sortCol = sortCol.Substring (0, sortCol.Length - 1); 111 string sortVal = req.QueryString.Get (key);111 string sortVal = _req.QueryString.Get (key); 112 112 113 113 list = ExecuteSort (list, sortCol, sortVal == "0"); … … 130 130 result.Add ("players", playersJsResult); 131 131 132 WriteJSON ( resp, result);132 WriteJSON (_resp, result); 133 133 } 134 134 135 135 private IEnumerable<JSONObject> ExecuteFilter (IEnumerable<JSONObject> _list, string _filterCol, 136 136 string _filterVal) { 137 if ( _list.Count () == 0) {137 if (!_list.Any()) { 138 138 return _list; 139 139 } … … 147 147 if (colType == typeof (JSONBoolean)) { 148 148 bool value = StringParsers.ParseBool (_filterVal); 149 return _list.Where ( line => ((JSONBoolean)line [_filterCol]).GetBool () == value);149 return _list.Where (_line => ((JSONBoolean) _line [_filterCol]).GetBool () == value); 150 150 } 151 151 … … 157 157 //Log.Out ("GetPlayerList: Filter on String with Regex '" + _filterVal + "'"); 158 158 Regex matcher = new Regex (_filterVal, RegexOptions.IgnoreCase); 159 return _list.Where ( line => matcher.IsMatch (((JSONString)line [_filterCol]).GetString ()));159 return _list.Where (_line => matcher.IsMatch (((JSONString) _line [_filterCol]).GetString ())); 160 160 } 161 161 } … … 198 198 } 199 199 200 return _list.Where (delegate (JSONObject line) {201 double objVal = ((JSONNumber) line [_filterCol]).GetDouble ();200 return _list.Where (delegate (JSONObject _line) { 201 double objVal = ((JSONNumber) _line [_filterCol]).GetDouble (); 202 202 switch (matchType) { 203 203 case NumberMatchType.Greater: … … 230 230 if (colType == typeof (JSONNumber)) { 231 231 if (_ascending) { 232 return _list.OrderBy ( line => ((JSONNumber)line [_sortCol]).GetDouble ());233 } 234 235 return _list.OrderByDescending ( line => ((JSONNumber)line [_sortCol]).GetDouble ());232 return _list.OrderBy (_line => ((JSONNumber) _line [_sortCol]).GetDouble ()); 233 } 234 235 return _list.OrderByDescending (_line => ((JSONNumber) _line [_sortCol]).GetDouble ()); 236 236 } 237 237 238 238 if (colType == typeof (JSONBoolean)) { 239 239 if (_ascending) { 240 return _list.OrderBy ( line => ((JSONBoolean)line [_sortCol]).GetBool ());241 } 242 243 return _list.OrderByDescending ( line => ((JSONBoolean)line [_sortCol]).GetBool ());240 return _list.OrderBy (_line => ((JSONBoolean) _line [_sortCol]).GetBool ()); 241 } 242 243 return _list.OrderByDescending (_line => ((JSONBoolean) _line [_sortCol]).GetBool ()); 244 244 } 245 245 246 246 if (_ascending) { 247 return _list.OrderBy ( line =>line [_sortCol].ToString ());248 } 249 250 return _list.OrderByDescending ( line =>line [_sortCol].ToString ());247 return _list.OrderBy (_line => _line [_sortCol].ToString ()); 248 } 249 250 return _list.OrderByDescending (_line => _line [_sortCol].ToString ()); 251 251 } 252 252 … … 255 255 256 256 257 private bool NearlyEqual (double a, double b, doubleepsilon) {258 double absA = Math.Abs ( a);259 double absB = Math.Abs ( b);260 double diff = Math.Abs ( a -b);261 262 if ( a ==b) {257 private bool NearlyEqual (double _a, double _b, double _epsilon) { 258 double absA = Math.Abs (_a); 259 double absB = Math.Abs (_b); 260 double diff = Math.Abs (_a - _b); 261 262 if (_a == _b) { 263 263 return true; 264 264 } 265 265 266 if ( a == 0 ||b == 0 || diff < double.Epsilon) {267 return diff < epsilon;268 } 269 270 return diff / (absA + absB) < epsilon;266 if (_a == 0 || _b == 0 || diff < double.Epsilon) { 267 return diff < _epsilon; 268 } 269 270 return diff / (absA + absB) < _epsilon; 271 271 } 272 272
Note:
See TracChangeset
for help on using the changeset viewer.