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

Last change on this file since 159 was 146, checked in by alloc, 10 years ago

Fixes

File size: 2.6 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace AllocsFixes.CustomCommands
5{
6 public class ListLandProtection : ConsoleCommand
7 {
8 public ListLandProtection (ConsoleSdtd cons) : base(cons)
9 {
10 }
11
12 public override string Description ()
13 {
14 return "lists all land protection blocks and owners";
15 }
16
17 public override string[] Names ()
18 {
19 return new string[] { "listlandprotection", "llp" };
20 }
21
22 public override void Run (string[] _params)
23 {
24 try {
25 World w = CommonMappingFunctions.GetGameManager ().World;
26 PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList ();
27
28 bool summaryOnly = false;
29 string steamIdFilter = string.Empty;
30
31 if (_params.Length == 1) {
32 long tempLong;
33
34 if (_params [0].ToLower ().Equals ("summary")) {
35 summaryOnly = true;
36 } else if (_params [0].Length == 17 && long.TryParse (_params [0], out tempLong)) {
37 steamIdFilter = _params [0];
38 } else {
39 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromNameOrID (_params [0], true);
40 if (ci != null) {
41 steamIdFilter = CommonMappingFunctions.GetSteamID (ci);
42 } else {
43 m_Console.SendResult ("Player name or entity id \"" + _params [0] + "\" not found.");
44 return;
45 }
46 }
47 }
48
49 Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner;
50 if (d != null) {
51 Dictionary<PersistentPlayerData, List<Vector3i>> owners = new Dictionary<PersistentPlayerData, List<Vector3i>> ();
52 foreach (KeyValuePair<Vector3i, PersistentPlayerData> kvp in d) {
53 if (!owners.ContainsKey (kvp.Value)) {
54 owners.Add (kvp.Value, new List<Vector3i> ());
55 }
56 owners [kvp.Value].Add (kvp.Key);
57 }
58
59 foreach (KeyValuePair<PersistentPlayerData, List<Vector3i>> kvp in owners) {
60 if (steamIdFilter.Length == 0 || kvp.Key.PlayerId.Equals (steamIdFilter)) {
61 string name = PersistentData.PersistentContainer.Instance.Players[kvp.Key.PlayerId].Name;
62 name += " (" + kvp.Key.PlayerId + ")";
63
64 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));
65 if (!summaryOnly) {
66 foreach (Vector3i v in kvp.Value) {
67 m_Console.SendResult (" (" + v.ToString () + ")");
68 }
69 }
70 }
71 }
72 }
73
74 if (steamIdFilter.Length == 0)
75 m_Console.SendResult ("Total of " + d.Count + " keystones in the game");
76 } catch (Exception e) {
77 Log.Out ("Error in ListLandProtection.Run: " + e);
78 }
79 }
80 }
81}
Note: See TracBrowser for help on using the repository browser.