Changeset 455 for binary-improvements/MapRendering/API/GetLandClaims.cs
- Timestamp:
- Jul 31, 2023, 4:06:13 PM (16 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/API/GetLandClaims.cs
r454 r455 1 1 using System.Collections.Generic; 2 2 using System.Net; 3 using AllocsFixes.JSON;4 3 using AllocsFixes.PersistentData; 4 using JetBrains.Annotations; 5 using Utf8Json; 5 6 using Webserver; 6 7 using Webserver.Permissions; … … 8 9 9 10 namespace AllocsFixes.WebAPIs { 11 [UsedImplicitly] 10 12 public class GetLandClaims : AbsWebAPI { 13 private static readonly byte[] jsonKeyClaimSize = JsonWriter.GetEncodedPropertyNameWithBeginObject ("claimsize"); 14 private static readonly byte[] jsonKeyClaimOwners = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("claimowners"); 15 16 private static readonly byte[] jsonKeySteamId = JsonWriter.GetEncodedPropertyNameWithBeginObject ("steamid"); 17 private static readonly byte[] jsonKeyCrossPlatformId = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("crossplatformid"); 18 private static readonly byte[] jsonKeyClaimActive = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("claimactive"); 19 private static readonly byte[] jsonKeyPlayerName = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("playername"); 20 private static readonly byte[] jsonKeyClaims = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("claims"); 21 11 22 public override void HandleRequest (RequestContext _context) { 12 23 PlatformUserIdentifierAbs requestedUserId = null; … … 23 34 bool bViewAll = PermissionUtils.CanViewAllClaims (_context.PermissionLevel); 24 35 25 JSONObject result = new JSONObject ();26 result.Add ("claimsize", new JSONNumber (GamePrefs.GetInt (EnumUtils.Parse<EnumGamePrefs> (nameof(EnumGamePrefs.LandClaimSize)))));27 28 JSONArray claimOwners = new JSONArray ();29 result.Add ("claimowners", claimOwners);30 31 36 LandClaimList.OwnerFilter[] ownerFilters = null; 32 37 if (requestedUserId != null || !bViewAll) { … … 34 39 ownerFilters = new[] { 35 40 LandClaimList.UserIdFilter (userId), 36 LandClaimList.UserIdFilter (requestedUserId) 41 LandClaimList.UserIdFilter (requestedUserId), 37 42 }; 38 43 } else if (!bViewAll) { … … 47 52 Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters); 48 53 54 JsonWriter writer = new JsonWriter (); 55 56 writer.WriteRaw (jsonKeyClaimSize); 57 writer.WriteInt32 (GamePrefs.GetInt (EnumUtils.Parse<EnumGamePrefs> (nameof(EnumGamePrefs.LandClaimSize)))); 58 59 writer.WriteRaw (jsonKeyClaimOwners); 60 writer.WriteBeginArray (); 61 62 bool first = true; 63 49 64 foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) { 50 JSONObject owner = new JSONObject (); 51 claimOwners.Add (owner); 52 53 owner.Add ("steamid", new JSONString (kvp.Key.PlatformId?.CombinedString ?? "")); 54 owner.Add ("crossplatformid", new JSONString (kvp.Key.CrossPlatformId?.CombinedString ?? "")); 55 owner.Add ("claimactive", new JSONBoolean (kvp.Key.LandProtectionActive)); 56 57 if (kvp.Key.Name.Length > 0) { 58 owner.Add ("playername", new JSONString (kvp.Key.Name)); 59 } else { 60 owner.Add ("playername", new JSONNull ()); 65 if (!first) { 66 writer.WriteValueSeparator (); 61 67 } 62 68 63 JSONArray claimsJson = new JSONArray (); 64 owner.Add ("claims", claimsJson); 69 first = false; 70 71 writer.WriteRaw (jsonKeySteamId); 72 writer.WriteString (kvp.Key.PlatformId?.CombinedString ?? ""); 73 74 writer.WriteRaw (jsonKeyCrossPlatformId); 75 writer.WriteString (kvp.Key.CrossPlatformId?.CombinedString ?? ""); 76 77 writer.WriteRaw (jsonKeyClaimActive); 78 writer.WriteBoolean (kvp.Key.LandProtectionActive); 79 80 writer.WriteRaw (jsonKeyPlayerName); 81 if (kvp.Key.Name.Length > 0) { 82 writer.WriteString (kvp.Key.Name); 83 } else { 84 writer.WriteNull (); 85 } 86 87 writer.WriteRaw (jsonKeyClaims); 88 writer.WriteBeginArray (); 89 90 bool first2 = true; 65 91 66 92 foreach (Vector3i v in kvp.Value) { 67 JSONObject claim = new JSONObject (); 68 claim.Add ("x", new JSONNumber (v.x)); 69 claim.Add ("y", new JSONNumber (v.y)); 70 claim.Add ("z", new JSONNumber (v.z)); 93 if (!first2) { 94 writer.WriteValueSeparator (); 95 } 71 96 72 claimsJson.Add (claim); 97 first2 = false; 98 99 JsonCommons.WriteVector3I (ref writer, v); 73 100 } 101 102 writer.WriteEndArray (); 103 104 writer.WriteEndObject (); 74 105 } 75 106 76 LegacyApiHelper.WriteJSON (_context.Response, result); 107 writer.WriteEndArray (); 108 109 writer.WriteEndObject (); 110 WebUtils.WriteJsonData (_context.Response, ref writer); 77 111 } 78 112 }
Note:
See TracChangeset
for help on using the changeset viewer.