aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Avatar/Friends
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/Friends')
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs189
1 files changed, 189 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs b/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs
new file mode 100644
index 0000000..e68f9d0
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs
@@ -0,0 +1,189 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Linq;
31using System.Reflection;
32using System.Text;
33using log4net;
34using Mono.Addins;
35using NDesk.Options;
36using Nini.Config;
37using OpenMetaverse;
38using OpenSim.Framework;
39using OpenSim.Framework.Console;
40using OpenSim.Framework.Statistics;
41using OpenSim.Region.ClientStack.LindenUDP;
42using OpenSim.Region.CoreModules.Avatar.Friends;
43using OpenSim.Region.Framework.Interfaces;
44using OpenSim.Region.Framework.Scenes;
45using OpenSim.Services.Interfaces;
46using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
47
48namespace OpenSim.Region.OptionalModules.Avatar.Friends
49{
50 /// <summary>
51 /// A module that just holds commands for inspecting avatar appearance.
52 /// </summary>
53 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "FriendsCommandModule")]
54 public class FriendsCommandsModule : ISharedRegionModule
55 {
56// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
57
58 private Scene m_scene;
59 private IFriendsModule m_friendsModule;
60 private IUserManagement m_userManagementModule;
61
62// private IAvatarFactoryModule m_avatarFactory;
63
64 public string Name { get { return "Appearance Information Module"; } }
65
66 public Type ReplaceableInterface { get { return null; } }
67
68 public void Initialise(IConfigSource source)
69 {
70// m_log.DebugFormat("[FRIENDS COMMAND MODULE]: INITIALIZED MODULE");
71 }
72
73 public void PostInitialise()
74 {
75// m_log.DebugFormat("[FRIENDS COMMAND MODULE]: POST INITIALIZED MODULE");
76 }
77
78 public void Close()
79 {
80// m_log.DebugFormat("[FRIENDS COMMAND MODULE]: CLOSED MODULE");
81 }
82
83 public void AddRegion(Scene scene)
84 {
85// m_log.DebugFormat("[FRIENDS COMMANDO MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
86 }
87
88 public void RemoveRegion(Scene scene)
89 {
90// m_log.DebugFormat("[FRIENDS COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
91 }
92
93 public void RegionLoaded(Scene scene)
94 {
95// m_log.DebugFormat("[APPEARANCE INFO MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
96
97 if (m_scene == null)
98 m_scene = scene;
99
100 m_friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
101 m_userManagementModule = m_scene.RequestModuleInterface<IUserManagement>();
102
103 if (m_friendsModule != null && m_userManagementModule != null)
104 {
105 m_scene.AddCommand(
106 "Friends", this, "friends show",
107 "friends show [--cache] <first-name> <last-name>",
108 "Show the friends for the given user if they exist.\n",
109 "The --cache option will show locally cached information for that user.",
110 HandleFriendsShowCommand);
111 }
112 }
113
114 protected void HandleFriendsShowCommand(string module, string[] cmd)
115 {
116 Dictionary<string, object> options = new Dictionary<string, object>();
117 OptionSet optionSet = new OptionSet().Add("c|cache", delegate (string v) { options["cache"] = v != null; });
118
119 List<string> mainParams = optionSet.Parse(cmd);
120
121 if (mainParams.Count != 4)
122 {
123 MainConsole.Instance.OutputFormat("Usage: friends show [--cache] <first-name> <last-name>");
124 return;
125 }
126
127 string firstName = mainParams[2];
128 string lastName = mainParams[3];
129
130 UUID userId = m_userManagementModule.GetUserIdByName(firstName, lastName);
131
132// UserAccount ua
133// = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, firstName, lastName);
134
135 if (userId == UUID.Zero)
136 {
137 MainConsole.Instance.OutputFormat("No such user as {0} {1}", firstName, lastName);
138 return;
139 }
140
141 FriendInfo[] friends;
142
143 if (options.ContainsKey("cache"))
144 {
145 if (!m_friendsModule.AreFriendsCached(userId))
146 {
147 MainConsole.Instance.OutputFormat("No friends cached on this simulator for {0} {1}", firstName, lastName);
148 return;
149 }
150 else
151 {
152 friends = m_friendsModule.GetFriendsFromCache(userId);
153 }
154 }
155 else
156 {
157 // FIXME: We're forced to do this right now because IFriendsService has no region connectors. We can't
158 // just expose FriendsModule.GetFriendsFromService() because it forces an IClientAPI requirement that
159 // can't currently be changed because of HGFriendsModule code that takes the scene from the client.
160 friends = ((FriendsModule)m_friendsModule).FriendsService.GetFriends(userId);
161 }
162
163 MainConsole.Instance.OutputFormat("Friends for {0} {1} {2}:", firstName, lastName, userId);
164
165 MainConsole.Instance.OutputFormat("UUID, Name, MyFlags, TheirFlags");
166
167 foreach (FriendInfo friend in friends)
168 {
169// MainConsole.Instance.OutputFormat(friend.PrincipalID.ToString());
170
171// string friendFirstName, friendLastName;
172//
173// UserAccount friendUa
174// = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friend.PrincipalID);
175
176 UUID friendId;
177 string friendName;
178
179 if (UUID.TryParse(friend.Friend, out friendId))
180 friendName = m_userManagementModule.GetUserName(friendId);
181 else
182 friendName = friend.Friend;
183
184 MainConsole.Instance.OutputFormat(
185 "{0} {1} {2} {3}", friend.Friend, friendName, friend.MyFlags, friend.TheirFlags);
186 }
187 }
188 }
189} \ No newline at end of file