| [230] | 1 | using AllocsFixes.JSON; | 
|---|
|  | 2 | using AllocsFixes.PersistentData; | 
|---|
|  | 3 | using System; | 
|---|
|  | 4 | using System.Collections.Generic; | 
|---|
|  | 5 | using System.Net; | 
|---|
|  | 6 |  | 
|---|
|  | 7 | namespace 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 |  | 
|---|
| [238] | 31 | Dictionary<Vector3i, PersistentPlayerData> d = GameManager.Instance.GetPersistentPlayerList ().m_lpBlockMap; | 
|---|
| [230] | 32 | if (d != null) { | 
|---|
|  | 33 | World w = GameManager.Instance.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; | 
|---|
| [238] | 47 | bool isActive = w.IsLandProtectionValidForPlayer (kvp.Key); | 
|---|
| [230] | 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 |  | 
|---|