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

Last change on this file since 419 was 369, checked in by alloc, 3 years ago

Preparations for A20 release
Changes usage of "SteamID" to "UserID" in console commands
Also changes a bunch of the WebAPI stuff to show / use UserIDs

File size: 2.7 KB
Line 
1using System.Collections.Generic;
2using AllocsFixes.PersistentData;
3
4namespace AllocsFixes.CustomCommands {
5 public class ListKnownPlayers : ConsoleCmdAbstract {
6 public override string GetDescription () {
7 return "lists all players that were ever online";
8 }
9
10 public override string GetHelp () {
11 return "Usage:\n" +
12 " 1. listknownplayers\n" +
13 " 2. listknownplayers -online\n" +
14 " 3. listknownplayers -notbanned\n" +
15 " 4. listknownplayers <player name / userid>\n" +
16 "1. Lists all players that have ever been online\n" +
17 "2. Lists only the players that are currently online\n" +
18 "3. Lists only the players that are not banned\n" +
19 "4. Lists all players whose name contains the given string or matches the given UserID";
20 }
21
22 public override string[] GetCommands () {
23 return new[] {"listknownplayers", "lkp"};
24 }
25
26 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
27 AdminTools admTools = GameManager.Instance.adminTools;
28
29 bool onlineOnly = false;
30 bool notBannedOnly = false;
31 string nameFilter = string.Empty;
32 PlatformUserIdentifierAbs userIdFilter = null;
33
34 if (_params.Count == 1) {
35 if (_params [0].EqualsCaseInsensitive ("-online")) {
36 onlineOnly = true;
37 } else if (_params [0].EqualsCaseInsensitive ("-notbanned")) {
38 notBannedOnly = true;
39 } else if (PlatformUserIdentifierAbs.TryFromCombinedString (_params [0], out userIdFilter)) {
40 // if true nothing to do, set by the out parameter
41 } else {
42 nameFilter = _params [0];
43 }
44 }
45
46 if (userIdFilter != null) {
47 Player p = PersistentContainer.Instance.Players [userIdFilter, false];
48
49 if (p != null) {
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}"
52 );
53 } else {
54 SdtdConsole.Instance.Output ($"SteamID {_params [0]} unknown!");
55 }
56 } else {
57 int num = 0;
58 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in PersistentContainer.Instance.Players.Dict) {
59 Player p = kvp.Value;
60
61 if (
62 (!onlineOnly || p.IsOnline)
63 && (!notBannedOnly || !admTools.IsBanned (kvp.Key, out _, out _))
64 && (nameFilter.Length == 0 || p.Name.ContainsCaseInsensitive (nameFilter))
65 ) {
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}"
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.