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

Last change on this file since 237 was 233, checked in by alloc, 10 years ago

Fixes for 11.4

File size: 1.8 KB
RevLine 
[224]1using AllocsFixes.PersistentData;
2using System;
3using System.Collections.Generic;
4
5namespace AllocsFixes.CustomCommands
6{
[230]7 public class ListKnownPlayers : ConsoleCmdAbstract
[224]8 {
[230]9 public override string GetDescription ()
[224]10 {
11 return "lists all players that were ever online (optionally filtered)";
12 }
13
[230]14 public override string[] GetCommands ()
[224]15 {
16 return new string[] { "listknownplayers", "lkp" };
17 }
18
[230]19 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
[224]20 {
21 try {
[230]22 AdminTools admTools = GameManager.Instance.adminTools;
[224]23
24 bool onlineOnly = false;
25 bool notBannedOnly = false;
26 string nameFilter = string.Empty;
27
[230]28 if (_params.Count == 1) {
[224]29 if (_params [0].ToLower ().Equals ("-online")) {
30 onlineOnly = true;
31 } else if (_params [0].ToLower ().Equals ("-notbanned")) {
32 notBannedOnly = true;
33 } else {
34 nameFilter = _params [0].ToLower ();
35 }
36 }
37
38 int num = 0;
39 foreach (string sid in PersistentContainer.Instance.Players.SteamIDs) {
[233]40 Player p = PersistentContainer.Instance.Players [sid, false];
[224]41
42 if (
43 (!onlineOnly || p.IsOnline)
44 && (!notBannedOnly || !admTools.IsBanned (sid))
45 && (nameFilter.Length == 0 || p.Name.ToLower ().Contains (nameFilter))
46 ) {
[230]47 SdtdConsole.Instance.Output (String.Format ("{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}",
[224]48 ++num, p.Name, p.EntityID, sid, p.IsOnline, p.IP,
49 p.TotalPlayTime / 60,
50 p.LastOnline.ToString ("yyyy-MM-dd HH:mm"))
51 );
52 }
53 }
[230]54 SdtdConsole.Instance.Output ("Total of " + PersistentContainer.Instance.Players.Count + " known");
[224]55 } catch (Exception e) {
56 Log.Out ("Error in ListKnownPlayers.Run: " + e);
57 }
58 }
59 }
60}
Note: See TracBrowser for help on using the repository browser.