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

Last change on this file since 368 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
RevLine 
[224]1using System;
2using System.Collections.Generic;
[325]3using AllocsFixes.PersistentData;
[224]4
[325]5namespace AllocsFixes.CustomCommands {
6 public class ListKnownPlayers : ConsoleCmdAbstract {
7 public override string GetDescription () {
[238]8 return "lists all players that were ever online";
[224]9 }
10
[238]11 public override string GetHelp () {
12 return "Usage:\n" +
[325]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";
[238]21 }
22
[325]23 public override string[] GetCommands () {
24 return new[] {"listknownplayers", "lkp"};
[224]25 }
26
[325]27 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo) {
[359]28 AdminTools admTools = GameManager.Instance.adminTools;
[224]29
[359]30 bool onlineOnly = false;
31 bool notBannedOnly = false;
32 string nameFilter = string.Empty;
33 bool isSteamId = false;
[224]34
[359]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];
[224]45 }
[359]46 }
[224]47
[359]48 if (isSteamId) {
49 Player p = PersistentContainer.Instance.Players [_params [0], false];
[224]50
[359]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 ) {
[325]71 SdtdConsole.Instance.Output (string.Format (
72 "{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}",
[359]73 ++num, p.Name, p.EntityID, kvp.Key, p.IsOnline, p.IP,
[278]74 p.TotalPlayTime / 60,
75 p.LastOnline.ToString ("yyyy-MM-dd HH:mm"))
[224]76 );
77 }
[359]78 }
[278]79
[359]80 SdtdConsole.Instance.Output ("Total of " + PersistentContainer.Instance.Players.Count + " known");
[224]81 }
82 }
83 }
[325]84}
Note: See TracBrowser for help on using the repository browser.