source: binary-improvements2/CommandExtensions/src/Commands/ListKnownPlayers.cs@ 420

Last change on this file since 420 was 405, checked in by alloc, 21 months ago

Refactored console commands for A21 caching

File size: 2.8 KB
RevLine 
[391]1using System.Collections.Generic;
2using AllocsFixes.PersistentData;
3using JetBrains.Annotations;
4
5namespace CommandExtensions.Commands {
6 [UsedImplicitly]
7 public class ListKnownPlayers : ConsoleCmdAbstract {
[405]8 protected override string getDescription () {
[391]9 return "lists all players that were ever online";
10 }
11
[405]12 protected override string getHelp () {
[391]13 return "Usage:\n" +
14 " 1. listknownplayers\n" +
15 " 2. listknownplayers -online\n" +
16 " 3. listknownplayers -notbanned\n" +
17 " 4. listknownplayers <player name / userid>\n" +
18 "1. Lists all players that have ever been online\n" +
19 "2. Lists only the players that are currently online\n" +
20 "3. Lists only the players that are not banned\n" +
21 "4. Lists all players whose name contains the given string or matches the given UserID";
22 }
23
[405]24 protected override string[] getCommands () {
[391]25 return new[] {"listknownplayers", "lkp"};
26 }
27
28 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
29 AdminTools admTools = GameManager.Instance.adminTools;
30
31 bool onlineOnly = false;
32 bool notBannedOnly = false;
33 string nameFilter = string.Empty;
34 PlatformUserIdentifierAbs userIdFilter = null;
35
36 if (_params.Count == 1) {
37 if (_params [0].EqualsCaseInsensitive ("-online")) {
38 onlineOnly = true;
39 } else if (_params [0].EqualsCaseInsensitive ("-notbanned")) {
40 notBannedOnly = true;
41 } else if (PlatformUserIdentifierAbs.TryFromCombinedString (_params [0], out userIdFilter)) {
42 // if true nothing to do, set by the out parameter
43 } else {
44 nameFilter = _params [0];
45 }
46 }
47
48 if (userIdFilter != null) {
49 Player p = PersistentContainer.Instance.Players [userIdFilter, false];
50
51 if (p != null) {
52 SdtdConsole.Instance.Output (
53 $"{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}"
54 );
55 } else {
56 SdtdConsole.Instance.Output ($"SteamID {_params [0]} unknown!");
57 }
58 } else {
59 int num = 0;
60 foreach ((PlatformUserIdentifierAbs userId, Player player) in PersistentContainer.Instance.Players.Dict) {
61 if (
62 (!onlineOnly || player.IsOnline)
[404]63 && (!notBannedOnly || !admTools.Blacklist.IsBanned (userId, out _, out _))
[391]64 && (nameFilter.Length == 0 || player.Name.ContainsCaseInsensitive (nameFilter))
65 ) {
66 SdtdConsole.Instance.Output (
67 $"{++num}. {player.Name}, id={player.EntityID}, steamid={userId}, online={player.IsOnline}, ip={player.IP}, playtime={player.TotalPlayTime / 60} m, seen={player.LastOnline:yyyy-MM-dd HH:mm}"
68 );
69 }
70 }
71
72 SdtdConsole.Instance.Output ($"Total of {PersistentContainer.Instance.Players.Count} known");
73 }
74 }
75 }
76}
Note: See TracBrowser for help on using the repository browser.