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

Last change on this file since 491 was 488, checked in by alloc, 5 months ago

27_32_48

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