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

Last change on this file since 231 was 230, checked in by alloc, 10 years ago

Binary improvements

File size: 1.8 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 (optionally filtered)";
12 }
13
14 public override string[] GetCommands ()
15 {
16 return new string[] { "listknownplayers", "lkp" };
17 }
18
19 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
20 {
21 try {
22 AdminTools admTools = GameManager.Instance.adminTools;
23
24 bool onlineOnly = false;
25 bool notBannedOnly = false;
26 string nameFilter = string.Empty;
27
28 if (_params.Count == 1) {
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) {
40 Player p = PersistentContainer.Instance.Players [sid];
41
42 if (
43 (!onlineOnly || p.IsOnline)
44 && (!notBannedOnly || !admTools.IsBanned (sid))
45 && (nameFilter.Length == 0 || p.Name.ToLower ().Contains (nameFilter))
46 ) {
47 SdtdConsole.Instance.Output (String.Format ("{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}",
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 }
54 SdtdConsole.Instance.Output ("Total of " + PersistentContainer.Instance.Players.Count + " known");
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.