source: binary-improvements/CoppisAdditions/src/Commands/ListPlayersFriends.cs@ 299

Last change on this file since 299 was 285, checked in by alloc, 8 years ago

Fixes #133

File size: 2.1 KB
RevLine 
[273]1using System;
2using System.Collections.Generic;
3using System.Reflection;
4
5namespace CoppisAdditions.CustomCommands
6{
7 public class ListPlayersFriends : ConsoleCmdAbstract
8 {
9 public override string GetDescription ()
10 {
11 return "list friends of a single player or all players";
12 }
13
14 public override string GetHelp ()
15 {
16 return "Usage:\n" +
17 " 1. lpf <steam id / player name / entity id>" +
18 " 2. lpf (to list all players friends)";
19 }
20
21 public override string[] GetCommands ()
22 {
23 return new string[] { "listplayerfriends", "lpf" };
24 }
25
26 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
27 {
28 try {
29 if (_params.Count > 1) {
30 SdtdConsole.Instance.Output ("Usage: listplayerfriends <entityid|playername|steamid> or listplayerfriends");
31 } else {
32 if (_params.Count == 0) {
[285]33 foreach (string steamid in GameManager.Instance.persistentPlayers.Players.Keys) {
34 PrintFriendsOfPlayer (steamid);
35 }
36 } else {
37 string steamid = null;
38
39 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
40 if (ci != null) {
41 steamid = ci.playerId;
42 }
43
44 if (steamid == null) {
45 if (ConsoleHelper.ParseParamSteamIdValid (_params [0])) {
46 steamid = _params [0];
[273]47 }
48 }
[285]49
50 if (steamid == null) {
[273]51 SdtdConsole.Instance.Output ("Playername or entity/steamid id not found.");
52 return;
53 }
54
[285]55 PrintFriendsOfPlayer (steamid);
[273]56 }
57 }
58 } catch (Exception e) {
59 Log.Out ("Error in ListPlayersFriends.Run: " + e);
60 }
61 }
[285]62
63 private void PrintFriendsOfPlayer (string _steamid) {
64 PersistentPlayerData data = GameManager.Instance.persistentPlayers.GetPlayerData (_steamid);
65 string friends = "";
66 if (data != null && data.ACL != null) {
67 foreach (string friend in data.ACL) {
68 if (!string.IsNullOrEmpty (friend)) {
69 if (!friends.Equals ("")) {
70 friends += ",";
71 }
72 friends += friend;
73 }
74 }
75 }
76 SdtdConsole.Instance.Output ("FriendsOf id=" + _steamid + ", friends=" + friends);
77 }
78
[273]79 }
80}
Note: See TracBrowser for help on using the repository browser.