source: binary-improvements/7dtd-server-fixes/src/CustomCommands/ListLandProtection.cs@ 208

Last change on this file since 208 was 202, checked in by alloc, 10 years ago

Server fixes

File size: 4.1 KB
RevLine 
[113]1using System;
2using System.Collections.Generic;
3
[130]4namespace AllocsFixes.CustomCommands
[113]5{
[130]6 public class ListLandProtection : ConsoleCommand
[113]7 {
[130]8 public ListLandProtection (ConsoleSdtd cons) : base(cons)
9 {
10 }
[113]11
[130]12 public override string Description ()
13 {
14 return "lists all land protection blocks and owners";
15 }
[113]16
[130]17 public override string[] Names ()
18 {
19 return new string[] { "listlandprotection", "llp" };
20 }
[113]21
[202]22 public override void ExecuteRemote (string _sender, string[] _params)
23 {
24 try {
25 if (_params.Length >= 1 && _params [0].ToLower ().Equals ("nearby")) {
26 string[] params2 = new string[_params.Length + 1];
27 for (int i = 0; i < _params.Length; i++)
28 params2 [i] = _params [i];
29 params2 [_params.Length] = _sender;
30 _params = params2;
31 }
32 Run (_params);
33 } catch (Exception e) {
34 Log.Out ("Error in ListLandProtection.ExecuteRemote: " + e);
35 }
36 }
37
[130]38 public override void Run (string[] _params)
39 {
40 try {
41 World w = CommonMappingFunctions.GetGameManager ().World;
42 PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList ();
[113]43
[139]44 bool summaryOnly = false;
45 string steamIdFilter = string.Empty;
[202]46 Vector3i closeTo = default(Vector3i);
47 bool onlyCloseToPlayer = false;
48 int closeToDistance = 32;
[139]49
50 if (_params.Length == 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 = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], true);
59 if (ci != null) {
60 steamIdFilter = CommonMappingFunctions.GetSteamID (ci);
61 } else {
62 m_Console.SendResult ("Player name or entity id \"" + _params [0] + "\" not found.");
63 return;
64 }
65 }
[202]66 } else if (_params.Length >= 2) {
67 if (_params [0].ToLower ().Equals ("nearby")) {
68 try {
69 if (_params.Length == 3) {
70 if (!int.TryParse (_params[1], out closeToDistance)) {
71 m_Console.SendResult ("Given radius is not an integer!");
72 }
73 }
74 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromSteamID (_params [_params.Length - 1]);
75 EntityPlayer ep = CommonMappingFunctions.GetEntityPlayer (ci);
76 closeTo = new Vector3i (ep.GetPosition ());
77 onlyCloseToPlayer = true;
78 } catch (Exception e) {
79 m_Console.SendResult ("Error getting current player's position");
80 Log.Out ("Error in ListLandProtection.Run: " + e);
81 }
82 } else {
83 m_Console.SendResult ("Illegal parameter list");
84 return;
85 }
[139]86 }
87
[130]88 Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner;
89 if (d != null) {
90 Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> ();
91 foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) {
[202]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);
[130]97 }
[113]98 }
99
[130]100 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
[139]101 if (steamIdFilter.Length == 0 || kvp.Key.PlayerId.Equals (steamIdFilter)) {
[202]102 string name = PersistentData.PersistentContainer.Instance.Players [kvp.Key.PlayerId].Name;
[139]103 name += " (" + kvp.Key.PlayerId + ")";
[113]104
[139]105 m_Console.SendResult (String.Format ("Player \"{0}\" owns {3} keystones (protected: {1}, current hardness multiplier: {2})", name, w.LandClaimIsActive (kvp.Key), w.LandClaimPower (kvp.Key), kvp.Value.Count));
106 if (!summaryOnly) {
107 foreach (Vector3i v in kvp.Value) {
108 m_Console.SendResult (" (" + v.ToString () + ")");
109 }
110 }
[130]111 }
[113]112 }
113 }
[130]114
[139]115 if (steamIdFilter.Length == 0)
116 m_Console.SendResult ("Total of " + d.Count + " keystones in the game");
[130]117 } catch (Exception e) {
118 Log.Out ("Error in ListLandProtection.Run: " + e);
[113]119 }
120 }
121 }
122}
Note: See TracBrowser for help on using the repository browser.