aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Avatar
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-03-30 01:05:29 +0100
committerJustin Clark-Casey (justincc)2012-03-30 01:05:29 +0100
commitbce7964ac2b0e67ff8c8e5ab00bb45b93da219ad (patch)
tree3a34b9280aa700c69ce3ceece1926b5a9304e027 /OpenSim/Region/OptionalModules/Avatar
parentAdd simple login test with online friends. Add IFriendsModule.GrantRights() ... (diff)
downloadopensim-SC_OLD-bce7964ac2b0e67ff8c8e5ab00bb45b93da219ad.zip
opensim-SC_OLD-bce7964ac2b0e67ff8c8e5ab00bb45b93da219ad.tar.gz
opensim-SC_OLD-bce7964ac2b0e67ff8c8e5ab00bb45b93da219ad.tar.bz2
opensim-SC_OLD-bce7964ac2b0e67ff8c8e5ab00bb45b93da219ad.tar.xz
refactor: Move "friends show cache" console command out into separate FriendsCommandsModule.
Expose required methods on IFriendsModule. Rename GetFriends() -> GetFriendsFromCache() for self-documentation
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar')
-rw-r--r--OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs165
1 files changed, 165 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..2bcb8a7
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs
@@ -0,0 +1,165 @@
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 Nini.Config;
36using OpenMetaverse;
37using OpenSim.Framework;
38using OpenSim.Framework.Console;
39using OpenSim.Framework.Statistics;
40using OpenSim.Region.ClientStack.LindenUDP;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes;
43using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
44
45namespace OpenSim.Region.OptionalModules.Avatar.Friends
46{
47 /// <summary>
48 /// A module that just holds commands for inspecting avatar appearance.
49 /// </summary>
50 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "FriendsCommandModule")]
51 public class FriendsCommandsModule : ISharedRegionModule
52 {
53// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
54
55 private Scene m_scene;
56 private IFriendsModule m_friendsModule;
57 private IUserManagement m_userManagementModule;
58
59// private IAvatarFactoryModule m_avatarFactory;
60
61 public string Name { get { return "Appearance Information Module"; } }
62
63 public Type ReplaceableInterface { get { return null; } }
64
65 public void Initialise(IConfigSource source)
66 {
67// m_log.DebugFormat("[FRIENDS COMMAND MODULE]: INITIALIZED MODULE");
68 }
69
70 public void PostInitialise()
71 {
72// m_log.DebugFormat("[FRIENDS COMMAND MODULE]: POST INITIALIZED MODULE");
73 }
74
75 public void Close()
76 {
77// m_log.DebugFormat("[FRIENDS COMMAND MODULE]: CLOSED MODULE");
78 }
79
80 public void AddRegion(Scene scene)
81 {
82// m_log.DebugFormat("[FRIENDS COMMANDO MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
83 }
84
85 public void RemoveRegion(Scene scene)
86 {
87// m_log.DebugFormat("[FRIENDS COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
88 }
89
90 public void RegionLoaded(Scene scene)
91 {
92// m_log.DebugFormat("[APPEARANCE INFO MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
93
94 if (m_scene == null)
95 m_scene = scene;
96
97 m_friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
98 m_userManagementModule = m_scene.RequestModuleInterface<IUserManagement>();
99
100 if (m_friendsModule != null && m_userManagementModule != null)
101 {
102 m_scene.AddCommand(
103 "Friends", this, "friends show cache",
104 "friends show cache [<first-name> <last-name>]",
105 "Show the friends cache for the given user",
106 HandleFriendsShowCacheCommand);
107 }
108 }
109
110 protected void HandleFriendsShowCacheCommand(string module, string[] cmd)
111 {
112 if (cmd.Length != 5)
113 {
114 MainConsole.Instance.OutputFormat("Usage: friends show cache [<first-name> <last-name>]");
115 return;
116 }
117
118 string firstName = cmd[3];
119 string lastName = cmd[4];
120
121 UUID userId = m_userManagementModule.GetUserIdByName(firstName, lastName);
122
123// UserAccount ua
124// = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, firstName, lastName);
125
126 if (userId == UUID.Zero)
127 {
128 MainConsole.Instance.OutputFormat("No such user as {0} {1}", firstName, lastName);
129 return;
130 }
131
132 if (m_friendsModule.AreFriendsCached(userId))
133 {
134 MainConsole.Instance.OutputFormat("No friends cached on this simulator for {0} {1}", firstName, lastName);
135 return;
136 }
137
138 MainConsole.Instance.OutputFormat("Cached friends for {0} {1}:", firstName, lastName);
139
140 MainConsole.Instance.OutputFormat("UUID\n");
141
142 FriendInfo[] friends = m_friendsModule.GetFriendsFromCache(userId);
143
144 foreach (FriendInfo friend in friends)
145 {
146// MainConsole.Instance.OutputFormat(friend.PrincipalID.ToString());
147
148// string friendFirstName, friendLastName;
149//
150// UserAccount friendUa
151// = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friend.PrincipalID);
152
153 UUID friendId;
154 string friendName;
155
156 if (UUID.TryParse(friend.Friend, out friendId))
157 friendName = m_userManagementModule.GetUserName(friendId);
158 else
159 friendName = friend.Friend;
160
161 MainConsole.Instance.OutputFormat("{0} {1} {2}", friendName, friend.MyFlags, friend.TheirFlags);
162 }
163 }
164 }
165} \ No newline at end of file