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

Last change on this file since 447 was 446, checked in by alloc, 18 months ago

24_27_41

File size: 2.7 KB
RevLine 
[224]1using System.Collections.Generic;
[325]2using AllocsFixes.PersistentData;
[224]3
[325]4namespace AllocsFixes.CustomCommands {
5 public class ListKnownPlayers : ConsoleCmdAbstract {
[420]6 protected override string getDescription () {
[238]7 return "lists all players that were ever online";
[224]8 }
9
[420]10 protected override string getHelp () {
[238]11 return "Usage:\n" +
[325]12 " 1. listknownplayers\n" +
13 " 2. listknownplayers -online\n" +
14 " 3. listknownplayers -notbanned\n" +
[369]15 " 4. listknownplayers <player name / userid>\n" +
[325]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" +
[369]19 "4. Lists all players whose name contains the given string or matches the given UserID";
[238]20 }
21
[420]22 protected override string[] getCommands () {
[325]23 return new[] {"listknownplayers", "lkp"};
[224]24 }
25
[325]26 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
[359]27 AdminTools admTools = GameManager.Instance.adminTools;
[224]28
[359]29 bool onlineOnly = false;
30 bool notBannedOnly = false;
31 string nameFilter = string.Empty;
[369]32 PlatformUserIdentifierAbs userIdFilter = null;
[224]33
[359]34 if (_params.Count == 1) {
35 if (_params [0].EqualsCaseInsensitive ("-online")) {
36 onlineOnly = true;
37 } else if (_params [0].EqualsCaseInsensitive ("-notbanned")) {
38 notBannedOnly = true;
[369]39 } else if (PlatformUserIdentifierAbs.TryFromCombinedString (_params [0], out userIdFilter)) {
40 // if true nothing to do, set by the out parameter
[359]41 } else {
42 nameFilter = _params [0];
[224]43 }
[359]44 }
[224]45
[369]46 if (userIdFilter != null) {
[446]47 Player p = PersistentContainer.Instance.Players.GetByInternalId (userIdFilter);
[224]48
[359]49 if (p != null) {
[369]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}"
[359]52 );
53 } else {
[369]54 SdtdConsole.Instance.Output ($"SteamID {_params [0]} unknown!");
[359]55 }
56 } else {
57 int num = 0;
[369]58 foreach (KeyValuePair<PlatformUserIdentifierAbs, Player> kvp in PersistentContainer.Instance.Players.Dict) {
[359]59 Player p = kvp.Value;
60
61 if (
62 (!onlineOnly || p.IsOnline)
[420]63 && (!notBannedOnly || !admTools.Blacklist.IsBanned (kvp.Key, out _, out _))
[359]64 && (nameFilter.Length == 0 || p.Name.ContainsCaseInsensitive (nameFilter))
65 ) {
[369]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}"
[224]68 );
69 }
[359]70 }
[278]71
[369]72 SdtdConsole.Instance.Output ($"Total of {PersistentContainer.Instance.Players.Count} known");
[224]73 }
74 }
75 }
[325]76}
Note: See TracBrowser for help on using the repository browser.