diff options
author | Melanie | 2010-03-03 02:07:03 +0000 |
---|---|---|
committer | Melanie | 2010-03-03 02:07:03 +0000 |
commit | 028a87fe37002e7a0611f66babf1deee46c83804 (patch) | |
tree | 387aec499fd60c2012bed8148e6a2ddc847c3d95 /OpenSim/Region/CoreModules/Avatar | |
parent | Revert "test" (diff) | |
parent | Fixes Region.Framework tests. Although these tests don't fail, they need to b... (diff) | |
download | opensim-SC_OLD-028a87fe37002e7a0611f66babf1deee46c83804.zip opensim-SC_OLD-028a87fe37002e7a0611f66babf1deee46c83804.tar.gz opensim-SC_OLD-028a87fe37002e7a0611f66babf1deee46c83804.tar.bz2 opensim-SC_OLD-028a87fe37002e7a0611f66babf1deee46c83804.tar.xz |
Merge branch 'master' into careminster-presence-refactor
This brings careminster on the level of master. To be tested
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar')
18 files changed, 1759 insertions, 2121 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs index 144c8d1..22c8937 100644 --- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs | |||
@@ -31,7 +31,7 @@ using log4net; | |||
31 | using Nini.Config; | 31 | using Nini.Config; |
32 | using OpenMetaverse; | 32 | using OpenMetaverse; |
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Framework.Communications.Cache; | 34 | |
35 | using OpenSim.Region.Framework.Interfaces; | 35 | using OpenSim.Region.Framework.Interfaces; |
36 | using OpenSim.Region.Framework.Scenes; | 36 | using OpenSim.Region.Framework.Scenes; |
37 | using OpenSim.Services.Interfaces; | 37 | using OpenSim.Services.Interfaces; |
@@ -46,21 +46,16 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory | |||
46 | 46 | ||
47 | public bool TryGetAvatarAppearance(UUID avatarId, out AvatarAppearance appearance) | 47 | public bool TryGetAvatarAppearance(UUID avatarId, out AvatarAppearance appearance) |
48 | { | 48 | { |
49 | CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(avatarId); | 49 | AvatarData avatar = m_scene.AvatarService.GetAvatar(avatarId); |
50 | //if ((profile != null) && (profile.RootFolder != null)) | 50 | //if ((profile != null) && (profile.RootFolder != null)) |
51 | if (profile != null) | 51 | if (avatar != null) |
52 | { | 52 | { |
53 | appearance = m_scene.CommsManager.AvatarService.GetUserAppearance(avatarId); | 53 | appearance = avatar.ToAvatarAppearance(avatarId); |
54 | if (appearance != null) | 54 | return true; |
55 | { | ||
56 | //SetAppearanceAssets(profile, ref appearance); | ||
57 | //m_log.DebugFormat("[APPEARANCE]: Found : {0}", appearance.ToString()); | ||
58 | return true; | ||
59 | } | ||
60 | } | 55 | } |
61 | 56 | ||
62 | appearance = CreateDefault(avatarId); | ||
63 | m_log.ErrorFormat("[APPEARANCE]: Appearance not found for {0}, creating default", avatarId); | 57 | m_log.ErrorFormat("[APPEARANCE]: Appearance not found for {0}, creating default", avatarId); |
58 | appearance = CreateDefault(avatarId); | ||
64 | return false; | 59 | return false; |
65 | } | 60 | } |
66 | 61 | ||
@@ -160,21 +155,23 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory | |||
160 | /// <param name="e"></param> | 155 | /// <param name="e"></param> |
161 | public void AvatarIsWearing(Object sender, AvatarWearingArgs e) | 156 | public void AvatarIsWearing(Object sender, AvatarWearingArgs e) |
162 | { | 157 | { |
158 | m_log.DebugFormat("[APPEARANCE]: AvatarIsWearing"); | ||
159 | |||
163 | IClientAPI clientView = (IClientAPI)sender; | 160 | IClientAPI clientView = (IClientAPI)sender; |
164 | ScenePresence avatar = m_scene.GetScenePresence(clientView.AgentId); | 161 | ScenePresence sp = m_scene.GetScenePresence(clientView.AgentId); |
165 | 162 | ||
166 | if (avatar == null) | 163 | if (sp == null) |
167 | { | 164 | { |
168 | m_log.Error("[APPEARANCE]: Avatar is child agent, ignoring AvatarIsWearing event"); | 165 | m_log.Error("[APPEARANCE]: Avatar is child agent, ignoring AvatarIsWearing event"); |
169 | return; | 166 | return; |
170 | } | 167 | } |
171 | 168 | ||
172 | AvatarAppearance avatAppearance = null; | 169 | AvatarAppearance avatAppearance = sp.Appearance; |
173 | if (!TryGetAvatarAppearance(clientView.AgentId, out avatAppearance)) | 170 | //if (!TryGetAvatarAppearance(clientView.AgentId, out avatAppearance)) |
174 | { | 171 | //{ |
175 | m_log.Warn("[APPEARANCE]: We didn't seem to find the appearance, falling back to ScenePresence"); | 172 | // m_log.Warn("[APPEARANCE]: We didn't seem to find the appearance, falling back to ScenePresence"); |
176 | avatAppearance = avatar.Appearance; | 173 | // avatAppearance = sp.Appearance; |
177 | } | 174 | //} |
178 | 175 | ||
179 | //m_log.DebugFormat("[APPEARANCE]: Received wearables for {0}", clientView.Name); | 176 | //m_log.DebugFormat("[APPEARANCE]: Received wearables for {0}", clientView.Name); |
180 | 177 | ||
@@ -186,10 +183,11 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory | |||
186 | } | 183 | } |
187 | } | 184 | } |
188 | 185 | ||
189 | SetAppearanceAssets(avatar.UUID, ref avatAppearance); | 186 | SetAppearanceAssets(sp.UUID, ref avatAppearance); |
187 | AvatarData adata = new AvatarData(avatAppearance); | ||
188 | m_scene.AvatarService.SetAvatar(clientView.AgentId, adata); | ||
190 | 189 | ||
191 | m_scene.CommsManager.AvatarService.UpdateUserAppearance(clientView.AgentId, avatAppearance); | 190 | sp.Appearance = avatAppearance; |
192 | avatar.Appearance = avatAppearance; | ||
193 | } | 191 | } |
194 | 192 | ||
195 | public static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams) | 193 | public static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams) |
@@ -200,7 +198,9 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory | |||
200 | 198 | ||
201 | public void UpdateDatabase(UUID user, AvatarAppearance appearance) | 199 | public void UpdateDatabase(UUID user, AvatarAppearance appearance) |
202 | { | 200 | { |
203 | m_scene.CommsManager.AvatarService.UpdateUserAppearance(user, appearance); | 201 | //m_log.DebugFormat("[APPEARANCE]: UpdateDatabase"); |
202 | AvatarData adata = new AvatarData(appearance); | ||
203 | m_scene.AvatarService.SetAvatar(user, adata); | ||
204 | } | 204 | } |
205 | 205 | ||
206 | private static byte[] GetDefaultVisualParams() | 206 | private static byte[] GetDefaultVisualParams() |
diff --git a/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs b/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs index 61b6d65..3614915 100644 --- a/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Combat/CombatModule.cs | |||
@@ -130,7 +130,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Combat.CombatModule | |||
130 | } | 130 | } |
131 | else | 131 | else |
132 | { | 132 | { |
133 | string killer = DeadAvatar.Scene.CommsManager.UUIDNameRequestString(part.OwnerID); | 133 | string killer = DeadAvatar.Scene.GetUserName(part.OwnerID); |
134 | DeadAvatar.ControllingClient.SendAgentAlertMessage("You impaled yourself on " + part.Name + " owned by " + killer +"!", true); | 134 | DeadAvatar.ControllingClient.SendAgentAlertMessage("You impaled yourself on " + part.Name + " owned by " + killer +"!", true); |
135 | } | 135 | } |
136 | //DeadAvatar.Scene. part.ObjectOwner | 136 | //DeadAvatar.Scene. part.ObjectOwner |
@@ -148,13 +148,19 @@ namespace OpenSim.Region.CoreModules.Avatar.Combat.CombatModule | |||
148 | private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID) | 148 | private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID) |
149 | { | 149 | { |
150 | ILandObject obj = avatar.Scene.LandChannel.GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); | 150 | ILandObject obj = avatar.Scene.LandChannel.GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); |
151 | if ((obj.LandData.Flags & (uint)ParcelFlags.AllowDamage) != 0) | 151 | try |
152 | { | 152 | { |
153 | avatar.Invulnerable = false; | 153 | if ((obj.LandData.Flags & (uint)ParcelFlags.AllowDamage) != 0) |
154 | { | ||
155 | avatar.Invulnerable = false; | ||
156 | } | ||
157 | else | ||
158 | { | ||
159 | avatar.Invulnerable = true; | ||
160 | } | ||
154 | } | 161 | } |
155 | else | 162 | catch (Exception) |
156 | { | 163 | { |
157 | avatar.Invulnerable = true; | ||
158 | } | 164 | } |
159 | } | 165 | } |
160 | } | 166 | } |
diff --git a/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs b/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs index 72ec869..fac052a 100644 --- a/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Dialog/DialogModule.cs | |||
@@ -31,9 +31,10 @@ using log4net; | |||
31 | using Nini.Config; | 31 | using Nini.Config; |
32 | using OpenMetaverse; | 32 | using OpenMetaverse; |
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Framework.Communications.Cache; | 34 | |
35 | using OpenSim.Region.Framework.Interfaces; | 35 | using OpenSim.Region.Framework.Interfaces; |
36 | using OpenSim.Region.Framework.Scenes; | 36 | using OpenSim.Region.Framework.Scenes; |
37 | using OpenSim.Services.Interfaces; | ||
37 | 38 | ||
38 | namespace OpenSim.Region.CoreModules.Avatar.Dialog | 39 | namespace OpenSim.Region.CoreModules.Avatar.Dialog |
39 | { | 40 | { |
@@ -116,12 +117,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Dialog | |||
116 | UUID avatarID, string objectName, UUID objectID, UUID ownerID, | 117 | UUID avatarID, string objectName, UUID objectID, UUID ownerID, |
117 | string message, UUID textureID, int ch, string[] buttonlabels) | 118 | string message, UUID textureID, int ch, string[] buttonlabels) |
118 | { | 119 | { |
119 | CachedUserInfo info = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(ownerID); | 120 | UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, ownerID); |
120 | string ownerFirstName, ownerLastName; | 121 | string ownerFirstName, ownerLastName; |
121 | if (info != null) | 122 | if (account != null) |
122 | { | 123 | { |
123 | ownerFirstName = info.UserProfile.FirstName; | 124 | ownerFirstName = account.FirstName; |
124 | ownerLastName = info.UserProfile.SurName; | 125 | ownerLastName = account.LastName; |
125 | } | 126 | } |
126 | else | 127 | else |
127 | { | 128 | { |
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index 086d4fe..de324c0 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | |||
@@ -28,7 +28,6 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Net; | ||
32 | using System.Reflection; | 31 | using System.Reflection; |
33 | using log4net; | 32 | using log4net; |
34 | using Nini.Config; | 33 | using Nini.Config; |
@@ -36,1119 +35,721 @@ using Nwc.XmlRpc; | |||
36 | using OpenMetaverse; | 35 | using OpenMetaverse; |
37 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
38 | using OpenSim.Framework.Communications; | 37 | using OpenSim.Framework.Communications; |
39 | using OpenSim.Framework.Communications.Cache; | ||
40 | using OpenSim.Region.Framework.Interfaces; | 38 | using OpenSim.Region.Framework.Interfaces; |
41 | using OpenSim.Region.Framework.Scenes; | 39 | using OpenSim.Region.Framework.Scenes; |
42 | using OpenSim.Services.Interfaces; | 40 | using OpenSim.Services.Interfaces; |
41 | using OpenSim.Services.Connectors.Friends; | ||
42 | using OpenSim.Server.Base; | ||
43 | using OpenSim.Framework.Servers.HttpServer; | ||
44 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
45 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; | ||
43 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | 46 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
44 | 47 | ||
45 | namespace OpenSim.Region.CoreModules.Avatar.Friends | 48 | namespace OpenSim.Region.CoreModules.Avatar.Friends |
46 | { | 49 | { |
47 | /* | 50 | public class FriendsModule : ISharedRegionModule, IFriendsModule |
48 | This module handles adding/removing friends, and the the presence | ||
49 | notification process for login/logoff of friends. | ||
50 | |||
51 | The presence notification works as follows: | ||
52 | - After the user initially connects to a region (so we now have a UDP | ||
53 | connection to work with), this module fetches the friends of user | ||
54 | (those are cached), their on-/offline status, and info about the | ||
55 | region they are in from the MessageServer. | ||
56 | - (*) It then informs the user about the on-/offline status of her friends. | ||
57 | - It then informs all online friends currently on this region-server about | ||
58 | user's new online status (this will save some network traffic, as local | ||
59 | messages don't have to be transferred inter-region, and it will be all | ||
60 | that has to be done in Standalone Mode). | ||
61 | - For the rest of the online friends (those not on this region-server), | ||
62 | this module uses the provided region-information to map users to | ||
63 | regions, and sends one notification to every region containing the | ||
64 | friends to inform on that server. | ||
65 | - The region-server will handle that in the following way: | ||
66 | - If it finds the friend, it informs her about the user being online. | ||
67 | - If it doesn't find the friend (maybe she TPed away in the meantime), | ||
68 | it stores that information. | ||
69 | - After it processed all friends, it returns the list of friends it | ||
70 | couldn't find. | ||
71 | - If this list isn't empty, the FriendsModule re-requests information | ||
72 | about those online friends that have been missed and starts at (*) | ||
73 | again until all friends have been found, or until it tried 3 times | ||
74 | (to prevent endless loops due to some uncaught error). | ||
75 | |||
76 | NOTE: Online/Offline notifications don't need to be sent on region change. | ||
77 | |||
78 | We implement two XMLRpc handlers here, handling all the inter-region things | ||
79 | we have to handle: | ||
80 | - On-/Offline-Notifications (bulk) | ||
81 | - Terminate Friendship messages (single) | ||
82 | */ | ||
83 | |||
84 | public class FriendsModule : IRegionModule, IFriendsModule | ||
85 | { | 51 | { |
86 | private class Transaction | 52 | protected class UserFriendData |
87 | { | 53 | { |
88 | public UUID agentID; | 54 | public UUID PrincipalID; |
89 | public string agentName; | 55 | public FriendInfo[] Friends; |
90 | public uint count; | 56 | public int Refcount; |
57 | public UUID RegionID; | ||
91 | 58 | ||
92 | public Transaction(UUID agentID, string agentName) | 59 | public bool IsFriend(string friend) |
93 | { | 60 | { |
94 | this.agentID = agentID; | 61 | foreach (FriendInfo fi in Friends) |
95 | this.agentName = agentName; | 62 | { |
96 | this.count = 1; | 63 | if (fi.Friend == friend) |
64 | return true; | ||
65 | } | ||
66 | |||
67 | return false; | ||
97 | } | 68 | } |
98 | } | 69 | } |
99 | 70 | ||
100 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 71 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
101 | 72 | ||
102 | private Cache m_friendLists = new Cache(CacheFlags.AllowUpdate); | 73 | protected List<Scene> m_Scenes = new List<Scene>(); |
103 | 74 | ||
104 | private Dictionary<UUID, ulong> m_rootAgents = new Dictionary<UUID, ulong>(); | 75 | protected IPresenceService m_PresenceService = null; |
76 | protected IFriendsService m_FriendsService = null; | ||
77 | protected FriendsSimConnector m_FriendsSimConnector; | ||
105 | 78 | ||
106 | private Dictionary<UUID, UUID> m_pendingCallingcardRequests = new Dictionary<UUID,UUID>(); | 79 | protected Dictionary<UUID, UserFriendData> m_Friends = |
80 | new Dictionary<UUID, UserFriendData>(); | ||
107 | 81 | ||
108 | private Scene m_initialScene; // saves a lookup if we don't have a specific scene | 82 | protected List<UUID> m_NeedsListOfFriends = new List<UUID>(); |
109 | private Dictionary<ulong, Scene> m_scenes = new Dictionary<ulong,Scene>(); | ||
110 | private IMessageTransferModule m_TransferModule = null; | ||
111 | 83 | ||
112 | private IGridService m_gridServices = null; | 84 | protected IPresenceService PresenceService |
113 | |||
114 | #region IRegionModule Members | ||
115 | |||
116 | public void Initialise(Scene scene, IConfigSource config) | ||
117 | { | 85 | { |
118 | lock (m_scenes) | 86 | get |
119 | { | 87 | { |
120 | if (m_scenes.Count == 0) | 88 | if (m_PresenceService == null) |
121 | { | 89 | { |
122 | MainServer.Instance.AddXmlRPCHandler("presence_update_bulk", processPresenceUpdateBulk); | 90 | if (m_Scenes.Count > 0) |
123 | MainServer.Instance.AddXmlRPCHandler("terminate_friend", processTerminateFriend); | 91 | m_PresenceService = m_Scenes[0].RequestModuleInterface<IPresenceService>(); |
124 | m_friendLists.DefaultTTL = new TimeSpan(1, 0, 0); // store entries for one hour max | ||
125 | m_initialScene = scene; | ||
126 | } | 92 | } |
127 | 93 | ||
128 | if (!m_scenes.ContainsKey(scene.RegionInfo.RegionHandle)) | 94 | return m_PresenceService; |
129 | m_scenes[scene.RegionInfo.RegionHandle] = scene; | ||
130 | } | 95 | } |
131 | |||
132 | scene.RegisterModuleInterface<IFriendsModule>(this); | ||
133 | |||
134 | scene.EventManager.OnNewClient += OnNewClient; | ||
135 | scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; | ||
136 | scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; | ||
137 | scene.EventManager.OnMakeChildAgent += MakeChildAgent; | ||
138 | scene.EventManager.OnClientClosed += ClientClosed; | ||
139 | } | 96 | } |
140 | 97 | ||
141 | public void PostInitialise() | 98 | protected IFriendsService FriendsService |
142 | { | 99 | { |
143 | if (m_scenes.Count > 0) | 100 | get |
144 | { | 101 | { |
145 | m_TransferModule = m_initialScene.RequestModuleInterface<IMessageTransferModule>(); | 102 | if (m_FriendsService == null) |
146 | m_gridServices = m_initialScene.GridService; | 103 | { |
147 | } | 104 | if (m_Scenes.Count > 0) |
148 | if (m_TransferModule == null) | 105 | m_FriendsService = m_Scenes[0].RequestModuleInterface<IFriendsService>(); |
149 | m_log.Error("[FRIENDS]: Unable to find a message transfer module, friendship offers will not work"); | 106 | } |
150 | } | ||
151 | |||
152 | public void Close() | ||
153 | { | ||
154 | } | ||
155 | 107 | ||
156 | public string Name | 108 | return m_FriendsService; |
157 | { | 109 | } |
158 | get { return "FriendsModule"; } | ||
159 | } | 110 | } |
160 | 111 | ||
161 | public bool IsSharedModule | 112 | protected IGridService GridService |
162 | { | 113 | { |
163 | get { return true; } | 114 | get |
115 | { | ||
116 | return m_Scenes[0].GridService; | ||
117 | } | ||
164 | } | 118 | } |
165 | 119 | ||
166 | #endregion | 120 | public IScene Scene |
167 | |||
168 | #region IInterregionFriendsComms | ||
169 | |||
170 | public List<UUID> InformFriendsInOtherRegion(UUID agentId, ulong destRegionHandle, List<UUID> friends, bool online) | ||
171 | { | 121 | { |
172 | List<UUID> tpdAway = new List<UUID>(); | 122 | get |
173 | |||
174 | // destRegionHandle is a region on another server | ||
175 | uint x = 0, y = 0; | ||
176 | Utils.LongToUInts(destRegionHandle, out x, out y); | ||
177 | GridRegion info = m_gridServices.GetRegionByPosition(m_initialScene.RegionInfo.ScopeID, (int)x, (int)y); | ||
178 | if (info != null) | ||
179 | { | 123 | { |
180 | string httpServer = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/presence_update_bulk"; | 124 | if (m_Scenes.Count > 0) |
181 | 125 | return m_Scenes[0]; | |
182 | Hashtable reqParams = new Hashtable(); | 126 | else |
183 | reqParams["agentID"] = agentId.ToString(); | 127 | return null; |
184 | reqParams["agentOnline"] = online; | ||
185 | int count = 0; | ||
186 | foreach (UUID uuid in friends) | ||
187 | { | ||
188 | reqParams["friendID_" + count++] = uuid.ToString(); | ||
189 | } | ||
190 | reqParams["friendCount"] = count; | ||
191 | |||
192 | IList parameters = new ArrayList(); | ||
193 | parameters.Add(reqParams); | ||
194 | try | ||
195 | { | ||
196 | XmlRpcRequest request = new XmlRpcRequest("presence_update_bulk", parameters); | ||
197 | XmlRpcResponse response = request.Send(httpServer, 5000); | ||
198 | Hashtable respData = (Hashtable)response.Value; | ||
199 | |||
200 | count = (int)respData["friendCount"]; | ||
201 | for (int i = 0; i < count; ++i) | ||
202 | { | ||
203 | UUID uuid; | ||
204 | if (UUID.TryParse((string)respData["friendID_" + i], out uuid)) tpdAway.Add(uuid); | ||
205 | } | ||
206 | } | ||
207 | catch (WebException e) | ||
208 | { | ||
209 | // Ignore connect failures, simulators come and go | ||
210 | // | ||
211 | if (!e.Message.Contains("ConnectFailure")) | ||
212 | { | ||
213 | m_log.Error("[OGS1 GRID SERVICES]: InformFriendsInOtherRegion XMLRPC failure: ", e); | ||
214 | } | ||
215 | } | ||
216 | catch (Exception e) | ||
217 | { | ||
218 | m_log.Error("[OGS1 GRID SERVICES]: InformFriendsInOtherRegion XMLRPC failure: ", e); | ||
219 | } | ||
220 | } | 128 | } |
221 | else m_log.WarnFormat("[OGS1 GRID SERVICES]: Couldn't find region {0}???", destRegionHandle); | ||
222 | |||
223 | return tpdAway; | ||
224 | } | 129 | } |
225 | 130 | ||
226 | public bool TriggerTerminateFriend(ulong destRegionHandle, UUID agentID, UUID exFriendID) | 131 | public void Initialise(IConfigSource config) |
227 | { | 132 | { |
228 | // destRegionHandle is a region on another server | 133 | IConfig friendsConfig = config.Configs["Friends"]; |
229 | uint x = 0, y = 0; | 134 | if (friendsConfig != null) |
230 | Utils.LongToUInts(destRegionHandle, out x, out y); | ||
231 | GridRegion info = m_gridServices.GetRegionByPosition(m_initialScene.RegionInfo.ScopeID, (int)x, (int)y); | ||
232 | if (info == null) | ||
233 | { | 135 | { |
234 | m_log.WarnFormat("[OGS1 GRID SERVICES]: Couldn't find region {0}", destRegionHandle); | 136 | int mPort = friendsConfig.GetInt("Port", 0); |
235 | return false; // region not found??? | ||
236 | } | ||
237 | 137 | ||
238 | string httpServer = "http://" + info.ExternalEndPoint.Address + ":" + info.HttpPort + "/presence_update_bulk"; | 138 | string connector = friendsConfig.GetString("Connector", String.Empty); |
139 | Object[] args = new Object[] { config }; | ||
239 | 140 | ||
240 | Hashtable reqParams = new Hashtable(); | 141 | m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(connector, args); |
241 | reqParams["agentID"] = agentID.ToString(); | 142 | m_FriendsSimConnector = new FriendsSimConnector(); |
242 | reqParams["friendID"] = exFriendID.ToString(); | ||
243 | 143 | ||
244 | IList parameters = new ArrayList(); | 144 | // Instantiate the request handler |
245 | parameters.Add(reqParams); | 145 | IHttpServer server = MainServer.GetHttpServer((uint)mPort); |
246 | try | 146 | server.AddStreamHandler(new FriendsRequestHandler(this)); |
247 | { | ||
248 | XmlRpcRequest request = new XmlRpcRequest("terminate_friend", parameters); | ||
249 | XmlRpcResponse response = request.Send(httpServer, 5000); | ||
250 | Hashtable respData = (Hashtable)response.Value; | ||
251 | 147 | ||
252 | return (bool)respData["success"]; | ||
253 | } | 148 | } |
254 | catch (Exception e) | 149 | |
150 | if (m_FriendsService == null) | ||
255 | { | 151 | { |
256 | m_log.Error("[OGS1 GRID SERVICES]: InformFriendsInOtherRegion XMLRPC failure: ", e); | 152 | m_log.Error("[FRIENDS]: No Connector defined in section Friends, or filed to load, cannot continue"); |
257 | return false; | 153 | throw new Exception("Connector load error"); |
258 | } | 154 | } |
155 | |||
259 | } | 156 | } |
260 | 157 | ||
261 | #endregion | 158 | public void PostInitialise() |
159 | { | ||
160 | } | ||
262 | 161 | ||
263 | #region Incoming XMLRPC messages | 162 | public void Close() |
264 | /// <summary> | ||
265 | /// Receive presence information changes about clients in other regions. | ||
266 | /// </summary> | ||
267 | /// <param name="req"></param> | ||
268 | /// <returns></returns> | ||
269 | public XmlRpcResponse processPresenceUpdateBulk(XmlRpcRequest req, IPEndPoint remoteClient) | ||
270 | { | 163 | { |
271 | Hashtable requestData = (Hashtable)req.Params[0]; | 164 | } |
272 | 165 | ||
273 | List<UUID> friendsNotHere = new List<UUID>(); | 166 | public void AddRegion(Scene scene) |
167 | { | ||
168 | m_Scenes.Add(scene); | ||
169 | scene.RegisterModuleInterface<IFriendsModule>(this); | ||
274 | 170 | ||
275 | // this is called with the expectation that all the friends in the request are on this region-server. | 171 | scene.EventManager.OnNewClient += OnNewClient; |
276 | // But as some time passed since we checked (on the other region-server, via the MessagingServer), | 172 | scene.EventManager.OnClientClosed += OnClientClosed; |
277 | // some of the friends might have teleported away. | 173 | scene.EventManager.OnMakeRootAgent += OnMakeRootAgent; |
278 | // Actually, even now, between this line and the sending below, some people could TP away. So, | 174 | scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; |
279 | // we'll have to lock the m_rootAgents list for the duration to prevent/delay that. | 175 | scene.EventManager.OnClientLogin += OnClientLogin; |
280 | lock (m_rootAgents) | 176 | } |
281 | { | ||
282 | List<ScenePresence> friendsHere = new List<ScenePresence>(); | ||
283 | |||
284 | try | ||
285 | { | ||
286 | UUID agentID = new UUID((string)requestData["agentID"]); | ||
287 | bool agentOnline = (bool)requestData["agentOnline"]; | ||
288 | int count = (int)requestData["friendCount"]; | ||
289 | for (int i = 0; i < count; ++i) | ||
290 | { | ||
291 | UUID uuid; | ||
292 | if (UUID.TryParse((string)requestData["friendID_" + i], out uuid)) | ||
293 | { | ||
294 | if (m_rootAgents.ContainsKey(uuid)) friendsHere.Add(GetRootPresenceFromAgentID(uuid)); | ||
295 | else friendsNotHere.Add(uuid); | ||
296 | } | ||
297 | } | ||
298 | 177 | ||
299 | // now send, as long as they are still here... | 178 | public void RegionLoaded(Scene scene) |
300 | UUID[] agentUUID = new UUID[] { agentID }; | 179 | { |
301 | if (agentOnline) | 180 | } |
302 | { | ||
303 | foreach (ScenePresence agent in friendsHere) | ||
304 | { | ||
305 | agent.ControllingClient.SendAgentOnline(agentUUID); | ||
306 | } | ||
307 | } | ||
308 | else | ||
309 | { | ||
310 | foreach (ScenePresence agent in friendsHere) | ||
311 | { | ||
312 | agent.ControllingClient.SendAgentOffline(agentUUID); | ||
313 | } | ||
314 | } | ||
315 | } | ||
316 | catch(Exception e) | ||
317 | { | ||
318 | m_log.Warn("[FRIENDS]: Got exception while parsing presence_update_bulk request:", e); | ||
319 | } | ||
320 | } | ||
321 | 181 | ||
322 | // no need to lock anymore; if TPs happen now, worst case is that we have an additional agent in this region, | 182 | public void RemoveRegion(Scene scene) |
323 | // which should be caught on the next iteration... | 183 | { |
324 | Hashtable result = new Hashtable(); | 184 | m_Scenes.Remove(scene); |
325 | int idx = 0; | 185 | } |
326 | foreach (UUID uuid in friendsNotHere) | ||
327 | { | ||
328 | result["friendID_" + idx++] = uuid.ToString(); | ||
329 | } | ||
330 | result["friendCount"] = idx; | ||
331 | 186 | ||
332 | XmlRpcResponse response = new XmlRpcResponse(); | 187 | public string Name |
333 | response.Value = result; | 188 | { |
189 | get { return "FriendsModule"; } | ||
190 | } | ||
334 | 191 | ||
335 | return response; | 192 | public Type ReplaceableInterface |
193 | { | ||
194 | get { return null; } | ||
336 | } | 195 | } |
337 | 196 | ||
338 | public XmlRpcResponse processTerminateFriend(XmlRpcRequest req, IPEndPoint remoteClient) | 197 | public uint GetFriendPerms(UUID principalID, UUID friendID) |
339 | { | 198 | { |
340 | Hashtable requestData = (Hashtable)req.Params[0]; | 199 | if (!m_Friends.ContainsKey(principalID)) |
200 | return 0; | ||
341 | 201 | ||
342 | bool success = false; | 202 | UserFriendData data = m_Friends[principalID]; |
343 | 203 | ||
344 | UUID agentID; | 204 | foreach (FriendInfo fi in data.Friends) |
345 | UUID friendID; | ||
346 | if (requestData.ContainsKey("agentID") && UUID.TryParse((string)requestData["agentID"], out agentID) && | ||
347 | requestData.ContainsKey("friendID") && UUID.TryParse((string)requestData["friendID"], out friendID)) | ||
348 | { | 205 | { |
349 | // try to find it and if it is there, prevent it to vanish before we sent the message | 206 | if (fi.Friend == friendID.ToString()) |
350 | lock (m_rootAgents) | 207 | return (uint)fi.TheirFlags; |
351 | { | ||
352 | if (m_rootAgents.ContainsKey(agentID)) | ||
353 | { | ||
354 | m_log.DebugFormat("[FRIEND]: Sending terminate friend {0} to agent {1}", friendID, agentID); | ||
355 | GetRootPresenceFromAgentID(agentID).ControllingClient.SendTerminateFriend(friendID); | ||
356 | success = true; | ||
357 | } | ||
358 | } | ||
359 | } | 208 | } |
360 | 209 | return 0; | |
361 | // return whether we were successful | ||
362 | Hashtable result = new Hashtable(); | ||
363 | result["success"] = success; | ||
364 | |||
365 | XmlRpcResponse response = new XmlRpcResponse(); | ||
366 | response.Value = result; | ||
367 | return response; | ||
368 | } | 210 | } |
369 | 211 | ||
370 | #endregion | ||
371 | |||
372 | #region Scene events | ||
373 | |||
374 | private void OnNewClient(IClientAPI client) | 212 | private void OnNewClient(IClientAPI client) |
375 | { | 213 | { |
376 | // All friends establishment protocol goes over instant message | ||
377 | // There's no way to send a message from the sim | ||
378 | // to a user to 'add a friend' without causing dialog box spam | ||
379 | |||
380 | // Subscribe to instant messages | ||
381 | client.OnInstantMessage += OnInstantMessage; | 214 | client.OnInstantMessage += OnInstantMessage; |
382 | |||
383 | // Friend list management | ||
384 | client.OnApproveFriendRequest += OnApproveFriendRequest; | 215 | client.OnApproveFriendRequest += OnApproveFriendRequest; |
385 | client.OnDenyFriendRequest += OnDenyFriendRequest; | 216 | client.OnDenyFriendRequest += OnDenyFriendRequest; |
386 | client.OnTerminateFriendship += OnTerminateFriendship; | 217 | client.OnTerminateFriendship += OnTerminateFriendship; |
387 | 218 | ||
388 | // ... calling card handling... | 219 | client.OnGrantUserRights += OnGrantUserRights; |
389 | client.OnOfferCallingCard += OnOfferCallingCard; | ||
390 | client.OnAcceptCallingCard += OnAcceptCallingCard; | ||
391 | client.OnDeclineCallingCard += OnDeclineCallingCard; | ||
392 | 220 | ||
393 | // we need this one exactly once per agent session (see comments in the handler below) | ||
394 | client.OnEconomyDataRequest += OnEconomyDataRequest; | ||
395 | |||
396 | // if it leaves, we want to know, too | ||
397 | client.OnLogout += OnLogout; | 221 | client.OnLogout += OnLogout; |
398 | |||
399 | client.OnGrantUserRights += GrantUserFriendRights; | ||
400 | client.OnTrackAgent += FindAgent; | ||
401 | client.OnFindAgent += FindAgent; | ||
402 | 222 | ||
223 | if (m_Friends.ContainsKey(client.AgentId)) | ||
224 | { | ||
225 | m_Friends[client.AgentId].Refcount++; | ||
226 | return; | ||
227 | } | ||
228 | |||
229 | UserFriendData newFriends = new UserFriendData(); | ||
230 | |||
231 | newFriends.PrincipalID = client.AgentId; | ||
232 | newFriends.Friends = m_FriendsService.GetFriends(client.AgentId); | ||
233 | newFriends.Refcount = 1; | ||
234 | newFriends.RegionID = UUID.Zero; | ||
235 | |||
236 | m_Friends.Add(client.AgentId, newFriends); | ||
237 | |||
238 | //StatusChange(client.AgentId, true); | ||
403 | } | 239 | } |
404 | 240 | ||
405 | private void ClientClosed(UUID AgentId, Scene scene) | 241 | private void OnClientClosed(UUID agentID, Scene scene) |
406 | { | 242 | { |
407 | // agent's client was closed. As we handle logout in OnLogout, this here has only to handle | 243 | if (m_Friends.ContainsKey(agentID)) |
408 | // TPing away (root agent is closed) or TPing/crossing in a region far enough away (client | ||
409 | // agent is closed). | ||
410 | // NOTE: In general, this doesn't mean that the agent logged out, just that it isn't around | ||
411 | // in one of the regions here anymore. | ||
412 | lock (m_rootAgents) | ||
413 | { | 244 | { |
414 | if (m_rootAgents.ContainsKey(AgentId)) | 245 | if (m_Friends[agentID].Refcount == 1) |
415 | { | 246 | m_Friends.Remove(agentID); |
416 | m_rootAgents.Remove(AgentId); | 247 | else |
417 | } | 248 | m_Friends[agentID].Refcount--; |
418 | } | 249 | } |
419 | } | 250 | } |
420 | 251 | ||
421 | private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID) | 252 | private void OnLogout(IClientAPI client) |
422 | { | 253 | { |
423 | lock (m_rootAgents) | 254 | StatusChange(client.AgentId, false); |
424 | { | 255 | m_Friends.Remove(client.AgentId); |
425 | m_rootAgents[avatar.UUID] = avatar.RegionHandle; | ||
426 | // Claim User! my user! Mine mine mine! | ||
427 | } | ||
428 | } | 256 | } |
429 | 257 | ||
430 | private void MakeChildAgent(ScenePresence avatar) | 258 | private void OnMakeRootAgent(ScenePresence sp) |
431 | { | 259 | { |
432 | lock (m_rootAgents) | 260 | UUID agentID = sp.ControllingClient.AgentId; |
261 | |||
262 | if (m_Friends.ContainsKey(agentID)) | ||
433 | { | 263 | { |
434 | if (m_rootAgents.ContainsKey(avatar.UUID)) | 264 | if (m_Friends[agentID].RegionID == UUID.Zero && m_Friends[agentID].Friends == null) |
435 | { | 265 | { |
436 | // only delete if the region matches. As this is a shared module, the avatar could be | 266 | m_Friends[agentID].Friends = |
437 | // root agent in another region on this server. | 267 | m_FriendsService.GetFriends(agentID); |
438 | if (m_rootAgents[avatar.UUID] == avatar.RegionHandle) | ||
439 | { | ||
440 | m_rootAgents.Remove(avatar.UUID); | ||
441 | // m_log.Debug("[FRIEND]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent"); | ||
442 | } | ||
443 | } | 268 | } |
269 | m_Friends[agentID].RegionID = | ||
270 | sp.ControllingClient.Scene.RegionInfo.RegionID; | ||
444 | } | 271 | } |
445 | } | 272 | } |
446 | #endregion | ||
447 | 273 | ||
448 | private ScenePresence GetRootPresenceFromAgentID(UUID AgentID) | 274 | |
275 | private void OnMakeChildAgent(ScenePresence sp) | ||
449 | { | 276 | { |
450 | ScenePresence returnAgent = null; | 277 | UUID agentID = sp.ControllingClient.AgentId; |
451 | lock (m_scenes) | 278 | |
279 | if (m_Friends.ContainsKey(agentID)) | ||
452 | { | 280 | { |
453 | ScenePresence queryagent = null; | 281 | if (m_Friends[agentID].RegionID == sp.ControllingClient.Scene.RegionInfo.RegionID) |
454 | foreach (Scene scene in m_scenes.Values) | 282 | m_Friends[agentID].RegionID = UUID.Zero; |
455 | { | ||
456 | queryagent = scene.GetScenePresence(AgentID); | ||
457 | if (queryagent != null) | ||
458 | { | ||
459 | if (!queryagent.IsChildAgent) | ||
460 | { | ||
461 | returnAgent = queryagent; | ||
462 | break; | ||
463 | } | ||
464 | } | ||
465 | } | ||
466 | } | 283 | } |
467 | return returnAgent; | ||
468 | } | 284 | } |
469 | 285 | ||
470 | private ScenePresence GetAnyPresenceFromAgentID(UUID AgentID) | 286 | private void OnClientLogin(IClientAPI client) |
471 | { | 287 | { |
472 | ScenePresence returnAgent = null; | 288 | UUID agentID = client.AgentId; |
473 | lock (m_scenes) | 289 | |
474 | { | 290 | // Inform the friends that this user is online |
475 | ScenePresence queryagent = null; | 291 | StatusChange(agentID, true); |
476 | foreach (Scene scene in m_scenes.Values) | 292 | |
293 | // Register that we need to send the list of online friends to this user | ||
294 | lock (m_NeedsListOfFriends) | ||
295 | if (!m_NeedsListOfFriends.Contains(agentID)) | ||
477 | { | 296 | { |
478 | queryagent = scene.GetScenePresence(AgentID); | 297 | m_NeedsListOfFriends.Add(agentID); |
479 | if (queryagent != null) | ||
480 | { | ||
481 | returnAgent = queryagent; | ||
482 | break; | ||
483 | } | ||
484 | } | 298 | } |
485 | } | ||
486 | return returnAgent; | ||
487 | } | 299 | } |
488 | 300 | ||
489 | public void OfferFriendship(UUID fromUserId, IClientAPI toUserClient, string offerMessage) | 301 | public void SendFriendsOnlineIfNeeded(IClientAPI client) |
490 | { | 302 | { |
491 | CachedUserInfo userInfo = m_initialScene.CommsManager.UserProfileCacheService.GetUserDetails(fromUserId); | 303 | UUID agentID = client.AgentId; |
492 | 304 | if (m_NeedsListOfFriends.Contains(agentID)) | |
493 | if (userInfo != null) | ||
494 | { | 305 | { |
495 | GridInstantMessage msg = new GridInstantMessage( | 306 | if (!m_Friends.ContainsKey(agentID)) |
496 | toUserClient.Scene, fromUserId, userInfo.UserProfile.Name, toUserClient.AgentId, | 307 | { |
497 | (byte)InstantMessageDialog.FriendshipOffered, offerMessage, false, Vector3.Zero); | 308 | m_log.DebugFormat("[FRIENDS MODULE]: agent {0} not found in local cache", agentID); |
498 | 309 | return; | |
499 | FriendshipOffered(msg); | 310 | } |
500 | } | ||
501 | else | ||
502 | { | ||
503 | m_log.ErrorFormat("[FRIENDS]: No user found for id {0} in OfferFriendship()", fromUserId); | ||
504 | } | ||
505 | } | ||
506 | 311 | ||
507 | #region FriendRequestHandling | 312 | // |
313 | // Send the friends online | ||
314 | // | ||
315 | List<UUID> online = GetOnlineFriends(agentID); | ||
316 | if (online.Count > 0) | ||
317 | { | ||
318 | m_log.DebugFormat("[FRIENDS MODULE]: User {0} in region {1} has {2} friends online", client.AgentId, client.Scene.RegionInfo.RegionName, online.Count); | ||
319 | client.SendAgentOnline(online.ToArray()); | ||
320 | } | ||
508 | 321 | ||
509 | private void OnInstantMessage(IClientAPI client, GridInstantMessage im) | 322 | // |
510 | { | 323 | // Send outstanding friendship offers |
511 | // Friend Requests go by Instant Message.. using the dialog param | 324 | // |
512 | // https://wiki.secondlife.com/wiki/ImprovedInstantMessage | 325 | if (m_Friends.ContainsKey(agentID)) |
326 | { | ||
327 | List<string> outstanding = new List<string>(); | ||
513 | 328 | ||
514 | if (im.dialog == (byte)InstantMessageDialog.FriendshipOffered) // 38 | 329 | foreach (FriendInfo fi in m_Friends[agentID].Friends) |
515 | { | 330 | if (fi.TheirFlags == -1) |
516 | // fromAgentName is the *destination* name (the friend we offer friendship to) | 331 | outstanding.Add(fi.Friend); |
517 | ScenePresence initiator = GetAnyPresenceFromAgentID(new UUID(im.fromAgentID)); | 332 | |
518 | im.fromAgentName = initiator != null ? initiator.Name : "(hippo)"; | 333 | GridInstantMessage im = new GridInstantMessage(client.Scene, UUID.Zero, "", agentID, (byte)InstantMessageDialog.FriendshipOffered, "Will you be my friend?", true, Vector3.Zero); |
519 | 334 | foreach (string fid in outstanding) | |
520 | FriendshipOffered(im); | 335 | { |
521 | } | 336 | try |
522 | else if (im.dialog == (byte)InstantMessageDialog.FriendshipAccepted) // 39 | 337 | { |
523 | { | 338 | im.fromAgentID = new Guid(fid); |
524 | FriendshipAccepted(client, im); | 339 | } |
525 | } | 340 | catch |
526 | else if (im.dialog == (byte)InstantMessageDialog.FriendshipDeclined) // 40 | 341 | { |
527 | { | 342 | continue; |
528 | FriendshipDeclined(client, im); | 343 | } |
529 | } | ||
530 | } | ||
531 | |||
532 | /// <summary> | ||
533 | /// Invoked when a user offers a friendship. | ||
534 | /// </summary> | ||
535 | /// | ||
536 | /// <param name="im"></param> | ||
537 | /// <param name="client"></param> | ||
538 | private void FriendshipOffered(GridInstantMessage im) | ||
539 | { | ||
540 | // this is triggered by the initiating agent: | ||
541 | // A local agent offers friendship to some possibly remote friend. | ||
542 | // A IM is triggered, processed here and sent to the friend (possibly in a remote region). | ||
543 | 344 | ||
544 | m_log.DebugFormat("[FRIEND]: Offer(38) - From: {0}, FromName: {1} To: {2}, Session: {3}, Message: {4}, Offline {5}", | 345 | UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, new UUID(im.fromAgentID)); |
545 | im.fromAgentID, im.fromAgentName, im.toAgentID, im.imSessionID, im.message, im.offline); | 346 | im.fromAgentName = account.FirstName + " " + account.LastName; |
546 | 347 | ||
547 | // 1.20 protocol sends an UUID in the message field, instead of the friendship offer text. | 348 | PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid }); |
548 | // For interoperability, we have to clear that | 349 | PresenceInfo presence = PresenceInfo.GetOnlinePresence(presences); |
549 | if (Util.isUUID(im.message)) im.message = ""; | 350 | if (presence != null) |
351 | im.offline = 0; | ||
550 | 352 | ||
551 | // be sneeky and use the initiator-UUID as transactionID. This means we can be stateless. | 353 | im.imSessionID = im.fromAgentID; |
552 | // we have to look up the agent name on friendship-approval, though. | ||
553 | im.imSessionID = im.fromAgentID; | ||
554 | 354 | ||
555 | if (m_TransferModule != null) | 355 | // Finally |
556 | { | 356 | LocalFriendshipOffered(agentID, im); |
557 | // Send it to whoever is the destination. | ||
558 | // If new friend is local, it will send an IM to the viewer. | ||
559 | // If new friend is remote, it will cause a OnGridInstantMessage on the remote server | ||
560 | m_TransferModule.SendInstantMessage( | ||
561 | im, | ||
562 | delegate(bool success) | ||
563 | { | ||
564 | m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); | ||
565 | } | 357 | } |
566 | ); | ||
567 | } | ||
568 | } | ||
569 | |||
570 | /// <summary> | ||
571 | /// Invoked when a user accepts a friendship offer. | ||
572 | /// </summary> | ||
573 | /// <param name="im"></param> | ||
574 | /// <param name="client"></param> | ||
575 | private void FriendshipAccepted(IClientAPI client, GridInstantMessage im) | ||
576 | { | ||
577 | m_log.DebugFormat("[FRIEND]: 39 - from client {0}, agent {2} {3}, imsession {4} to {5}: {6} (dialog {7})", | ||
578 | client.AgentId, im.fromAgentID, im.fromAgentName, im.imSessionID, im.toAgentID, im.message, im.dialog); | ||
579 | } | ||
580 | |||
581 | /// <summary> | ||
582 | /// Invoked when a user declines a friendship offer. | ||
583 | /// </summary> | ||
584 | /// May not currently be used - see OnDenyFriendRequest() instead | ||
585 | /// <param name="im"></param> | ||
586 | /// <param name="client"></param> | ||
587 | private void FriendshipDeclined(IClientAPI client, GridInstantMessage im) | ||
588 | { | ||
589 | UUID fromAgentID = new UUID(im.fromAgentID); | ||
590 | UUID toAgentID = new UUID(im.toAgentID); | ||
591 | |||
592 | // declining the friendship offer causes a type 40 IM being sent to the (possibly remote) initiator | ||
593 | // toAgentID is initiator, fromAgentID declined friendship | ||
594 | m_log.DebugFormat("[FRIEND]: 40 - from client {0}, agent {1} {2}, imsession {3} to {4}: {5} (dialog {6})", | ||
595 | client != null ? client.AgentId.ToString() : "<null>", | ||
596 | fromAgentID, im.fromAgentName, im.imSessionID, im.toAgentID, im.message, im.dialog); | ||
597 | |||
598 | // Send the decline to whoever is the destination. | ||
599 | GridInstantMessage msg | ||
600 | = new GridInstantMessage( | ||
601 | client.Scene, fromAgentID, client.Name, toAgentID, | ||
602 | im.dialog, im.message, im.offline != 0, im.Position); | ||
603 | |||
604 | // If new friend is local, it will send an IM to the viewer. | ||
605 | // If new friend is remote, it will cause a OnGridInstantMessage on the remote server | ||
606 | m_TransferModule.SendInstantMessage(msg, | ||
607 | delegate(bool success) { | ||
608 | m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); | ||
609 | } | 358 | } |
610 | ); | ||
611 | } | ||
612 | |||
613 | private void OnGridInstantMessage(GridInstantMessage msg) | ||
614 | { | ||
615 | // This event won't be raised unless we have that agent, | ||
616 | // so we can depend on the above not trying to send | ||
617 | // via grid again | ||
618 | //m_log.DebugFormat("[FRIEND]: Got GridIM from {0}, to {1}, imSession {2}, message {3}, dialog {4}", | ||
619 | // msg.fromAgentID, msg.toAgentID, msg.imSessionID, msg.message, msg.dialog); | ||
620 | |||
621 | if (msg.dialog == (byte)InstantMessageDialog.FriendshipOffered || | ||
622 | msg.dialog == (byte)InstantMessageDialog.FriendshipAccepted || | ||
623 | msg.dialog == (byte)InstantMessageDialog.FriendshipDeclined) | ||
624 | { | ||
625 | // this should succeed as we *know* the root agent is here. | ||
626 | m_TransferModule.SendInstantMessage(msg, | ||
627 | delegate(bool success) { | ||
628 | //m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); | ||
629 | } | ||
630 | ); | ||
631 | } | ||
632 | 359 | ||
633 | if (msg.dialog == (byte)InstantMessageDialog.FriendshipAccepted) | 360 | lock (m_NeedsListOfFriends) |
634 | { | 361 | m_NeedsListOfFriends.Remove(agentID); |
635 | // for accept friendship, we have to do a bit more | ||
636 | ApproveFriendship(new UUID(msg.fromAgentID), new UUID(msg.toAgentID), msg.fromAgentName); | ||
637 | } | 362 | } |
638 | } | 363 | } |
639 | 364 | ||
640 | private void ApproveFriendship(UUID fromAgentID, UUID toAgentID, string fromName) | 365 | List<UUID> GetOnlineFriends(UUID userID) |
641 | { | 366 | { |
642 | m_log.DebugFormat("[FRIEND]: Approve friendship from {0} (ID: {1}) to {2}", | 367 | List<string> friendList = new List<string>(); |
643 | fromAgentID, fromName, toAgentID); | ||
644 | 368 | ||
645 | // a new friend was added in the initiator's and friend's data, so the cache entries are wrong now. | 369 | foreach (FriendInfo fi in m_Friends[userID].Friends) |
646 | lock (m_friendLists) | ||
647 | { | 370 | { |
648 | m_friendLists.Invalidate(fromAgentID.ToString()); | 371 | if (((fi.TheirFlags & 1) != 0) && (fi.TheirFlags != -1)) |
649 | m_friendLists.Invalidate(toAgentID.ToString()); | 372 | friendList.Add(fi.Friend); |
650 | } | 373 | } |
651 | 374 | ||
652 | // now send presence update and add a calling card for the new friend | 375 | PresenceInfo[] presence = PresenceService.GetAgents(friendList.ToArray()); |
653 | 376 | ||
654 | ScenePresence initiator = GetAnyPresenceFromAgentID(toAgentID); | 377 | List<UUID> online = new List<UUID>(); |
655 | if (initiator == null) | ||
656 | { | ||
657 | // quite wrong. Shouldn't happen. | ||
658 | m_log.WarnFormat("[FRIEND]: Coudn't find initiator of friend request {0}", toAgentID); | ||
659 | return; | ||
660 | } | ||
661 | 378 | ||
662 | m_log.DebugFormat("[FRIEND]: Tell {0} that {1} is online", | 379 | foreach (PresenceInfo pi in presence) |
663 | initiator.Name, fromName); | ||
664 | // tell initiator that friend is online | ||
665 | initiator.ControllingClient.SendAgentOnline(new UUID[] { fromAgentID }); | ||
666 | |||
667 | // find the folder for the friend... | ||
668 | //InventoryFolderImpl folder = | ||
669 | // initiator.Scene.CommsManager.UserProfileCacheService.GetUserDetails(toAgentID).FindFolderForType((int)InventoryType.CallingCard); | ||
670 | IInventoryService invService = initiator.Scene.InventoryService; | ||
671 | InventoryFolderBase folder = invService.GetFolderForType(toAgentID, AssetType.CallingCard); | ||
672 | if (folder != null) | ||
673 | { | 380 | { |
674 | // ... and add the calling card | 381 | if (pi.Online) |
675 | CreateCallingCard(initiator.ControllingClient, fromAgentID, folder.ID, fromName); | 382 | { |
383 | online.Add(new UUID(pi.UserID)); | ||
384 | //m_log.DebugFormat("[XXX] {0} friend online {1}", userID, pi.UserID); | ||
385 | } | ||
676 | } | 386 | } |
387 | |||
388 | return online; | ||
677 | } | 389 | } |
678 | 390 | ||
679 | private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) | 391 | // |
392 | // Find the client for a ID | ||
393 | // | ||
394 | public IClientAPI LocateClientObject(UUID agentID) | ||
680 | { | 395 | { |
681 | m_log.DebugFormat("[FRIEND]: Got approve friendship from {0} {1}, agentID {2}, tid {3}", | 396 | Scene scene = GetClientScene(agentID); |
682 | client.Name, client.AgentId, agentID, friendID); | 397 | if(scene == null) |
683 | 398 | return null; | |
684 | // store the new friend persistently for both avatars | ||
685 | m_initialScene.StoreAddFriendship(friendID, agentID, (uint) FriendRights.CanSeeOnline); | ||
686 | 399 | ||
687 | // The cache entries aren't valid anymore either, as we just added a friend to both sides. | 400 | ScenePresence presence = scene.GetScenePresence(agentID); |
688 | lock (m_friendLists) | 401 | if(presence == null) |
689 | { | 402 | return null; |
690 | m_friendLists.Invalidate(agentID.ToString()); | ||
691 | m_friendLists.Invalidate(friendID.ToString()); | ||
692 | } | ||
693 | 403 | ||
694 | // if it's a local friend, we don't have to do the lookup | 404 | return presence.ControllingClient; |
695 | ScenePresence friendPresence = GetAnyPresenceFromAgentID(friendID); | 405 | } |
696 | 406 | ||
697 | if (friendPresence != null) | 407 | // |
408 | // Find the scene for an agent | ||
409 | // | ||
410 | private Scene GetClientScene(UUID agentId) | ||
411 | { | ||
412 | lock (m_Scenes) | ||
698 | { | 413 | { |
699 | m_log.Debug("[FRIEND]: Local agent detected."); | 414 | foreach (Scene scene in m_Scenes) |
700 | 415 | { | |
701 | // create calling card | 416 | ScenePresence presence = scene.GetScenePresence(agentId); |
702 | CreateCallingCard(client, friendID, callingCardFolders[0], friendPresence.Name); | 417 | if (presence != null) |
703 | 418 | { | |
704 | // local message means OnGridInstantMessage won't be triggered, so do the work here. | 419 | if (!presence.IsChildAgent) |
705 | friendPresence.ControllingClient.SendInstantMessage( | 420 | return scene; |
706 | new GridInstantMessage(client.Scene, agentID, | 421 | } |
707 | client.Name, friendID, | 422 | } |
708 | (byte)InstantMessageDialog.FriendshipAccepted, | ||
709 | agentID.ToString(), false, Vector3.Zero)); | ||
710 | ApproveFriendship(agentID, friendID, client.Name); | ||
711 | } | 423 | } |
712 | else | 424 | return null; |
713 | { | 425 | } |
714 | m_log.Debug("[FRIEND]: Remote agent detected."); | ||
715 | |||
716 | // fetch the friend's name for the calling card. | ||
717 | CachedUserInfo info = m_initialScene.CommsManager.UserProfileCacheService.GetUserDetails(friendID); | ||
718 | |||
719 | // create calling card | ||
720 | CreateCallingCard(client, friendID, callingCardFolders[0], | ||
721 | info.UserProfile.FirstName + " " + info.UserProfile.SurName); | ||
722 | 426 | ||
723 | // Compose (remote) response to friend. | 427 | /// <summary> |
724 | GridInstantMessage msg = new GridInstantMessage(client.Scene, agentID, client.Name, friendID, | 428 | /// Caller beware! Call this only for root agents. |
725 | (byte)InstantMessageDialog.FriendshipAccepted, | 429 | /// </summary> |
726 | agentID.ToString(), false, Vector3.Zero); | 430 | /// <param name="agentID"></param> |
727 | if (m_TransferModule != null) | 431 | /// <param name="online"></param> |
432 | private void StatusChange(UUID agentID, bool online) | ||
433 | { | ||
434 | if (m_Friends.ContainsKey(agentID)) | ||
435 | { | ||
436 | List<FriendInfo> friendList = new List<FriendInfo>(); | ||
437 | foreach (FriendInfo fi in m_Friends[agentID].Friends) | ||
728 | { | 438 | { |
729 | m_TransferModule.SendInstantMessage(msg, | 439 | if (((fi.MyFlags & 1) != 0) && (fi.TheirFlags != -1)) |
730 | delegate(bool success) { | 440 | friendList.Add(fi); |
731 | m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); | 441 | } |
732 | } | 442 | foreach (FriendInfo fi in friendList) |
733 | ); | 443 | { |
444 | // Notify about this user status | ||
445 | StatusNotify(fi, agentID, online); | ||
734 | } | 446 | } |
735 | } | 447 | } |
736 | |||
737 | // tell client that new friend is online | ||
738 | client.SendAgentOnline(new UUID[] { friendID }); | ||
739 | } | 448 | } |
740 | 449 | ||
741 | private void OnDenyFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) | 450 | private void StatusNotify(FriendInfo friend, UUID userID, bool online) |
742 | { | 451 | { |
743 | m_log.DebugFormat("[FRIEND]: Got deny friendship from {0} {1}, agentID {2}, tid {3}", | 452 | UUID friendID = UUID.Zero; |
744 | client.Name, client.AgentId, agentID, friendID); | 453 | |
745 | 454 | if (UUID.TryParse(friend.Friend, out friendID)) | |
746 | // Compose response to other agent. | ||
747 | GridInstantMessage msg = new GridInstantMessage(client.Scene, agentID, client.Name, friendID, | ||
748 | (byte)InstantMessageDialog.FriendshipDeclined, | ||
749 | agentID.ToString(), false, Vector3.Zero); | ||
750 | // send decline to initiator | ||
751 | if (m_TransferModule != null) | ||
752 | { | 455 | { |
753 | m_TransferModule.SendInstantMessage(msg, | 456 | // Try local |
754 | delegate(bool success) { | 457 | if (LocalStatusNotification(userID, friendID, online)) |
755 | m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); | 458 | return; |
756 | } | 459 | |
757 | ); | 460 | // The friend is not here [as root]. Let's forward. |
461 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); | ||
462 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); | ||
463 | if (friendSession != null) | ||
464 | { | ||
465 | GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); | ||
466 | m_FriendsSimConnector.StatusNotify(region, userID, friendID, online); | ||
467 | } | ||
468 | |||
469 | // Friend is not online. Ignore. | ||
758 | } | 470 | } |
759 | } | 471 | } |
760 | 472 | ||
761 | private void OnTerminateFriendship(IClientAPI client, UUID agentID, UUID exfriendID) | 473 | private void OnInstantMessage(IClientAPI client, GridInstantMessage im) |
762 | { | 474 | { |
763 | // client.AgentId == agentID! | 475 | if (im.dialog == (byte)OpenMetaverse.InstantMessageDialog.FriendshipOffered) |
476 | { | ||
477 | // we got a friendship offer | ||
478 | UUID principalID = new UUID(im.fromAgentID); | ||
479 | UUID friendID = new UUID(im.toAgentID); | ||
764 | 480 | ||
765 | // this removes the friends from the stored friendlists. After the next login, they will be gone... | 481 | m_log.DebugFormat("[FRIENDS]: {0} offered friendship to {1}", principalID, friendID); |
766 | m_initialScene.StoreRemoveFriendship(agentID, exfriendID); | ||
767 | 482 | ||
768 | // ... now tell the two involved clients that they aren't friends anymore. | 483 | // This user wants to be friends with the other user. |
484 | // Let's add both relations to the DB, but one of them is inactive (-1) | ||
485 | FriendsService.StoreFriend(friendID, principalID.ToString(), 0); | ||
769 | 486 | ||
770 | // I don't know why we have to tell <agent>, as this was caused by her, but that's how it works in SL... | 487 | // Now let's ask the other user to be friends with this user |
771 | client.SendTerminateFriend(exfriendID); | 488 | ForwardFriendshipOffer(principalID, friendID, im); |
772 | |||
773 | // now send the friend, if online | ||
774 | ScenePresence presence = GetAnyPresenceFromAgentID(exfriendID); | ||
775 | if (presence != null) | ||
776 | { | ||
777 | m_log.DebugFormat("[FRIEND]: Sending terminate friend {0} to agent {1}", agentID, exfriendID); | ||
778 | presence.ControllingClient.SendTerminateFriend(agentID); | ||
779 | } | 489 | } |
780 | else | 490 | } |
781 | { | ||
782 | // retry 3 times, in case the agent TPed from the last known region... | ||
783 | for (int retry = 0; retry < 3; ++retry) | ||
784 | { | ||
785 | // wasn't sent, so ex-friend wasn't around on this region-server. Fetch info and try to send | ||
786 | UserAgentData data = m_initialScene.CommsManager.UserService.GetAgentByUUID(exfriendID); | ||
787 | |||
788 | if (null == data) | ||
789 | break; | ||
790 | |||
791 | if (!data.AgentOnline) | ||
792 | { | ||
793 | m_log.DebugFormat("[FRIEND]: {0} is offline, so not sending TerminateFriend", exfriendID); | ||
794 | break; // if ex-friend isn't online, we don't need to send | ||
795 | } | ||
796 | 491 | ||
797 | m_log.DebugFormat("[FRIEND]: Sending remote terminate friend {0} to agent {1}@{2}", | 492 | private void ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im) |
798 | agentID, exfriendID, data.Handle); | 493 | { |
494 | // !!!!!!!! This is a hack so that we don't have to keep state (transactionID/imSessionID) | ||
495 | // We stick this agent's ID as imSession, so that it's directly available on the receiving end | ||
496 | im.imSessionID = im.fromAgentID; | ||
799 | 497 | ||
800 | // try to send to foreign region, retry if it fails (friend TPed away, for example) | 498 | // Try the local sim |
801 | if (TriggerTerminateFriend(data.Handle, exfriendID, agentID)) break; | 499 | if (LocalFriendshipOffered(friendID, im)) |
802 | } | 500 | return; |
803 | } | ||
804 | 501 | ||
805 | // clean up cache: FriendList is wrong now... | 502 | // The prospective friend is not here [as root]. Let's forward. |
806 | lock (m_friendLists) | 503 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); |
504 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); | ||
505 | if (friendSession != null) | ||
807 | { | 506 | { |
808 | m_friendLists.Invalidate(agentID.ToString()); | 507 | GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); |
809 | m_friendLists.Invalidate(exfriendID.ToString()); | 508 | m_FriendsSimConnector.FriendshipOffered(region, agentID, friendID, im.message); |
810 | } | 509 | } |
510 | |||
511 | // If the prospective friend is not online, he'll get the message upon login. | ||
811 | } | 512 | } |
812 | 513 | ||
813 | #endregion | 514 | private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) |
515 | { | ||
516 | FriendsService.StoreFriend(agentID, friendID.ToString(), 1); | ||
517 | FriendsService.StoreFriend(friendID, agentID.ToString(), 1); | ||
518 | // update the local cache | ||
519 | m_Friends[agentID].Friends = FriendsService.GetFriends(agentID); | ||
814 | 520 | ||
815 | #region CallingCards | 521 | m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", agentID, friendID); |
816 | 522 | ||
817 | private void OnOfferCallingCard(IClientAPI client, UUID destID, UUID transactionID) | 523 | // |
818 | { | 524 | // Notify the friend |
819 | m_log.DebugFormat("[CALLING CARD]: got offer from {0} for {1}, transaction {2}", | 525 | // |
820 | client.AgentId, destID, transactionID); | 526 | |
821 | // This might be slightly wrong. On a multi-region server, we might get the child-agent instead of the root-agent | 527 | // Try Local |
822 | // (or the root instead of the child) | 528 | if (LocalFriendshipApproved(agentID, client.Name, friendID)) |
823 | ScenePresence destAgent = GetAnyPresenceFromAgentID(destID); | ||
824 | if (destAgent == null) | ||
825 | { | 529 | { |
826 | client.SendAlertMessage("The person you have offered a card to can't be found anymore."); | 530 | client.SendAgentOnline(new UUID[] { friendID }); |
827 | return; | 531 | return; |
828 | } | 532 | } |
829 | 533 | ||
830 | lock (m_pendingCallingcardRequests) | 534 | // The friend is not here |
535 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); | ||
536 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); | ||
537 | if (friendSession != null) | ||
831 | { | 538 | { |
832 | m_pendingCallingcardRequests[transactionID] = client.AgentId; | 539 | GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); |
540 | m_FriendsSimConnector.FriendshipApproved(region, agentID, client.Name, friendID); | ||
541 | client.SendAgentOnline(new UUID[] { friendID }); | ||
833 | } | 542 | } |
834 | // inform the destination agent about the offer | ||
835 | destAgent.ControllingClient.SendOfferCallingCard(client.AgentId, transactionID); | ||
836 | } | ||
837 | 543 | ||
838 | private void CreateCallingCard(IClientAPI client, UUID creator, UUID folder, string name) | ||
839 | { | ||
840 | InventoryItemBase item = new InventoryItemBase(); | ||
841 | item.AssetID = UUID.Zero; | ||
842 | item.AssetType = (int)AssetType.CallingCard; | ||
843 | item.BasePermissions = (uint)PermissionMask.Copy; | ||
844 | item.CreationDate = Util.UnixTimeSinceEpoch(); | ||
845 | item.CreatorId = creator.ToString(); | ||
846 | item.CurrentPermissions = item.BasePermissions; | ||
847 | item.Description = ""; | ||
848 | item.EveryOnePermissions = (uint)PermissionMask.None; | ||
849 | item.Flags = 0; | ||
850 | item.Folder = folder; | ||
851 | item.GroupID = UUID.Zero; | ||
852 | item.GroupOwned = false; | ||
853 | item.ID = UUID.Random(); | ||
854 | item.InvType = (int)InventoryType.CallingCard; | ||
855 | item.Name = name; | ||
856 | item.NextPermissions = item.EveryOnePermissions; | ||
857 | item.Owner = client.AgentId; | ||
858 | item.SalePrice = 10; | ||
859 | item.SaleType = (byte)SaleType.Not; | ||
860 | ((Scene)client.Scene).AddInventoryItem(client, item); | ||
861 | } | 544 | } |
862 | 545 | ||
863 | private void OnAcceptCallingCard(IClientAPI client, UUID transactionID, UUID folderID) | 546 | private void OnDenyFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) |
864 | { | 547 | { |
865 | m_log.DebugFormat("[CALLING CARD]: User {0} ({1} {2}) accepted tid {3}, folder {4}", | 548 | m_log.DebugFormat("[FRIENDS]: {0} denied friendship to {1}", agentID, friendID); |
866 | client.AgentId, | ||
867 | client.FirstName, client.LastName, | ||
868 | transactionID, folderID); | ||
869 | UUID destID; | ||
870 | lock (m_pendingCallingcardRequests) | ||
871 | { | ||
872 | if (!m_pendingCallingcardRequests.TryGetValue(transactionID, out destID)) | ||
873 | { | ||
874 | m_log.WarnFormat("[CALLING CARD]: Got a AcceptCallingCard from {0} without an offer before.", | ||
875 | client.Name); | ||
876 | return; | ||
877 | } | ||
878 | // else found pending calling card request with that transaction. | ||
879 | m_pendingCallingcardRequests.Remove(transactionID); | ||
880 | } | ||
881 | 549 | ||
550 | FriendsService.Delete(agentID, friendID.ToString()); | ||
551 | FriendsService.Delete(friendID, agentID.ToString()); | ||
882 | 552 | ||
883 | ScenePresence destAgent = GetAnyPresenceFromAgentID(destID); | 553 | // |
884 | // inform sender of the card that destination declined the offer | 554 | // Notify the friend |
885 | if (destAgent != null) destAgent.ControllingClient.SendAcceptCallingCard(transactionID); | 555 | // |
886 | 556 | ||
887 | // put a calling card into the inventory of receiver | 557 | // Try local |
888 | CreateCallingCard(client, destID, folderID, destAgent.Name); | 558 | if (LocalFriendshipDenied(agentID, client.Name, friendID)) |
889 | } | 559 | return; |
890 | 560 | ||
891 | private void OnDeclineCallingCard(IClientAPI client, UUID transactionID) | 561 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); |
892 | { | 562 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); |
893 | m_log.DebugFormat("[CALLING CARD]: User {0} (ID:{1}) declined card, tid {2}", | 563 | if (friendSession != null) |
894 | client.Name, client.AgentId, transactionID); | ||
895 | UUID destID; | ||
896 | lock (m_pendingCallingcardRequests) | ||
897 | { | 564 | { |
898 | if (!m_pendingCallingcardRequests.TryGetValue(transactionID, out destID)) | 565 | GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); |
899 | { | 566 | m_FriendsSimConnector.FriendshipDenied(region, agentID, client.Name, friendID); |
900 | m_log.WarnFormat("[CALLING CARD]: Got a AcceptCallingCard from {0} without an offer before.", | ||
901 | client.Name); | ||
902 | return; | ||
903 | } | ||
904 | // else found pending calling card request with that transaction. | ||
905 | m_pendingCallingcardRequests.Remove(transactionID); | ||
906 | } | 567 | } |
907 | |||
908 | ScenePresence destAgent = GetAnyPresenceFromAgentID(destID); | ||
909 | // inform sender of the card that destination declined the offer | ||
910 | if (destAgent != null) destAgent.ControllingClient.SendDeclineCallingCard(transactionID); | ||
911 | } | 568 | } |
912 | 569 | ||
913 | /// <summary> | 570 | private void OnTerminateFriendship(IClientAPI client, UUID agentID, UUID exfriendID) |
914 | /// Send presence information about a client to other clients in both this region and others. | ||
915 | /// </summary> | ||
916 | /// <param name="client"></param> | ||
917 | /// <param name="friendList"></param> | ||
918 | /// <param name="iAmOnline"></param> | ||
919 | private void SendPresenceState(IClientAPI client, List<FriendListItem> friendList, bool iAmOnline) | ||
920 | { | 571 | { |
921 | //m_log.DebugFormat("[FRIEND]: {0} logged {1}; sending presence updates", client.Name, iAmOnline ? "in" : "out"); | 572 | FriendsService.Delete(agentID, exfriendID.ToString()); |
573 | FriendsService.Delete(exfriendID, agentID.ToString()); | ||
922 | 574 | ||
923 | if (friendList == null || friendList.Count == 0) | 575 | // Update local cache |
924 | { | 576 | m_Friends[agentID].Friends = FriendsService.GetFriends(agentID); |
925 | //m_log.DebugFormat("[FRIEND]: {0} doesn't have friends.", client.Name); | ||
926 | return; // nothing we can do if she doesn't have friends... | ||
927 | } | ||
928 | 577 | ||
929 | // collect sets of friendIDs; to send to (online and offline), and to receive from | 578 | client.SendTerminateFriend(exfriendID); |
930 | // TODO: If we ever switch to .NET >= 3, replace those Lists with HashSets. | ||
931 | // I can't believe that we have Dictionaries, but no Sets, considering Java introduced them years ago... | ||
932 | List<UUID> friendIDsToSendTo = new List<UUID>(); | ||
933 | List<UUID> candidateFriendIDsToReceive = new List<UUID>(); | ||
934 | |||
935 | foreach (FriendListItem item in friendList) | ||
936 | { | ||
937 | if (((item.FriendListOwnerPerms | item.FriendPerms) & (uint)FriendRights.CanSeeOnline) != 0) | ||
938 | { | ||
939 | // friend is allowed to see my presence => add | ||
940 | if ((item.FriendListOwnerPerms & (uint)FriendRights.CanSeeOnline) != 0) | ||
941 | friendIDsToSendTo.Add(item.Friend); | ||
942 | 579 | ||
943 | if ((item.FriendPerms & (uint)FriendRights.CanSeeOnline) != 0) | 580 | // |
944 | candidateFriendIDsToReceive.Add(item.Friend); | 581 | // Notify the friend |
945 | } | 582 | // |
946 | } | ||
947 | 583 | ||
948 | // we now have a list of "interesting" friends (which we have to find out on-/offline state for), | 584 | // Try local |
949 | // friends we want to send our online state to (if *they* are online, too), and | 585 | if (LocalFriendshipTerminated(exfriendID)) |
950 | // friends we want to receive online state for (currently unknown whether online or not) | 586 | return; |
951 | 587 | ||
952 | // as this processing might take some time and friends might TP away, we try up to three times to | 588 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { exfriendID.ToString() }); |
953 | // reach them. Most of the time, we *will* reach them, and this loop won't loop | 589 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); |
954 | int retry = 0; | 590 | if (friendSession != null) |
955 | do | ||
956 | { | 591 | { |
957 | // build a list of friends to look up region-information and on-/offline-state for | 592 | GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); |
958 | List<UUID> friendIDsToLookup = new List<UUID>(friendIDsToSendTo); | 593 | m_FriendsSimConnector.FriendshipTerminated(region, agentID, exfriendID); |
959 | foreach (UUID uuid in candidateFriendIDsToReceive) | 594 | } |
960 | { | 595 | } |
961 | if (!friendIDsToLookup.Contains(uuid)) friendIDsToLookup.Add(uuid); | ||
962 | } | ||
963 | |||
964 | m_log.DebugFormat( | ||
965 | "[FRIEND]: {0} to lookup, {1} to send to, {2} candidates to receive from for agent {3}", | ||
966 | friendIDsToLookup.Count, friendIDsToSendTo.Count, candidateFriendIDsToReceive.Count, client.Name); | ||
967 | |||
968 | // we have to fetch FriendRegionInfos, as the (cached) FriendListItems don't | ||
969 | // necessarily contain the correct online state... | ||
970 | Dictionary<UUID, FriendRegionInfo> friendRegions = m_initialScene.GetFriendRegionInfos(friendIDsToLookup); | ||
971 | m_log.DebugFormat( | ||
972 | "[FRIEND]: Found {0} regionInfos for {1} friends of {2}", | ||
973 | friendRegions.Count, friendIDsToLookup.Count, client.Name); | ||
974 | 596 | ||
975 | // argument for SendAgentOn/Offline; we shouldn't generate that repeatedly within loops. | 597 | private void OnGrantUserRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) |
976 | UUID[] agentArr = new UUID[] { client.AgentId }; | 598 | { |
599 | if (!m_Friends.ContainsKey(remoteClient.AgentId)) | ||
600 | return; | ||
977 | 601 | ||
978 | // first, send to friend presence state to me, if I'm online... | 602 | m_log.DebugFormat("[FRIENDS MODULE]: User {0} changing rights to {1} for friend {2}", requester, rights, target); |
979 | if (iAmOnline) | 603 | // Let's find the friend in this user's friend list |
980 | { | 604 | UserFriendData fd = m_Friends[remoteClient.AgentId]; |
981 | List<UUID> friendIDsToReceive = new List<UUID>(); | 605 | FriendInfo friend = null; |
982 | 606 | foreach (FriendInfo fi in fd.Friends) | |
983 | for (int i = candidateFriendIDsToReceive.Count - 1; i >= 0; --i) | 607 | if (fi.Friend == target.ToString()) |
984 | { | 608 | friend = fi; |
985 | UUID uuid = candidateFriendIDsToReceive[i]; | ||
986 | FriendRegionInfo info; | ||
987 | if (friendRegions.TryGetValue(uuid, out info) && info != null && info.isOnline) | ||
988 | { | ||
989 | friendIDsToReceive.Add(uuid); | ||
990 | } | ||
991 | } | ||
992 | |||
993 | m_log.DebugFormat( | ||
994 | "[FRIEND]: Sending {0} online friends to {1}", friendIDsToReceive.Count, client.Name); | ||
995 | |||
996 | if (friendIDsToReceive.Count > 0) | ||
997 | client.SendAgentOnline(friendIDsToReceive.ToArray()); | ||
998 | |||
999 | // clear them for a possible second iteration; we don't have to repeat this | ||
1000 | candidateFriendIDsToReceive.Clear(); | ||
1001 | } | ||
1002 | 609 | ||
1003 | // now, send my presence state to my friends | 610 | if (friend != null) // Found it |
1004 | for (int i = friendIDsToSendTo.Count - 1; i >= 0; --i) | 611 | { |
1005 | { | 612 | // Store it on the DB |
1006 | UUID uuid = friendIDsToSendTo[i]; | 613 | FriendsService.StoreFriend(requester, target.ToString(), rights); |
1007 | FriendRegionInfo info; | ||
1008 | if (friendRegions.TryGetValue(uuid, out info) && info != null && info.isOnline) | ||
1009 | { | ||
1010 | // any client is good enough, root or child... | ||
1011 | ScenePresence agent = GetAnyPresenceFromAgentID(uuid); | ||
1012 | if (agent != null) | ||
1013 | { | ||
1014 | //m_log.DebugFormat("[FRIEND]: Found local agent {0}", agent.Name); | ||
1015 | 614 | ||
1016 | // friend is online and on this server... | 615 | // Store it in the local cache |
1017 | if (iAmOnline) agent.ControllingClient.SendAgentOnline(agentArr); | 616 | int myFlags = friend.MyFlags; |
1018 | else agent.ControllingClient.SendAgentOffline(agentArr); | 617 | friend.MyFlags = rights; |
1019 | 618 | ||
1020 | // done, remove it | 619 | // Always send this back to the original client |
1021 | friendIDsToSendTo.RemoveAt(i); | 620 | remoteClient.SendChangeUserRights(requester, target, rights); |
1022 | } | ||
1023 | } | ||
1024 | else | ||
1025 | { | ||
1026 | //m_log.DebugFormat("[FRIEND]: Friend {0} ({1}) is offline; not sending.", uuid, i); | ||
1027 | 621 | ||
1028 | // friend is offline => no need to try sending | 622 | // |
1029 | friendIDsToSendTo.RemoveAt(i); | 623 | // Notify the friend |
1030 | } | 624 | // |
1031 | } | ||
1032 | 625 | ||
1033 | m_log.DebugFormat("[FRIEND]: Have {0} friends to contact via inter-region comms.", friendIDsToSendTo.Count); | 626 | // Try local |
627 | if (LocalGrantRights(requester, target, myFlags, rights)) | ||
628 | return; | ||
1034 | 629 | ||
1035 | // we now have all the friends left that are online (we think), but not on this region-server | 630 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { target.ToString() }); |
1036 | if (friendIDsToSendTo.Count > 0) | 631 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); |
632 | if (friendSession != null) | ||
1037 | { | 633 | { |
1038 | // sort them into regions | 634 | GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); |
1039 | Dictionary<ulong, List<UUID>> friendsInRegion = new Dictionary<ulong,List<UUID>>(); | 635 | // TODO: You might want to send the delta to save the lookup |
1040 | foreach (UUID uuid in friendIDsToSendTo) | 636 | // on the other end!! |
1041 | { | 637 | m_FriendsSimConnector.GrantRights(region, requester, target, myFlags, rights); |
1042 | ulong handle = friendRegions[uuid].regionHandle; // this can't fail as we filtered above already | ||
1043 | List<UUID> friends; | ||
1044 | if (!friendsInRegion.TryGetValue(handle, out friends)) | ||
1045 | { | ||
1046 | friends = new List<UUID>(); | ||
1047 | friendsInRegion[handle] = friends; | ||
1048 | } | ||
1049 | friends.Add(uuid); | ||
1050 | } | ||
1051 | m_log.DebugFormat("[FRIEND]: Found {0} regions to send to.", friendRegions.Count); | ||
1052 | |||
1053 | // clear uuids list and collect missed friends in it for the next retry | ||
1054 | friendIDsToSendTo.Clear(); | ||
1055 | |||
1056 | // send bulk updates to the region | ||
1057 | foreach (KeyValuePair<ulong, List<UUID>> pair in friendsInRegion) | ||
1058 | { | ||
1059 | //m_log.DebugFormat("[FRIEND]: Inform {0} friends in region {1} that user {2} is {3}line", | ||
1060 | // pair.Value.Count, pair.Key, client.Name, iAmOnline ? "on" : "off"); | ||
1061 | |||
1062 | friendIDsToSendTo.AddRange(InformFriendsInOtherRegion(client.AgentId, pair.Key, pair.Value, iAmOnline)); | ||
1063 | } | ||
1064 | } | 638 | } |
1065 | // now we have in friendIDsToSendTo only the agents left that TPed away while we tried to contact them. | ||
1066 | // In most cases, it will be empty, and it won't loop here. But sometimes, we have to work harder and try again... | ||
1067 | } | 639 | } |
1068 | while (++retry < 3 && friendIDsToSendTo.Count > 0); | ||
1069 | } | 640 | } |
1070 | 641 | ||
1071 | private void OnEconomyDataRequest(UUID agentID) | 642 | #region Local |
643 | |||
644 | public bool LocalFriendshipOffered(UUID toID, GridInstantMessage im) | ||
1072 | { | 645 | { |
1073 | // KLUDGE: This is the only way I found to get a message (only) after login was completed and the | 646 | IClientAPI friendClient = LocateClientObject(toID); |
1074 | // client is connected enough to receive UDP packets). | 647 | if (friendClient != null) |
1075 | // This packet seems to be sent only once, just after connection was established to the first | ||
1076 | // region after login. | ||
1077 | // We use it here to trigger a presence update; the old update-on-login was never be heard by | ||
1078 | // the freshly logged in viewer, as it wasn't connected to the region at that time. | ||
1079 | // TODO: Feel free to replace this by a better solution if you find one. | ||
1080 | |||
1081 | // get the agent. This should work every time, as we just got a packet from it | ||
1082 | //ScenePresence agent = GetRootPresenceFromAgentID(agentID); | ||
1083 | // KLUDGE 2: As this is sent quite early, the avatar isn't here as root agent yet. So, we have to cheat a bit | ||
1084 | ScenePresence agent = GetAnyPresenceFromAgentID(agentID); | ||
1085 | |||
1086 | // just to be paranoid... | ||
1087 | if (agent == null) | ||
1088 | { | 648 | { |
1089 | m_log.ErrorFormat("[FRIEND]: Got a packet from agent {0} who can't be found anymore!?", agentID); | 649 | // the prospective friend in this sim as root agent |
1090 | return; | 650 | friendClient.SendInstantMessage(im); |
651 | // we're done | ||
652 | return true; | ||
1091 | } | 653 | } |
654 | return false; | ||
655 | } | ||
1092 | 656 | ||
1093 | List<FriendListItem> fl; | 657 | public bool LocalFriendshipApproved(UUID userID, string userName, UUID friendID) |
1094 | lock (m_friendLists) | 658 | { |
659 | IClientAPI friendClient = LocateClientObject(friendID); | ||
660 | if (friendClient != null) | ||
1095 | { | 661 | { |
1096 | fl = (List<FriendListItem>)m_friendLists.Get(agent.ControllingClient.AgentId.ToString(), | 662 | // the prospective friend in this sim as root agent |
1097 | m_initialScene.GetFriendList); | 663 | GridInstantMessage im = new GridInstantMessage(Scene, userID, userName, friendID, |
664 | (byte)OpenMetaverse.InstantMessageDialog.FriendshipAccepted, userID.ToString(), false, Vector3.Zero); | ||
665 | friendClient.SendInstantMessage(im); | ||
666 | // update the local cache | ||
667 | m_Friends[friendID].Friends = FriendsService.GetFriends(friendID); | ||
668 | // we're done | ||
669 | return true; | ||
1098 | } | 670 | } |
1099 | 671 | ||
1100 | // tell everyone that we are online | 672 | return false; |
1101 | SendPresenceState(agent.ControllingClient, fl, true); | ||
1102 | } | 673 | } |
1103 | 674 | ||
1104 | private void OnLogout(IClientAPI remoteClient) | 675 | public bool LocalFriendshipDenied(UUID userID, string userName, UUID friendID) |
1105 | { | 676 | { |
1106 | List<FriendListItem> fl; | 677 | IClientAPI friendClient = LocateClientObject(friendID); |
1107 | lock (m_friendLists) | 678 | if (friendClient != null) |
1108 | { | 679 | { |
1109 | fl = (List<FriendListItem>)m_friendLists.Get(remoteClient.AgentId.ToString(), | 680 | // the prospective friend in this sim as root agent |
1110 | m_initialScene.GetFriendList); | ||
1111 | } | ||
1112 | 681 | ||
1113 | // tell everyone that we are offline | 682 | GridInstantMessage im = new GridInstantMessage(Scene, userID, userName, friendID, |
1114 | SendPresenceState(remoteClient, fl, false); | 683 | (byte)OpenMetaverse.InstantMessageDialog.FriendshipDeclined, userID.ToString(), false, Vector3.Zero); |
684 | friendClient.SendInstantMessage(im); | ||
685 | // we're done | ||
686 | return true; | ||
687 | } | ||
688 | |||
689 | return false; | ||
1115 | } | 690 | } |
1116 | private void GrantUserFriendRights(IClientAPI remoteClient, UUID requester, UUID target, int rights) | 691 | |
692 | public bool LocalFriendshipTerminated(UUID exfriendID) | ||
1117 | { | 693 | { |
1118 | ((Scene)remoteClient.Scene).CommsManager.UpdateUserFriendPerms(requester, target, (uint)rights); | 694 | IClientAPI friendClient = LocateClientObject(exfriendID); |
695 | if (friendClient != null) | ||
696 | { | ||
697 | // the friend in this sim as root agent | ||
698 | friendClient.SendTerminateFriend(exfriendID); | ||
699 | // update local cache | ||
700 | m_Friends[exfriendID].Friends = FriendsService.GetFriends(exfriendID); | ||
701 | // we're done | ||
702 | return true; | ||
703 | } | ||
704 | |||
705 | return false; | ||
1119 | } | 706 | } |
1120 | public void FindAgent(IClientAPI remoteClient, UUID hunter, UUID target) | 707 | |
708 | public bool LocalGrantRights(UUID userID, UUID friendID, int userFlags, int rights) | ||
1121 | { | 709 | { |
1122 | List<FriendListItem> friendList = GetUserFriends(hunter); | 710 | IClientAPI friendClient = LocateClientObject(friendID); |
1123 | foreach (FriendListItem item in friendList) | 711 | if (friendClient != null) |
1124 | { | 712 | { |
1125 | if (item.onlinestatus == true) | 713 | bool onlineBitChanged = ((rights ^ userFlags) & (int)FriendRights.CanSeeOnline) != 0; |
714 | if (onlineBitChanged) | ||
1126 | { | 715 | { |
1127 | if (item.Friend == target && (item.FriendPerms & (uint)FriendRights.CanSeeOnMap) != 0) | 716 | if ((rights & (int)FriendRights.CanSeeOnline) == 1) |
1128 | { | 717 | friendClient.SendAgentOnline(new UUID[] { new UUID(userID) }); |
1129 | ScenePresence SPTarget = ((Scene)remoteClient.Scene).GetScenePresence(target); | 718 | else |
1130 | string regionname = SPTarget.Scene.RegionInfo.RegionName; | 719 | friendClient.SendAgentOffline(new UUID[] { new UUID(userID) }); |
1131 | remoteClient.SendScriptTeleportRequest("FindAgent", regionname,new Vector3(SPTarget.AbsolutePosition),new Vector3(SPTarget.Lookat)); | ||
1132 | } | ||
1133 | } | 720 | } |
1134 | else | 721 | else |
1135 | { | 722 | { |
1136 | remoteClient.SendAgentAlertMessage("The agent you are looking for is not online.", false); | 723 | bool canEditObjectsChanged = ((rights ^ userFlags) & (int)FriendRights.CanModifyObjects) != 0; |
724 | if (canEditObjectsChanged) | ||
725 | friendClient.SendChangeUserRights(userID, friendID, rights); | ||
1137 | } | 726 | } |
727 | |||
728 | return true; | ||
1138 | } | 729 | } |
730 | |||
731 | return false; | ||
732 | |||
1139 | } | 733 | } |
1140 | 734 | ||
1141 | public List<FriendListItem> GetUserFriends(UUID agentID) | 735 | public bool LocalStatusNotification(UUID userID, UUID friendID, bool online) |
1142 | { | 736 | { |
1143 | List<FriendListItem> fl; | 737 | IClientAPI friendClient = LocateClientObject(friendID); |
1144 | lock (m_friendLists) | 738 | if (friendClient != null) |
1145 | { | 739 | { |
1146 | fl = (List<FriendListItem>)m_friendLists.Get(agentID.ToString(), | 740 | //m_log.DebugFormat("[FRIENDS]: Notify {0} that user {1} is {2}", friend.Friend, userID, online); |
1147 | m_initialScene.GetFriendList); | 741 | // the friend in this sim as root agent |
742 | if (online) | ||
743 | friendClient.SendAgentOnline(new UUID[] { userID }); | ||
744 | else | ||
745 | friendClient.SendAgentOffline(new UUID[] { userID }); | ||
746 | // we're done | ||
747 | return true; | ||
1148 | } | 748 | } |
1149 | 749 | ||
1150 | return fl; | 750 | return false; |
1151 | } | 751 | } |
752 | #endregion | ||
753 | |||
1152 | } | 754 | } |
1153 | #endregion | ||
1154 | } | 755 | } |
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs new file mode 100644 index 0000000..0883c5b --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs | |||
@@ -0,0 +1,293 @@ | |||
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.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Xml; | ||
33 | |||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Server.Base; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
38 | |||
39 | using OpenMetaverse; | ||
40 | using log4net; | ||
41 | |||
42 | namespace OpenSim.Region.CoreModules.Avatar.Friends | ||
43 | { | ||
44 | public class FriendsRequestHandler : BaseStreamHandler | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private FriendsModule m_FriendsModule; | ||
49 | |||
50 | public FriendsRequestHandler(FriendsModule fmodule) | ||
51 | : base("POST", "/friends") | ||
52 | { | ||
53 | m_FriendsModule = fmodule; | ||
54 | } | ||
55 | |||
56 | public override byte[] Handle(string path, Stream requestData, | ||
57 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
58 | { | ||
59 | StreamReader sr = new StreamReader(requestData); | ||
60 | string body = sr.ReadToEnd(); | ||
61 | sr.Close(); | ||
62 | body = body.Trim(); | ||
63 | |||
64 | m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
65 | |||
66 | try | ||
67 | { | ||
68 | Dictionary<string, object> request = | ||
69 | ServerUtils.ParseQueryString(body); | ||
70 | |||
71 | if (!request.ContainsKey("METHOD")) | ||
72 | return FailureResult(); | ||
73 | |||
74 | string method = request["METHOD"].ToString(); | ||
75 | request.Remove("METHOD"); | ||
76 | |||
77 | switch (method) | ||
78 | { | ||
79 | case "friendship_offered": | ||
80 | return FriendshipOffered(request); | ||
81 | case "friendship_approved": | ||
82 | return FriendshipApproved(request); | ||
83 | case "friendship_denied": | ||
84 | return FriendshipDenied(request); | ||
85 | case "friendship_terminated": | ||
86 | return FriendshipTerminated(request); | ||
87 | case "grant_rights": | ||
88 | return GrantRights(request); | ||
89 | case "status": | ||
90 | return StatusNotification(request); | ||
91 | } | ||
92 | } | ||
93 | catch (Exception e) | ||
94 | { | ||
95 | m_log.Debug("[FRIENDS]: Exception {0}" + e.ToString()); | ||
96 | } | ||
97 | |||
98 | return FailureResult(); | ||
99 | } | ||
100 | |||
101 | byte[] FriendshipOffered(Dictionary<string, object> request) | ||
102 | { | ||
103 | UUID fromID = UUID.Zero; | ||
104 | UUID toID = UUID.Zero; | ||
105 | string message = string.Empty; | ||
106 | |||
107 | if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID")) | ||
108 | return FailureResult(); | ||
109 | |||
110 | message = request["Message"].ToString(); | ||
111 | |||
112 | if (!UUID.TryParse(request["FromID"].ToString(), out fromID)) | ||
113 | return FailureResult(); | ||
114 | |||
115 | if (!UUID.TryParse(request["ToID"].ToString(), out toID)) | ||
116 | return FailureResult(); | ||
117 | |||
118 | GridInstantMessage im = new GridInstantMessage(m_FriendsModule.Scene, fromID, "", toID, | ||
119 | (byte)InstantMessageDialog.FriendshipOffered, message, false, Vector3.Zero); | ||
120 | |||
121 | if (m_FriendsModule.LocalFriendshipOffered(toID, im)) | ||
122 | return SuccessResult(); | ||
123 | |||
124 | return FailureResult(); | ||
125 | } | ||
126 | |||
127 | byte[] FriendshipApproved(Dictionary<string, object> request) | ||
128 | { | ||
129 | UUID fromID = UUID.Zero; | ||
130 | UUID toID = UUID.Zero; | ||
131 | string fromName = string.Empty; | ||
132 | |||
133 | if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID")) | ||
134 | return FailureResult(); | ||
135 | |||
136 | if (!UUID.TryParse(request["FromID"].ToString(), out fromID)) | ||
137 | return FailureResult(); | ||
138 | |||
139 | if (!UUID.TryParse(request["ToID"].ToString(), out toID)) | ||
140 | return FailureResult(); | ||
141 | |||
142 | if (request.ContainsKey("FromName")) | ||
143 | fromName = request["FromName"].ToString(); | ||
144 | |||
145 | if (m_FriendsModule.LocalFriendshipApproved(fromID, fromName, toID)) | ||
146 | return SuccessResult(); | ||
147 | |||
148 | return FailureResult(); | ||
149 | } | ||
150 | |||
151 | byte[] FriendshipDenied(Dictionary<string, object> request) | ||
152 | { | ||
153 | UUID fromID = UUID.Zero; | ||
154 | UUID toID = UUID.Zero; | ||
155 | string fromName = string.Empty; | ||
156 | |||
157 | if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID")) | ||
158 | return FailureResult(); | ||
159 | |||
160 | if (!UUID.TryParse(request["FromID"].ToString(), out fromID)) | ||
161 | return FailureResult(); | ||
162 | |||
163 | if (!UUID.TryParse(request["ToID"].ToString(), out toID)) | ||
164 | return FailureResult(); | ||
165 | |||
166 | if (request.ContainsKey("FromName")) | ||
167 | fromName = request["FromName"].ToString(); | ||
168 | |||
169 | if (m_FriendsModule.LocalFriendshipDenied(fromID, fromName, toID)) | ||
170 | return SuccessResult(); | ||
171 | |||
172 | return FailureResult(); | ||
173 | } | ||
174 | |||
175 | byte[] FriendshipTerminated(Dictionary<string, object> request) | ||
176 | { | ||
177 | UUID fromID = UUID.Zero; | ||
178 | UUID toID = UUID.Zero; | ||
179 | |||
180 | if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID")) | ||
181 | return FailureResult(); | ||
182 | |||
183 | if (!UUID.TryParse(request["FromID"].ToString(), out fromID)) | ||
184 | return FailureResult(); | ||
185 | |||
186 | if (!UUID.TryParse(request["ToID"].ToString(), out toID)) | ||
187 | return FailureResult(); | ||
188 | |||
189 | if (m_FriendsModule.LocalFriendshipTerminated(toID)) | ||
190 | return SuccessResult(); | ||
191 | |||
192 | return FailureResult(); | ||
193 | } | ||
194 | |||
195 | byte[] GrantRights(Dictionary<string, object> request) | ||
196 | { | ||
197 | UUID fromID = UUID.Zero; | ||
198 | UUID toID = UUID.Zero; | ||
199 | int rights = 0, userFlags = 0; | ||
200 | |||
201 | if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID")) | ||
202 | return FailureResult(); | ||
203 | |||
204 | if (!UUID.TryParse(request["FromID"].ToString(), out fromID)) | ||
205 | return FailureResult(); | ||
206 | |||
207 | if (!UUID.TryParse(request["ToID"].ToString(), out toID)) | ||
208 | return FailureResult(); | ||
209 | |||
210 | if (!Int32.TryParse(request["UserFlags"].ToString(), out userFlags)) | ||
211 | return FailureResult(); | ||
212 | |||
213 | if (!Int32.TryParse(request["Rights"].ToString(), out rights)) | ||
214 | return FailureResult(); | ||
215 | |||
216 | if (m_FriendsModule.LocalGrantRights(UUID.Zero, UUID.Zero, userFlags, rights)) | ||
217 | return SuccessResult(); | ||
218 | |||
219 | return FailureResult(); | ||
220 | } | ||
221 | |||
222 | byte[] StatusNotification(Dictionary<string, object> request) | ||
223 | { | ||
224 | UUID fromID = UUID.Zero; | ||
225 | UUID toID = UUID.Zero; | ||
226 | bool online = false; | ||
227 | |||
228 | if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID") || !request.ContainsKey("Online")) | ||
229 | return FailureResult(); | ||
230 | |||
231 | if (!UUID.TryParse(request["FromID"].ToString(), out fromID)) | ||
232 | return FailureResult(); | ||
233 | |||
234 | if (!UUID.TryParse(request["ToID"].ToString(), out toID)) | ||
235 | return FailureResult(); | ||
236 | |||
237 | if (!Boolean.TryParse(request["Online"].ToString(), out online)) | ||
238 | return FailureResult(); | ||
239 | |||
240 | if (m_FriendsModule.LocalStatusNotification(fromID, toID, online)) | ||
241 | return SuccessResult(); | ||
242 | |||
243 | return FailureResult(); | ||
244 | } | ||
245 | |||
246 | #region Misc | ||
247 | |||
248 | private byte[] FailureResult() | ||
249 | { | ||
250 | return BoolResult(false); | ||
251 | } | ||
252 | |||
253 | private byte[] SuccessResult() | ||
254 | { | ||
255 | return BoolResult(true); | ||
256 | } | ||
257 | |||
258 | private byte[] BoolResult(bool value) | ||
259 | { | ||
260 | XmlDocument doc = new XmlDocument(); | ||
261 | |||
262 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
263 | "", ""); | ||
264 | |||
265 | doc.AppendChild(xmlnode); | ||
266 | |||
267 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
268 | ""); | ||
269 | |||
270 | doc.AppendChild(rootElement); | ||
271 | |||
272 | XmlElement result = doc.CreateElement("", "RESULT", ""); | ||
273 | result.AppendChild(doc.CreateTextNode(value.ToString())); | ||
274 | |||
275 | rootElement.AppendChild(result); | ||
276 | |||
277 | return DocToBytes(doc); | ||
278 | } | ||
279 | |||
280 | private byte[] DocToBytes(XmlDocument doc) | ||
281 | { | ||
282 | MemoryStream ms = new MemoryStream(); | ||
283 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
284 | xw.Formatting = Formatting.Indented; | ||
285 | doc.WriteTo(xw); | ||
286 | xw.Flush(); | ||
287 | |||
288 | return ms.ToArray(); | ||
289 | } | ||
290 | |||
291 | #endregion | ||
292 | } | ||
293 | } | ||
diff --git a/OpenSim/Region/CoreModules/Avatar/Gestures/GesturesModule.cs b/OpenSim/Region/CoreModules/Avatar/Gestures/GesturesModule.cs index 8ce5092..7303fe7 100644 --- a/OpenSim/Region/CoreModules/Avatar/Gestures/GesturesModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Gestures/GesturesModule.cs | |||
@@ -30,7 +30,7 @@ using log4net; | |||
30 | using Nini.Config; | 30 | using Nini.Config; |
31 | using OpenMetaverse; | 31 | using OpenMetaverse; |
32 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
33 | using OpenSim.Framework.Communications.Cache; | 33 | |
34 | using OpenSim.Region.Framework.Interfaces; | 34 | using OpenSim.Region.Framework.Interfaces; |
35 | using OpenSim.Region.Framework.Scenes; | 35 | using OpenSim.Region.Framework.Scenes; |
36 | using OpenSim.Services.Interfaces; | 36 | using OpenSim.Services.Interfaces; |
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs index 9a68749..ab141eb 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs | |||
@@ -24,6 +24,7 @@ | |||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | using System; | ||
27 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
28 | using System.Reflection; | 29 | using System.Reflection; |
29 | using log4net; | 30 | using log4net; |
@@ -36,9 +37,10 @@ using OpenSim.Region.Framework.Scenes; | |||
36 | 37 | ||
37 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | 38 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage |
38 | { | 39 | { |
39 | public class InstantMessageModule : IRegionModule | 40 | public class InstantMessageModule : ISharedRegionModule |
40 | { | 41 | { |
41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 42 | private static readonly ILog m_log = LogManager.GetLogger( |
43 | MethodBase.GetCurrentMethod().DeclaringType); | ||
42 | 44 | ||
43 | /// <value> | 45 | /// <value> |
44 | /// Is this module enabled? | 46 | /// Is this module enabled? |
@@ -51,7 +53,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
51 | 53 | ||
52 | private IMessageTransferModule m_TransferModule = null; | 54 | private IMessageTransferModule m_TransferModule = null; |
53 | 55 | ||
54 | public void Initialise(Scene scene, IConfigSource config) | 56 | public void Initialise(IConfigSource config) |
55 | { | 57 | { |
56 | if (config.Configs["Messaging"] != null) | 58 | if (config.Configs["Messaging"] != null) |
57 | { | 59 | { |
@@ -62,6 +64,12 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
62 | } | 64 | } |
63 | 65 | ||
64 | m_enabled = true; | 66 | m_enabled = true; |
67 | } | ||
68 | |||
69 | public void AddRegion(Scene scene) | ||
70 | { | ||
71 | if (!m_enabled) | ||
72 | return; | ||
65 | 73 | ||
66 | lock (m_scenes) | 74 | lock (m_scenes) |
67 | { | 75 | { |
@@ -74,6 +82,39 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
74 | } | 82 | } |
75 | } | 83 | } |
76 | 84 | ||
85 | public void RegionLoaded(Scene scene) | ||
86 | { | ||
87 | if (!m_enabled) | ||
88 | return; | ||
89 | |||
90 | if (m_TransferModule == null) | ||
91 | { | ||
92 | m_TransferModule = | ||
93 | scene.RequestModuleInterface<IMessageTransferModule>(); | ||
94 | |||
95 | if (m_TransferModule == null) | ||
96 | { | ||
97 | m_log.Error("[INSTANT MESSAGE]: No message transfer module, IM will not work!"); | ||
98 | scene.EventManager.OnClientConnect -= OnClientConnect; | ||
99 | scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage; | ||
100 | |||
101 | m_scenes.Clear(); | ||
102 | m_enabled = false; | ||
103 | } | ||
104 | } | ||
105 | } | ||
106 | |||
107 | public void RemoveRegion(Scene scene) | ||
108 | { | ||
109 | if (!m_enabled) | ||
110 | return; | ||
111 | |||
112 | lock (m_scenes) | ||
113 | { | ||
114 | m_scenes.Remove(scene); | ||
115 | } | ||
116 | } | ||
117 | |||
77 | void OnClientConnect(IClientCore client) | 118 | void OnClientConnect(IClientCore client) |
78 | { | 119 | { |
79 | IClientIM clientIM; | 120 | IClientIM clientIM; |
@@ -85,15 +126,6 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
85 | 126 | ||
86 | public void PostInitialise() | 127 | public void PostInitialise() |
87 | { | 128 | { |
88 | if (!m_enabled) | ||
89 | return; | ||
90 | |||
91 | m_TransferModule = | ||
92 | m_scenes[0].RequestModuleInterface<IMessageTransferModule>(); | ||
93 | |||
94 | if (m_TransferModule == null) | ||
95 | m_log.Error("[INSTANT MESSAGE]: No message transfer module, "+ | ||
96 | "IM will not work!"); | ||
97 | } | 129 | } |
98 | 130 | ||
99 | public void Close() | 131 | public void Close() |
@@ -105,9 +137,9 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
105 | get { return "InstantMessageModule"; } | 137 | get { return "InstantMessageModule"; } |
106 | } | 138 | } |
107 | 139 | ||
108 | public bool IsSharedModule | 140 | public Type ReplaceableInterface |
109 | { | 141 | { |
110 | get { return true; } | 142 | get { return null; } |
111 | } | 143 | } |
112 | 144 | ||
113 | #endregion | 145 | #endregion |
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs index e5159b3..c0d3f31 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs | |||
@@ -37,21 +37,33 @@ using OpenSim.Framework; | |||
37 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
38 | using OpenSim.Region.Framework.Scenes; | 38 | using OpenSim.Region.Framework.Scenes; |
39 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | 39 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
40 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; | ||
41 | using OpenSim.Services.Interfaces; | ||
40 | 42 | ||
41 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | 43 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage |
42 | { | 44 | { |
43 | public class MessageTransferModule : IRegionModule, IMessageTransferModule | 45 | public class MessageTransferModule : ISharedRegionModule, IMessageTransferModule |
44 | { | 46 | { |
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
46 | 48 | ||
47 | // private bool m_Enabled = false; | 49 | private bool m_Enabled = false; |
48 | protected bool m_Gridmode = false; | ||
49 | protected List<Scene> m_Scenes = new List<Scene>(); | 50 | protected List<Scene> m_Scenes = new List<Scene>(); |
50 | protected Dictionary<UUID, ulong> m_UserRegionMap = new Dictionary<UUID, ulong>(); | 51 | protected Dictionary<UUID, UUID> m_UserRegionMap = new Dictionary<UUID, UUID>(); |
51 | 52 | ||
52 | public event UndeliveredMessage OnUndeliveredMessage; | 53 | public event UndeliveredMessage OnUndeliveredMessage; |
53 | 54 | ||
54 | public virtual void Initialise(Scene scene, IConfigSource config) | 55 | private IPresenceService m_PresenceService; |
56 | protected IPresenceService PresenceService | ||
57 | { | ||
58 | get | ||
59 | { | ||
60 | if (m_PresenceService == null) | ||
61 | m_PresenceService = m_Scenes[0].RequestModuleInterface<IPresenceService>(); | ||
62 | return m_PresenceService; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | public virtual void Initialise(IConfigSource config) | ||
55 | { | 67 | { |
56 | IConfig cnf = config.Configs["Messaging"]; | 68 | IConfig cnf = config.Configs["Messaging"]; |
57 | if (cnf != null && cnf.GetString( | 69 | if (cnf != null && cnf.GetString( |
@@ -62,20 +74,16 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
62 | return; | 74 | return; |
63 | } | 75 | } |
64 | 76 | ||
65 | cnf = config.Configs["Startup"]; | 77 | m_Enabled = true; |
66 | if (cnf != null) | 78 | } |
67 | m_Gridmode = cnf.GetBoolean("gridmode", false); | ||
68 | 79 | ||
69 | // m_Enabled = true; | 80 | public virtual void AddRegion(Scene scene) |
81 | { | ||
82 | if (!m_Enabled) | ||
83 | return; | ||
70 | 84 | ||
71 | lock (m_Scenes) | 85 | lock (m_Scenes) |
72 | { | 86 | { |
73 | if (m_Scenes.Count == 0) | ||
74 | { | ||
75 | MainServer.Instance.AddXmlRPCHandler( | ||
76 | "grid_instant_message", processXMLRPCGridInstantMessage); | ||
77 | } | ||
78 | |||
79 | m_log.Debug("[MESSAGE TRANSFER]: Message transfer module active"); | 87 | m_log.Debug("[MESSAGE TRANSFER]: Message transfer module active"); |
80 | scene.RegisterModuleInterface<IMessageTransferModule>(this); | 88 | scene.RegisterModuleInterface<IMessageTransferModule>(this); |
81 | m_Scenes.Add(scene); | 89 | m_Scenes.Add(scene); |
@@ -84,6 +92,26 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
84 | 92 | ||
85 | public virtual void PostInitialise() | 93 | public virtual void PostInitialise() |
86 | { | 94 | { |
95 | if (!m_Enabled) | ||
96 | return; | ||
97 | |||
98 | MainServer.Instance.AddXmlRPCHandler( | ||
99 | "grid_instant_message", processXMLRPCGridInstantMessage); | ||
100 | } | ||
101 | |||
102 | public virtual void RegionLoaded(Scene scene) | ||
103 | { | ||
104 | } | ||
105 | |||
106 | public virtual void RemoveRegion(Scene scene) | ||
107 | { | ||
108 | if (!m_Enabled) | ||
109 | return; | ||
110 | |||
111 | lock(m_Scenes) | ||
112 | { | ||
113 | m_Scenes.Remove(scene); | ||
114 | } | ||
87 | } | 115 | } |
88 | 116 | ||
89 | public virtual void Close() | 117 | public virtual void Close() |
@@ -95,9 +123,9 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
95 | get { return "MessageTransferModule"; } | 123 | get { return "MessageTransferModule"; } |
96 | } | 124 | } |
97 | 125 | ||
98 | public virtual bool IsSharedModule | 126 | public virtual Type ReplaceableInterface |
99 | { | 127 | { |
100 | get { return true; } | 128 | get { return null; } |
101 | } | 129 | } |
102 | 130 | ||
103 | public virtual void SendInstantMessage(GridInstantMessage im, MessageResultNotification result) | 131 | public virtual void SendInstantMessage(GridInstantMessage im, MessageResultNotification result) |
@@ -148,15 +176,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
148 | } | 176 | } |
149 | } | 177 | } |
150 | 178 | ||
151 | if (m_Gridmode) | 179 | SendGridInstantMessageViaXMLRPC(im, result); |
152 | { | ||
153 | //m_log.DebugFormat("[INSTANT MESSAGE]: Delivering via grid"); | ||
154 | // Still here, try send via Grid | ||
155 | SendGridInstantMessageViaXMLRPC(im, result); | ||
156 | return; | ||
157 | } | ||
158 | |||
159 | HandleUndeliveredMessage(im, result); | ||
160 | 180 | ||
161 | return; | 181 | return; |
162 | } | 182 | } |
@@ -409,7 +429,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
409 | /// <summary> | 429 | /// <summary> |
410 | /// delegate for sending a grid instant message asynchronously | 430 | /// delegate for sending a grid instant message asynchronously |
411 | /// </summary> | 431 | /// </summary> |
412 | public delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result, ulong prevRegionHandle); | 432 | public delegate void GridInstantMessageDelegate(GridInstantMessage im, MessageResultNotification result, UUID prevRegionID); |
413 | 433 | ||
414 | protected virtual void GridInstantMessageCompleted(IAsyncResult iar) | 434 | protected virtual void GridInstantMessageCompleted(IAsyncResult iar) |
415 | { | 435 | { |
@@ -423,7 +443,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
423 | { | 443 | { |
424 | GridInstantMessageDelegate d = SendGridInstantMessageViaXMLRPCAsync; | 444 | GridInstantMessageDelegate d = SendGridInstantMessageViaXMLRPCAsync; |
425 | 445 | ||
426 | d.BeginInvoke(im, result, 0, GridInstantMessageCompleted, d); | 446 | d.BeginInvoke(im, result, UUID.Zero, GridInstantMessageCompleted, d); |
427 | } | 447 | } |
428 | 448 | ||
429 | /// <summary> | 449 | /// <summary> |
@@ -438,11 +458,11 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
438 | /// Pass in 0 the first time this method is called. It will be called recursively with the last | 458 | /// Pass in 0 the first time this method is called. It will be called recursively with the last |
439 | /// regionhandle tried | 459 | /// regionhandle tried |
440 | /// </param> | 460 | /// </param> |
441 | protected virtual void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result, ulong prevRegionHandle) | 461 | protected virtual void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im, MessageResultNotification result, UUID prevRegionID) |
442 | { | 462 | { |
443 | UUID toAgentID = new UUID(im.toAgentID); | 463 | UUID toAgentID = new UUID(im.toAgentID); |
444 | 464 | ||
445 | UserAgentData upd = null; | 465 | PresenceInfo upd = null; |
446 | 466 | ||
447 | bool lookupAgent = false; | 467 | bool lookupAgent = false; |
448 | 468 | ||
@@ -450,13 +470,13 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
450 | { | 470 | { |
451 | if (m_UserRegionMap.ContainsKey(toAgentID)) | 471 | if (m_UserRegionMap.ContainsKey(toAgentID)) |
452 | { | 472 | { |
453 | upd = new UserAgentData(); | 473 | upd = new PresenceInfo(); |
454 | upd.AgentOnline = true; | 474 | upd.Online = true; |
455 | upd.Handle = m_UserRegionMap[toAgentID]; | 475 | upd.RegionID = m_UserRegionMap[toAgentID]; |
456 | 476 | ||
457 | // We need to compare the current regionhandle with the previous region handle | 477 | // We need to compare the current regionhandle with the previous region handle |
458 | // or the recursive loop will never end because it will never try to lookup the agent again | 478 | // or the recursive loop will never end because it will never try to lookup the agent again |
459 | if (prevRegionHandle == upd.Handle) | 479 | if (prevRegionID == upd.RegionID) |
460 | { | 480 | { |
461 | lookupAgent = true; | 481 | lookupAgent = true; |
462 | } | 482 | } |
@@ -472,14 +492,23 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
472 | if (lookupAgent) | 492 | if (lookupAgent) |
473 | { | 493 | { |
474 | // Non-cached user agent lookup. | 494 | // Non-cached user agent lookup. |
475 | upd = m_Scenes[0].CommsManager.UserService.GetAgentByUUID(toAgentID); | 495 | PresenceInfo[] presences = PresenceService.GetAgents(new string[] { toAgentID.ToString() }); |
496 | if (presences != null) | ||
497 | { | ||
498 | foreach (PresenceInfo p in presences) | ||
499 | if (p.Online) | ||
500 | { | ||
501 | upd = presences[0]; | ||
502 | break; | ||
503 | } | ||
504 | } | ||
476 | 505 | ||
477 | if (upd != null) | 506 | if (upd != null) |
478 | { | 507 | { |
479 | // check if we've tried this before.. | 508 | // check if we've tried this before.. |
480 | // This is one way to end the recursive loop | 509 | // This is one way to end the recursive loop |
481 | // | 510 | // |
482 | if (upd.Handle == prevRegionHandle) | 511 | if (upd.RegionID == prevRegionID) |
483 | { | 512 | { |
484 | m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message"); | 513 | m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message"); |
485 | HandleUndeliveredMessage(im, result); | 514 | HandleUndeliveredMessage(im, result); |
@@ -496,12 +525,10 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
496 | 525 | ||
497 | if (upd != null) | 526 | if (upd != null) |
498 | { | 527 | { |
499 | if (upd.AgentOnline) | 528 | if (upd.Online) |
500 | { | 529 | { |
501 | uint x = 0, y = 0; | 530 | GridRegion reginfo = m_Scenes[0].GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, |
502 | Utils.LongToUInts(upd.Handle, out x, out y); | 531 | upd.RegionID); |
503 | GridRegion reginfo = m_Scenes[0].GridService.GetRegionByPosition(m_Scenes[0].RegionInfo.ScopeID, | ||
504 | (int)x, (int)y); | ||
505 | if (reginfo != null) | 532 | if (reginfo != null) |
506 | { | 533 | { |
507 | Hashtable msgdata = ConvertGridInstantMessageToXMLRPC(im); | 534 | Hashtable msgdata = ConvertGridInstantMessageToXMLRPC(im); |
@@ -517,11 +544,11 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
517 | { | 544 | { |
518 | if (m_UserRegionMap.ContainsKey(toAgentID)) | 545 | if (m_UserRegionMap.ContainsKey(toAgentID)) |
519 | { | 546 | { |
520 | m_UserRegionMap[toAgentID] = upd.Handle; | 547 | m_UserRegionMap[toAgentID] = upd.RegionID; |
521 | } | 548 | } |
522 | else | 549 | else |
523 | { | 550 | { |
524 | m_UserRegionMap.Add(toAgentID, upd.Handle); | 551 | m_UserRegionMap.Add(toAgentID, upd.RegionID); |
525 | } | 552 | } |
526 | } | 553 | } |
527 | result(true); | 554 | result(true); |
@@ -536,12 +563,12 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
536 | 563 | ||
537 | // This is recursive!!!!! | 564 | // This is recursive!!!!! |
538 | SendGridInstantMessageViaXMLRPCAsync(im, result, | 565 | SendGridInstantMessageViaXMLRPCAsync(im, result, |
539 | upd.Handle); | 566 | upd.RegionID); |
540 | } | 567 | } |
541 | } | 568 | } |
542 | else | 569 | else |
543 | { | 570 | { |
544 | m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find region {0}", upd.Handle); | 571 | m_log.WarnFormat("[GRID INSTANT MESSAGE]: Unable to find region {0}", upd.RegionID); |
545 | HandleUndeliveredMessage(im, result); | 572 | HandleUndeliveredMessage(im, result); |
546 | } | 573 | } |
547 | } | 574 | } |
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModule.cs index 2d4a635..24cbaeb 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MuteListModule.cs | |||
@@ -37,9 +37,9 @@ using OpenSim.Framework.Client; | |||
37 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
38 | using OpenSim.Region.Framework.Scenes; | 38 | using OpenSim.Region.Framework.Scenes; |
39 | 39 | ||
40 | namespace OpenSim.Region.CoreModules.Avatar.MuteList | 40 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage |
41 | { | 41 | { |
42 | public class MuteListModule : IRegionModule | 42 | public class MuteListModule : ISharedRegionModule |
43 | { | 43 | { |
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
45 | 45 | ||
@@ -47,11 +47,8 @@ namespace OpenSim.Region.CoreModules.Avatar.MuteList | |||
47 | private List<Scene> m_SceneList = new List<Scene>(); | 47 | private List<Scene> m_SceneList = new List<Scene>(); |
48 | private string m_RestURL = String.Empty; | 48 | private string m_RestURL = String.Empty; |
49 | 49 | ||
50 | public void Initialise(Scene scene, IConfigSource config) | 50 | public void Initialise(IConfigSource config) |
51 | { | 51 | { |
52 | if (!enabled) | ||
53 | return; | ||
54 | |||
55 | IConfig cnf = config.Configs["Messaging"]; | 52 | IConfig cnf = config.Configs["Messaging"]; |
56 | if (cnf == null) | 53 | if (cnf == null) |
57 | { | 54 | { |
@@ -59,39 +56,53 @@ namespace OpenSim.Region.CoreModules.Avatar.MuteList | |||
59 | return; | 56 | return; |
60 | } | 57 | } |
61 | 58 | ||
62 | if (cnf != null && cnf.GetString( | 59 | if (cnf != null && cnf.GetString("MuteListModule", "None") != |
63 | "MuteListModule", "None") != | ||
64 | "MuteListModule") | 60 | "MuteListModule") |
65 | { | 61 | { |
66 | enabled = false; | 62 | enabled = false; |
67 | return; | 63 | return; |
68 | } | 64 | } |
69 | 65 | ||
66 | m_RestURL = cnf.GetString("MuteListURL", ""); | ||
67 | if (m_RestURL == "") | ||
68 | { | ||
69 | m_log.Error("[MUTE LIST] Module was enabled, but no URL is given, disabling"); | ||
70 | enabled = false; | ||
71 | return; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | public void AddRegion(Scene scene) | ||
76 | { | ||
77 | if (!enabled) | ||
78 | return; | ||
79 | |||
70 | lock (m_SceneList) | 80 | lock (m_SceneList) |
71 | { | 81 | { |
72 | if (m_SceneList.Count == 0) | 82 | m_SceneList.Add(scene); |
73 | { | ||
74 | m_RestURL = cnf.GetString("MuteListURL", ""); | ||
75 | if (m_RestURL == "") | ||
76 | { | ||
77 | m_log.Error("[MUTE LIST] Module was enabled, but no URL is given, disabling"); | ||
78 | enabled = false; | ||
79 | return; | ||
80 | } | ||
81 | } | ||
82 | if (!m_SceneList.Contains(scene)) | ||
83 | m_SceneList.Add(scene); | ||
84 | 83 | ||
85 | scene.EventManager.OnNewClient += OnNewClient; | 84 | scene.EventManager.OnNewClient += OnNewClient; |
86 | } | 85 | } |
87 | } | 86 | } |
88 | 87 | ||
89 | public void PostInitialise() | 88 | public void RegionLoaded(Scene scene) |
89 | { | ||
90 | } | ||
91 | |||
92 | public void RemoveRegion(Scene scene) | ||
90 | { | 93 | { |
91 | if (!enabled) | 94 | if (!enabled) |
92 | return; | 95 | return; |
93 | 96 | ||
94 | if (m_SceneList.Count == 0) | 97 | lock (m_SceneList) |
98 | { | ||
99 | m_SceneList.Remove(scene); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | public void PostInitialise() | ||
104 | { | ||
105 | if (!enabled) | ||
95 | return; | 106 | return; |
96 | 107 | ||
97 | m_log.Debug("[MUTE LIST] Mute list enabled"); | 108 | m_log.Debug("[MUTE LIST] Mute list enabled"); |
@@ -102,26 +113,15 @@ namespace OpenSim.Region.CoreModules.Avatar.MuteList | |||
102 | get { return "MuteListModule"; } | 113 | get { return "MuteListModule"; } |
103 | } | 114 | } |
104 | 115 | ||
105 | public bool IsSharedModule | 116 | public Type ReplaceableInterface |
106 | { | 117 | { |
107 | get { return true; } | 118 | get { return null; } |
108 | } | 119 | } |
109 | 120 | ||
110 | public void Close() | 121 | public void Close() |
111 | { | 122 | { |
112 | } | 123 | } |
113 | 124 | ||
114 | // private IClientAPI FindClient(UUID agentID) | ||
115 | // { | ||
116 | // foreach (Scene s in m_SceneList) | ||
117 | // { | ||
118 | // ScenePresence presence = s.GetScenePresence(agentID); | ||
119 | // if (presence != null && !presence.IsChildAgent) | ||
120 | // return presence.ControllingClient; | ||
121 | // } | ||
122 | // return null; | ||
123 | // } | ||
124 | |||
125 | private void OnNewClient(IClientAPI client) | 125 | private void OnNewClient(IClientAPI client) |
126 | { | 126 | { |
127 | client.OnMuteListRequest += OnMuteListRequest; | 127 | client.OnMuteListRequest += OnMuteListRequest; |
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs index 0727fa9..9412735 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs | |||
@@ -40,82 +40,91 @@ using OpenSim.Region.Framework.Scenes; | |||
40 | 40 | ||
41 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | 41 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage |
42 | { | 42 | { |
43 | public class OfflineMessageModule : IRegionModule | 43 | public class OfflineMessageModule : ISharedRegionModule |
44 | { | 44 | { |
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
46 | 46 | ||
47 | private bool enabled = true; | 47 | private bool enabled = true; |
48 | private List<Scene> m_SceneList = new List<Scene>(); | 48 | private List<Scene> m_SceneList = new List<Scene>(); |
49 | private string m_RestURL = String.Empty; | 49 | private string m_RestURL = String.Empty; |
50 | IMessageTransferModule m_TransferModule = null; | ||
50 | private bool m_ForwardOfflineGroupMessages = true; | 51 | private bool m_ForwardOfflineGroupMessages = true; |
51 | 52 | ||
52 | public void Initialise(Scene scene, IConfigSource config) | 53 | public void Initialise(IConfigSource config) |
53 | { | 54 | { |
54 | if (!enabled) | ||
55 | return; | ||
56 | |||
57 | IConfig cnf = config.Configs["Messaging"]; | 55 | IConfig cnf = config.Configs["Messaging"]; |
58 | if (cnf == null) | 56 | if (cnf == null) |
59 | { | 57 | { |
60 | enabled = false; | 58 | enabled = false; |
61 | return; | 59 | return; |
62 | } | 60 | } |
63 | if (cnf != null && cnf.GetString( | 61 | if (cnf != null && cnf.GetString("OfflineMessageModule", "None") != |
64 | "OfflineMessageModule", "None") != | ||
65 | "OfflineMessageModule") | 62 | "OfflineMessageModule") |
66 | { | 63 | { |
67 | enabled = false; | 64 | enabled = false; |
68 | return; | 65 | return; |
69 | } | 66 | } |
70 | 67 | ||
71 | if (cnf != null) | 68 | m_RestURL = cnf.GetString("OfflineMessageURL", ""); |
72 | m_ForwardOfflineGroupMessages = cnf.GetBoolean("ForwardOfflineGroupMessages", m_ForwardOfflineGroupMessages); | 69 | if (m_RestURL == "") |
70 | { | ||
71 | m_log.Error("[OFFLINE MESSAGING] Module was enabled, but no URL is given, disabling"); | ||
72 | enabled = false; | ||
73 | return; | ||
74 | } | ||
75 | |||
76 | m_ForwardOfflineGroupMessages = cnf.GetBoolean("ForwardOfflineGroupMessages", m_ForwardOfflineGroupMessages); | ||
77 | } | ||
78 | |||
79 | public void AddRegion(Scene scene) | ||
80 | { | ||
81 | if (!enabled) | ||
82 | return; | ||
73 | 83 | ||
74 | lock (m_SceneList) | 84 | lock (m_SceneList) |
75 | { | 85 | { |
76 | if (m_SceneList.Count == 0) | 86 | m_SceneList.Add(scene); |
77 | { | ||
78 | m_RestURL = cnf.GetString("OfflineMessageURL", ""); | ||
79 | if (m_RestURL == "") | ||
80 | { | ||
81 | m_log.Error("[OFFLINE MESSAGING] Module was enabled, but no URL is given, disabling"); | ||
82 | enabled = false; | ||
83 | return; | ||
84 | } | ||
85 | } | ||
86 | if (!m_SceneList.Contains(scene)) | ||
87 | m_SceneList.Add(scene); | ||
88 | 87 | ||
89 | scene.EventManager.OnNewClient += OnNewClient; | 88 | scene.EventManager.OnNewClient += OnNewClient; |
90 | } | 89 | } |
91 | } | 90 | } |
92 | 91 | ||
93 | public void PostInitialise() | 92 | public void RegionLoaded(Scene scene) |
94 | { | 93 | { |
95 | if (!enabled) | 94 | if (!enabled) |
96 | return; | 95 | return; |
97 | 96 | ||
98 | if (m_SceneList.Count == 0) | 97 | if (m_TransferModule == null) |
99 | return; | ||
100 | |||
101 | IMessageTransferModule trans = m_SceneList[0].RequestModuleInterface<IMessageTransferModule>(); | ||
102 | if (trans == null) | ||
103 | { | 98 | { |
104 | enabled = false; | 99 | m_TransferModule = scene.RequestModuleInterface<IMessageTransferModule>(); |
105 | 100 | if (m_TransferModule == null) | |
106 | lock (m_SceneList) | ||
107 | { | 101 | { |
108 | foreach (Scene s in m_SceneList) | 102 | scene.EventManager.OnNewClient -= OnNewClient; |
109 | s.EventManager.OnNewClient -= OnNewClient; | ||
110 | 103 | ||
104 | enabled = false; | ||
111 | m_SceneList.Clear(); | 105 | m_SceneList.Clear(); |
106 | |||
107 | m_log.Error("[OFFLINE MESSAGING] No message transfer module is enabled. Diabling offline messages"); | ||
112 | } | 108 | } |
109 | m_TransferModule.OnUndeliveredMessage += UndeliveredMessage; | ||
110 | } | ||
111 | } | ||
113 | 112 | ||
114 | m_log.Error("[OFFLINE MESSAGING] No message transfer module is enabled. Diabling offline messages"); | 113 | public void RemoveRegion(Scene scene) |
114 | { | ||
115 | if (!enabled) | ||
115 | return; | 116 | return; |
117 | |||
118 | lock (m_SceneList) | ||
119 | { | ||
120 | m_SceneList.Remove(scene); | ||
116 | } | 121 | } |
122 | } | ||
117 | 123 | ||
118 | trans.OnUndeliveredMessage += UndeliveredMessage; | 124 | public void PostInitialise() |
125 | { | ||
126 | if (!enabled) | ||
127 | return; | ||
119 | 128 | ||
120 | m_log.Debug("[OFFLINE MESSAGING] Offline messages enabled"); | 129 | m_log.Debug("[OFFLINE MESSAGING] Offline messages enabled"); |
121 | } | 130 | } |
@@ -125,9 +134,9 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | |||
125 | get { return "OfflineMessageModule"; } | 134 | get { return "OfflineMessageModule"; } |
126 | } | 135 | } |
127 | 136 | ||
128 | public bool IsSharedModule | 137 | public Type ReplaceableInterface |
129 | { | 138 | { |
130 | get { return true; } | 139 | get { return null; } |
131 | } | 140 | } |
132 | 141 | ||
133 | public void Close() | 142 | public void Close() |
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/PresenceModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/PresenceModule.cs index f5ab454..bafad82 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/PresenceModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/PresenceModule.cs | |||
@@ -24,6 +24,7 @@ | |||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | using System; | ||
27 | using System.Collections; | 28 | using System.Collections; |
28 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
29 | using System.Net; | 30 | using System.Net; |
@@ -35,408 +36,123 @@ using OpenMetaverse; | |||
35 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
36 | using OpenSim.Region.Framework.Interfaces; | 37 | using OpenSim.Region.Framework.Interfaces; |
37 | using OpenSim.Region.Framework.Scenes; | 38 | using OpenSim.Region.Framework.Scenes; |
39 | using OpenSim.Services.Interfaces; | ||
38 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | 40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
41 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; | ||
39 | 42 | ||
40 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage | 43 | namespace OpenSim.Region.CoreModules.Avatar.InstantMessage |
41 | { | 44 | { |
42 | public class PresenceModule : IRegionModule, IPresenceModule | 45 | public class PresenceModule : ISharedRegionModule, IPresenceModule |
43 | { | 46 | { |
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 47 | private static readonly ILog m_log = LogManager.GetLogger( |
45 | 48 | MethodBase.GetCurrentMethod().DeclaringType); | |
46 | private bool m_Enabled = false; | ||
47 | private bool m_Gridmode = false; | ||
48 | |||
49 | // some default scene for doing things that aren't connected to a specific scene. Avoids locking. | ||
50 | private Scene m_initialScene; | ||
51 | |||
52 | private List<Scene> m_Scenes = new List<Scene>(); | ||
53 | |||
54 | // we currently are only interested in root-agents. If the root isn't here, we don't know the region the | ||
55 | // user is in, so we have to ask the messaging server anyway. | ||
56 | private Dictionary<UUID, Scene> m_RootAgents = | ||
57 | new Dictionary<UUID, Scene>(); | ||
58 | 49 | ||
59 | public event PresenceChange OnPresenceChange; | 50 | public event PresenceChange OnPresenceChange; |
60 | public event BulkPresenceData OnBulkPresenceData; | 51 | public event BulkPresenceData OnBulkPresenceData; |
61 | 52 | ||
62 | public void Initialise(Scene scene, IConfigSource config) | 53 | protected List<Scene> m_Scenes = new List<Scene>(); |
63 | { | ||
64 | lock (m_Scenes) | ||
65 | { | ||
66 | // This is a shared module; Initialise will be called for every region on this server. | ||
67 | // Only check config once for the first region. | ||
68 | if (m_Scenes.Count == 0) | ||
69 | { | ||
70 | IConfig cnf = config.Configs["Messaging"]; | ||
71 | if (cnf != null && cnf.GetString( | ||
72 | "PresenceModule", "PresenceModule") != | ||
73 | "PresenceModule") | ||
74 | return; | ||
75 | |||
76 | cnf = config.Configs["Startup"]; | ||
77 | if (cnf != null) | ||
78 | m_Gridmode = cnf.GetBoolean("gridmode", false); | ||
79 | 54 | ||
80 | m_Enabled = true; | 55 | protected IPresenceService m_PresenceService = null; |
81 | 56 | ||
82 | m_initialScene = scene; | 57 | protected IPresenceService PresenceService |
83 | } | ||
84 | |||
85 | if (m_Gridmode) | ||
86 | NotifyMessageServerOfStartup(scene); | ||
87 | |||
88 | m_Scenes.Add(scene); | ||
89 | } | ||
90 | |||
91 | scene.RegisterModuleInterface<IPresenceModule>(this); | ||
92 | |||
93 | scene.EventManager.OnNewClient += OnNewClient; | ||
94 | scene.EventManager.OnSetRootAgentScene += OnSetRootAgentScene; | ||
95 | scene.EventManager.OnMakeChildAgent += OnMakeChildAgent; | ||
96 | } | ||
97 | |||
98 | public void PostInitialise() | ||
99 | { | ||
100 | } | ||
101 | |||
102 | public void Close() | ||
103 | { | 58 | { |
104 | if (!m_Gridmode || !m_Enabled) | 59 | get |
105 | return; | ||
106 | |||
107 | if (OnPresenceChange != null) | ||
108 | { | 60 | { |
109 | lock (m_RootAgents) | 61 | if (m_PresenceService == null) |
110 | { | 62 | { |
111 | // on shutdown, users are kicked, too | 63 | if (m_Scenes.Count > 0) |
112 | foreach (KeyValuePair<UUID, Scene> pair in m_RootAgents) | 64 | m_PresenceService = m_Scenes[0].RequestModuleInterface<IPresenceService>(); |
113 | { | ||
114 | OnPresenceChange(new PresenceInfo(pair.Key, UUID.Zero)); | ||
115 | } | ||
116 | } | 65 | } |
117 | } | ||
118 | 66 | ||
119 | lock (m_Scenes) | 67 | return m_PresenceService; |
120 | { | ||
121 | foreach (Scene scene in m_Scenes) | ||
122 | NotifyMessageServerOfShutdown(scene); | ||
123 | } | 68 | } |
124 | } | 69 | } |
125 | 70 | ||
126 | public string Name | 71 | public void Initialise(IConfigSource config) |
127 | { | ||
128 | get { return "PresenceModule"; } | ||
129 | } | ||
130 | |||
131 | public bool IsSharedModule | ||
132 | { | 72 | { |
133 | get { return true; } | ||
134 | } | 73 | } |
135 | 74 | ||
136 | public void RequestBulkPresenceData(UUID[] users) | 75 | public void AddRegion(Scene scene) |
137 | { | 76 | { |
138 | if (OnBulkPresenceData != null) | 77 | m_Scenes.Add(scene); |
139 | { | ||
140 | PresenceInfo[] result = new PresenceInfo[users.Length]; | ||
141 | if (m_Gridmode) | ||
142 | { | ||
143 | // first check the local information | ||
144 | List<UUID> uuids = new List<UUID>(); // the uuids to check remotely | ||
145 | List<int> indices = new List<int>(); // just for performance. | ||
146 | lock (m_RootAgents) | ||
147 | { | ||
148 | for (int i = 0; i < uuids.Count; ++i) | ||
149 | { | ||
150 | Scene scene; | ||
151 | if (m_RootAgents.TryGetValue(users[i], out scene)) | ||
152 | { | ||
153 | result[i] = new PresenceInfo(users[i], scene.RegionInfo.RegionID); | ||
154 | } | ||
155 | else | ||
156 | { | ||
157 | uuids.Add(users[i]); | ||
158 | indices.Add(i); | ||
159 | } | ||
160 | } | ||
161 | } | ||
162 | 78 | ||
163 | // now we have filtered out all the local root agents. The rest we have to request info about | 79 | scene.EventManager.OnNewClient += OnNewClient; |
164 | Dictionary<UUID, FriendRegionInfo> infos = m_initialScene.GetFriendRegionInfos(uuids); | ||
165 | for (int i = 0; i < uuids.Count; ++i) | ||
166 | { | ||
167 | FriendRegionInfo info; | ||
168 | if (infos.TryGetValue(uuids[i], out info) && info.isOnline) | ||
169 | { | ||
170 | UUID regionID = info.regionID; | ||
171 | if (regionID == UUID.Zero) | ||
172 | { | ||
173 | // TODO this is the old messaging-server protocol; only the regionHandle is available. | ||
174 | // Fetch region-info to get the id | ||
175 | uint x = 0, y = 0; | ||
176 | Utils.LongToUInts(info.regionHandle, out x, out y); | ||
177 | GridRegion regionInfo = m_initialScene.GridService.GetRegionByPosition(m_initialScene.RegionInfo.ScopeID, | ||
178 | (int)x, (int)y); | ||
179 | regionID = regionInfo.RegionID; | ||
180 | } | ||
181 | result[indices[i]] = new PresenceInfo(uuids[i], regionID); | ||
182 | } | ||
183 | else result[indices[i]] = new PresenceInfo(uuids[i], UUID.Zero); | ||
184 | } | ||
185 | } | ||
186 | else | ||
187 | { | ||
188 | // in standalone mode, we have all the info locally available. | ||
189 | lock (m_RootAgents) | ||
190 | { | ||
191 | for (int i = 0; i < users.Length; ++i) | ||
192 | { | ||
193 | Scene scene; | ||
194 | if (m_RootAgents.TryGetValue(users[i], out scene)) | ||
195 | { | ||
196 | result[i] = new PresenceInfo(users[i], scene.RegionInfo.RegionID); | ||
197 | } | ||
198 | else | ||
199 | { | ||
200 | result[i] = new PresenceInfo(users[i], UUID.Zero); | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | } | ||
205 | 80 | ||
206 | // tell everyone | 81 | scene.RegisterModuleInterface<IPresenceModule>(this); |
207 | OnBulkPresenceData(result); | ||
208 | } | ||
209 | } | 82 | } |
210 | 83 | ||
211 | // new client doesn't mean necessarily that user logged in, it just means it entered one of the | 84 | public void RegionLoaded(Scene scene) |
212 | // the regions on this server | ||
213 | public void OnNewClient(IClientAPI client) | ||
214 | { | 85 | { |
215 | client.OnConnectionClosed += OnConnectionClosed; | ||
216 | client.OnLogout += OnLogout; | ||
217 | |||
218 | // KLUDGE: See handler for details. | ||
219 | client.OnEconomyDataRequest += OnEconomyDataRequest; | ||
220 | } | 86 | } |
221 | 87 | ||
222 | // connection closed just means *one* client connection has been closed. It doesn't mean that the | 88 | public void RemoveRegion(Scene scene) |
223 | // user has logged off; it might have just TPed away. | ||
224 | public void OnConnectionClosed(IClientAPI client) | ||
225 | { | 89 | { |
226 | // TODO: Have to think what we have to do here... | 90 | m_Scenes.Remove(scene); |
227 | // Should we just remove the root from the list (if scene matches)? | ||
228 | if (!(client.Scene is Scene)) | ||
229 | return; | ||
230 | Scene scene = (Scene)client.Scene; | ||
231 | |||
232 | lock (m_RootAgents) | ||
233 | { | ||
234 | Scene rootScene; | ||
235 | if (!(m_RootAgents.TryGetValue(client.AgentId, out rootScene)) || scene != rootScene) | ||
236 | return; | ||
237 | |||
238 | m_RootAgents.Remove(client.AgentId); | ||
239 | } | ||
240 | |||
241 | // Should it have logged off, we'll do the logout part in OnLogout, even if no root is stored | ||
242 | // anymore. It logged off, after all... | ||
243 | } | 91 | } |
244 | 92 | ||
245 | // Triggered when the user logs off. | 93 | public void PostInitialise() |
246 | public void OnLogout(IClientAPI client) | ||
247 | { | 94 | { |
248 | if (!(client.Scene is Scene)) | ||
249 | return; | ||
250 | Scene scene = (Scene)client.Scene; | ||
251 | |||
252 | // On logout, we really remove the client from rootAgents, even if the scene doesn't match | ||
253 | lock (m_RootAgents) | ||
254 | { | ||
255 | if (m_RootAgents.ContainsKey(client.AgentId)) m_RootAgents.Remove(client.AgentId); | ||
256 | } | ||
257 | |||
258 | // now inform the messaging server and anyone who is interested | ||
259 | NotifyMessageServerOfAgentLeaving(client.AgentId, scene.RegionInfo.RegionID, scene.RegionInfo.RegionHandle); | ||
260 | if (OnPresenceChange != null) OnPresenceChange(new PresenceInfo(client.AgentId, UUID.Zero)); | ||
261 | } | 95 | } |
262 | 96 | ||
263 | public void OnSetRootAgentScene(UUID agentID, Scene scene) | 97 | public void Close() |
264 | { | 98 | { |
265 | // OnSetRootAgentScene can be called from several threads at once (with different agentID). | ||
266 | // Concurrent access to m_RootAgents is prone to failure on multi-core/-processor systems without | ||
267 | // correct locking). | ||
268 | lock (m_RootAgents) | ||
269 | { | ||
270 | Scene rootScene; | ||
271 | if (m_RootAgents.TryGetValue(agentID, out rootScene) && scene == rootScene) | ||
272 | { | ||
273 | return; | ||
274 | } | ||
275 | m_RootAgents[agentID] = scene; | ||
276 | } | ||
277 | |||
278 | // inform messaging server that agent changed the region | ||
279 | Util.FireAndForget( | ||
280 | delegate(object o) | ||
281 | { | ||
282 | NotifyMessageServerOfAgentLocation(agentID, scene.RegionInfo.RegionID, scene.RegionInfo.RegionHandle); | ||
283 | } | ||
284 | ); | ||
285 | } | 99 | } |
286 | 100 | ||
287 | private void OnEconomyDataRequest(UUID agentID) | 101 | public string Name |
288 | { | 102 | { |
289 | // KLUDGE: This is the only way I found to get a message (only) after login was completed and the | 103 | get { return "PresenceModule"; } |
290 | // client is connected enough to receive UDP packets. | ||
291 | // This packet seems to be sent only once, just after connection was established to the first | ||
292 | // region after login. | ||
293 | // We use it here to trigger a presence update; the old update-on-login was never be heard by | ||
294 | // the freshly logged in viewer, as it wasn't connected to the region at that time. | ||
295 | // TODO: Feel free to replace this by a better solution if you find one. | ||
296 | |||
297 | // get the agent. This should work every time, as we just got a packet from it | ||
298 | ScenePresence agent = null; | ||
299 | lock (m_Scenes) | ||
300 | { | ||
301 | foreach (Scene scene in m_Scenes) | ||
302 | { | ||
303 | agent = scene.GetScenePresence(agentID); | ||
304 | if (agent != null) break; | ||
305 | } | ||
306 | } | ||
307 | |||
308 | // just to be paranoid... | ||
309 | if (agent == null) | ||
310 | { | ||
311 | m_log.ErrorFormat("[PRESENCE]: Got a packet from agent {0} who can't be found anymore!?", agentID); | ||
312 | return; | ||
313 | } | ||
314 | |||
315 | // we are a bit premature here, but the next packet will switch this child agent to root. | ||
316 | if (OnPresenceChange != null) OnPresenceChange(new PresenceInfo(agentID, agent.Scene.RegionInfo.RegionID)); | ||
317 | } | 104 | } |
318 | 105 | ||
319 | public void OnMakeChildAgent(ScenePresence agent) | 106 | public Type ReplaceableInterface |
320 | { | 107 | { |
321 | // OnMakeChildAgent can be called from several threads at once (with different agent). | 108 | get { return null; } |
322 | // Concurrent access to m_RootAgents is prone to failure on multi-core/-processor systems without | ||
323 | // correct locking). | ||
324 | lock (m_RootAgents) | ||
325 | { | ||
326 | Scene rootScene; | ||
327 | if (m_RootAgents.TryGetValue(agent.UUID, out rootScene) && agent.Scene == rootScene) | ||
328 | { | ||
329 | m_RootAgents.Remove(agent.UUID); | ||
330 | } | ||
331 | } | ||
332 | // don't notify the messaging-server; either this agent just had been downgraded and another one will be upgraded | ||
333 | // to root momentarily (which will notify the messaging-server), or possibly it will be closed in a moment, | ||
334 | // which will update the messaging-server, too. | ||
335 | } | 109 | } |
336 | 110 | ||
337 | private void NotifyMessageServerOfStartup(Scene scene) | 111 | public void RequestBulkPresenceData(UUID[] users) |
338 | { | 112 | { |
339 | Hashtable xmlrpcdata = new Hashtable(); | ||
340 | xmlrpcdata["RegionUUID"] = scene.RegionInfo.RegionID.ToString(); | ||
341 | ArrayList SendParams = new ArrayList(); | ||
342 | SendParams.Add(xmlrpcdata); | ||
343 | try | ||
344 | { | ||
345 | XmlRpcRequest UpRequest = new XmlRpcRequest("region_startup", SendParams); | ||
346 | XmlRpcResponse resp = UpRequest.Send(scene.CommsManager.NetworkServersInfo.MessagingURL, 5000); | ||
347 | |||
348 | Hashtable responseData = (Hashtable)resp.Value; | ||
349 | if (responseData == null || (!responseData.ContainsKey("success")) || (string)responseData["success"] != "TRUE") | ||
350 | { | ||
351 | m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of region startup for region {0}", scene.RegionInfo.RegionName); | ||
352 | } | ||
353 | } | ||
354 | catch (WebException) | ||
355 | { | ||
356 | m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of region startup for region {0}", scene.RegionInfo.RegionName); | ||
357 | } | ||
358 | } | 113 | } |
359 | 114 | ||
360 | private void NotifyMessageServerOfShutdown(Scene scene) | 115 | public void OnNewClient(IClientAPI client) |
361 | { | 116 | { |
362 | if (m_Scenes[0].CommsManager.NetworkServersInfo.MessagingURL == string.Empty) | 117 | client.AddGenericPacketHandler("requestonlinenotification", OnRequestOnlineNotification); |
363 | return; | ||
364 | |||
365 | Hashtable xmlrpcdata = new Hashtable(); | ||
366 | xmlrpcdata["RegionUUID"] = scene.RegionInfo.RegionID.ToString(); | ||
367 | ArrayList SendParams = new ArrayList(); | ||
368 | SendParams.Add(xmlrpcdata); | ||
369 | try | ||
370 | { | ||
371 | XmlRpcRequest DownRequest = new XmlRpcRequest("region_shutdown", SendParams); | ||
372 | XmlRpcResponse resp = DownRequest.Send(scene.CommsManager.NetworkServersInfo.MessagingURL, 5000); | ||
373 | |||
374 | Hashtable responseData = (Hashtable)resp.Value; | ||
375 | if ((!responseData.ContainsKey("success")) || (string)responseData["success"] != "TRUE") | ||
376 | { | ||
377 | m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of region shutdown for region {0}", scene.RegionInfo.RegionName); | ||
378 | } | ||
379 | } | ||
380 | catch (WebException) | ||
381 | { | ||
382 | m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of region shutdown for region {0}", scene.RegionInfo.RegionName); | ||
383 | } | ||
384 | } | 118 | } |
385 | 119 | ||
386 | private void NotifyMessageServerOfAgentLocation(UUID agentID, UUID region, ulong regionHandle) | 120 | public void OnRequestOnlineNotification(Object sender, string method, List<String> args) |
387 | { | 121 | { |
388 | if (m_Scenes[0].CommsManager.NetworkServersInfo.MessagingURL == string.Empty) | 122 | if (!(sender is IClientAPI)) |
389 | return; | 123 | return; |
390 | 124 | ||
391 | Hashtable xmlrpcdata = new Hashtable(); | 125 | IClientAPI client = (IClientAPI)sender; |
392 | xmlrpcdata["AgentID"] = agentID.ToString(); | 126 | m_log.DebugFormat("[PRESENCE MODULE]: OnlineNotification requested by {0}", client.Name); |
393 | xmlrpcdata["RegionUUID"] = region.ToString(); | ||
394 | xmlrpcdata["RegionHandle"] = regionHandle.ToString(); | ||
395 | ArrayList SendParams = new ArrayList(); | ||
396 | SendParams.Add(xmlrpcdata); | ||
397 | try | ||
398 | { | ||
399 | XmlRpcRequest LocationRequest = new XmlRpcRequest("agent_location", SendParams); | ||
400 | XmlRpcResponse resp = LocationRequest.Send(m_Scenes[0].CommsManager.NetworkServersInfo.MessagingURL, 5000); | ||
401 | 127 | ||
402 | Hashtable responseData = (Hashtable)resp.Value; | 128 | PresenceInfo[] status = PresenceService.GetAgents(args.ToArray()); |
403 | if ((!responseData.ContainsKey("success")) || (string)responseData["success"] != "TRUE") | ||
404 | { | ||
405 | m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of agent location for {0}", agentID.ToString()); | ||
406 | } | ||
407 | } | ||
408 | catch (WebException) | ||
409 | { | ||
410 | m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of agent location for {0}", agentID.ToString()); | ||
411 | } | ||
412 | } | ||
413 | 129 | ||
414 | private void NotifyMessageServerOfAgentLeaving(UUID agentID, UUID region, ulong regionHandle) | 130 | List<UUID> online = new List<UUID>(); |
415 | { | 131 | List<UUID> offline = new List<UUID>(); |
416 | if (m_Scenes[0].CommsManager.NetworkServersInfo.MessagingURL == string.Empty) | ||
417 | return; | ||
418 | 132 | ||
419 | Hashtable xmlrpcdata = new Hashtable(); | 133 | foreach (PresenceInfo pi in status) |
420 | xmlrpcdata["AgentID"] = agentID.ToString(); | ||
421 | xmlrpcdata["RegionUUID"] = region.ToString(); | ||
422 | xmlrpcdata["RegionHandle"] = regionHandle.ToString(); | ||
423 | ArrayList SendParams = new ArrayList(); | ||
424 | SendParams.Add(xmlrpcdata); | ||
425 | try | ||
426 | { | 134 | { |
427 | XmlRpcRequest LeavingRequest = new XmlRpcRequest("agent_leaving", SendParams); | 135 | UUID uuid = new UUID(pi.UserID); |
428 | XmlRpcResponse resp = LeavingRequest.Send(m_Scenes[0].CommsManager.NetworkServersInfo.MessagingURL, 5000); | 136 | if (pi.Online) |
429 | |||
430 | Hashtable responseData = (Hashtable)resp.Value; | ||
431 | if ((!responseData.ContainsKey("success")) || (string)responseData["success"] != "TRUE") | ||
432 | { | 137 | { |
433 | m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of agent leaving for {0}", agentID.ToString()); | 138 | if (!online.Contains(uuid)) |
139 | { | ||
140 | online.Add(uuid); | ||
141 | if (offline.Contains(uuid)) | ||
142 | offline.Remove(uuid); | ||
143 | } | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | if (!online.Contains(uuid) && !offline.Contains(uuid)) | ||
148 | offline.Add(uuid); | ||
434 | } | 149 | } |
435 | } | 150 | } |
436 | catch (WebException) | 151 | |
437 | { | 152 | if (online.Count > 0) |
438 | m_log.ErrorFormat("[PRESENCE]: Failed to notify message server of agent leaving for {0}", agentID.ToString()); | 153 | client.SendAgentOnline(online.ToArray()); |
439 | } | 154 | if (offline.Count > 0) |
155 | client.SendAgentOffline(offline.ToArray()); | ||
440 | } | 156 | } |
441 | } | 157 | } |
442 | } | 158 | } |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index 160a9bd..dc7439c 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs | |||
@@ -37,7 +37,7 @@ using log4net; | |||
37 | using OpenMetaverse; | 37 | using OpenMetaverse; |
38 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
39 | using OpenSim.Framework.Communications; | 39 | using OpenSim.Framework.Communications; |
40 | using OpenSim.Framework.Communications.Cache; | 40 | |
41 | using OpenSim.Framework.Communications.Osp; | 41 | using OpenSim.Framework.Communications.Osp; |
42 | using OpenSim.Framework.Serialization; | 42 | using OpenSim.Framework.Serialization; |
43 | using OpenSim.Framework.Serialization.External; | 43 | using OpenSim.Framework.Serialization.External; |
@@ -53,7 +53,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
53 | 53 | ||
54 | protected TarArchiveReader archive; | 54 | protected TarArchiveReader archive; |
55 | 55 | ||
56 | private CachedUserInfo m_userInfo; | 56 | private UserAccount m_userInfo; |
57 | private string m_invPath; | 57 | private string m_invPath; |
58 | 58 | ||
59 | /// <value> | 59 | /// <value> |
@@ -67,7 +67,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
67 | private Stream m_loadStream; | 67 | private Stream m_loadStream; |
68 | 68 | ||
69 | public InventoryArchiveReadRequest( | 69 | public InventoryArchiveReadRequest( |
70 | Scene scene, CachedUserInfo userInfo, string invPath, string loadPath) | 70 | Scene scene, UserAccount userInfo, string invPath, string loadPath) |
71 | : this( | 71 | : this( |
72 | scene, | 72 | scene, |
73 | userInfo, | 73 | userInfo, |
@@ -77,7 +77,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
77 | } | 77 | } |
78 | 78 | ||
79 | public InventoryArchiveReadRequest( | 79 | public InventoryArchiveReadRequest( |
80 | Scene scene, CachedUserInfo userInfo, string invPath, Stream loadStream) | 80 | Scene scene, UserAccount userInfo, string invPath, Stream loadStream) |
81 | { | 81 | { |
82 | m_scene = scene; | 82 | m_scene = scene; |
83 | m_userInfo = userInfo; | 83 | m_userInfo = userInfo; |
@@ -103,7 +103,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
103 | //InventoryFolderImpl rootDestinationFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath); | 103 | //InventoryFolderImpl rootDestinationFolder = m_userInfo.RootFolder.FindFolderByPath(m_invPath); |
104 | InventoryFolderBase rootDestinationFolder | 104 | InventoryFolderBase rootDestinationFolder |
105 | = InventoryArchiveUtils.FindFolderByPath( | 105 | = InventoryArchiveUtils.FindFolderByPath( |
106 | m_scene.InventoryService, m_userInfo.UserProfile.ID, m_invPath); | 106 | m_scene.InventoryService, m_userInfo.PrincipalID, m_invPath); |
107 | 107 | ||
108 | if (null == rootDestinationFolder) | 108 | if (null == rootDestinationFolder) |
109 | { | 109 | { |
@@ -280,7 +280,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
280 | // even though there is a AssetType.RootCategory | 280 | // even though there is a AssetType.RootCategory |
281 | destFolder | 281 | destFolder |
282 | = new InventoryFolderBase( | 282 | = new InventoryFolderBase( |
283 | newFolderId, newFolderName, m_userInfo.UserProfile.ID, | 283 | newFolderId, newFolderName, m_userInfo.PrincipalID, |
284 | (short)AssetType.Unknown, destFolder.ID, 1); | 284 | (short)AssetType.Unknown, destFolder.ID, 1); |
285 | m_scene.InventoryService.AddFolder(destFolder); | 285 | m_scene.InventoryService.AddFolder(destFolder); |
286 | 286 | ||
@@ -357,7 +357,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
357 | // Don't use the item ID that's in the file | 357 | // Don't use the item ID that's in the file |
358 | item.ID = UUID.Random(); | 358 | item.ID = UUID.Random(); |
359 | 359 | ||
360 | UUID ospResolvedId = OspResolver.ResolveOspa(item.CreatorId, m_scene.CommsManager); | 360 | UUID ospResolvedId = OspResolver.ResolveOspa(item.CreatorId, m_scene.UserAccountService); |
361 | if (UUID.Zero != ospResolvedId) | 361 | if (UUID.Zero != ospResolvedId) |
362 | { | 362 | { |
363 | item.CreatorIdAsUuid = ospResolvedId; | 363 | item.CreatorIdAsUuid = ospResolvedId; |
@@ -368,10 +368,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
368 | } | 368 | } |
369 | else | 369 | else |
370 | { | 370 | { |
371 | item.CreatorIdAsUuid = m_userInfo.UserProfile.ID; | 371 | item.CreatorIdAsUuid = m_userInfo.PrincipalID; |
372 | } | 372 | } |
373 | 373 | ||
374 | item.Owner = m_userInfo.UserProfile.ID; | 374 | item.Owner = m_userInfo.PrincipalID; |
375 | 375 | ||
376 | // Reset folder ID to the one in which we want to load it | 376 | // Reset folder ID to the one in which we want to load it |
377 | item.Folder = loadFolder.ID; | 377 | item.Folder = loadFolder.ID; |
@@ -416,7 +416,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
416 | 416 | ||
417 | //m_log.DebugFormat("[INVENTORY ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType); | 417 | //m_log.DebugFormat("[INVENTORY ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType); |
418 | 418 | ||
419 | AssetBase asset = new AssetBase(new UUID(uuid), "RandomName", assetType); | 419 | AssetBase asset = new AssetBase(new UUID(uuid), "RandomName", assetType, UUID.Zero.ToString()); |
420 | asset.Data = data; | 420 | asset.Data = data; |
421 | 421 | ||
422 | m_scene.AssetService.Store(asset); | 422 | m_scene.AssetService.Store(asset); |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index 98b686e..ef10104 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs | |||
@@ -37,10 +37,11 @@ using OpenSim.Framework; | |||
37 | using OpenSim.Framework.Serialization; | 37 | using OpenSim.Framework.Serialization; |
38 | using OpenSim.Framework.Serialization.External; | 38 | using OpenSim.Framework.Serialization.External; |
39 | using OpenSim.Framework.Communications; | 39 | using OpenSim.Framework.Communications; |
40 | using OpenSim.Framework.Communications.Cache; | 40 | |
41 | using OpenSim.Framework.Communications.Osp; | 41 | using OpenSim.Framework.Communications.Osp; |
42 | using OpenSim.Region.CoreModules.World.Archiver; | 42 | using OpenSim.Region.CoreModules.World.Archiver; |
43 | using OpenSim.Region.Framework.Scenes; | 43 | using OpenSim.Region.Framework.Scenes; |
44 | using OpenSim.Services.Interfaces; | ||
44 | 45 | ||
45 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | 46 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver |
46 | { | 47 | { |
@@ -54,7 +55,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
54 | private const string STAR_WILDCARD = "*"; | 55 | private const string STAR_WILDCARD = "*"; |
55 | 56 | ||
56 | private InventoryArchiverModule m_module; | 57 | private InventoryArchiverModule m_module; |
57 | private CachedUserInfo m_userInfo; | 58 | private UserAccount m_userInfo; |
58 | private string m_invPath; | 59 | private string m_invPath; |
59 | protected TarArchiveWriter m_archiveWriter; | 60 | protected TarArchiveWriter m_archiveWriter; |
60 | protected UuidGatherer m_assetGatherer; | 61 | protected UuidGatherer m_assetGatherer; |
@@ -89,7 +90,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
89 | /// </summary> | 90 | /// </summary> |
90 | public InventoryArchiveWriteRequest( | 91 | public InventoryArchiveWriteRequest( |
91 | Guid id, InventoryArchiverModule module, Scene scene, | 92 | Guid id, InventoryArchiverModule module, Scene scene, |
92 | CachedUserInfo userInfo, string invPath, string savePath) | 93 | UserAccount userInfo, string invPath, string savePath) |
93 | : this( | 94 | : this( |
94 | id, | 95 | id, |
95 | module, | 96 | module, |
@@ -105,7 +106,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
105 | /// </summary> | 106 | /// </summary> |
106 | public InventoryArchiveWriteRequest( | 107 | public InventoryArchiveWriteRequest( |
107 | Guid id, InventoryArchiverModule module, Scene scene, | 108 | Guid id, InventoryArchiverModule module, Scene scene, |
108 | CachedUserInfo userInfo, string invPath, Stream saveStream) | 109 | UserAccount userInfo, string invPath, Stream saveStream) |
109 | { | 110 | { |
110 | m_id = id; | 111 | m_id = id; |
111 | m_module = module; | 112 | m_module = module; |
@@ -148,7 +149,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
148 | m_userUuids[inventoryItem.CreatorIdAsUuid] = 1; | 149 | m_userUuids[inventoryItem.CreatorIdAsUuid] = 1; |
149 | 150 | ||
150 | InventoryItemBase saveItem = (InventoryItemBase)inventoryItem.Clone(); | 151 | InventoryItemBase saveItem = (InventoryItemBase)inventoryItem.Clone(); |
151 | saveItem.CreatorId = OspResolver.MakeOspa(saveItem.CreatorIdAsUuid, m_scene.CommsManager); | 152 | saveItem.CreatorId = OspResolver.MakeOspa(saveItem.CreatorIdAsUuid, m_scene.UserAccountService); |
152 | 153 | ||
153 | string serialization = UserInventoryItemSerializer.Serialize(saveItem); | 154 | string serialization = UserInventoryItemSerializer.Serialize(saveItem); |
154 | m_archiveWriter.WriteFile(filename, serialization); | 155 | m_archiveWriter.WriteFile(filename, serialization); |
@@ -215,7 +216,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
215 | { | 216 | { |
216 | InventoryFolderBase inventoryFolder = null; | 217 | InventoryFolderBase inventoryFolder = null; |
217 | InventoryItemBase inventoryItem = null; | 218 | InventoryItemBase inventoryItem = null; |
218 | InventoryFolderBase rootFolder = m_scene.InventoryService.GetRootFolder(m_userInfo.UserProfile.ID); | 219 | InventoryFolderBase rootFolder = m_scene.InventoryService.GetRootFolder(m_userInfo.PrincipalID); |
219 | 220 | ||
220 | bool foundStar = false; | 221 | bool foundStar = false; |
221 | 222 | ||
@@ -318,14 +319,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
318 | foreach (UUID creatorId in m_userUuids.Keys) | 319 | foreach (UUID creatorId in m_userUuids.Keys) |
319 | { | 320 | { |
320 | // Record the creator of this item | 321 | // Record the creator of this item |
321 | CachedUserInfo creator | 322 | UserAccount creator = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, creatorId); |
322 | = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(creatorId); | ||
323 | 323 | ||
324 | if (creator != null) | 324 | if (creator != null) |
325 | { | 325 | { |
326 | m_archiveWriter.WriteFile( | 326 | m_archiveWriter.WriteFile( |
327 | ArchiveConstants.USERS_PATH + creator.UserProfile.Name + ".xml", | 327 | ArchiveConstants.USERS_PATH + creator.FirstName + " " + creator.LastName + ".xml", |
328 | UserProfileSerializer.Serialize(creator.UserProfile)); | 328 | UserProfileSerializer.Serialize(creator.PrincipalID, creator.FirstName, creator.LastName)); |
329 | } | 329 | } |
330 | else | 330 | else |
331 | { | 331 | { |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs index ecd60bd..71b3062 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiverModule.cs | |||
@@ -34,7 +34,7 @@ using Nini.Config; | |||
34 | using OpenMetaverse; | 34 | using OpenMetaverse; |
35 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
36 | using OpenSim.Framework.Communications; | 36 | using OpenSim.Framework.Communications; |
37 | using OpenSim.Framework.Communications.Cache; | 37 | |
38 | using OpenSim.Region.Framework.Interfaces; | 38 | using OpenSim.Region.Framework.Interfaces; |
39 | using OpenSim.Region.Framework.Scenes; | 39 | using OpenSim.Region.Framework.Scenes; |
40 | using OpenSim.Services.Interfaces; | 40 | using OpenSim.Services.Interfaces; |
@@ -113,7 +113,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
113 | /// Trigger the inventory archive saved event. | 113 | /// Trigger the inventory archive saved event. |
114 | /// </summary> | 114 | /// </summary> |
115 | protected internal void TriggerInventoryArchiveSaved( | 115 | protected internal void TriggerInventoryArchiveSaved( |
116 | Guid id, bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, | 116 | Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream, |
117 | Exception reportedException) | 117 | Exception reportedException) |
118 | { | 118 | { |
119 | InventoryArchiveSaved handlerInventoryArchiveSaved = OnInventoryArchiveSaved; | 119 | InventoryArchiveSaved handlerInventoryArchiveSaved = OnInventoryArchiveSaved; |
@@ -125,20 +125,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
125 | { | 125 | { |
126 | if (m_scenes.Count > 0) | 126 | if (m_scenes.Count > 0) |
127 | { | 127 | { |
128 | CachedUserInfo userInfo = GetUserInfo(firstName, lastName, pass); | 128 | UserAccount userInfo = GetUserInfo(firstName, lastName, pass); |
129 | 129 | ||
130 | if (userInfo != null) | 130 | if (userInfo != null) |
131 | { | 131 | { |
132 | if (CheckPresence(userInfo.UserProfile.ID)) | 132 | if (CheckPresence(userInfo.PrincipalID)) |
133 | { | 133 | { |
134 | new InventoryArchiveWriteRequest(id, this, m_aScene, userInfo, invPath, saveStream).Execute(); | 134 | try |
135 | { | ||
136 | new InventoryArchiveWriteRequest(id, this, m_aScene, userInfo, invPath, saveStream).Execute(); | ||
137 | } | ||
138 | catch (EntryPointNotFoundException e) | ||
139 | { | ||
140 | m_log.ErrorFormat( | ||
141 | "[ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream." | ||
142 | + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); | ||
143 | m_log.Error(e); | ||
144 | |||
145 | return false; | ||
146 | } | ||
147 | |||
135 | return true; | 148 | return true; |
136 | } | 149 | } |
137 | else | 150 | else |
138 | { | 151 | { |
139 | m_log.ErrorFormat( | 152 | m_log.ErrorFormat( |
140 | "[INVENTORY ARCHIVER]: User {0} {1} not logged in to this region simulator", | 153 | "[INVENTORY ARCHIVER]: User {0} {1} {2} not logged in to this region simulator", |
141 | userInfo.UserProfile.Name, userInfo.UserProfile.ID); | 154 | userInfo.FirstName, userInfo.LastName, userInfo.PrincipalID); |
142 | } | 155 | } |
143 | } | 156 | } |
144 | } | 157 | } |
@@ -150,20 +163,33 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
150 | { | 163 | { |
151 | if (m_scenes.Count > 0) | 164 | if (m_scenes.Count > 0) |
152 | { | 165 | { |
153 | CachedUserInfo userInfo = GetUserInfo(firstName, lastName, pass); | 166 | UserAccount userInfo = GetUserInfo(firstName, lastName, pass); |
154 | 167 | ||
155 | if (userInfo != null) | 168 | if (userInfo != null) |
156 | { | 169 | { |
157 | if (CheckPresence(userInfo.UserProfile.ID)) | 170 | if (CheckPresence(userInfo.PrincipalID)) |
158 | { | 171 | { |
159 | new InventoryArchiveWriteRequest(id, this, m_aScene, userInfo, invPath, savePath).Execute(); | 172 | try |
173 | { | ||
174 | new InventoryArchiveWriteRequest(id, this, m_aScene, userInfo, invPath, savePath).Execute(); | ||
175 | } | ||
176 | catch (EntryPointNotFoundException e) | ||
177 | { | ||
178 | m_log.ErrorFormat( | ||
179 | "[ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream." | ||
180 | + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); | ||
181 | m_log.Error(e); | ||
182 | |||
183 | return false; | ||
184 | } | ||
185 | |||
160 | return true; | 186 | return true; |
161 | } | 187 | } |
162 | else | 188 | else |
163 | { | 189 | { |
164 | m_log.ErrorFormat( | 190 | m_log.ErrorFormat( |
165 | "[INVENTORY ARCHIVER]: User {0} {1} not logged in to this region simulator", | 191 | "[INVENTORY ARCHIVER]: User {0} {1} {2} not logged in to this region simulator", |
166 | userInfo.UserProfile.Name, userInfo.UserProfile.ID); | 192 | userInfo.FirstName, userInfo.LastName, userInfo.PrincipalID); |
167 | } | 193 | } |
168 | } | 194 | } |
169 | } | 195 | } |
@@ -175,14 +201,28 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
175 | { | 201 | { |
176 | if (m_scenes.Count > 0) | 202 | if (m_scenes.Count > 0) |
177 | { | 203 | { |
178 | CachedUserInfo userInfo = GetUserInfo(firstName, lastName, pass); | 204 | UserAccount userInfo = GetUserInfo(firstName, lastName, pass); |
179 | 205 | ||
180 | if (userInfo != null) | 206 | if (userInfo != null) |
181 | { | 207 | { |
182 | if (CheckPresence(userInfo.UserProfile.ID)) | 208 | if (CheckPresence(userInfo.PrincipalID)) |
183 | { | 209 | { |
184 | InventoryArchiveReadRequest request = | 210 | InventoryArchiveReadRequest request; |
185 | new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadStream); | 211 | |
212 | try | ||
213 | { | ||
214 | request = new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadStream); | ||
215 | } | ||
216 | catch (EntryPointNotFoundException e) | ||
217 | { | ||
218 | m_log.ErrorFormat( | ||
219 | "[ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream." | ||
220 | + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); | ||
221 | m_log.Error(e); | ||
222 | |||
223 | return false; | ||
224 | } | ||
225 | |||
186 | UpdateClientWithLoadedNodes(userInfo, request.Execute()); | 226 | UpdateClientWithLoadedNodes(userInfo, request.Execute()); |
187 | 227 | ||
188 | return true; | 228 | return true; |
@@ -190,8 +230,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
190 | else | 230 | else |
191 | { | 231 | { |
192 | m_log.ErrorFormat( | 232 | m_log.ErrorFormat( |
193 | "[INVENTORY ARCHIVER]: User {0} {1} not logged in to this region simulator", | 233 | "[INVENTORY ARCHIVER]: User {0} {1} {2} not logged in to this region simulator", |
194 | userInfo.UserProfile.Name, userInfo.UserProfile.ID); | 234 | userInfo.FirstName, userInfo.LastName, userInfo.PrincipalID); |
195 | } | 235 | } |
196 | } | 236 | } |
197 | } | 237 | } |
@@ -203,14 +243,28 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
203 | { | 243 | { |
204 | if (m_scenes.Count > 0) | 244 | if (m_scenes.Count > 0) |
205 | { | 245 | { |
206 | CachedUserInfo userInfo = GetUserInfo(firstName, lastName, pass); | 246 | UserAccount userInfo = GetUserInfo(firstName, lastName, pass); |
207 | 247 | ||
208 | if (userInfo != null) | 248 | if (userInfo != null) |
209 | { | 249 | { |
210 | if (CheckPresence(userInfo.UserProfile.ID)) | 250 | if (CheckPresence(userInfo.PrincipalID)) |
211 | { | 251 | { |
212 | InventoryArchiveReadRequest request = | 252 | InventoryArchiveReadRequest request; |
213 | new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadPath); | 253 | |
254 | try | ||
255 | { | ||
256 | request = new InventoryArchiveReadRequest(m_aScene, userInfo, invPath, loadPath); | ||
257 | } | ||
258 | catch (EntryPointNotFoundException e) | ||
259 | { | ||
260 | m_log.ErrorFormat( | ||
261 | "[ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream." | ||
262 | + "If you've manually installed Mono, have you appropriately updated zlib1g as well?"); | ||
263 | m_log.Error(e); | ||
264 | |||
265 | return false; | ||
266 | } | ||
267 | |||
214 | UpdateClientWithLoadedNodes(userInfo, request.Execute()); | 268 | UpdateClientWithLoadedNodes(userInfo, request.Execute()); |
215 | 269 | ||
216 | return true; | 270 | return true; |
@@ -218,8 +272,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
218 | else | 272 | else |
219 | { | 273 | { |
220 | m_log.ErrorFormat( | 274 | m_log.ErrorFormat( |
221 | "[INVENTORY ARCHIVER]: User {0} {1} not logged in to this region simulator", | 275 | "[INVENTORY ARCHIVER]: User {0} {1} {2} not logged in to this region simulator", |
222 | userInfo.UserProfile.Name, userInfo.UserProfile.ID); | 276 | userInfo.FirstName, userInfo.LastName, userInfo.PrincipalID); |
223 | } | 277 | } |
224 | } | 278 | } |
225 | } | 279 | } |
@@ -291,7 +345,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
291 | } | 345 | } |
292 | 346 | ||
293 | private void SaveInvConsoleCommandCompleted( | 347 | private void SaveInvConsoleCommandCompleted( |
294 | Guid id, bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, | 348 | Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream, |
295 | Exception reportedException) | 349 | Exception reportedException) |
296 | { | 350 | { |
297 | lock (m_pendingConsoleSaves) | 351 | lock (m_pendingConsoleSaves) |
@@ -304,13 +358,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
304 | 358 | ||
305 | if (succeeded) | 359 | if (succeeded) |
306 | { | 360 | { |
307 | m_log.InfoFormat("[INVENTORY ARCHIVER]: Saved archive for {0}", userInfo.UserProfile.Name); | 361 | m_log.InfoFormat("[INVENTORY ARCHIVER]: Saved archive for {0} {1}", userInfo.FirstName, userInfo.LastName); |
308 | } | 362 | } |
309 | else | 363 | else |
310 | { | 364 | { |
311 | m_log.ErrorFormat( | 365 | m_log.ErrorFormat( |
312 | "[INVENTORY ARCHIVER]: Archive save for {0} failed - {1}", | 366 | "[INVENTORY ARCHIVER]: Archive save for {0} {1} failed - {2}", |
313 | userInfo.UserProfile.Name, reportedException.Message); | 367 | userInfo.FirstName, userInfo.LastName, reportedException.Message); |
314 | } | 368 | } |
315 | } | 369 | } |
316 | 370 | ||
@@ -321,11 +375,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
321 | /// <param name="lastName"></param> | 375 | /// <param name="lastName"></param> |
322 | /// <param name="pass">User password</param> | 376 | /// <param name="pass">User password</param> |
323 | /// <returns></returns> | 377 | /// <returns></returns> |
324 | protected CachedUserInfo GetUserInfo(string firstName, string lastName, string pass) | 378 | protected UserAccount GetUserInfo(string firstName, string lastName, string pass) |
325 | { | 379 | { |
326 | CachedUserInfo userInfo = m_aScene.CommsManager.UserProfileCacheService.GetUserDetails(firstName, lastName); | 380 | UserAccount account = m_aScene.UserAccountService.GetUserAccount(m_aScene.RegionInfo.ScopeID, firstName, lastName); |
327 | //m_aScene.CommsManager.UserService.GetUserProfile(firstName, lastName); | 381 | if (null == account) |
328 | if (null == userInfo) | ||
329 | { | 382 | { |
330 | m_log.ErrorFormat( | 383 | m_log.ErrorFormat( |
331 | "[INVENTORY ARCHIVER]: Failed to find user info for {0} {1}", | 384 | "[INVENTORY ARCHIVER]: Failed to find user info for {0} {1}", |
@@ -335,9 +388,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
335 | 388 | ||
336 | try | 389 | try |
337 | { | 390 | { |
338 | if (m_aScene.CommsManager.UserService.AuthenticateUserByPassword(userInfo.UserProfile.ID, pass)) | 391 | if (m_aScene.AuthenticationService.Authenticate(account.PrincipalID, pass, 1) != string.Empty) |
339 | { | 392 | { |
340 | return userInfo; | 393 | return account; |
341 | } | 394 | } |
342 | else | 395 | else |
343 | { | 396 | { |
@@ -358,14 +411,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver | |||
358 | /// Notify the client of loaded nodes if they are logged in | 411 | /// Notify the client of loaded nodes if they are logged in |
359 | /// </summary> | 412 | /// </summary> |
360 | /// <param name="loadedNodes">Can be empty. In which case, nothing happens</param> | 413 | /// <param name="loadedNodes">Can be empty. In which case, nothing happens</param> |
361 | private void UpdateClientWithLoadedNodes(CachedUserInfo userInfo, List<InventoryNodeBase> loadedNodes) | 414 | private void UpdateClientWithLoadedNodes(UserAccount userInfo, List<InventoryNodeBase> loadedNodes) |
362 | { | 415 | { |
363 | if (loadedNodes.Count == 0) | 416 | if (loadedNodes.Count == 0) |
364 | return; | 417 | return; |
365 | 418 | ||
366 | foreach (Scene scene in m_scenes.Values) | 419 | foreach (Scene scene in m_scenes.Values) |
367 | { | 420 | { |
368 | ScenePresence user = scene.GetScenePresence(userInfo.UserProfile.ID); | 421 | ScenePresence user = scene.GetScenePresence(userInfo.PrincipalID); |
369 | 422 | ||
370 | if (user != null && !user.IsChildAgent) | 423 | if (user != null && !user.IsChildAgent) |
371 | { | 424 | { |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs index e4dad18..9c95e78 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs | |||
@@ -38,7 +38,7 @@ using OpenSim.Framework; | |||
38 | using OpenSim.Framework.Serialization; | 38 | using OpenSim.Framework.Serialization; |
39 | using OpenSim.Framework.Serialization.External; | 39 | using OpenSim.Framework.Serialization.External; |
40 | using OpenSim.Framework.Communications; | 40 | using OpenSim.Framework.Communications; |
41 | using OpenSim.Framework.Communications.Cache; | 41 | |
42 | using OpenSim.Framework.Communications.Osp; | 42 | using OpenSim.Framework.Communications.Osp; |
43 | using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver; | 43 | using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver; |
44 | using OpenSim.Region.CoreModules.World.Serialiser; | 44 | using OpenSim.Region.CoreModules.World.Serialiser; |
@@ -65,7 +65,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
65 | } | 65 | } |
66 | 66 | ||
67 | private void SaveCompleted( | 67 | private void SaveCompleted( |
68 | Guid id, bool succeeded, CachedUserInfo userInfo, string invPath, Stream saveStream, | 68 | Guid id, bool succeeded, UserAccount userInfo, string invPath, Stream saveStream, |
69 | Exception reportedException) | 69 | Exception reportedException) |
70 | { | 70 | { |
71 | mre.Set(); | 71 | mre.Set(); |
@@ -76,124 +76,126 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
76 | /// </summary> | 76 | /// </summary> |
77 | // Commenting for now! The mock inventory service needs more beef, at least for | 77 | // Commenting for now! The mock inventory service needs more beef, at least for |
78 | // GetFolderForType | 78 | // GetFolderForType |
79 | [Test] | 79 | // REFACTORING PROBLEM. This needs to be rewritten. |
80 | public void TestSaveIarV0_1() | 80 | |
81 | { | 81 | // [Test] |
82 | TestHelper.InMethod(); | 82 | // public void TestSaveIarV0_1() |
83 | //log4net.Config.XmlConfigurator.Configure(); | 83 | // { |
84 | 84 | // TestHelper.InMethod(); | |
85 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); | 85 | // //log4net.Config.XmlConfigurator.Configure(); |
86 | 86 | ||
87 | Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | 87 | // InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); |
88 | SceneSetupHelpers.SetupSceneModules(scene, archiverModule); | 88 | |
89 | CommunicationsManager cm = scene.CommsManager; | 89 | // Scene scene = SceneSetupHelpers.SetupScene("Inventory"); |
90 | 90 | // SceneSetupHelpers.SetupSceneModules(scene, archiverModule); | |
91 | // Create user | 91 | // CommunicationsManager cm = scene.CommsManager; |
92 | string userFirstName = "Jock"; | 92 | |
93 | string userLastName = "Stirrup"; | 93 | // // Create user |
94 | UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020"); | 94 | // string userFirstName = "Jock"; |
95 | 95 | // string userLastName = "Stirrup"; | |
96 | lock (this) | 96 | // UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020"); |
97 | { | 97 | |
98 | UserProfileTestUtils.CreateUserWithInventory( | 98 | // lock (this) |
99 | cm, userFirstName, userLastName, userId, InventoryReceived); | 99 | // { |
100 | Monitor.Wait(this, 60000); | 100 | // UserProfileTestUtils.CreateUserWithInventory( |
101 | } | 101 | // cm, userFirstName, userLastName, userId, InventoryReceived); |
102 | 102 | // Monitor.Wait(this, 60000); | |
103 | // Create asset | 103 | // } |
104 | SceneObjectGroup object1; | 104 | |
105 | SceneObjectPart part1; | 105 | // // Create asset |
106 | { | 106 | // SceneObjectGroup object1; |
107 | string partName = "My Little Dog Object"; | 107 | // SceneObjectPart part1; |
108 | UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); | 108 | // { |
109 | PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); | 109 | // string partName = "My Little Dog Object"; |
110 | Vector3 groupPosition = new Vector3(10, 20, 30); | 110 | // UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); |
111 | Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); | 111 | // PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); |
112 | Vector3 offsetPosition = new Vector3(5, 10, 15); | 112 | // Vector3 groupPosition = new Vector3(10, 20, 30); |
113 | 113 | // Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); | |
114 | part1 | 114 | // Vector3 offsetPosition = new Vector3(5, 10, 15); |
115 | = new SceneObjectPart( | 115 | |
116 | ownerId, shape, groupPosition, rotationOffset, offsetPosition); | 116 | // part1 |
117 | part1.Name = partName; | 117 | // = new SceneObjectPart( |
118 | 118 | // ownerId, shape, groupPosition, rotationOffset, offsetPosition); | |
119 | object1 = new SceneObjectGroup(part1); | 119 | // part1.Name = partName; |
120 | scene.AddNewSceneObject(object1, false); | 120 | |
121 | } | 121 | // object1 = new SceneObjectGroup(part1); |
122 | 122 | // scene.AddNewSceneObject(object1, false); | |
123 | UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); | 123 | // } |
124 | AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); | 124 | |
125 | scene.AssetService.Store(asset1); | 125 | // UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); |
126 | 126 | // AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); | |
127 | // Create item | 127 | // scene.AssetService.Store(asset1); |
128 | UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); | 128 | |
129 | InventoryItemBase item1 = new InventoryItemBase(); | 129 | // // Create item |
130 | item1.Name = "My Little Dog"; | 130 | // UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); |
131 | item1.AssetID = asset1.FullID; | 131 | // InventoryItemBase item1 = new InventoryItemBase(); |
132 | item1.ID = item1Id; | 132 | // item1.Name = "My Little Dog"; |
133 | InventoryFolderBase objsFolder | 133 | // item1.AssetID = asset1.FullID; |
134 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects"); | 134 | // item1.ID = item1Id; |
135 | item1.Folder = objsFolder.ID; | 135 | // InventoryFolderBase objsFolder |
136 | scene.AddInventoryItem(userId, item1); | 136 | // = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects"); |
137 | 137 | // item1.Folder = objsFolder.ID; | |
138 | MemoryStream archiveWriteStream = new MemoryStream(); | 138 | // scene.AddInventoryItem(userId, item1); |
139 | archiverModule.OnInventoryArchiveSaved += SaveCompleted; | 139 | |
140 | 140 | // MemoryStream archiveWriteStream = new MemoryStream(); | |
141 | mre.Reset(); | 141 | // archiverModule.OnInventoryArchiveSaved += SaveCompleted; |
142 | archiverModule.ArchiveInventory( | 142 | |
143 | Guid.NewGuid(), userFirstName, userLastName, "Objects", "troll", archiveWriteStream); | 143 | // mre.Reset(); |
144 | mre.WaitOne(60000, false); | 144 | // archiverModule.ArchiveInventory( |
145 | 145 | // Guid.NewGuid(), userFirstName, userLastName, "Objects", "troll", archiveWriteStream); | |
146 | byte[] archive = archiveWriteStream.ToArray(); | 146 | // mre.WaitOne(60000, false); |
147 | MemoryStream archiveReadStream = new MemoryStream(archive); | 147 | |
148 | TarArchiveReader tar = new TarArchiveReader(archiveReadStream); | 148 | // byte[] archive = archiveWriteStream.ToArray(); |
149 | 149 | // MemoryStream archiveReadStream = new MemoryStream(archive); | |
150 | //bool gotControlFile = false; | 150 | // TarArchiveReader tar = new TarArchiveReader(archiveReadStream); |
151 | bool gotObject1File = false; | 151 | |
152 | //bool gotObject2File = false; | 152 | // //bool gotControlFile = false; |
153 | string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1); | 153 | // bool gotObject1File = false; |
154 | string expectedObject1FilePath = string.Format( | 154 | // //bool gotObject2File = false; |
155 | "{0}{1}{2}", | 155 | // string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1); |
156 | ArchiveConstants.INVENTORY_PATH, | 156 | // string expectedObject1FilePath = string.Format( |
157 | InventoryArchiveWriteRequest.CreateArchiveFolderName(objsFolder), | 157 | // "{0}{1}{2}", |
158 | expectedObject1FileName); | 158 | // ArchiveConstants.INVENTORY_PATH, |
159 | 159 | // InventoryArchiveWriteRequest.CreateArchiveFolderName(objsFolder), | |
160 | string filePath; | 160 | // expectedObject1FileName); |
161 | TarArchiveReader.TarEntryType tarEntryType; | 161 | |
162 | 162 | // string filePath; | |
163 | Console.WriteLine("Reading archive"); | 163 | // TarArchiveReader.TarEntryType tarEntryType; |
164 | 164 | ||
165 | while (tar.ReadEntry(out filePath, out tarEntryType) != null) | 165 | // Console.WriteLine("Reading archive"); |
166 | { | 166 | |
167 | Console.WriteLine("Got {0}", filePath); | 167 | // while (tar.ReadEntry(out filePath, out tarEntryType) != null) |
168 | 168 | // { | |
169 | // if (ArchiveConstants.CONTROL_FILE_PATH == filePath) | 169 | // Console.WriteLine("Got {0}", filePath); |
170 | |||
171 | //// if (ArchiveConstants.CONTROL_FILE_PATH == filePath) | ||
172 | //// { | ||
173 | //// gotControlFile = true; | ||
174 | //// } | ||
175 | |||
176 | // if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml")) | ||
170 | // { | 177 | // { |
171 | // gotControlFile = true; | 178 | //// string fileName = filePath.Remove(0, "Objects/".Length); |
179 | //// | ||
180 | //// if (fileName.StartsWith(part1.Name)) | ||
181 | //// { | ||
182 | // Assert.That(expectedObject1FilePath, Is.EqualTo(filePath)); | ||
183 | // gotObject1File = true; | ||
184 | //// } | ||
185 | //// else if (fileName.StartsWith(part2.Name)) | ||
186 | //// { | ||
187 | //// Assert.That(fileName, Is.EqualTo(expectedObject2FileName)); | ||
188 | //// gotObject2File = true; | ||
189 | //// } | ||
172 | // } | 190 | // } |
173 | 191 | // } | |
174 | if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml")) | ||
175 | { | ||
176 | // string fileName = filePath.Remove(0, "Objects/".Length); | ||
177 | // | ||
178 | // if (fileName.StartsWith(part1.Name)) | ||
179 | // { | ||
180 | Assert.That(expectedObject1FilePath, Is.EqualTo(filePath)); | ||
181 | gotObject1File = true; | ||
182 | // } | ||
183 | // else if (fileName.StartsWith(part2.Name)) | ||
184 | // { | ||
185 | // Assert.That(fileName, Is.EqualTo(expectedObject2FileName)); | ||
186 | // gotObject2File = true; | ||
187 | // } | ||
188 | } | ||
189 | } | ||
190 | 192 | ||
191 | // Assert.That(gotControlFile, Is.True, "No control file in archive"); | 193 | //// Assert.That(gotControlFile, Is.True, "No control file in archive"); |
192 | Assert.That(gotObject1File, Is.True, "No item1 file in archive"); | 194 | // Assert.That(gotObject1File, Is.True, "No item1 file in archive"); |
193 | // Assert.That(gotObject2File, Is.True, "No object2 file in archive"); | 195 | //// Assert.That(gotObject2File, Is.True, "No object2 file in archive"); |
194 | 196 | ||
195 | // TODO: Test presence of more files and contents of files. | 197 | // // TODO: Test presence of more files and contents of files. |
196 | } | 198 | // } |
197 | 199 | ||
198 | /// <summary> | 200 | /// <summary> |
199 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | 201 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where |
@@ -201,187 +203,189 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
201 | /// </summary> | 203 | /// </summary> |
202 | /// | 204 | /// |
203 | /// This test also does some deeper probing of loading into nested inventory structures | 205 | /// This test also does some deeper probing of loading into nested inventory structures |
204 | [Test] | 206 | /// REFACTORING PROBLEM. This needs to be rewritten. |
205 | public void TestLoadIarV0_1ExistingUsers() | 207 | // [Test] |
206 | { | 208 | // public void TestLoadIarV0_1ExistingUsers() |
207 | TestHelper.InMethod(); | 209 | // { |
208 | 210 | // TestHelper.InMethod(); | |
209 | //log4net.Config.XmlConfigurator.Configure(); | 211 | |
210 | 212 | // //log4net.Config.XmlConfigurator.Configure(); | |
211 | string userFirstName = "Mr"; | 213 | |
212 | string userLastName = "Tiddles"; | 214 | // string userFirstName = "Mr"; |
213 | UUID userUuid = UUID.Parse("00000000-0000-0000-0000-000000000555"); | 215 | // string userLastName = "Tiddles"; |
214 | string userItemCreatorFirstName = "Lord"; | 216 | // UUID userUuid = UUID.Parse("00000000-0000-0000-0000-000000000555"); |
215 | string userItemCreatorLastName = "Lucan"; | 217 | // string userItemCreatorFirstName = "Lord"; |
216 | UUID userItemCreatorUuid = UUID.Parse("00000000-0000-0000-0000-000000000666"); | 218 | // string userItemCreatorLastName = "Lucan"; |
217 | 219 | // UUID userItemCreatorUuid = UUID.Parse("00000000-0000-0000-0000-000000000666"); | |
218 | string item1Name = "b.lsl"; | 220 | |
219 | string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1Name, UUID.Random()); | 221 | // string item1Name = "b.lsl"; |
220 | 222 | // string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1Name, UUID.Random()); | |
221 | MemoryStream archiveWriteStream = new MemoryStream(); | 223 | |
222 | TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | 224 | // MemoryStream archiveWriteStream = new MemoryStream(); |
223 | 225 | // TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | |
224 | InventoryItemBase item1 = new InventoryItemBase(); | 226 | |
225 | item1.Name = item1Name; | 227 | // InventoryItemBase item1 = new InventoryItemBase(); |
226 | item1.AssetID = UUID.Random(); | 228 | // item1.Name = item1Name; |
227 | item1.GroupID = UUID.Random(); | 229 | // item1.AssetID = UUID.Random(); |
228 | item1.CreatorId = OspResolver.MakeOspa(userItemCreatorFirstName, userItemCreatorLastName); | 230 | // item1.GroupID = UUID.Random(); |
229 | //item1.CreatorId = userUuid.ToString(); | 231 | // item1.CreatorId = OspResolver.MakeOspa(userItemCreatorFirstName, userItemCreatorLastName); |
230 | //item1.CreatorId = "00000000-0000-0000-0000-000000000444"; | 232 | // //item1.CreatorId = userUuid.ToString(); |
231 | item1.Owner = UUID.Zero; | 233 | // //item1.CreatorId = "00000000-0000-0000-0000-000000000444"; |
232 | 234 | // item1.Owner = UUID.Zero; | |
233 | string item1FileName | 235 | |
234 | = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); | 236 | // string item1FileName |
235 | tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1)); | 237 | // = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); |
236 | tar.Close(); | 238 | // tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1)); |
237 | 239 | // tar.Close(); | |
238 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | 240 | |
239 | SerialiserModule serialiserModule = new SerialiserModule(); | 241 | // MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); |
240 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); | 242 | // SerialiserModule serialiserModule = new SerialiserModule(); |
241 | 243 | // InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); | |
242 | // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene | 244 | |
243 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | 245 | // // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene |
244 | IUserAdminService userAdminService = scene.CommsManager.UserAdminService; | 246 | // Scene scene = SceneSetupHelpers.SetupScene("inventory"); |
245 | 247 | // IUserAdminService userAdminService = scene.CommsManager.UserAdminService; | |
246 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | 248 | |
247 | userAdminService.AddUser( | 249 | // SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); |
248 | userFirstName, userLastName, "meowfood", String.Empty, 1000, 1000, userUuid); | 250 | // userAdminService.AddUser( |
249 | userAdminService.AddUser( | 251 | // userFirstName, userLastName, "meowfood", String.Empty, 1000, 1000, userUuid); |
250 | userItemCreatorFirstName, userItemCreatorLastName, "hampshire", | 252 | // userAdminService.AddUser( |
251 | String.Empty, 1000, 1000, userItemCreatorUuid); | 253 | // userItemCreatorFirstName, userItemCreatorLastName, "hampshire", |
252 | 254 | // String.Empty, 1000, 1000, userItemCreatorUuid); | |
253 | archiverModule.DearchiveInventory(userFirstName, userLastName, "/", "meowfood", archiveReadStream); | 255 | |
254 | 256 | // archiverModule.DearchiveInventory(userFirstName, userLastName, "/", "meowfood", archiveReadStream); | |
255 | CachedUserInfo userInfo | 257 | |
256 | = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); | 258 | // CachedUserInfo userInfo |
257 | 259 | // = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); | |
258 | InventoryItemBase foundItem1 | 260 | |
259 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, item1Name); | 261 | // InventoryItemBase foundItem1 |
260 | 262 | // = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, item1Name); | |
261 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | 263 | |
262 | 264 | // Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | |
263 | // We have to disable this check since loaded items that did find users via OSPA resolution are now only storing the | 265 | |
264 | // UUID, not the OSPA itself. | 266 | //// We have to disable this check since loaded items that did find users via OSPA resolution are now only storing the |
267 | //// UUID, not the OSPA itself. | ||
268 | //// Assert.That( | ||
269 | //// foundItem1.CreatorId, Is.EqualTo(item1.CreatorId), | ||
270 | //// "Loaded item non-uuid creator doesn't match original"); | ||
265 | // Assert.That( | 271 | // Assert.That( |
266 | // foundItem1.CreatorId, Is.EqualTo(item1.CreatorId), | 272 | // foundItem1.CreatorId, Is.EqualTo(userItemCreatorUuid.ToString()), |
267 | // "Loaded item non-uuid creator doesn't match original"); | 273 | // "Loaded item non-uuid creator doesn't match original"); |
268 | Assert.That( | ||
269 | foundItem1.CreatorId, Is.EqualTo(userItemCreatorUuid.ToString()), | ||
270 | "Loaded item non-uuid creator doesn't match original"); | ||
271 | |||
272 | Assert.That( | ||
273 | foundItem1.CreatorIdAsUuid, Is.EqualTo(userItemCreatorUuid), | ||
274 | "Loaded item uuid creator doesn't match original"); | ||
275 | Assert.That(foundItem1.Owner, Is.EqualTo(userUuid), | ||
276 | "Loaded item owner doesn't match inventory reciever"); | ||
277 | |||
278 | // Now try loading to a root child folder | ||
279 | UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, userInfo.UserProfile.ID, "xA"); | ||
280 | archiveReadStream = new MemoryStream(archiveReadStream.ToArray()); | ||
281 | archiverModule.DearchiveInventory(userFirstName, userLastName, "xA", "meowfood", archiveReadStream); | ||
282 | |||
283 | InventoryItemBase foundItem2 | ||
284 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, "xA/" + item1Name); | ||
285 | Assert.That(foundItem2, Is.Not.Null, "Didn't find loaded item 2"); | ||
286 | |||
287 | // Now try loading to a more deeply nested folder | ||
288 | UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, userInfo.UserProfile.ID, "xB/xC"); | ||
289 | archiveReadStream = new MemoryStream(archiveReadStream.ToArray()); | ||
290 | archiverModule.DearchiveInventory(userFirstName, userLastName, "xB/xC", "meowfood", archiveReadStream); | ||
291 | |||
292 | InventoryItemBase foundItem3 | ||
293 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, "xB/xC/" + item1Name); | ||
294 | Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3"); | ||
295 | } | ||
296 | |||
297 | [Test] | ||
298 | public void TestIarV0_1WithEscapedChars() | ||
299 | { | ||
300 | TestHelper.InMethod(); | ||
301 | // log4net.Config.XmlConfigurator.Configure(); | ||
302 | |||
303 | string itemName = "You & you are a mean/man/"; | ||
304 | string humanEscapedItemName = @"You & you are a mean\/man\/"; | ||
305 | string userPassword = "meowfood"; | ||
306 | |||
307 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); | ||
308 | |||
309 | Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
310 | SceneSetupHelpers.SetupSceneModules(scene, archiverModule); | ||
311 | CommunicationsManager cm = scene.CommsManager; | ||
312 | |||
313 | // Create user | ||
314 | string userFirstName = "Jock"; | ||
315 | string userLastName = "Stirrup"; | ||
316 | UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020"); | ||
317 | |||
318 | lock (this) | ||
319 | { | ||
320 | UserProfileTestUtils.CreateUserWithInventory( | ||
321 | cm, userFirstName, userLastName, userPassword, userId, InventoryReceived); | ||
322 | Monitor.Wait(this, 60000); | ||
323 | } | ||
324 | |||
325 | // Create asset | ||
326 | SceneObjectGroup object1; | ||
327 | SceneObjectPart part1; | ||
328 | { | ||
329 | string partName = "part name"; | ||
330 | UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); | ||
331 | PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); | ||
332 | Vector3 groupPosition = new Vector3(10, 20, 30); | ||
333 | Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); | ||
334 | Vector3 offsetPosition = new Vector3(5, 10, 15); | ||
335 | |||
336 | part1 | ||
337 | = new SceneObjectPart( | ||
338 | ownerId, shape, groupPosition, rotationOffset, offsetPosition); | ||
339 | part1.Name = partName; | ||
340 | |||
341 | object1 = new SceneObjectGroup(part1); | ||
342 | scene.AddNewSceneObject(object1, false); | ||
343 | } | ||
344 | |||
345 | UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); | ||
346 | AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); | ||
347 | scene.AssetService.Store(asset1); | ||
348 | |||
349 | // Create item | ||
350 | UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); | ||
351 | InventoryItemBase item1 = new InventoryItemBase(); | ||
352 | item1.Name = itemName; | ||
353 | item1.AssetID = asset1.FullID; | ||
354 | item1.ID = item1Id; | ||
355 | InventoryFolderBase objsFolder | ||
356 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects"); | ||
357 | item1.Folder = objsFolder.ID; | ||
358 | scene.AddInventoryItem(userId, item1); | ||
359 | |||
360 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
361 | archiverModule.OnInventoryArchiveSaved += SaveCompleted; | ||
362 | |||
363 | mre.Reset(); | ||
364 | archiverModule.ArchiveInventory( | ||
365 | Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream); | ||
366 | mre.WaitOne(60000, false); | ||
367 | |||
368 | // LOAD ITEM | ||
369 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
370 | |||
371 | archiverModule.DearchiveInventory(userFirstName, userLastName, "Scripts", userPassword, archiveReadStream); | ||
372 | |||
373 | InventoryItemBase foundItem1 | ||
374 | = InventoryArchiveUtils.FindItemByPath( | ||
375 | scene.InventoryService, userId, "Scripts/Objects/" + humanEscapedItemName); | ||
376 | 274 | ||
377 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | ||
378 | // Assert.That( | 275 | // Assert.That( |
379 | // foundItem1.CreatorId, Is.EqualTo(userUuid), | 276 | // foundItem1.CreatorIdAsUuid, Is.EqualTo(userItemCreatorUuid), |
380 | // "Loaded item non-uuid creator doesn't match that of the loading user"); | 277 | // "Loaded item uuid creator doesn't match original"); |
381 | Assert.That( | 278 | // Assert.That(foundItem1.Owner, Is.EqualTo(userUuid), |
382 | foundItem1.Name, Is.EqualTo(itemName), | 279 | // "Loaded item owner doesn't match inventory reciever"); |
383 | "Loaded item name doesn't match saved name"); | 280 | |
384 | } | 281 | // // Now try loading to a root child folder |
282 | // UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, userInfo.UserProfile.ID, "xA"); | ||
283 | // archiveReadStream = new MemoryStream(archiveReadStream.ToArray()); | ||
284 | // archiverModule.DearchiveInventory(userFirstName, userLastName, "xA", "meowfood", archiveReadStream); | ||
285 | |||
286 | // InventoryItemBase foundItem2 | ||
287 | // = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, "xA/" + item1Name); | ||
288 | // Assert.That(foundItem2, Is.Not.Null, "Didn't find loaded item 2"); | ||
289 | |||
290 | // // Now try loading to a more deeply nested folder | ||
291 | // UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, userInfo.UserProfile.ID, "xB/xC"); | ||
292 | // archiveReadStream = new MemoryStream(archiveReadStream.ToArray()); | ||
293 | // archiverModule.DearchiveInventory(userFirstName, userLastName, "xB/xC", "meowfood", archiveReadStream); | ||
294 | |||
295 | // InventoryItemBase foundItem3 | ||
296 | // = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, "xB/xC/" + item1Name); | ||
297 | // Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3"); | ||
298 | //} | ||
299 | |||
300 | // REFACTORING PROBLEM. Needs rewrite. | ||
301 | // [Test] | ||
302 | // public void TestIarV0_1WithEscapedChars() | ||
303 | // { | ||
304 | // TestHelper.InMethod(); | ||
305 | //// log4net.Config.XmlConfigurator.Configure(); | ||
306 | |||
307 | // string itemName = "You & you are a mean/man/"; | ||
308 | // string humanEscapedItemName = @"You & you are a mean\/man\/"; | ||
309 | // string userPassword = "meowfood"; | ||
310 | |||
311 | // InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); | ||
312 | |||
313 | // Scene scene = SceneSetupHelpers.SetupScene("Inventory"); | ||
314 | // SceneSetupHelpers.SetupSceneModules(scene, archiverModule); | ||
315 | // CommunicationsManager cm = scene.CommsManager; | ||
316 | |||
317 | // // Create user | ||
318 | // string userFirstName = "Jock"; | ||
319 | // string userLastName = "Stirrup"; | ||
320 | // UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020"); | ||
321 | |||
322 | // lock (this) | ||
323 | // { | ||
324 | // UserProfileTestUtils.CreateUserWithInventory( | ||
325 | // cm, userFirstName, userLastName, userPassword, userId, InventoryReceived); | ||
326 | // Monitor.Wait(this, 60000); | ||
327 | // } | ||
328 | |||
329 | // // Create asset | ||
330 | // SceneObjectGroup object1; | ||
331 | // SceneObjectPart part1; | ||
332 | // { | ||
333 | // string partName = "part name"; | ||
334 | // UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040"); | ||
335 | // PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere(); | ||
336 | // Vector3 groupPosition = new Vector3(10, 20, 30); | ||
337 | // Quaternion rotationOffset = new Quaternion(20, 30, 40, 50); | ||
338 | // Vector3 offsetPosition = new Vector3(5, 10, 15); | ||
339 | |||
340 | // part1 | ||
341 | // = new SceneObjectPart( | ||
342 | // ownerId, shape, groupPosition, rotationOffset, offsetPosition); | ||
343 | // part1.Name = partName; | ||
344 | |||
345 | // object1 = new SceneObjectGroup(part1); | ||
346 | // scene.AddNewSceneObject(object1, false); | ||
347 | // } | ||
348 | |||
349 | // UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060"); | ||
350 | // AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1); | ||
351 | // scene.AssetService.Store(asset1); | ||
352 | |||
353 | // // Create item | ||
354 | // UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080"); | ||
355 | // InventoryItemBase item1 = new InventoryItemBase(); | ||
356 | // item1.Name = itemName; | ||
357 | // item1.AssetID = asset1.FullID; | ||
358 | // item1.ID = item1Id; | ||
359 | // InventoryFolderBase objsFolder | ||
360 | // = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects"); | ||
361 | // item1.Folder = objsFolder.ID; | ||
362 | // scene.AddInventoryItem(userId, item1); | ||
363 | |||
364 | // MemoryStream archiveWriteStream = new MemoryStream(); | ||
365 | // archiverModule.OnInventoryArchiveSaved += SaveCompleted; | ||
366 | |||
367 | // mre.Reset(); | ||
368 | // archiverModule.ArchiveInventory( | ||
369 | // Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream); | ||
370 | // mre.WaitOne(60000, false); | ||
371 | |||
372 | // // LOAD ITEM | ||
373 | // MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
374 | |||
375 | // archiverModule.DearchiveInventory(userFirstName, userLastName, "Scripts", userPassword, archiveReadStream); | ||
376 | |||
377 | // InventoryItemBase foundItem1 | ||
378 | // = InventoryArchiveUtils.FindItemByPath( | ||
379 | // scene.InventoryService, userId, "Scripts/Objects/" + humanEscapedItemName); | ||
380 | |||
381 | // Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | ||
382 | //// Assert.That( | ||
383 | //// foundItem1.CreatorId, Is.EqualTo(userUuid), | ||
384 | //// "Loaded item non-uuid creator doesn't match that of the loading user"); | ||
385 | // Assert.That( | ||
386 | // foundItem1.Name, Is.EqualTo(itemName), | ||
387 | // "Loaded item name doesn't match saved name"); | ||
388 | // } | ||
385 | 389 | ||
386 | /// <summary> | 390 | /// <summary> |
387 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | 391 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where |
@@ -390,199 +394,203 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests | |||
390 | /// | 394 | /// |
391 | /// This may possibly one day get overtaken by the as yet incomplete temporary profiles feature | 395 | /// This may possibly one day get overtaken by the as yet incomplete temporary profiles feature |
392 | /// (as tested in the a later commented out test) | 396 | /// (as tested in the a later commented out test) |
393 | [Test] | 397 | /// REFACTORING PROBLEM. Needs rewrite. |
394 | public void TestLoadIarV0_1AbsentUsers() | 398 | // [Test] |
395 | { | 399 | // public void TestLoadIarV0_1AbsentUsers() |
396 | TestHelper.InMethod(); | 400 | // { |
397 | 401 | // TestHelper.InMethod(); | |
398 | //log4net.Config.XmlConfigurator.Configure(); | 402 | |
399 | 403 | // //log4net.Config.XmlConfigurator.Configure(); | |
400 | string userFirstName = "Charlie"; | 404 | |
401 | string userLastName = "Chan"; | 405 | // string userFirstName = "Charlie"; |
402 | UUID userUuid = UUID.Parse("00000000-0000-0000-0000-000000000999"); | 406 | // string userLastName = "Chan"; |
403 | string userItemCreatorFirstName = "Bat"; | 407 | // UUID userUuid = UUID.Parse("00000000-0000-0000-0000-000000000999"); |
404 | string userItemCreatorLastName = "Man"; | 408 | // string userItemCreatorFirstName = "Bat"; |
405 | //UUID userItemCreatorUuid = UUID.Parse("00000000-0000-0000-0000-000000008888"); | 409 | // string userItemCreatorLastName = "Man"; |
406 | 410 | // //UUID userItemCreatorUuid = UUID.Parse("00000000-0000-0000-0000-000000008888"); | |
407 | string itemName = "b.lsl"; | 411 | |
408 | string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(itemName, UUID.Random()); | 412 | // string itemName = "b.lsl"; |
409 | 413 | // string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(itemName, UUID.Random()); | |
410 | MemoryStream archiveWriteStream = new MemoryStream(); | 414 | |
411 | TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | 415 | // MemoryStream archiveWriteStream = new MemoryStream(); |
412 | 416 | // TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | |
413 | InventoryItemBase item1 = new InventoryItemBase(); | 417 | |
414 | item1.Name = itemName; | 418 | // InventoryItemBase item1 = new InventoryItemBase(); |
415 | item1.AssetID = UUID.Random(); | 419 | // item1.Name = itemName; |
416 | item1.GroupID = UUID.Random(); | 420 | // item1.AssetID = UUID.Random(); |
417 | item1.CreatorId = OspResolver.MakeOspa(userItemCreatorFirstName, userItemCreatorLastName); | 421 | // item1.GroupID = UUID.Random(); |
418 | //item1.CreatorId = userUuid.ToString(); | 422 | // item1.CreatorId = OspResolver.MakeOspa(userItemCreatorFirstName, userItemCreatorLastName); |
419 | //item1.CreatorId = "00000000-0000-0000-0000-000000000444"; | 423 | // //item1.CreatorId = userUuid.ToString(); |
420 | item1.Owner = UUID.Zero; | 424 | // //item1.CreatorId = "00000000-0000-0000-0000-000000000444"; |
421 | 425 | // item1.Owner = UUID.Zero; | |
422 | string item1FileName | 426 | |
423 | = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); | 427 | // string item1FileName |
424 | tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1)); | 428 | // = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); |
425 | tar.Close(); | 429 | // tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1)); |
426 | 430 | // tar.Close(); | |
427 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | 431 | |
428 | SerialiserModule serialiserModule = new SerialiserModule(); | 432 | // MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); |
429 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); | 433 | // SerialiserModule serialiserModule = new SerialiserModule(); |
430 | 434 | // InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); | |
431 | // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene | 435 | |
432 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | 436 | // // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene |
433 | IUserAdminService userAdminService = scene.CommsManager.UserAdminService; | 437 | // Scene scene = SceneSetupHelpers.SetupScene("inventory"); |
434 | 438 | // IUserAdminService userAdminService = scene.CommsManager.UserAdminService; | |
435 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | 439 | |
436 | userAdminService.AddUser( | 440 | // SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); |
437 | userFirstName, userLastName, "meowfood", String.Empty, 1000, 1000, userUuid); | 441 | // userAdminService.AddUser( |
438 | 442 | // userFirstName, userLastName, "meowfood", String.Empty, 1000, 1000, userUuid); | |
439 | archiverModule.DearchiveInventory(userFirstName, userLastName, "/", "meowfood", archiveReadStream); | 443 | |
440 | 444 | // archiverModule.DearchiveInventory(userFirstName, userLastName, "/", "meowfood", archiveReadStream); | |
441 | CachedUserInfo userInfo | 445 | |
442 | = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); | 446 | // CachedUserInfo userInfo |
443 | 447 | // = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); | |
444 | InventoryItemBase foundItem1 | 448 | |
445 | = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, itemName); | 449 | // InventoryItemBase foundItem1 |
446 | 450 | // = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, itemName); | |
447 | Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | 451 | |
452 | // Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); | ||
453 | //// Assert.That( | ||
454 | //// foundItem1.CreatorId, Is.EqualTo(userUuid), | ||
455 | //// "Loaded item non-uuid creator doesn't match that of the loading user"); | ||
448 | // Assert.That( | 456 | // Assert.That( |
449 | // foundItem1.CreatorId, Is.EqualTo(userUuid), | 457 | // foundItem1.CreatorIdAsUuid, Is.EqualTo(userUuid), |
450 | // "Loaded item non-uuid creator doesn't match that of the loading user"); | 458 | // "Loaded item uuid creator doesn't match that of the loading user"); |
451 | Assert.That( | 459 | // } |
452 | foundItem1.CreatorIdAsUuid, Is.EqualTo(userUuid), | ||
453 | "Loaded item uuid creator doesn't match that of the loading user"); | ||
454 | } | ||
455 | 460 | ||
456 | /// <summary> | 461 | /// <summary> |
457 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where | 462 | /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where |
458 | /// no account exists with the creator name | 463 | /// no account exists with the creator name |
459 | /// </summary> | 464 | /// </summary> |
460 | /// Disabled since temporary profiles have not yet been implemented. | 465 | /// Disabled since temporary profiles have not yet been implemented. |
466 | /// REFACTORING PROBLEM. Needs rewrite. | ||
467 | /// | ||
461 | //[Test] | 468 | //[Test] |
462 | public void TestLoadIarV0_1TempProfiles() | 469 | //public void TestLoadIarV0_1TempProfiles() |
463 | { | 470 | //{ |
464 | TestHelper.InMethod(); | 471 | // TestHelper.InMethod(); |
465 | 472 | ||
466 | //log4net.Config.XmlConfigurator.Configure(); | 473 | // //log4net.Config.XmlConfigurator.Configure(); |
467 | 474 | ||
468 | string userFirstName = "Dennis"; | 475 | // string userFirstName = "Dennis"; |
469 | string userLastName = "Menace"; | 476 | // string userLastName = "Menace"; |
470 | UUID userUuid = UUID.Parse("00000000-0000-0000-0000-000000000aaa"); | 477 | // UUID userUuid = UUID.Parse("00000000-0000-0000-0000-000000000aaa"); |
471 | string user2FirstName = "Walter"; | 478 | // string user2FirstName = "Walter"; |
472 | string user2LastName = "Mitty"; | 479 | // string user2LastName = "Mitty"; |
473 | 480 | ||
474 | string itemName = "b.lsl"; | 481 | // string itemName = "b.lsl"; |
475 | string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(itemName, UUID.Random()); | 482 | // string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(itemName, UUID.Random()); |
476 | 483 | ||
477 | MemoryStream archiveWriteStream = new MemoryStream(); | 484 | // MemoryStream archiveWriteStream = new MemoryStream(); |
478 | TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | 485 | // TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); |
479 | 486 | ||
480 | InventoryItemBase item1 = new InventoryItemBase(); | 487 | // InventoryItemBase item1 = new InventoryItemBase(); |
481 | item1.Name = itemName; | 488 | // item1.Name = itemName; |
482 | item1.AssetID = UUID.Random(); | 489 | // item1.AssetID = UUID.Random(); |
483 | item1.GroupID = UUID.Random(); | 490 | // item1.GroupID = UUID.Random(); |
484 | item1.CreatorId = OspResolver.MakeOspa(user2FirstName, user2LastName); | 491 | // item1.CreatorId = OspResolver.MakeOspa(user2FirstName, user2LastName); |
485 | item1.Owner = UUID.Zero; | 492 | // item1.Owner = UUID.Zero; |
486 | 493 | ||
487 | string item1FileName | 494 | // string item1FileName |
488 | = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); | 495 | // = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, archiveItemName); |
489 | tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1)); | 496 | // tar.WriteFile(item1FileName, UserInventoryItemSerializer.Serialize(item1)); |
490 | tar.Close(); | 497 | // tar.Close(); |
491 | 498 | ||
492 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | 499 | // MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); |
493 | SerialiserModule serialiserModule = new SerialiserModule(); | 500 | // SerialiserModule serialiserModule = new SerialiserModule(); |
494 | InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); | 501 | // InventoryArchiverModule archiverModule = new InventoryArchiverModule(true); |
495 | 502 | ||
496 | // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene | 503 | // // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene |
497 | Scene scene = SceneSetupHelpers.SetupScene(); | 504 | // Scene scene = SceneSetupHelpers.SetupScene(); |
498 | IUserAdminService userAdminService = scene.CommsManager.UserAdminService; | 505 | // IUserAdminService userAdminService = scene.CommsManager.UserAdminService; |
499 | 506 | ||
500 | SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); | 507 | // SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule); |
501 | userAdminService.AddUser( | 508 | // userAdminService.AddUser( |
502 | userFirstName, userLastName, "meowfood", String.Empty, 1000, 1000, userUuid); | 509 | // userFirstName, userLastName, "meowfood", String.Empty, 1000, 1000, userUuid); |
503 | 510 | ||
504 | archiverModule.DearchiveInventory(userFirstName, userLastName, "/", "troll", archiveReadStream); | 511 | // archiverModule.DearchiveInventory(userFirstName, userLastName, "/", "troll", archiveReadStream); |
505 | 512 | ||
506 | // Check that a suitable temporary user profile has been created. | 513 | // // Check that a suitable temporary user profile has been created. |
507 | UserProfileData user2Profile | 514 | // UserProfileData user2Profile |
508 | = scene.CommsManager.UserService.GetUserProfile( | 515 | // = scene.CommsManager.UserService.GetUserProfile( |
509 | OspResolver.HashName(user2FirstName + " " + user2LastName)); | 516 | // OspResolver.HashName(user2FirstName + " " + user2LastName)); |
510 | Assert.That(user2Profile, Is.Not.Null); | 517 | // Assert.That(user2Profile, Is.Not.Null); |
511 | Assert.That(user2Profile.FirstName == user2FirstName); | 518 | // Assert.That(user2Profile.FirstName == user2FirstName); |
512 | Assert.That(user2Profile.SurName == user2LastName); | 519 | // Assert.That(user2Profile.SurName == user2LastName); |
513 | 520 | ||
514 | CachedUserInfo userInfo | 521 | // CachedUserInfo userInfo |
515 | = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); | 522 | // = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); |
516 | userInfo.OnInventoryReceived += InventoryReceived; | 523 | // userInfo.OnInventoryReceived += InventoryReceived; |
517 | 524 | ||
518 | lock (this) | 525 | // lock (this) |
519 | { | 526 | // { |
520 | userInfo.FetchInventory(); | 527 | // userInfo.FetchInventory(); |
521 | Monitor.Wait(this, 60000); | 528 | // Monitor.Wait(this, 60000); |
522 | } | 529 | // } |
523 | 530 | ||
524 | InventoryItemBase foundItem = userInfo.RootFolder.FindItemByPath(itemName); | 531 | // InventoryItemBase foundItem = userInfo.RootFolder.FindItemByPath(itemName); |
525 | 532 | ||
526 | Assert.That(foundItem.CreatorId, Is.EqualTo(item1.CreatorId)); | 533 | // Assert.That(foundItem.CreatorId, Is.EqualTo(item1.CreatorId)); |
527 | Assert.That( | 534 | // Assert.That( |
528 | foundItem.CreatorIdAsUuid, Is.EqualTo(OspResolver.HashName(user2FirstName + " " + user2LastName))); | 535 | // foundItem.CreatorIdAsUuid, Is.EqualTo(OspResolver.HashName(user2FirstName + " " + user2LastName))); |
529 | Assert.That(foundItem.Owner, Is.EqualTo(userUuid)); | 536 | // Assert.That(foundItem.Owner, Is.EqualTo(userUuid)); |
530 | 537 | ||
531 | Console.WriteLine("### Successfully completed {0} ###", MethodBase.GetCurrentMethod()); | 538 | // Console.WriteLine("### Successfully completed {0} ###", MethodBase.GetCurrentMethod()); |
532 | } | 539 | //} |
533 | 540 | ||
534 | /// <summary> | 541 | /// <summary> |
535 | /// Test replication of an archive path to the user's inventory. | 542 | /// Test replication of an archive path to the user's inventory. |
536 | /// </summary> | 543 | /// </summary> |
537 | [Test] | 544 | //[Test] |
538 | public void TestReplicateArchivePathToUserInventory() | 545 | //public void TestReplicateArchivePathToUserInventory() |
539 | { | 546 | //{ |
540 | TestHelper.InMethod(); | 547 | // TestHelper.InMethod(); |
541 | 548 | ||
542 | //log4net.Config.XmlConfigurator.Configure(); | 549 | // //log4net.Config.XmlConfigurator.Configure(); |
543 | 550 | ||
544 | Scene scene = SceneSetupHelpers.SetupScene("inventory"); | 551 | // Scene scene = SceneSetupHelpers.SetupScene("inventory"); |
545 | CommunicationsManager commsManager = scene.CommsManager; | 552 | // CommunicationsManager commsManager = scene.CommsManager; |
546 | CachedUserInfo userInfo; | 553 | // CachedUserInfo userInfo; |
547 | 554 | ||
548 | lock (this) | 555 | // lock (this) |
549 | { | 556 | // { |
550 | userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager, InventoryReceived); | 557 | // // !!! REFACTORING PROBLEM. This needs to be rewritten |
551 | Monitor.Wait(this, 60000); | 558 | // userInfo = UserProfileTestUtils.CreateUserWithInventory(commsManager, InventoryReceived); |
552 | } | 559 | // Monitor.Wait(this, 60000); |
553 | 560 | // } | |
554 | //Console.WriteLine("userInfo.RootFolder 1: {0}", userInfo.RootFolder); | 561 | |
555 | 562 | // //Console.WriteLine("userInfo.RootFolder 1: {0}", userInfo.RootFolder); | |
556 | Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>(); | 563 | |
557 | List<InventoryNodeBase> nodesLoaded = new List<InventoryNodeBase>(); | 564 | // Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>(); |
558 | 565 | // List<InventoryNodeBase> nodesLoaded = new List<InventoryNodeBase>(); | |
559 | string folder1Name = "a"; | 566 | |
560 | string folder2Name = "b"; | 567 | // string folder1Name = "a"; |
561 | string itemName = "c.lsl"; | 568 | // string folder2Name = "b"; |
562 | 569 | // string itemName = "c.lsl"; | |
563 | string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1Name, UUID.Random()); | 570 | |
564 | string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random()); | 571 | // string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1Name, UUID.Random()); |
565 | string itemArchiveName = InventoryArchiveWriteRequest.CreateArchiveItemName(itemName, UUID.Random()); | 572 | // string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random()); |
566 | 573 | // string itemArchiveName = InventoryArchiveWriteRequest.CreateArchiveItemName(itemName, UUID.Random()); | |
567 | string itemArchivePath | 574 | |
568 | = string.Format( | 575 | // string itemArchivePath |
569 | "{0}{1}{2}{3}", | 576 | // = string.Format( |
570 | ArchiveConstants.INVENTORY_PATH, folder1ArchiveName, folder2ArchiveName, itemArchiveName); | 577 | // "{0}{1}{2}{3}", |
571 | 578 | // ArchiveConstants.INVENTORY_PATH, folder1ArchiveName, folder2ArchiveName, itemArchiveName); | |
572 | //Console.WriteLine("userInfo.RootFolder 2: {0}", userInfo.RootFolder); | 579 | |
573 | 580 | // //Console.WriteLine("userInfo.RootFolder 2: {0}", userInfo.RootFolder); | |
574 | new InventoryArchiveReadRequest(scene, userInfo, null, (Stream)null) | 581 | |
575 | .ReplicateArchivePathToUserInventory( | 582 | // new InventoryArchiveReadRequest(scene, userInfo, null, (Stream)null) |
576 | itemArchivePath, false, scene.InventoryService.GetRootFolder(userInfo.UserProfile.ID), | 583 | // .ReplicateArchivePathToUserInventory( |
577 | foldersCreated, nodesLoaded); | 584 | // itemArchivePath, false, scene.InventoryService.GetRootFolder(userInfo.UserProfile.ID), |
578 | 585 | // foldersCreated, nodesLoaded); | |
579 | //Console.WriteLine("userInfo.RootFolder 3: {0}", userInfo.RootFolder); | 586 | |
580 | //InventoryFolderImpl folder1 = userInfo.RootFolder.FindFolderByPath("a"); | 587 | // //Console.WriteLine("userInfo.RootFolder 3: {0}", userInfo.RootFolder); |
581 | InventoryFolderBase folder1 | 588 | // //InventoryFolderImpl folder1 = userInfo.RootFolder.FindFolderByPath("a"); |
582 | = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userInfo.UserProfile.ID, "a"); | 589 | // InventoryFolderBase folder1 |
583 | Assert.That(folder1, Is.Not.Null, "Could not find folder a"); | 590 | // = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userInfo.UserProfile.ID, "a"); |
584 | InventoryFolderBase folder2 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, "b"); | 591 | // Assert.That(folder1, Is.Not.Null, "Could not find folder a"); |
585 | Assert.That(folder2, Is.Not.Null, "Could not find folder b"); | 592 | // InventoryFolderBase folder2 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, "b"); |
586 | } | 593 | // Assert.That(folder2, Is.Not.Null, "Could not find folder b"); |
594 | //} | ||
587 | } | 595 | } |
588 | } | 596 | } |
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs index b60b32b..09552a8 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Transfer/InventoryTransferModule.cs | |||
@@ -32,14 +32,14 @@ using log4net; | |||
32 | using Nini.Config; | 32 | using Nini.Config; |
33 | using OpenMetaverse; | 33 | using OpenMetaverse; |
34 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
35 | using OpenSim.Framework.Communications.Cache; | 35 | |
36 | using OpenSim.Region.Framework.Interfaces; | 36 | using OpenSim.Region.Framework.Interfaces; |
37 | using OpenSim.Region.Framework.Scenes; | 37 | using OpenSim.Region.Framework.Scenes; |
38 | using OpenSim.Services.Interfaces; | 38 | using OpenSim.Services.Interfaces; |
39 | 39 | ||
40 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer | 40 | namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer |
41 | { | 41 | { |
42 | public class InventoryTransferModule : IInventoryTransferModule, IRegionModule | 42 | public class InventoryTransferModule : IInventoryTransferModule, ISharedRegionModule |
43 | { | 43 | { |
44 | private static readonly ILog m_log | 44 | private static readonly ILog m_log |
45 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 45 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
@@ -50,10 +50,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer | |||
50 | new Dictionary<UUID, Scene>(); | 50 | new Dictionary<UUID, Scene>(); |
51 | 51 | ||
52 | private IMessageTransferModule m_TransferModule = null; | 52 | private IMessageTransferModule m_TransferModule = null; |
53 | private bool m_Enabled = true; | ||
53 | 54 | ||
54 | #region IRegionModule Members | 55 | #region IRegionModule Members |
55 | 56 | ||
56 | public void Initialise(Scene scene, IConfigSource config) | 57 | public void Initialise(IConfigSource config) |
57 | { | 58 | { |
58 | if (config.Configs["Messaging"] != null) | 59 | if (config.Configs["Messaging"] != null) |
59 | { | 60 | { |
@@ -62,29 +63,56 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer | |||
62 | if (config.Configs["Messaging"].GetString( | 63 | if (config.Configs["Messaging"].GetString( |
63 | "InventoryTransferModule", "InventoryTransferModule") != | 64 | "InventoryTransferModule", "InventoryTransferModule") != |
64 | "InventoryTransferModule") | 65 | "InventoryTransferModule") |
66 | { | ||
67 | m_Enabled = false; | ||
65 | return; | 68 | return; |
69 | } | ||
66 | } | 70 | } |
71 | } | ||
67 | 72 | ||
68 | if (!m_Scenelist.Contains(scene)) | 73 | public void AddRegion(Scene scene) |
69 | { | 74 | { |
70 | m_Scenelist.Add(scene); | 75 | if (!m_Enabled) |
76 | return; | ||
71 | 77 | ||
72 | scene.RegisterModuleInterface<IInventoryTransferModule>(this); | 78 | m_Scenelist.Add(scene); |
73 | 79 | ||
74 | scene.EventManager.OnNewClient += OnNewClient; | 80 | scene.RegisterModuleInterface<IInventoryTransferModule>(this); |
75 | scene.EventManager.OnClientClosed += ClientLoggedOut; | 81 | |
76 | scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; | 82 | scene.EventManager.OnNewClient += OnNewClient; |
77 | } | 83 | scene.EventManager.OnClientClosed += ClientLoggedOut; |
84 | scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; | ||
78 | } | 85 | } |
79 | 86 | ||
80 | public void PostInitialise() | 87 | public void RegionLoaded(Scene scene) |
81 | { | 88 | { |
82 | if (m_Scenelist.Count > 0) | 89 | if (m_TransferModule == null) |
83 | { | 90 | { |
84 | m_TransferModule = m_Scenelist[0].RequestModuleInterface<IMessageTransferModule>(); | 91 | m_TransferModule = m_Scenelist[0].RequestModuleInterface<IMessageTransferModule>(); |
85 | if (m_TransferModule == null) | 92 | if (m_TransferModule == null) |
93 | { | ||
86 | m_log.Error("[INVENTORY TRANSFER] No Message transfer module found, transfers will be local only"); | 94 | m_log.Error("[INVENTORY TRANSFER] No Message transfer module found, transfers will be local only"); |
95 | m_Enabled = false; | ||
96 | |||
97 | m_Scenelist.Clear(); | ||
98 | scene.EventManager.OnNewClient -= OnNewClient; | ||
99 | scene.EventManager.OnClientClosed -= ClientLoggedOut; | ||
100 | scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage; | ||
101 | } | ||
87 | } | 102 | } |
103 | |||
104 | } | ||
105 | |||
106 | public void RemoveRegion(Scene scene) | ||
107 | { | ||
108 | scene.EventManager.OnNewClient -= OnNewClient; | ||
109 | scene.EventManager.OnClientClosed -= ClientLoggedOut; | ||
110 | scene.EventManager.OnIncomingInstantMessage -= OnGridInstantMessage; | ||
111 | m_Scenelist.Remove(scene); | ||
112 | } | ||
113 | |||
114 | public void PostInitialise() | ||
115 | { | ||
88 | } | 116 | } |
89 | 117 | ||
90 | public void Close() | 118 | public void Close() |
@@ -96,9 +124,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Transfer | |||
96 | get { return "InventoryModule"; } | 124 | get { return "InventoryModule"; } |
97 | } | 125 | } |
98 | 126 | ||
99 | public bool IsSharedModule | 127 | public Type ReplaceableInterface |
100 | { | 128 | { |
101 | get { return true; } | 129 | get { return null; } |
102 | } | 130 | } |
103 | 131 | ||
104 | #endregion | 132 | #endregion |
diff --git a/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs b/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs index 261bd6c..d1d7df2 100644 --- a/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Lure/LureModule.cs | |||
@@ -37,34 +37,72 @@ using OpenSim.Region.Framework.Scenes; | |||
37 | 37 | ||
38 | namespace OpenSim.Region.CoreModules.Avatar.Lure | 38 | namespace OpenSim.Region.CoreModules.Avatar.Lure |
39 | { | 39 | { |
40 | public class LureModule : IRegionModule | 40 | public class LureModule : ISharedRegionModule |
41 | { | 41 | { |
42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 42 | private static readonly ILog m_log = LogManager.GetLogger( |
43 | MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | 44 | ||
44 | private readonly List<Scene> m_scenes = new List<Scene>(); | 45 | private readonly List<Scene> m_scenes = new List<Scene>(); |
45 | 46 | ||
46 | private IMessageTransferModule m_TransferModule = null; | 47 | private IMessageTransferModule m_TransferModule = null; |
48 | private bool m_Enabled = true; | ||
47 | 49 | ||
48 | public void Initialise(Scene scene, IConfigSource config) | 50 | public void Initialise(IConfigSource config) |
49 | { | 51 | { |
50 | if (config.Configs["Messaging"] != null) | 52 | if (config.Configs["Messaging"] != null) |
51 | { | 53 | { |
52 | if (config.Configs["Messaging"].GetString( | 54 | if (config.Configs["Messaging"].GetString( |
53 | "LureModule", "LureModule") != | 55 | "LureModule", "LureModule") != |
54 | "LureModule") | 56 | "LureModule") |
55 | return; | 57 | m_Enabled = false; |
56 | } | 58 | } |
59 | } | ||
60 | |||
61 | public void AddRegion(Scene scene) | ||
62 | { | ||
63 | if (!m_Enabled) | ||
64 | return; | ||
57 | 65 | ||
58 | lock (m_scenes) | 66 | lock (m_scenes) |
59 | { | 67 | { |
60 | if (!m_scenes.Contains(scene)) | 68 | m_scenes.Add(scene); |
69 | scene.EventManager.OnNewClient += OnNewClient; | ||
70 | scene.EventManager.OnIncomingInstantMessage += | ||
71 | OnGridInstantMessage; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | public void RegionLoaded(Scene scene) | ||
76 | { | ||
77 | if (m_TransferModule == null) | ||
78 | { | ||
79 | m_TransferModule = | ||
80 | scene.RequestModuleInterface<IMessageTransferModule>(); | ||
81 | |||
82 | if (m_TransferModule == null) | ||
61 | { | 83 | { |
62 | m_scenes.Add(scene); | 84 | m_log.Error("[INSTANT MESSAGE]: No message transfer module, "+ |
63 | scene.EventManager.OnNewClient += OnNewClient; | 85 | "lures will not work!"); |
64 | scene.EventManager.OnIncomingInstantMessage += | 86 | |
87 | m_Enabled = false; | ||
88 | m_scenes.Clear(); | ||
89 | scene.EventManager.OnNewClient -= OnNewClient; | ||
90 | scene.EventManager.OnIncomingInstantMessage -= | ||
65 | OnGridInstantMessage; | 91 | OnGridInstantMessage; |
66 | } | 92 | } |
67 | } | 93 | } |
94 | |||
95 | } | ||
96 | |||
97 | public void RemoveRegion(Scene scene) | ||
98 | { | ||
99 | lock (m_scenes) | ||
100 | { | ||
101 | m_scenes.Remove(scene); | ||
102 | scene.EventManager.OnNewClient -= OnNewClient; | ||
103 | scene.EventManager.OnIncomingInstantMessage -= | ||
104 | OnGridInstantMessage; | ||
105 | } | ||
68 | } | 106 | } |
69 | 107 | ||
70 | void OnNewClient(IClientAPI client) | 108 | void OnNewClient(IClientAPI client) |
@@ -76,12 +114,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure | |||
76 | 114 | ||
77 | public void PostInitialise() | 115 | public void PostInitialise() |
78 | { | 116 | { |
79 | m_TransferModule = | ||
80 | m_scenes[0].RequestModuleInterface<IMessageTransferModule>(); | ||
81 | |||
82 | if (m_TransferModule == null) | ||
83 | m_log.Error("[INSTANT MESSAGE]: No message transfer module, "+ | ||
84 | "lures will not work!"); | ||
85 | } | 117 | } |
86 | 118 | ||
87 | public void Close() | 119 | public void Close() |
@@ -93,9 +125,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Lure | |||
93 | get { return "LureModule"; } | 125 | get { return "LureModule"; } |
94 | } | 126 | } |
95 | 127 | ||
96 | public bool IsSharedModule | 128 | public Type ReplaceableInterface |
97 | { | 129 | { |
98 | get { return true; } | 130 | get { return null; } |
99 | } | 131 | } |
100 | 132 | ||
101 | public void OnInstantMessage(IClientAPI client, GridInstantMessage im) | 133 | public void OnInstantMessage(IClientAPI client, GridInstantMessage im) |
diff --git a/OpenSim/Region/CoreModules/Avatar/Profiles/AvatarProfilesModule.cs b/OpenSim/Region/CoreModules/Avatar/Profiles/AvatarProfilesModule.cs deleted file mode 100644 index 8cf58c6..0000000 --- a/OpenSim/Region/CoreModules/Avatar/Profiles/AvatarProfilesModule.cs +++ /dev/null | |||
@@ -1,168 +0,0 @@ | |||
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; | ||
30 | using System.Globalization; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Region.Framework.Interfaces; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | |||
39 | namespace OpenSim.Region.CoreModules.Avatar.Profiles | ||
40 | { | ||
41 | public class AvatarProfilesModule : IRegionModule | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | private Scene m_scene; | ||
45 | private IProfileModule m_profileModule = null; | ||
46 | private bool m_enabled = true; | ||
47 | |||
48 | public AvatarProfilesModule() | ||
49 | { | ||
50 | } | ||
51 | |||
52 | #region IRegionModule Members | ||
53 | |||
54 | public void Initialise(Scene scene, IConfigSource config) | ||
55 | { | ||
56 | IConfig profileConfig = config.Configs["Profile"]; | ||
57 | if (profileConfig != null) | ||
58 | { | ||
59 | if (profileConfig.GetString("Module", Name) != Name) | ||
60 | { | ||
61 | m_enabled = false; | ||
62 | return; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | m_scene = scene; | ||
67 | m_scene.EventManager.OnNewClient += NewClient; | ||
68 | } | ||
69 | |||
70 | public void PostInitialise() | ||
71 | { | ||
72 | if (!m_enabled) | ||
73 | return; | ||
74 | m_profileModule = m_scene.RequestModuleInterface<IProfileModule>(); | ||
75 | } | ||
76 | |||
77 | public void Close() | ||
78 | { | ||
79 | } | ||
80 | |||
81 | public string Name | ||
82 | { | ||
83 | get { return "AvatarProfilesModule"; } | ||
84 | } | ||
85 | |||
86 | public bool IsSharedModule | ||
87 | { | ||
88 | get { return false; } | ||
89 | } | ||
90 | |||
91 | #endregion | ||
92 | |||
93 | public void NewClient(IClientAPI client) | ||
94 | { | ||
95 | client.OnRequestAvatarProperties += RequestAvatarProperty; | ||
96 | client.OnUpdateAvatarProperties += UpdateAvatarProperties; | ||
97 | } | ||
98 | |||
99 | public void RemoveClient(IClientAPI client) | ||
100 | { | ||
101 | client.OnRequestAvatarProperties -= RequestAvatarProperty; | ||
102 | client.OnUpdateAvatarProperties -= UpdateAvatarProperties; | ||
103 | } | ||
104 | |||
105 | /// <summary> | ||
106 | /// | ||
107 | /// </summary> | ||
108 | /// <param name="remoteClient"></param> | ||
109 | /// <param name="avatarID"></param> | ||
110 | public void RequestAvatarProperty(IClientAPI remoteClient, UUID avatarID) | ||
111 | { | ||
112 | // FIXME: finish adding fields such as url, masking, etc. | ||
113 | UserProfileData profile = m_scene.CommsManager.UserService.GetUserProfile(avatarID); | ||
114 | if (null != profile) | ||
115 | { | ||
116 | Byte[] charterMember; | ||
117 | if (profile.CustomType == "") | ||
118 | { | ||
119 | charterMember = new Byte[1]; | ||
120 | charterMember[0] = (Byte)((profile.UserFlags & 0xf00) >> 8); | ||
121 | } | ||
122 | else | ||
123 | { | ||
124 | charterMember = Utils.StringToBytes(profile.CustomType); | ||
125 | } | ||
126 | |||
127 | if (m_profileModule != null) | ||
128 | { | ||
129 | Hashtable profileData = m_profileModule.GetProfileData(remoteClient.AgentId); | ||
130 | if (profileData["ProfileUrl"] != null) | ||
131 | profile.ProfileUrl = profileData["ProfileUrl"].ToString(); | ||
132 | } | ||
133 | remoteClient.SendAvatarProperties(profile.ID, profile.AboutText, | ||
134 | Util.ToDateTime(profile.Created).ToString("M/d/yyyy", CultureInfo.InvariantCulture), | ||
135 | charterMember, profile.FirstLifeAboutText, (uint)(profile.UserFlags & 0xff), | ||
136 | profile.FirstLifeImage, profile.Image, profile.ProfileUrl, profile.Partner); | ||
137 | } | ||
138 | else | ||
139 | { | ||
140 | m_log.Debug("[AvatarProfilesModule]: Got null for profile for " + avatarID.ToString()); | ||
141 | } | ||
142 | } | ||
143 | |||
144 | public void UpdateAvatarProperties(IClientAPI remoteClient, UserProfileData newProfile) | ||
145 | { | ||
146 | UserProfileData Profile = m_scene.CommsManager.UserService.GetUserProfile(newProfile.ID); | ||
147 | |||
148 | // if it's the profile of the user requesting the update, then we change only a few things. | ||
149 | if (remoteClient.AgentId.CompareTo(Profile.ID) == 0) | ||
150 | { | ||
151 | Profile.Image = newProfile.Image; | ||
152 | Profile.FirstLifeImage = newProfile.FirstLifeImage; | ||
153 | Profile.AboutText = newProfile.AboutText; | ||
154 | Profile.FirstLifeAboutText = newProfile.FirstLifeAboutText; | ||
155 | Profile.ProfileUrl = newProfile.ProfileUrl; | ||
156 | } | ||
157 | else | ||
158 | { | ||
159 | return; | ||
160 | } | ||
161 | |||
162 | if (m_scene.CommsManager.UserService.UpdateUserProfile(Profile)) | ||
163 | { | ||
164 | RequestAvatarProperty(remoteClient, newProfile.ID); | ||
165 | } | ||
166 | } | ||
167 | } | ||
168 | } | ||