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

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

Server fixes for A12

File size: 2.3 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 {
[238]11 return "lists all players that were ever online";
[224]12 }
13
[238]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
[230]26 public override string[] GetCommands ()
[224]27 {
28 return new string[] { "listknownplayers", "lkp" };
29 }
30
[230]31 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
[224]32 {
33 try {
[230]34 AdminTools admTools = GameManager.Instance.adminTools;
[224]35
36 bool onlineOnly = false;
37 bool notBannedOnly = false;
38 string nameFilter = string.Empty;
39
[230]40 if (_params.Count == 1) {
[224]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) {
[233]52 Player p = PersistentContainer.Instance.Players [sid, false];
[224]53
54 if (
55 (!onlineOnly || p.IsOnline)
56 && (!notBannedOnly || !admTools.IsBanned (sid))
57 && (nameFilter.Length == 0 || p.Name.ToLower ().Contains (nameFilter))
58 ) {
[230]59 SdtdConsole.Instance.Output (String.Format ("{0}. {1}, id={2}, steamid={3}, online={4}, ip={5}, playtime={6} m, seen={7}",
[224]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 }
[230]66 SdtdConsole.Instance.Output ("Total of " + PersistentContainer.Instance.Players.Count + " known");
[224]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.