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

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

Server fixes for A12

File size: 4.7 KB
RevLine 
[224]1using System;
2using System.Collections.Generic;
3
4namespace AllocsFixes.CustomCommands
5{
[230]6 public class ListLandProtection : ConsoleCmdAbstract
[224]7 {
[230]8 public override string GetDescription ()
[224]9 {
10 return "lists all land protection blocks and owners";
11 }
12
[238]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
[230]27 public override string[] GetCommands ()
[224]28 {
29 return new string[] { "listlandprotection", "llp" };
30 }
31
[230]32 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
[224]33 {
34 try {
[230]35 if (_senderInfo.RemoteClientInfo != null) {
36 if (_params.Count >= 1 && _params [0].ToLower ().Equals ("nearby")) {
37 _params.Add (_senderInfo.RemoteClientInfo.playerId);
38 }
[224]39 }
40
[230]41 World w = GameManager.Instance.World;
42 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList ();
[224]43
44 bool summaryOnly = false;
45 string steamIdFilter = string.Empty;
46 Vector3i closeTo = default(Vector3i);
47 bool onlyCloseToPlayer = false;
48 int closeToDistance = 32;
49
[230]50 if (_params.Count == 1) {
[224]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 {
[230]58 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
[224]59 if (ci != null) {
[230]60 steamIdFilter = ci.playerId;
[224]61 } else {
[230]62 SdtdConsole.Instance.Output ("Player name or entity id \"" + _params [0] + "\" not found.");
[224]63 return;
64 }
65 }
[230]66 } else if (_params.Count >= 2) {
[224]67 if (_params [0].ToLower ().Equals ("nearby")) {
68 try {
[230]69 if (_params.Count == 3) {
[224]70 if (!int.TryParse (_params[1], out closeToDistance)) {
[230]71 SdtdConsole.Instance.Output ("Given radius is not an integer!");
[224]72 }
73 }
[230]74 ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]);
75 EntityPlayer ep = w.Players.dict [ci.entityId];
[224]76 closeTo = new Vector3i (ep.GetPosition ());
77 onlyCloseToPlayer = true;
78 } catch (Exception e) {
[230]79 SdtdConsole.Instance.Output ("Error getting current player's position");
[224]80 Log.Out ("Error in ListLandProtection.Run: " + e);
81 }
82 } else {
[230]83 SdtdConsole.Instance.Output ("Illegal parameter list");
[224]84 return;
85 }
86 }
87
[238]88 Dictionary<Vector3i, PersistentPlayerData> d = ppl.m_lpBlockMap;
[224]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)) {
[233]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 }
[224]107 name += " (" + kvp.Key.PlayerId + ")";
108
[238]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));
[224]110 if (!summaryOnly) {
111 foreach (Vector3i v in kvp.Value) {
[230]112 SdtdConsole.Instance.Output (" (" + v.ToString () + ")");
[224]113 }
114 }
115 }
116 }
117 }
118
119 if (steamIdFilter.Length == 0)
[230]120 SdtdConsole.Instance.Output ("Total of " + d.Count + " keystones in the game");
[224]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.