source: binary-improvements/AllocsCommands/Commands/ListKnownPlayers.cs@ 461

Last change on this file since 461 was 455, checked in by alloc, 16 months ago

25_30_44

  • Got rid (mostly) of custom JSON serialization
  • Some code cleanup
File size: 2.8 KB
Line 
1using System.Collections.Generic;
2using AllocsFixes.PersistentData;
3using JetBrains.Annotations;
4
5namespace AllocsFixes.CustomCommands {
6 [UsedImplicitly]
7 public class ListKnownPlayers : ConsoleCmdAbstract {
8 protected override string getDescription () {
9 return "lists all players that were ever online";
10 }
11
12 protected override string getHelp () {
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
24 protected override string[] getCommands () {
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.GetByInternalId (userIdFilter);
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 (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in PersistentContainer.Instance.Players.Dict) {
61 Player p = kvp.Value;
62
63 if (
64 (!onlineOnly || p.IsOnline)
65 && (!notBannedOnly || !admTools.Blacklist.IsBanned (kvp.Key, out _, out _))
66 && (nameFilter.Length == 0 || p.Name.ContainsCaseInsensitive (nameFilter))
67 ) {
68 SdtdConsole.Instance.Output (
69 $"{++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}"
70 );
71 }
72 }
73
74 SdtdConsole.Instance.Output ($"Total of {PersistentContainer.Instance.Players.Count} known");
75 }
76 }
77 }
78}
Note: See TracBrowser for help on using the repository browser.