source: binary-improvements/AllocsCommands/Commands/ListLandProtection.cs@ 246

Last change on this file since 246 was 238, checked in by alloc, 9 years ago

Server fixes for A12

File size: 4.7 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace AllocsFixes.CustomCommands
5{
6 public class ListLandProtection : ConsoleCmdAbstract
7 {
8 public override string GetDescription ()
9 {
10 return "lists all land protection blocks and owners";
11 }
12
13 public override string GetHelp () {
14 return "Usage:\n" +
15 " 1. listlandprotection summary\n" +
16 " 2. listlandprotection <steam id>\n" +
17 " 3. listlandprotection <player name / entity id>\n" +
18 " 4. listlandprotection nearby\n" +
19 " 5. listlandprotection nearby <radius>\n" +
20 "1. Lists only players that own claimstones, the number they own and the protection status\n" +
21 "2. Lists only the claims of the player given by his SteamID including the individual claim positions\n" +
22 "3. Same as 2 but player given by his player name or entity id (as given by e.g. \"lpi\")\n" +
23 "4. Lists claims in a square with edge length of 64 around the executing player\n" +
24 "5. Same as 4 but square edge length can be specified";
25 }
26
27 public override string[] GetCommands ()
28 {
29 return new string[] { "listlandprotection", "llp" };
30 }
31
32 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
33 {
34 try {
35 if (_senderInfo.RemoteClientInfo != null) {
36 if (_params.Count >= 1 && _params [0].ToLower ().Equals ("nearby")) {
37 _params.Add (_senderInfo.RemoteClientInfo.playerId);
38 }
39 }
40
41 World w = GameManager.Instance.World;
42 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
43
44 bool summaryOnly = false;
45 string steamIdFilter = string.Empty;
46 Vector3i closeTo = default(Vector3i);
47 bool onlyCloseToPlayer = false;
48 int closeToDistance = 32;
49
50 if (_params.Count == 1) {
51 long tempLong;
52
53 if (_params [0].ToLower ().Equals ("summary")) {
54 summaryOnly = true;
55 } else if (_params [0].Length == 17 && long.TryParse (_params [0], out tempLong)) {
56 steamIdFilter = _params [0];
57 } else {
58 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
59 if (ci != null) {
60 steamIdFilter = ci.playerId;
61 } else {
62 SdtdConsole.Instance.Output ("Player name or entity id \"" + _params [0] + "\" not found.");
63 return;
64 }
65 }
66 } else if (_params.Count >= 2) {
67 if (_params [0].ToLower ().Equals ("nearby")) {
68 try {
69 if (_params.Count == 3) {
70 if (!int.TryParse (_params[1], out closeToDistance)) {
71 SdtdConsole.Instance.Output ("Given radius is not an integer!");
72 }
73 }
74 ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]);
75 EntityPlayer ep = w.Players.dict [ci.entityId];
76 closeTo = new Vector3i (ep.GetPosition ());
77 onlyCloseToPlayer = true;
78 } catch (Exception e) {
79 SdtdConsole.Instance.Output ("Error getting current player's position");
80 Log.Out ("Error in ListLandProtection.Run: " + e);
81 }
82 } else {
83 SdtdConsole.Instance.Output ("Illegal parameter list");
84 return;
85 }
86 }
87
88 Dictionary<Vector3i, PersistentPlayerData> d = ppl.m_lpBlockMap;
89 if (d != null) {
90 Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> ();
91 foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) {
92 if (!onlyCloseToPlayer || (Math.Abs (kvp.Key.x - closeTo.x) <= closeToDistance && Math.Abs (kvp.Key.z - closeTo.z) <= closeToDistance)) {
93 if (!owners.ContainsKey (kvp.Value)) {
94 owners.Add (kvp.Value, new List<Vector3i> ());
95 }
96 owners [kvp.Value].Add (kvp.Key);
97 }
98 }
99
100 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
101 if (steamIdFilter.Length == 0 || kvp.Key.PlayerId.Equals (steamIdFilter)) {
102 PersistentData.Player p = PersistentData.PersistentContainer.Instance.Players [kvp.Key.PlayerId, false];
103 string name = string.Empty;
104 if (p != null) {
105 name = p.Name;
106 }
107 name += " (" + kvp.Key.PlayerId + ")";
108
109 SdtdConsole.Instance.Output (String.Format ("Player \"{0}\" owns {3} keystones (protected: {1}, current hardness multiplier: {2})", name, w.IsLandProtectionValidForPlayer (kvp.Key), w.GetLandProtectionHardnessModifierForPlayer (kvp.Key), kvp.Value.Count));
110 if (!summaryOnly) {
111 foreach (Vector3i v in kvp.Value) {
112 SdtdConsole.Instance.Output (" (" + v.ToString () + ")");
113 }
114 }
115 }
116 }
117 }
118
119 if (steamIdFilter.Length == 0)
120 SdtdConsole.Instance.Output ("Total of " + d.Count + " keystones in the game");
121 } catch (Exception e) {
122 Log.Out ("Error in ListLandProtection.Run: " + e);
123 }
124 }
125 }
126}
Note: See TracBrowser for help on using the repository browser.