source: binary-improvements/WebInterface/Web/API/GetLandClaims.cs@ 226

Last change on this file since 226 was 224, checked in by alloc, 10 years ago

A11 preps

File size: 2.4 KB
Line 
1using AllocsFixes.JSON;
2using AllocsFixes.PersistentData;
3using System;
4using System.Collections.Generic;
5using System.Net;
6
7namespace AllocsFixes.NetConnections.Servers.Web.API
8{
9 public class GetLandClaims : WebAPI
10 {
11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, HttpListenerBasicIdentity user)
12 {
13 string steamid = string.Empty;
14
15 if (req.QueryString ["steamid"] != null) {
16 long tempLong;
17 steamid = req.QueryString ["steamid"];
18 if (steamid.Length != 17 || !long.TryParse (steamid, out tempLong)) {
19 resp.StatusCode = (int)HttpStatusCode.InternalServerError;
20 Web.SetResponseTextContent (resp, "Invalid SteamID given");
21 return;
22 }
23 }
24
25 JSONObject result = new JSONObject ();
26 result.Add ("claimsize", new JSONNumber (GamePrefs.GetInt (EnumGamePrefs.LandClaimSize)));
27
28 JSONArray claimOwners = new JSONArray ();
29 result.Add ("claimowners", claimOwners);
30
31 Dictionary<Vector3i, PersistentPlayerData> d = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList ().positionToLPBlockOwner;
32 if (d != null) {
33 World w = CommonMappingFunctions.GetGameManager ().World;
34 Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> ();
35 foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) {
36 if (steamid.Length == 0 || kvp.Value.PlayerId.Equals (steamid)) {
37 if (!owners.ContainsKey (kvp.Value)) {
38 owners.Add (kvp.Value, new List<Vector3i> ());
39 }
40 owners [kvp.Value].Add (kvp.Key);
41 }
42 }
43
44 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
45 if (steamid.Length == 0 || kvp.Key.PlayerId.Equals (steamid)) {
46 string curID = kvp.Key.PlayerId;
47 bool isActive = w.LandClaimIsActive (kvp.Key);
48
49 JSONObject owner = new JSONObject ();
50 claimOwners.Add (owner);
51
52 owner.Add ("steamid", new JSONString (curID));
53 owner.Add ("claimactive", new JSONBoolean (isActive));
54
55 JSONArray claims = new JSONArray ();
56 owner.Add ("claims", claims);
57
58 foreach (Vector3i v in kvp.Value) {
59 JSONObject claim = new JSONObject ();
60 claim.Add ("x", new JSONNumber (v.x));
61 claim.Add ("y", new JSONNumber (v.y));
62 claim.Add ("z", new JSONNumber (v.z));
63
64 claims.Add (claim);
65 }
66 }
67 }
68 }
69
70 WriteJSON (resp, result);
71 }
72 }
73}
74
Note: See TracBrowser for help on using the repository browser.