Changeset 369 for binary-improvements/MapRendering/Web/API
- Timestamp:
- Nov 9, 2021, 6:28:33 PM (3 years ago)
- Location:
- binary-improvements/MapRendering/Web/API
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/API/GetLandClaims.cs
r351 r369 8 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 9 int _permissionLevel) { 10 string requestedSteamID = string.Empty; 11 12 if (_req.QueryString ["steamid"] != null) { 13 ulong lViewersSteamID; 14 requestedSteamID = _req.QueryString ["steamid"]; 15 if (requestedSteamID.Length != 17 || !ulong.TryParse (requestedSteamID, out lViewersSteamID)) { 10 PlatformUserIdentifierAbs requestedUserId = null; 11 if (_req.QueryString ["userid"] != null) { 12 if (!PlatformUserIdentifierAbs.TryFromCombinedString (_req.QueryString ["userid"], out requestedUserId)) { 16 13 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 17 Web.SetResponseTextContent (_resp, "Invalid SteamIDgiven");14 Web.SetResponseTextContent (_resp, "Invalid user id given"); 18 15 return; 19 16 } … … 21 18 22 19 // default user, cheap way to avoid 'null reference exception' 23 _user = _user ?? new WebConnection ("", IPAddress.None, 0L);20 PlatformUserIdentifierAbs userId = _user?.UserId; 24 21 25 22 bool bViewAll = WebConnection.CanViewAllClaims (_permissionLevel); … … 32 29 33 30 LandClaimList.OwnerFilter[] ownerFilters = null; 34 if ( !string.IsNullOrEmpty (requestedSteamID)|| !bViewAll) {35 if ( !string.IsNullOrEmpty (requestedSteamID)&& !bViewAll) {31 if (requestedUserId != null || !bViewAll) { 32 if (requestedUserId != null && !bViewAll) { 36 33 ownerFilters = new[] { 37 LandClaimList. SteamIdFilter (_user.SteamID.ToString ()),38 LandClaimList. SteamIdFilter (requestedSteamID)34 LandClaimList.UserIdFilter (userId), 35 LandClaimList.UserIdFilter (requestedUserId) 39 36 }; 40 37 } else if (!bViewAll) { 41 ownerFilters = new[] {LandClaimList. SteamIdFilter (_user.SteamID.ToString ())};38 ownerFilters = new[] {LandClaimList.UserIdFilter (userId)}; 42 39 } else { 43 ownerFilters = new[] {LandClaimList. SteamIdFilter (requestedSteamID)};40 ownerFilters = new[] {LandClaimList.UserIdFilter (requestedUserId)}; 44 41 } 45 42 } … … 50 47 51 48 foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) { 52 // try { 53 JSONObject owner = new JSONObject (); 54 claimOwners.Add (owner); 49 JSONObject owner = new JSONObject (); 50 claimOwners.Add (owner); 55 51 56 owner.Add ("steamid", new JSONString (kvp.Key.SteamID));57 52 owner.Add ("steamid", new JSONString (kvp.Key.PlatformId.CombinedString)); 53 owner.Add ("claimactive", new JSONBoolean (kvp.Key.LandProtectionActive)); 58 54 59 60 61 62 63 55 if (kvp.Key.Name.Length > 0) { 56 owner.Add ("playername", new JSONString (kvp.Key.Name)); 57 } else { 58 owner.Add ("playername", new JSONNull ()); 59 } 64 60 65 66 61 JSONArray claimsJson = new JSONArray (); 62 owner.Add ("claims", claimsJson); 67 63 68 69 70 71 72 64 foreach (Vector3i v in kvp.Value) { 65 JSONObject claim = new JSONObject (); 66 claim.Add ("x", new JSONNumber (v.x)); 67 claim.Add ("y", new JSONNumber (v.y)); 68 claim.Add ("z", new JSONNumber (v.z)); 73 69 74 claimsJson.Add (claim); 75 } 76 // } catch { 77 // } 70 claimsJson.Add (claim); 71 } 78 72 } 79 73 -
binary-improvements/MapRendering/Web/API/GetPlayerInventories.cs
r349 r369 8 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 9 int _permissionLevel) { 10 11 bool showIconColor, showIconName; 12 GetPlayerInventory.GetInventoryArguments (_req, out showIconColor, out showIconName); 10 GetPlayerInventory.GetInventoryArguments (_req, out bool showIconColor, out bool showIconName); 13 11 14 12 JSONArray AllInventoriesResult = new JSONArray (); 15 13 16 foreach (KeyValuePair< string, Player> kvp in PersistentContainer.Instance.Players.Dict) {14 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in PersistentContainer.Instance.Players.Dict) { 17 15 Player p = kvp.Value; 18 16 … … 22 20 23 21 if (p.IsOnline) { 24 AllInventoriesResult.Add (GetPlayerInventory.DoPlayer (kvp.Key , p, showIconColor, showIconName));22 AllInventoriesResult.Add (GetPlayerInventory.DoPlayer (kvp.Key.CombinedString, p, showIconColor, showIconName)); 25 23 } 26 24 } -
binary-improvements/MapRendering/Web/API/GetPlayerInventory.cs
r348 r369 8 8 public override void HandleRequest (HttpListenerRequest _req, HttpListenerResponse _resp, WebConnection _user, 9 9 int _permissionLevel) { 10 if (_req.QueryString [" steamid"] == null) {10 if (_req.QueryString ["userid"] == null) { 11 11 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 12 Web.SetResponseTextContent (_resp, "No SteamIDgiven");12 Web.SetResponseTextContent (_resp, "No user id given"); 13 13 return; 14 14 } 15 15 16 string steamId = _req.QueryString ["steamid"]; 17 18 Player p = PersistentContainer.Instance.Players [steamId, false]; 19 if (p == null) { 20 _resp.StatusCode = (int) HttpStatusCode.NotFound; 21 Web.SetResponseTextContent (_resp, "Invalid or unknown SteamID given"); 16 string userIdString = _req.QueryString ["userid"]; 17 if (!PlatformUserIdentifierAbs.TryFromCombinedString (userIdString, out PlatformUserIdentifierAbs userId)) { 18 _resp.StatusCode = (int) HttpStatusCode.BadRequest; 19 Web.SetResponseTextContent (_resp, "Invalid user id given"); 22 20 return; 23 21 } 24 22 25 bool showIconColor, showIconName; 26 GetInventoryArguments (_req, out showIconColor, out showIconName); 23 Player p = PersistentContainer.Instance.Players [userId, false]; 24 if (p == null) { 25 _resp.StatusCode = (int) HttpStatusCode.NotFound; 26 Web.SetResponseTextContent (_resp, "Unknown user id given"); 27 return; 28 } 27 29 28 JSONObject result = DoPlayer (steamId, p, showIconColor, showIconName); 30 GetInventoryArguments (_req, out bool showIconColor, out bool showIconName); 31 32 JSONObject result = DoPlayer (userIdString, p, showIconColor, showIconName); 29 33 30 34 WriteJSON (_resp, result); … … 49 53 JSONArray belt = new JSONArray (); 50 54 JSONObject equipment = new JSONObject (); 51 result.Add (" steamid", new JSONString (_steamId));55 result.Add ("userid", new JSONString (_steamId)); 52 56 result.Add ("entityid", new JSONNumber (_player.EntityID)); 53 57 result.Add ("playername", new JSONString (_player.Name)); … … 86 90 87 91 for (int i = 0; i < slotindices.Length; i++) { 88 if (_items != null && _items[slotindices [i]] != null) {92 if (_items? [slotindices [i]] != null) { 89 93 InvItem item = _items [slotindices [i]]; 90 94 _eq.Add (_slotname, GetJsonForItem (item, _showIconColor, _showIconName)); -
binary-improvements/MapRendering/Web/API/GetPlayerList.cs
r351 r369 6 6 using AllocsFixes.JSON; 7 7 using AllocsFixes.PersistentData; 8 using UnityEngine.Profiling;9 8 10 9 namespace AllocsFixes.NetConnections.Servers.Web.API { … … 14 13 15 14 #if ENABLE_PROFILER 16 private static readonly CustomSampler jsonSerializeSampler =CustomSampler.Create ("JSON_Build");15 private static readonly UnityEngine.Profiling.CustomSampler jsonSerializeSampler = UnityEngine.Profiling.CustomSampler.Create ("JSON_Build"); 17 16 #endif 18 17 … … 20 19 int _permissionLevel) { 21 20 AdminTools admTools = GameManager.Instance.adminTools; 22 _user = _user ?? new WebConnection ("", IPAddress.None, 0L);21 PlatformUserIdentifierAbs userId = _user?.UserId; 23 22 24 23 bool bViewAll = WebConnection.CanViewAllPlayers (_permissionLevel); … … 47 46 #endif 48 47 49 foreach (KeyValuePair< string, Player> kvp in playersList.Dict) {48 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in playersList.Dict) { 50 49 Player p = kvp.Value; 51 50 52 ulong player_steam_ID; 53 if (!ulong.TryParse (kvp.Key, out player_steam_ID)) { 54 player_steam_ID = 0L; 55 } 56 57 if (player_steam_ID == _user.SteamID || bViewAll) { 51 if (bViewAll || p.PlatformId.Equals (userId)) { 58 52 JSONObject pos = new JSONObject (); 59 53 pos.Add ("x", new JSONNumber (p.LastPosition.x)); … … 62 56 63 57 JSONObject pJson = new JSONObject (); 64 pJson.Add ("steamid", new JSONString (kvp.Key ));58 pJson.Add ("steamid", new JSONString (kvp.Key.CombinedString)); 65 59 pJson.Add ("entityid", new JSONNumber (p.EntityID)); 66 60 pJson.Add ("ip", new JSONString (p.IP)); … … 74 68 pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1)); 75 69 76 JSONBoolean banned; 77 if (admTools != null) { 78 banned = new JSONBoolean (admTools.IsBanned (kvp.Key)); 79 } else { 80 banned = new JSONBoolean (false); 81 } 70 JSONBoolean banned = admTools != null ? new JSONBoolean (admTools.IsBanned (kvp.Key, out _, out _)) : new JSONBoolean (false); 82 71 83 72 pJson.Add ("banned", banned); -
binary-improvements/MapRendering/Web/API/GetPlayersLocation.cs
r351 r369 9 9 int _permissionLevel) { 10 10 AdminTools admTools = GameManager.Instance.adminTools; 11 _user = _user ?? new WebConnection ("", IPAddress.None, 0L);11 PlatformUserIdentifierAbs userId = _user?.UserId; 12 12 13 13 bool listOffline = false; … … 22 22 Players playersList = PersistentContainer.Instance.Players; 23 23 24 foreach (KeyValuePair< string, Player> kvp in playersList.Dict) {24 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in playersList.Dict) { 25 25 if (admTools != null) { 26 if (admTools.IsBanned (kvp.Key )) {26 if (admTools.IsBanned (kvp.Key, out _, out _)) { 27 27 continue; 28 28 } … … 32 32 33 33 if (listOffline || p.IsOnline) { 34 ulong player_steam_ID; 35 if (!ulong.TryParse (kvp.Key, out player_steam_ID)) { 36 player_steam_ID = 0L; 37 } 38 39 if (player_steam_ID == _user.SteamID || bViewAll) { 34 if (bViewAll || p.PlatformId.Equals (userId)) { 40 35 JSONObject pos = new JSONObject (); 41 36 pos.Add ("x", new JSONNumber (p.LastPosition.x)); … … 44 39 45 40 JSONObject pJson = new JSONObject (); 46 pJson.Add ("steamid", new JSONString (kvp.Key ));41 pJson.Add ("steamid", new JSONString (kvp.Key.CombinedString)); 47 42 48 43 // pJson.Add("entityid", new JSONNumber (p.EntityID)); -
binary-improvements/MapRendering/Web/API/GetPlayersOnline.cs
r351 r369 13 13 foreach (KeyValuePair<int, EntityPlayer> current in w.Players.dict) { 14 14 ClientInfo ci = ConnectionManager.Instance.Clients.ForEntityId (current.Key); 15 Player player = PersistentContainer.Instance.Players [ci. playerId, false];15 Player player = PersistentContainer.Instance.Players [ci.PlatformId, false]; 16 16 17 17 JSONObject pos = new JSONObject (); … … 21 21 22 22 JSONObject p = new JSONObject (); 23 p.Add ("steamid", new JSONString (ci. playerId));23 p.Add ("steamid", new JSONString (ci.PlatformId.CombinedString)); 24 24 p.Add ("entityid", new JSONNumber (ci.entityId)); 25 25 p.Add ("ip", new JSONString (ci.ip)); … … 28 28 p.Add ("position", pos); 29 29 30 // Deprecated! 31 p.Add ("experience", new JSONNumber (-1)); 32 33 p.Add ("level", new JSONNumber (player != null ? player.Level : -1)); 30 p.Add ("level", new JSONNumber (player?.Level ?? -1)); 34 31 p.Add ("health", new JSONNumber (current.Value.Health)); 35 32 p.Add ("stamina", new JSONNumber (current.Value.Stamina)); … … 39 36 p.Add ("score", new JSONNumber (current.Value.Score)); 40 37 41 p.Add ("totalplaytime", new JSONNumber (player != null ? player.TotalPlayTime :-1));38 p.Add ("totalplaytime", new JSONNumber (player?.TotalPlayTime ?? -1)); 42 39 p.Add ("lastonline", new JSONString (player != null ? player.LastOnline.ToString ("s") : string.Empty)); 43 40 p.Add ("ping", new JSONNumber (ci.ping));
Note:
See TracChangeset
for help on using the changeset viewer.