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

Last change on this file since 279 was 273, checked in by alloc, 9 years ago

fixes 8_10_13_1

File size: 3.0 KB
Line 
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) {
33 Dictionary<int, EntityPlayer>.Enumerator playerEnum = GameManager.Instance.World.Players.dict.GetEnumerator ();
34 while (playerEnum.MoveNext ()) {
35 try {
36 KeyValuePair<int, EntityPlayer> pair = playerEnum.Current;
37 ClientInfo ci1 = ConsoleHelper.ParseParamIdOrName (pair.Value.entityId.ToString ());
38 PersistentPlayerData data = GameManager.Instance.persistentPlayers.GetPlayerData (ci1.playerId);
39 HashSet<string>.Enumerator enumeratorFriends = data.ACL.GetEnumerator ();
40 String friends = "";
41 while (enumeratorFriends.MoveNext ()) {
42 string str = enumeratorFriends.Current;
43 if (str != null) {
44 if (!friends.Equals ("")) {
45 friends += ",";
46 }
47 friends += str;
48 }
49 }
50 SdtdConsole.Instance.Output ("FriendsOf id=" + pair.Value.entityId + ", friends=" + friends);
51 } catch (Exception e) {
52
53 }
54 }
55 } else {
56 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_params [0]);
57 if (ci == null) {
58 SdtdConsole.Instance.Output ("Playername or entity/steamid id not found.");
59 return;
60 }
61 EntityPlayer ep = GameManager.Instance.World.Players.dict [ci.entityId];
62 PersistentPlayerData data = GameManager.Instance.persistentPlayers.GetPlayerDataFromEntityID (ci.entityId);
63
64 HashSet<string>.Enumerator enumerator = data.ACL.GetEnumerator ();
65 //int count = 0;
66 String friends = "";
67 while (enumerator.MoveNext ()) {
68 string str = enumerator.Current;
69 if (!friends.Equals ("")) {
70 friends += ",";
71 }
72 friends += str;
73
74 //Player p = PersistentContainer.Instance.Players[str, false];
75 //if (p == null)
76 //{
77 // continue;
78 //}
79 //count++;
80 //SdtdConsole.Instance.Output(count + ": " + p.EntityID + " - " + p.Name);
81 }
82 SdtdConsole.Instance.Output ("FriendsOf id=" + ci.entityId + ", friends=" + friends);
83 }
84 }
85 } catch (Exception e) {
86 Log.Out ("Error in ListPlayersFriends.Run: " + e);
87 }
88 }
89 }
90}
Note: See TracBrowser for help on using the repository browser.