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

Last change on this file since 346 was 332, checked in by alloc, 6 years ago

*Latest optimizations

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