[224] | 1 | using AllocsFixes.PersistentData;
|
---|
| 2 | using System;
|
---|
| 3 | using System.Collections.Generic;
|
---|
| 4 |
|
---|
| 5 | namespace AllocsFixes.CustomCommands
|
---|
| 6 | {
|
---|
[230] | 7 | public class ListKnownPlayers : ConsoleCmdAbstract
|
---|
[224] | 8 | {
|
---|
[230] | 9 | public override string GetDescription ()
|
---|
[224] | 10 | {
|
---|
[238] | 11 | return "lists all players that were ever online";
|
---|
[224] | 12 | }
|
---|
| 13 |
|
---|
[238] | 14 | public override string GetHelp () {
|
---|
| 15 | return "Usage:\n" +
|
---|
| 16 | " 1. listknownplayers\n" +
|
---|
| 17 | " 2. listknownplayers -online\n" +
|
---|
| 18 | " 3. listknownplayers -notbanned\n" +
|
---|
[278] | 19 | " 4. listknownplayers <player name / steamid>\n" +
|
---|
[238] | 20 | "1. Lists all players that have ever been online\n" +
|
---|
| 21 | "2. Lists only the players that are currently online\n" +
|
---|
| 22 | "3. Lists only the players that are not banned\n" +
|
---|
[278] | 23 | "4. Lists all players whose name contains the given string or matches the given SteamID";
|
---|
[238] | 24 | }
|
---|
| 25 |
|
---|
[230] | 26 | public override string[] GetCommands ()
|
---|
[224] | 27 | {
|
---|
| 28 | return new string[] { "listknownplayers", "lkp" };
|
---|
| 29 | }
|
---|
| 30 |
|
---|
[230] | 31 | public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
|
---|
[224] | 32 | {
|
---|
| 33 | try {
|
---|
[230] | 34 | AdminTools admTools = GameManager.Instance.adminTools;
|
---|
[224] | 35 |
|
---|
| 36 | bool onlineOnly = false;
|
---|
| 37 | bool notBannedOnly = false;
|
---|
| 38 | string nameFilter = string.Empty;
|
---|
[278] | 39 | bool isSteamId = false;
|
---|
[224] | 40 |
|
---|
[230] | 41 | if (_params.Count == 1) {
|
---|
[278] | 42 | long steamid = -1;
|
---|
[224] | 43 | if (_params [0].ToLower ().Equals ("-online")) {
|
---|
| 44 | onlineOnly = true;
|
---|
| 45 | } else if (_params [0].ToLower ().Equals ("-notbanned")) {
|
---|
| 46 | notBannedOnly = true;
|
---|
[278] | 47 | } else if (_params [0].Length == 17 && long.TryParse (_params [0], out steamid)) {
|
---|
| 48 | isSteamId = true;
|
---|
[224] | 49 | } else {
|
---|
| 50 | nameFilter = _params [0].ToLower ();
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
[278] | 54 | if (isSteamId) {
|
---|
| 55 | Player p = PersistentContainer.Instance.Players [nameFilter, false];
|
---|
[224] | 56 |
|
---|
[278] | 57 | if (p != null) {
|
---|
[230] | 58 | SdtdConsole.Instance.Output (String.Format ("{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}",
|
---|
[278] | 59 | 0, p.Name, p.EntityID, nameFilter, p.IsOnline, p.IP,
|
---|
| 60 | p.TotalPlayTime / 60,
|
---|
| 61 | p.LastOnline.ToString ("yyyy-MM-dd HH:mm"))
|
---|
[224] | 62 | );
|
---|
[278] | 63 | } else {
|
---|
| 64 | SdtdConsole.Instance.Output (String.Format ("SteamID {0} unknown!", nameFilter));
|
---|
[224] | 65 | }
|
---|
[278] | 66 | } else {
|
---|
| 67 | int num = 0;
|
---|
| 68 | foreach (string sid in PersistentContainer.Instance.Players.SteamIDs) {
|
---|
| 69 | Player p = PersistentContainer.Instance.Players [sid, false];
|
---|
| 70 |
|
---|
| 71 | if (
|
---|
| 72 | (!onlineOnly || p.IsOnline)
|
---|
| 73 | && (!notBannedOnly || !admTools.IsBanned (sid))
|
---|
| 74 | && (nameFilter.Length == 0 || p.Name.ToLower ().Contains (nameFilter))
|
---|
| 75 | ) {
|
---|
| 76 | SdtdConsole.Instance.Output (String.Format ("{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}",
|
---|
| 77 | ++num, p.Name, p.EntityID, sid, p.IsOnline, p.IP,
|
---|
| 78 | p.TotalPlayTime / 60,
|
---|
| 79 | p.LastOnline.ToString ("yyyy-MM-dd HH:mm"))
|
---|
| 80 | );
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | SdtdConsole.Instance.Output ("Total of " + PersistentContainer.Instance.Players.Count + " known");
|
---|
[224] | 84 | }
|
---|
| 85 | } catch (Exception e) {
|
---|
| 86 | Log.Out ("Error in ListKnownPlayers.Run: " + e);
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | }
|
---|