- Timestamp:
- Jul 31, 2023, 4:06:13 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/API/GetPlayersLocation.cs
r454 r455 1 1 using System.Collections.Generic; 2 using AllocsFixes.JSON;3 2 using AllocsFixes.PersistentData; 3 using JetBrains.Annotations; 4 using Utf8Json; 4 5 using Webserver; 5 6 using Webserver.Permissions; … … 7 8 8 9 namespace AllocsFixes.WebAPIs { 10 [UsedImplicitly] 9 11 public class GetPlayersLocation : AbsWebAPI { 12 private static readonly byte[] jsonKeySteamId = JsonWriter.GetEncodedPropertyNameWithBeginObject ("steamid"); 13 private static readonly byte[] jsonKeyCrossPlatformId = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("crossplatformid"); 14 private static readonly byte[] jsonKeyName = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("name"); 15 private static readonly byte[] jsonKeyOnline = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("online"); 16 private static readonly byte[] jsonKeyPosition = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("position"); 17 10 18 public override void HandleRequest (RequestContext _context) { 11 19 AdminTools admTools = GameManager.Instance.adminTools; … … 19 27 bool bViewAll = PermissionUtils.CanViewAllPlayers (_context.PermissionLevel); 20 28 21 JSONArray playersJsResult = new JSONArray (); 29 JsonWriter writer = new JsonWriter (); 30 31 writer.WriteBeginArray (); 32 33 bool first = true; 22 34 23 35 Players playersList = PersistentContainer.Instance.Players; … … 34 46 if (listOffline || p.IsOnline) { 35 47 if (bViewAll || p.InternalId.Equals (userId)) { 36 JSONObject pos = new JSONObject ();37 pos.Add ("x", new JSONNumber (p.LastPosition.x));38 pos.Add ("y", new JSONNumber (p.LastPosition.y));39 pos.Add ("z", new JSONNumber (p.LastPosition.z));40 48 41 JSONObject pJson = new JSONObject ();42 pJson.Add ("steamid", new JSONString (kvp.Value.PlatformId.CombinedString));43 pJson.Add ("crossplatformid", new JSONString (kvp.Value.CrossPlatformId?.CombinedString ?? ""));49 if (!first) { 50 writer.WriteValueSeparator (); 51 } 44 52 45 // pJson.Add("entityid", new JSONNumber (p.EntityID)); 46 // pJson.Add("ip", new JSONString (p.IP)); 47 pJson.Add ("name", new JSONString (p.Name)); 48 pJson.Add ("online", new JSONBoolean (p.IsOnline)); 49 pJson.Add ("position", pos); 50 51 // pJson.Add ("totalplaytime", new JSONNumber (p.TotalPlayTime)); 52 // pJson.Add ("lastonline", new JSONString (p.LastOnline.ToString ("s"))); 53 // pJson.Add ("ping", new JSONNumber (p.IsOnline ? p.ClientInfo.ping : -1)); 54 55 playersJsResult.Add (pJson); 53 first = false; 54 55 writer.WriteRaw (jsonKeySteamId); 56 writer.WriteString (kvp.Value.PlatformId.CombinedString); 57 58 writer.WriteRaw (jsonKeyCrossPlatformId); 59 writer.WriteString (kvp.Value.CrossPlatformId?.CombinedString ?? ""); 60 61 writer.WriteRaw (jsonKeyName); 62 writer.WriteString (p.Name); 63 64 writer.WriteRaw (jsonKeyOnline); 65 writer.WriteBoolean (p.IsOnline); 66 67 writer.WriteRaw (jsonKeyPosition); 68 JsonCommons.WriteVector3I (ref writer, p.LastPosition); 69 70 writer.WriteEndObject (); 56 71 } 57 72 } 58 73 } 59 60 LegacyApiHelper.WriteJSON (_context.Response, playersJsResult); 74 75 writer.WriteEndArray (); 76 77 WebUtils.WriteJsonData (_context.Response, ref writer); 61 78 } 62 79 }
Note:
See TracChangeset
for help on using the changeset viewer.