source: binary-improvements/7dtd-server-fixes/src/CustomCommands/ListKnownPlayers.cs@ 181

Last change on this file since 181 was 147, checked in by alloc, 10 years ago

Fixes

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