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

Last change on this file since 145 was 139, checked in by alloc, 10 years ago

Fixes: fixed #43

File size: 2.7 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 ClientInfo ci = CommonMappingFunctions.GetClientInfoFromEntityID (kvp.Key.EntityId);
62 string name = string.Empty;
63 if (ci != null) {
64 name = CommonMappingFunctions.GetPlayerName (ci);
65 }
66 name += " (" + kvp.Key.PlayerId + ")";
67
68 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));
69 if (!summaryOnly) {
70 foreach (Vector3i v in kvp.Value) {
71 m_Console.SendResult (" (" + v.ToString () + ")");
72 }
73 }
74 }
75 }
76 }
77
78 if (steamIdFilter.Length == 0)
79 m_Console.SendResult ("Total of " + d.Count + " keystones in the game");
80 } catch (Exception e) {
81 Log.Out ("Error in ListLandProtection.Run: " + e);
82 }
83 }
84 }
85}
Note: See TracBrowser for help on using the repository browser.