Changeset 369 for binary-improvements/AllocsCommands/Commands
- Timestamp:
- Nov 9, 2021, 6:28:33 PM (3 years ago)
- Location:
- binary-improvements/AllocsCommands/Commands
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/AllocsCommands/Commands/ListKnownPlayers.cs
r359 r369 1 using System;2 1 using System.Collections.Generic; 3 2 using AllocsFixes.PersistentData; … … 14 13 " 2. listknownplayers -online\n" + 15 14 " 3. listknownplayers -notbanned\n" + 16 " 4. listknownplayers <player name / steamid>\n" +15 " 4. listknownplayers <player name / userid>\n" + 17 16 "1. Lists all players that have ever been online\n" + 18 17 "2. Lists only the players that are currently online\n" + 19 18 "3. Lists only the players that are not banned\n" + 20 "4. Lists all players whose name contains the given string or matches the given SteamID";19 "4. Lists all players whose name contains the given string or matches the given UserID"; 21 20 } 22 21 … … 31 30 bool notBannedOnly = false; 32 31 string nameFilter = string.Empty; 33 bool isSteamId = false;32 PlatformUserIdentifierAbs userIdFilter = null; 34 33 35 34 if (_params.Count == 1) { 36 long steamid;37 35 if (_params [0].EqualsCaseInsensitive ("-online")) { 38 36 onlineOnly = true; 39 37 } else if (_params [0].EqualsCaseInsensitive ("-notbanned")) { 40 38 notBannedOnly = true; 41 } else if ( _params [0].Length == 17 && long.TryParse (_params [0], out steamid)) {42 isSteamId = true;39 } else if (PlatformUserIdentifierAbs.TryFromCombinedString (_params [0], out userIdFilter)) { 40 // if true nothing to do, set by the out parameter 43 41 } else { 44 42 nameFilter = _params [0]; … … 46 44 } 47 45 48 if ( isSteamId) {49 Player p = PersistentContainer.Instance.Players [ _params [0], false];46 if (userIdFilter != null) { 47 Player p = PersistentContainer.Instance.Players [userIdFilter, false]; 50 48 51 49 if (p != null) { 52 SdtdConsole.Instance.Output (string.Format ( 53 "{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}", 54 0, p.Name, p.EntityID, _params [0], p.IsOnline, p.IP, 55 p.TotalPlayTime / 60, 56 p.LastOnline.ToString ("yyyy-MM-dd HH:mm")) 50 SdtdConsole.Instance.Output ( 51 $"{0}. {p.Name}, id={p.EntityID}, steamid={_params [0]}, online={p.IsOnline}, ip={p.IP}, playtime={p.TotalPlayTime / 60} m, seen={p.LastOnline:yyyy-MM-dd HH:mm}" 57 52 ); 58 53 } else { 59 SdtdConsole.Instance.Output ( string.Format ("SteamID {0} unknown!", _params [0]));54 SdtdConsole.Instance.Output ($"SteamID {_params [0]} unknown!"); 60 55 } 61 56 } else { 62 57 int num = 0; 63 foreach (KeyValuePair< string, Player> kvp in PersistentContainer.Instance.Players.Dict) {58 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in PersistentContainer.Instance.Players.Dict) { 64 59 Player p = kvp.Value; 65 60 66 61 if ( 67 62 (!onlineOnly || p.IsOnline) 68 && (!notBannedOnly || !admTools.IsBanned (kvp.Key ))63 && (!notBannedOnly || !admTools.IsBanned (kvp.Key, out _, out _)) 69 64 && (nameFilter.Length == 0 || p.Name.ContainsCaseInsensitive (nameFilter)) 70 65 ) { 71 SdtdConsole.Instance.Output (string.Format ( 72 "{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}", 73 ++num, p.Name, p.EntityID, kvp.Key, p.IsOnline, p.IP, 74 p.TotalPlayTime / 60, 75 p.LastOnline.ToString ("yyyy-MM-dd HH:mm")) 66 SdtdConsole.Instance.Output ( 67 $"{++num}. {p.Name}, id={p.EntityID}, steamid={kvp.Key}, online={p.IsOnline}, ip={p.IP}, playtime={p.TotalPlayTime / 60} m, seen={p.LastOnline:yyyy-MM-dd HH:mm}" 76 68 ); 77 69 } 78 70 } 79 71 80 SdtdConsole.Instance.Output ( "Total of " + PersistentContainer.Instance.Players.Count + "known");72 SdtdConsole.Instance.Output ($"Total of {PersistentContainer.Instance.Players.Count} known"); 81 73 } 82 74 } -
binary-improvements/AllocsCommands/Commands/ListLandProtection.cs
r359 r369 12 12 return "Usage:\n" + 13 13 " 1. listlandprotection summary\n" + 14 " 2. listlandprotection < steamid / player name / entity id> [parseable]\n" +14 " 2. listlandprotection <user id / player name / entity id> [parseable]\n" + 15 15 " 3. listlandprotection nearby [length]\n" + 16 16 "1. Lists only players that own claimstones, the number they own and the protection status\n" + 17 "2. Lists only the claims of the player given by his SteamID / entity id / playername, including the individual claim positions.\n" +17 "2. Lists only the claims of the player given by his UserID / entity id / playername, including the individual claim positions.\n" + 18 18 " If \"parseable\" is specified the output of the individual claims will be in a format better suited for programmatical readout.\n" + 19 19 "3. Lists claims in a square with edge length of 64 (or the optionally specified size) around the executing player\n"; … … 25 25 26 26 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) { 27 if (_senderInfo.RemoteClientInfo != null) { 28 if (_params.Count >= 1 && _params [0].EqualsCaseInsensitive ("nearby")) { 29 _params.Add (_senderInfo.RemoteClientInfo.playerId); 27 if (_params.Count >= 1 && _params [0].EqualsCaseInsensitive ("nearby")) { 28 if (_senderInfo.RemoteClientInfo != null) { 29 _params.Add (_senderInfo.RemoteClientInfo.entityId.ToString ()); 30 } else if (_senderInfo.IsLocalGame && !GameManager.IsDedicatedServer) { 31 _params.Add (GameManager.Instance.World.GetPrimaryPlayerId ().ToString ()); 30 32 } 31 33 } … … 35 37 36 38 bool summaryOnly = false; 37 string steamIdFilter = string.Empty;39 PlatformUserIdentifierAbs userIdFilter = null; 38 40 Vector3i closeTo = default (Vector3i); 39 41 bool onlyCloseToPlayer = false; … … 47 49 48 50 if (_params.Count == 1) { 49 long tempLong;50 51 51 if (_params [0].EqualsCaseInsensitive ("summary")) { 52 52 summaryOnly = true; 53 } else if (_params [0].Length == 17 && long.TryParse (_params [0], out tempLong)) { 54 steamIdFilter = _params [0]; 53 } else if (PlatformUserIdentifierAbs.TryFromCombinedString (_params[0], out userIdFilter)) { 55 54 } else { 56 55 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]); 57 56 if (ci != null) { 58 steamIdFilter = ci.playerId;57 userIdFilter = ci.PlatformId; 59 58 } else { 60 59 SdtdConsole.Instance.Output ("Player name or entity id \"" + _params [0] + "\" not found."); … … 74 73 } 75 74 76 ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]);77 EntityPlayer ep = w.Players.dict [ ci.entityId];75 int entityId = int.Parse (_params [_params.Count - 1]); 76 EntityPlayer ep = w.Players.dict [entityId]; 78 77 closeTo = new Vector3i (ep.GetPosition ()); 79 78 onlyCloseToPlayer = true; … … 91 90 92 91 LandClaimList.OwnerFilter[] ownerFilters = null; 93 if ( !string.IsNullOrEmpty (steamIdFilter)) {94 ownerFilters = new[] {LandClaimList. SteamIdFilter (steamIdFilter)};92 if (userIdFilter != null) { 93 ownerFilters = new[] {LandClaimList.UserIdFilter (userIdFilter)}; 95 94 } 96 95 … … 106 105 "Player \"{0} ({1})\" owns {4} keystones (protected: {2}, current hardness multiplier: {3})", 107 106 kvp.Key.Name, 108 kvp.Key. SteamID,107 kvp.Key.PlatformId, 109 108 kvp.Key.LandProtectionActive, 110 109 kvp.Key.LandProtectionMultiplier, … … 113 112 foreach (Vector3i v in kvp.Value) { 114 113 if (parseableOutput) { 115 SdtdConsole.Instance.Output ("LandProtectionOf: id=" + kvp.Key. SteamID+114 SdtdConsole.Instance.Output ("LandProtectionOf: id=" + kvp.Key.PlatformId + 116 115 ", playerName=" + kvp.Key.Name + ", location=" + v); 117 116 } else { … … 122 121 } 123 122 124 if ( string.IsNullOrEmpty (steamIdFilter)) {123 if (userIdFilter == null) { 125 124 SdtdConsole.Instance.Output ("Total of " + ppl.m_lpBlockMap.Count + " keystones in the game"); 126 125 } -
binary-improvements/AllocsCommands/Commands/RemoveLandProtection.cs
r359 r369 11 11 public override string GetHelp () { 12 12 return "Usage:" + 13 " 1. removelandprotection < steamid>\n" +13 " 1. removelandprotection <userid>\n" + 14 14 " 2. removelandprotection <x> <y> <z>\n" + 15 15 " 3. removelandprotection nearby [length]\n" + 16 "1. Remove all land claims owned by the user with the given SteamID\n" +16 "1. Remove all land claims owned by the user with the given UserID\n" + 17 17 "2. Remove only the claim block on the exactly given block position\n" + 18 18 "3. Remove all claims in a square with edge length of 64 (or the optionally specified size) around the executing player"; … … 25 25 private void removeById (string _id) { 26 26 try { 27 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList (); 28 29 if (_id.Length < 1 || !ppl.Players.ContainsKey (_id)) { 27 if (!PlatformUserIdentifierAbs.TryFromCombinedString (_id, out PlatformUserIdentifierAbs userId)) { 30 28 SdtdConsole.Instance.Output ( 31 29 "Not a valid Steam ID or user has never logged on. Use \"listlandprotection\" to get a list of keystones."); 32 30 return; 33 31 } 32 33 PersistentPlayerList ppl = GameManager.Instance.GetPersistentPlayerList (); 34 34 35 if (ppl.Players [ _id].LPBlocks == null || ppl.Players [_id].LPBlocks.Count == 0) {35 if (ppl.Players [userId].LPBlocks == null || ppl.Players [userId].LPBlocks.Count == 0) { 36 36 SdtdConsole.Instance.Output ( 37 37 "Player does not own any keystones. Use \"listlandprotection\" to get a list of keystones."); … … 40 40 41 41 List<BlockChangeInfo> changes = new List<BlockChangeInfo> (); 42 foreach (Vector3i pos in ppl.Players [ _id].LPBlocks) {42 foreach (Vector3i pos in ppl.Players [userId].LPBlocks) { 43 43 BlockChangeInfo bci = new BlockChangeInfo (pos, new BlockValue (0), true, false); 44 44 changes.Add (bci); … … 58 58 59 59 private void removeByPosition (List<string> _coords) { 60 int x, y, z; 61 int.TryParse (_coords [0], out x); 62 int.TryParse (_coords [1], out y); 63 int.TryParse (_coords [2], out z); 60 int.TryParse (_coords [0], out int x); 61 int.TryParse (_coords [1], out int y); 62 int.TryParse (_coords [2], out int z); 64 63 65 64 if (x == int.MinValue || y == int.MinValue || z == int.MinValue) { … … 81 80 BlockChangeInfo bci = new BlockChangeInfo (v, new BlockValue (0), true, false); 82 81 83 List<BlockChangeInfo> changes = new List<BlockChangeInfo> (); 84 changes.Add (bci); 82 List<BlockChangeInfo> changes = new List<BlockChangeInfo> {bci}; 85 83 86 84 GameManager.Instance.SetBlocksRPC (changes); … … 90 88 91 89 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) { 92 try{90 if (_params.Count > 0 && _params [0].EqualsCaseInsensitive ("nearby")) { 93 91 if (_senderInfo.RemoteClientInfo != null) { 94 if (_params.Count >= 1 && _params [0].EqualsCaseInsensitive ("nearby")) {95 _params.Add (_senderInfo.RemoteClientInfo.playerId);96 }92 _params.Add (_senderInfo.RemoteClientInfo.entityId.ToString ()); 93 } else if (_senderInfo.IsLocalGame && !GameManager.IsDedicatedServer) { 94 _params.Add (GameManager.Instance.World.GetPrimaryPlayerId ().ToString ()); 97 95 } 98 96 99 if (_params.Count > 0 && _params [0].EqualsCaseInsensitive ("nearby")) { 100 try { 101 int closeToDistance = 32; 102 if (_params.Count == 3) { 103 if (!int.TryParse (_params [1], out closeToDistance)) { 104 SdtdConsole.Instance.Output ("Given length is not an integer!"); 105 return; 106 } 107 108 closeToDistance /= 2; 97 try { 98 int closeToDistance = 32; 99 if (_params.Count == 3) { 100 if (!int.TryParse (_params [1], out closeToDistance)) { 101 SdtdConsole.Instance.Output ("Given length is not an integer!"); 102 return; 109 103 } 110 104 111 ClientInfo ci = ConsoleHelper.ParseParamSteamIdOnline (_params [_params.Count - 1]); 112 EntityPlayer ep = GameManager.Instance.World.Players.dict [ci.entityId]; 113 Vector3i closeTo = new Vector3i (ep.GetPosition ()); 114 LandClaimList.PositionFilter[] posFilters = 115 {LandClaimList.CloseToFilter2dRect (closeTo, closeToDistance)}; 116 Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (null, posFilters); 105 closeToDistance /= 2; 106 } 117 107 118 try { 119 List<BlockChangeInfo> changes = new List<BlockChangeInfo> (); 120 foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) { 121 foreach (Vector3i v in kvp.Value) { 122 BlockChangeInfo bci = new BlockChangeInfo (v, new BlockValue (0), true, false); 123 changes.Add (bci); 124 } 108 int entityId = int.Parse (_params [_params.Count - 1]); 109 EntityPlayer ep = GameManager.Instance.World.Players.dict [entityId]; 110 Vector3i closeTo = new Vector3i (ep.GetPosition ()); 111 LandClaimList.PositionFilter[] posFilters = 112 {LandClaimList.CloseToFilter2dRect (closeTo, closeToDistance)}; 113 Dictionary<Player, List<Vector3i>> claims = LandClaimList.GetLandClaims (null, posFilters); 114 115 try { 116 List<BlockChangeInfo> changes = new List<BlockChangeInfo> (); 117 foreach (KeyValuePair<Player, List<Vector3i>> kvp in claims) { 118 foreach (Vector3i v in kvp.Value) { 119 BlockChangeInfo bci = new BlockChangeInfo (v, new BlockValue (0), true, false); 120 changes.Add (bci); 125 121 } 122 } 126 123 127 GameManager.Instance.SetBlocksRPC (changes); 128 } catch (Exception e) { 129 SdtdConsole.Instance.Output ("Error removing claims"); 130 Log.Out ("Error in RemoveLandProtection.Run: " + e); 131 } 124 GameManager.Instance.SetBlocksRPC (changes); 132 125 } catch (Exception e) { 133 SdtdConsole.Instance.Output ("Error getting current player's position");126 SdtdConsole.Instance.Output ("Error removing claims"); 134 127 Log.Out ("Error in RemoveLandProtection.Run: " + e); 135 128 } 136 } else if (_params.Count == 1) { 137 removeById (_params [0]); 138 } else if (_params.Count == 3) { 139 removeByPosition (_params); 140 } else { 141 SdtdConsole.Instance.Output ("Illegal parameters"); 129 } catch (Exception e) { 130 SdtdConsole.Instance.Output ("Error getting current player's position"); 131 Log.Out ("Error in RemoveLandProtection.Run: " + e); 142 132 } 143 } catch (Exception e) { 144 Log.Out ("Error in RemoveLandProtection.Run: " + e); 133 } else if (_params.Count == 1) { 134 removeById (_params [0]); 135 } else if (_params.Count == 3) { 136 removeByPosition (_params); 137 } else { 138 SdtdConsole.Instance.Output ("Illegal parameters"); 145 139 } 146 140 } -
binary-improvements/AllocsCommands/Commands/ShowInventory.cs
r359 r369 11 11 public override string GetHelp () { 12 12 return "Usage:\n" + 13 " showinventory < steamid / player name / entity id> [tag]\n" +14 "Show the inventory of the player given by his SteamID, player name or\n" +13 " showinventory <user id / player name / entity id> [tag]\n" + 14 "Show the inventory of the player given by his UserID, player name or\n" + 15 15 "entity id (as given by e.g. \"lpi\").\n" + 16 16 "Optionally specify a tag that is included in each line of the output. In\n" + … … 30 30 } 31 31 32 stringsteamid = PersistentContainer.Instance.Players.GetSteamID (_params [0], true);32 PlatformUserIdentifierAbs steamid = PersistentContainer.Instance.Players.GetSteamID (_params [0], true); 33 33 if (steamid == null) { 34 34 SdtdConsole.Instance.Output (
Note:
See TracChangeset
for help on using the changeset viewer.