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

Last change on this file since 360 was 359, checked in by alloc, 5 years ago

Removed unnecessary try-catch-blocks from commands (command handler catches exceptions anyway and provides more detailed output)

File size: 2.8 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 AdminTools admTools = GameManager.Instance.adminTools;
29
30 bool onlineOnly = false;
31 bool notBannedOnly = false;
32 string nameFilter = string.Empty;
33 bool isSteamId = false;
34
35 if (_params.Count == 1) {
36 long steamid;
37 if (_params [0].EqualsCaseInsensitive ("-online")) {
38 onlineOnly = true;
39 } else if (_params [0].EqualsCaseInsensitive ("-notbanned")) {
40 notBannedOnly = true;
41 } else if (_params [0].Length == 17 && long.TryParse (_params [0], out steamid)) {
42 isSteamId = true;
43 } else {
44 nameFilter = _params [0];
45 }
46 }
47
48 if (isSteamId) {
49 Player p = PersistentContainer.Instance.Players [_params [0], false];
50
51 if (p != null) {
52 SdtdConsole.Instance.Output (string.Format (
53 "{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}",
54 0, p.Name, p.EntityID, _params [0], p.IsOnline, p.IP,
55 p.TotalPlayTime / 60,
56 p.LastOnline.ToString ("yyyy-MM-dd HH:mm"))
57 );
58 } else {
59 SdtdConsole.Instance.Output (string.Format ("SteamID {0} unknown!", _params [0]));
60 }
61 } else {
62 int num = 0;
63 foreach (KeyValuePair<string, Player> kvp in PersistentContainer.Instance.Players.Dict) {
64 Player p = kvp.Value;
65
66 if (
67 (!onlineOnly || p.IsOnline)
68 && (!notBannedOnly || !admTools.IsBanned (kvp.Key))
69 && (nameFilter.Length == 0 || p.Name.ContainsCaseInsensitive (nameFilter))
70 ) {
71 SdtdConsole.Instance.Output (string.Format (
72 "{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}",
73 ++num, p.Name, p.EntityID, kvp.Key, p.IsOnline, p.IP,
74 p.TotalPlayTime / 60,
75 p.LastOnline.ToString ("yyyy-MM-dd HH:mm"))
76 );
77 }
78 }
79
80 SdtdConsole.Instance.Output ("Total of " + PersistentContainer.Instance.Players.Count + " known");
81 }
82 }
83 }
84}
Note: See TracBrowser for help on using the repository browser.