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

Last change on this file since 243 was 238, checked in by alloc, 9 years ago

Server fixes for A12

File size: 2.3 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";
12 }
13
14 public override string GetHelp () {
15 return "Usage:\n" +
16 " 1. listknownplayers\n" +
17 " 2. listknownplayers -online\n" +
18 " 3. listknownplayers -notbanned\n" +
19 " 4. listknownplayers <player name>\n" +
20 "1. Lists all players that have ever been online\n" +
21 "2. Lists only the players that are currently online\n" +
22 "3. Lists only the players that are not banned\n" +
23 "4. Lists all players whose name contains the given string";
24 }
25
26 public override string[] GetCommands ()
27 {
28 return new string[] { "listknownplayers", "lkp" };
29 }
30
31 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
32 {
33 try {
34 AdminTools admTools = GameManager.Instance.adminTools;
35
36 bool onlineOnly = false;
37 bool notBannedOnly = false;
38 string nameFilter = string.Empty;
39
40 if (_params.Count == 1) {
41 if (_params [0].ToLower ().Equals ("-online")) {
42 onlineOnly = true;
43 } else if (_params [0].ToLower ().Equals ("-notbanned")) {
44 notBannedOnly = true;
45 } else {
46 nameFilter = _params [0].ToLower ();
47 }
48 }
49
50 int num = 0;
51 foreach (string sid in PersistentContainer.Instance.Players.SteamIDs) {
52 Player p = PersistentContainer.Instance.Players [sid, false];
53
54 if (
55 (!onlineOnly || p.IsOnline)
56 && (!notBannedOnly || !admTools.IsBanned (sid))
57 && (nameFilter.Length == 0 || p.Name.ToLower ().Contains (nameFilter))
58 ) {
59 SdtdConsole.Instance.Output (String.Format ("{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}",
60 ++num, p.Name, p.EntityID, sid, p.IsOnline, p.IP,
61 p.TotalPlayTime / 60,
62 p.LastOnline.ToString ("yyyy-MM-dd HH:mm"))
63 );
64 }
65 }
66 SdtdConsole.Instance.Output ("Total of " + PersistentContainer.Instance.Players.Count + " known");
67 } catch (Exception e) {
68 Log.Out ("Error in ListKnownPlayers.Run: " + e);
69 }
70 }
71 }
72}
Note: See TracBrowser for help on using the repository browser.