source: binary-improvements/7dtd-server-fixes/src/CustomCommands/RemoveLandProtection.cs@ 207

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

Server fixes

File size: 3.4 KB
RevLine 
[113]1using System;
2using System.Collections.Generic;
3
[130]4namespace AllocsFixes.CustomCommands
[113]5{
[130]6 public class RemoveLandProtection : ConsoleCommand
[113]7 {
[130]8 public RemoveLandProtection (ConsoleSdtd cons) : base(cons)
9 {
10 }
[113]11
[130]12 public override string Description ()
13 {
14 return "removes the association of a land protection block to the owner";
15 }
[113]16
[130]17 public override string[] Names ()
18 {
19 return new string[] { "removelandprotection", "rlp" };
20 }
[113]21
[130]22 private void removeById (string _id)
23 {
24 try {
25 PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList ();
[123]26
[130]27 if (_id.Length < 1 || !ppl.Players.ContainsKey (_id)) {
28 m_Console.SendResult ("Not a valid Steam ID or user has never logged on. Use \"listlandprotection\" to get a list of keystones.");
29 return;
30 }
31 if (ppl.Players [_id].LPBlocks == null || ppl.Players [_id].LPBlocks.Count == 0) {
32 m_Console.SendResult ("Player does not own any keystones. Use \"listlandprotection\" to get a list of keystones.");
33 return;
34 }
[113]35
[130]36 List<BlockChangeInfo> changes = new List<BlockChangeInfo> ();
37 foreach (Vector3i pos in ppl.Players[_id].LPBlocks) {
38 BlockChangeInfo bci = new BlockChangeInfo (pos, 0, true);
39 changes.Add (bci);
40 }
41 CommonMappingFunctions.GetGameManager ().SetBlocksRPC (changes);
42
[202]43 m_Console.SendResult ("Tried to remove #" + changes.Count + " land protection blocks for player \"" + _id + "\". Note "+
44 "that only blocks in chunks that are currently loaded (close to any player) could be removed. "+
45 "Please check for remaining blocks by running:");
46 m_Console.SendResult(" listlandprotection " + _id);
[130]47 } catch (Exception e) {
48 Log.Out ("Error in RemoveLandProtection.removeById: " + e);
[123]49 }
50 }
51
[130]52 private void removeByPosition (string[] _coords)
53 {
54 try {
55 int x = int.MinValue;
56 int.TryParse (_coords [0], out x);
57 int y = int.MinValue;
58 int.TryParse (_coords [1], out y);
59 int z = int.MinValue;
60 int.TryParse (_coords [2], out z);
[113]61
[130]62 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) {
63 m_Console.SendResult ("At least one of the given coordinates is not a valid integer");
64 return;
65 }
[113]66
[130]67 Vector3i v = new Vector3i (x, y, z);
[113]68
[130]69 PersistentPlayerList ppl = CommonMappingFunctions.GetGameManager ().GetPersistentPlayerList ();
[113]70
[130]71 Dictionary<Vector3i, PersistentPlayerData> d = ppl.positionToLPBlockOwner;
72 if (d == null || !d.ContainsKey (v)) {
73 m_Console.SendResult ("No land protection block at the given position or not a valid position. Use \"listlandprotection\" to get a list of keystones.");
74 return;
75 }
[113]76
[130]77 BlockChangeInfo bci = new BlockChangeInfo (v, 0, true);
[123]78
[130]79 List<BlockChangeInfo> changes = new List<BlockChangeInfo> ();
80 changes.Add (bci);
[123]81
[130]82 CommonMappingFunctions.GetGameManager ().SetBlocksRPC (changes);
[123]83
[130]84 m_Console.SendResult ("Land protection block at (" + v.ToString () + ") removed");
85 } catch (Exception e) {
86 Log.Out ("Error in RemoveLandProtection.removeByPosition: " + e);
87 }
[123]88 }
89
[130]90 public override void Run (string[] _params)
91 {
92 try {
93 if (_params.Length == 1) {
94 removeById (_params [0]);
95 } else if (_params.Length == 3) {
96 removeByPosition (_params);
97 } else {
98 m_Console.SendResult ("Usage: removelandprotection <x> <y> <z> OR removelandprotection <steamid>");
99 }
100 } catch (Exception e) {
101 Log.Out ("Error in RemoveLandProtection.Run: " + e);
[123]102 }
[113]103 }
104 }
105}
Note: See TracBrowser for help on using the repository browser.