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

Last change on this file since 302 was 284, checked in by alloc, 8 years ago

Fixes #132

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