clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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  
28 using System;
29 using System.Collections.Generic;
30 using System.Linq;
31 using System.Reflection;
32 using System.Text;
33 using log4net;
34 using Mono.Addins;
35 using NDesk.Options;
36 using Nini.Config;
37 using OpenMetaverse;
38 using OpenSim.Framework;
39 using OpenSim.Framework.Console;
40 using OpenSim.Framework.Monitoring;
41 using OpenSim.Region.ClientStack.LindenUDP;
42 using OpenSim.Region.CoreModules.Avatar.Friends;
43 using OpenSim.Region.Framework.Interfaces;
44 using OpenSim.Region.Framework.Scenes;
45 using OpenSim.Services.Interfaces;
46 using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
47  
48 namespace 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 private IPresenceService m_presenceService;
62  
63 // private IAvatarFactoryModule m_avatarFactory;
64  
65 public string Name { get { return "Appearance Information Module"; } }
66  
67 public Type ReplaceableInterface { get { return null; } }
68  
69 public void Initialise(IConfigSource source)
70 {
71 // m_log.DebugFormat("[FRIENDS COMMAND MODULE]: INITIALIZED MODULE");
72 }
73  
74 public void PostInitialise()
75 {
76 // m_log.DebugFormat("[FRIENDS COMMAND MODULE]: POST INITIALIZED MODULE");
77 }
78  
79 public void Close()
80 {
81 // m_log.DebugFormat("[FRIENDS COMMAND MODULE]: CLOSED MODULE");
82 }
83  
84 public void AddRegion(Scene scene)
85 {
86 // m_log.DebugFormat("[FRIENDS COMMANDO MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
87 }
88  
89 public void RemoveRegion(Scene scene)
90 {
91 // m_log.DebugFormat("[FRIENDS COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
92 }
93  
94 public void RegionLoaded(Scene scene)
95 {
96 // m_log.DebugFormat("[APPEARANCE INFO MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
97  
98 if (m_scene == null)
99 m_scene = scene;
100  
101 m_friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
102 m_userManagementModule = m_scene.RequestModuleInterface<IUserManagement>();
103 m_presenceService = m_scene.RequestModuleInterface<IPresenceService>();
104  
105 if (m_friendsModule != null && m_userManagementModule != null && m_presenceService != null)
106 {
107 m_scene.AddCommand(
108 "Friends", this, "friends show",
109 "friends show [--cache] <first-name> <last-name>",
110 "Show the friends for the given user if they exist.\n",
111 "The --cache option will show locally cached information for that user.",
112 HandleFriendsShowCommand);
113 }
114 }
115  
116 protected void HandleFriendsShowCommand(string module, string[] cmd)
117 {
118 Dictionary<string, object> options = new Dictionary<string, object>();
119 OptionSet optionSet = new OptionSet().Add("c|cache", delegate (string v) { options["cache"] = v != null; });
120  
121 List<string> mainParams = optionSet.Parse(cmd);
122  
123 if (mainParams.Count != 4)
124 {
125 MainConsole.Instance.OutputFormat("Usage: friends show [--cache] <first-name> <last-name>");
126 return;
127 }
128  
129 string firstName = mainParams[2];
130 string lastName = mainParams[3];
131  
132 UUID userId = m_userManagementModule.GetUserIdByName(firstName, lastName);
133  
134 // UserAccount ua
135 // = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, firstName, lastName);
136  
137 if (userId == UUID.Zero)
138 {
139 MainConsole.Instance.OutputFormat("No such user as {0} {1}", firstName, lastName);
140 return;
141 }
142  
143 FriendInfo[] friends;
144  
145 if (options.ContainsKey("cache"))
146 {
147 if (!m_friendsModule.AreFriendsCached(userId))
148 {
149 MainConsole.Instance.OutputFormat("No friends cached on this simulator for {0} {1}", firstName, lastName);
150 return;
151 }
152 else
153 {
154 friends = m_friendsModule.GetFriendsFromCache(userId);
155 }
156 }
157 else
158 {
159 // FIXME: We're forced to do this right now because IFriendsService has no region connectors. We can't
160 // just expose FriendsModule.GetFriendsFromService() because it forces an IClientAPI requirement that
161 // can't currently be changed because of HGFriendsModule code that takes the scene from the client.
162 friends = ((FriendsModule)m_friendsModule).FriendsService.GetFriends(userId);
163 }
164  
165 MainConsole.Instance.OutputFormat("Friends for {0} {1} {2}:", firstName, lastName, userId);
166  
167 MainConsole.Instance.OutputFormat(
168 "{0,-36} {1,-36} {2,-7} {3,7} {4,10}", "UUID", "Name", "Status", "MyFlags", "TheirFlags");
169  
170 foreach (FriendInfo friend in friends)
171 {
172 // MainConsole.Instance.OutputFormat(friend.PrincipalID.ToString());
173  
174 // string friendFirstName, friendLastName;
175 //
176 // UserAccount friendUa
177 // = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friend.PrincipalID);
178  
179 UUID friendId;
180 string friendName;
181 string onlineText;
182  
183 if (UUID.TryParse(friend.Friend, out friendId))
184 friendName = m_userManagementModule.GetUserName(friendId);
185 else
186 friendName = friend.Friend;
187  
188 OpenSim.Services.Interfaces.PresenceInfo[] pi = m_presenceService.GetAgents(new string[] { friend.Friend });
189 if (pi.Length > 0)
190 onlineText = "online";
191 else
192 onlineText = "offline";
193  
194 MainConsole.Instance.OutputFormat(
195 "{0,-36} {1,-36} {2,-7} {3,-7} {4,-10}",
196 friend.Friend, friendName, onlineText, friend.MyFlags, friend.TheirFlags);
197 }
198 }
199 }
200 }