Changeset 454 for binary-improvements/MapRendering/API/GetPlayerList.cs
- Timestamp:
- Jul 28, 2023, 8:42:10 PM (16 months ago)
- Location:
- binary-improvements/MapRendering/API
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.