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

Last change on this file since 327 was 326, checked in by alloc, 6 years ago

More cleanup, allocation improvements

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