source: binary-improvements/MapRendering/Web/API/ExecuteConsoleCommand.cs@ 266

Last change on this file since 266 was 245, checked in by alloc, 9 years ago

Fixes

File size: 3.0 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 ExecuteConsoleCommand : WebAPI
10 {
11 public override void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, WebConnection user, int permissionLevel) {
12 if (string.IsNullOrEmpty (req.QueryString ["command"])) {
13 resp.StatusCode = (int)HttpStatusCode.BadRequest;
14 Web.SetResponseTextContent (resp, "No command given");
15 return;
16 }
17
18 string commandName = req.QueryString ["command"];
19
20 IConsoleCommand command = SdtdConsole.Instance.GetCommand (commandName);
21
22 if (command == null) {
23 resp.StatusCode = (int)HttpStatusCode.NotImplemented;
24 Web.SetResponseTextContent (resp, "Unknown command");
25 return;
26 }
27
28 AdminToolsCommandPermissions atcp = GameManager.Instance.adminTools.GetAdminToolsCommandPermission (command.GetCommands ());
29
30 if (permissionLevel > atcp.PermissionLevel) {
31 resp.StatusCode = (int)HttpStatusCode.Forbidden;
32 Web.SetResponseTextContent (resp, "You are not allowed to execute this command");
33 return;
34 }
35
36 // TODO: Execute command (store resp as IConsoleConnection instance to deliver response to the single client?)
37
38// JSONObject result = new JSONObject ();
39// result.Add ("claimsize", new JSONNumber (GamePrefs.GetInt (EnumGamePrefs.LandClaimSize)));
40//
41// JSONArray claimOwners = new JSONArray ();
42// result.Add ("claimowners", claimOwners);
43//
44// Dictionary<Vector3i, PersistentPlayerData> d = GameManager.Instance.GetPersistentPlayerList ().m_lpBlockMap;
45// if (d != null) {
46// World w = GameManager.Instance.World;
47// Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> ();
48// foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) {
49// if (steamid.Length == 0 || kvp.Value.PlayerId.Equals (steamid)) {
50// if (!owners.ContainsKey (kvp.Value)) {
51// owners.Add (kvp.Value, new List<Vector3i> ());
52// }
53// owners [kvp.Value].Add (kvp.Key);
54// }
55// }
56//
57// foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
58// if (steamid.Length == 0 || kvp.Key.PlayerId.Equals (steamid)) {
59// string curID = kvp.Key.PlayerId;
60// bool isActive = w.IsLandProtectionValidForPlayer (kvp.Key);
61//
62// JSONObject owner = new JSONObject ();
63// claimOwners.Add (owner);
64//
65// owner.Add ("steamid", new JSONString (curID));
66// owner.Add ("claimactive", new JSONBoolean (isActive));
67//
68// JSONArray claims = new JSONArray ();
69// owner.Add ("claims", claims);
70//
71// foreach (Vector3i v in kvp.Value) {
72// JSONObject claim = new JSONObject ();
73// claim.Add ("x", new JSONNumber (v.x));
74// claim.Add ("y", new JSONNumber (v.y));
75// claim.Add ("z", new JSONNumber (v.z));
76//
77// claims.Add (claim);
78// }
79// }
80// }
81// }
82//
83// WriteJSON (resp, result);
84 }
85 }
86}
87
Note: See TracBrowser for help on using the repository browser.