source: binary-improvements2/WebServer/src/WebAPI/APIs/GetLandClaims.cs@ 402

Last change on this file since 402 was 402, checked in by alloc, 22 months ago
  • Major refactoring
  • Using Utf8Json for (de)serialization
  • Moving APIs to REST
  • Removing dependencies from WebServer and MapRenderer to ServerFixes
File size: 2.8 KB
Line 
1// using System.Collections.Generic;
2// using System.Net;
3// using AllocsFixes;
4// using AllocsFixes.PersistentData;
5// using JetBrains.Annotations;
6//
7// namespace Webserver.WebAPI.APIs {
8// [UsedImplicitly]
9// public class GetLandClaims : AbsWebAPI {
10// public override void HandleRequest (RequestContext _context) {
11// PlatformUserIdentifierAbs requestedUserId = null;
12// if (_context.Request.QueryString ["userid"] != null) {
13// if (!PlatformUserIdentifierAbs.TryFromCombinedString (_context.Request.QueryString ["userid"], out requestedUserId)) {
14// WebUtils.WriteText (_context.Response, "Invalid user id given", HttpStatusCode.BadRequest);
15// return;
16// }
17// }
18//
19// // default user, cheap way to avoid 'null reference exception'
20// PlatformUserIdentifierAbs userId = _context.Connection?.UserId;
21//
22// bool bViewAll = WebConnection.CanViewAllClaims (_context.PermissionLevel);
23//
24// JsonObject result = new JsonObject ();
25// result.Add ("claimsize",
26// new JsonNumber (GamePrefs.GetInt (EnumUtils.Parse<EnumGamePrefs> (nameof (EnumGamePrefs.LandClaimSize)))));
27//
28// JsonArray claimOwners = new JsonArray ();
29// result.Add ("claimowners", claimOwners);
30//
31// LandClaimList.OwnerFilter[] ownerFilters = null;
32// if (requestedUserId != null || !bViewAll) {
33// if (requestedUserId != null && !bViewAll) {
34// ownerFilters = new[] {
35// LandClaimList.UserIdFilter (userId),
36// LandClaimList.UserIdFilter (requestedUserId)
37// };
38// } else if (!bViewAll) {
39// ownerFilters = new[] {LandClaimList.UserIdFilter (userId)};
40// } else {
41// ownerFilters = new[] {LandClaimList.UserIdFilter (requestedUserId)};
42// }
43// }
44//
45// LandClaimList.PositionFilter[] posFilters = null;
46//
47// Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (ownerFilters, posFilters);
48//
49// foreach ((Player player, List<Vector3i> claimPositions) in claims) {
50// JsonObject owner = new JsonObject ();
51// claimOwners.Add (owner);
52//
53// owner.Add ("steamid", new JsonString (player.PlatformId.CombinedString));
54// owner.Add ("claimactive", new JsonBoolean (player.LandProtectionActive));
55//
56// if (player.Name.Length > 0) {
57// owner.Add ("playername", new JsonString (player.Name));
58// } else {
59// owner.Add ("playername", new JsonNull ());
60// }
61//
62// JsonArray claimsJson = new JsonArray ();
63// owner.Add ("claims", claimsJson);
64//
65// foreach (Vector3i v in claimPositions) {
66// JsonObject claim = new JsonObject ();
67// claim.Add ("x", new JsonNumber (v.x));
68// claim.Add ("y", new JsonNumber (v.y));
69// claim.Add ("z", new JsonNumber (v.z));
70//
71// claimsJson.Add (claim);
72// }
73// }
74//
75// WebUtils.WriteJson (_context.Response, result);
76// }
77// }
78// }
Note: See TracBrowser for help on using the repository browser.