clockwerk-opensim-stable – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ |
||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
||
4 | * |
||
5 | * Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions are met: |
||
7 | * * Redistributions of source code must retain the above copyright |
||
8 | * notice, this list of conditions and the following disclaimer. |
||
9 | * * Redistributions in binary form must reproduce the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer in the |
||
11 | * documentation and/or other materials provided with the distribution. |
||
12 | * * Neither the name of the OpenSimulator Project nor the |
||
13 | * names of its contributors may be used to endorse or promote products |
||
14 | * derived from this software without specific prior written permission. |
||
15 | * |
||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
26 | */ |
||
27 | |||
28 | using System; |
||
29 | using System.Collections; |
||
30 | using System.Collections.Generic; |
||
31 | using System.Reflection; |
||
32 | using System.Threading; |
||
33 | using log4net; |
||
34 | using Nini.Config; |
||
35 | using Nwc.XmlRpc; |
||
36 | using Mono.Addins; |
||
37 | using OpenMetaverse; |
||
38 | using OpenSim.Framework; |
||
39 | using OpenSim.Region.Framework.Interfaces; |
||
40 | using OpenSim.Region.Framework.Scenes; |
||
41 | using OpenSim.Services.Interfaces; |
||
42 | using OpenSim.Services.Connectors.Hypergrid; |
||
43 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; |
||
44 | using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; |
||
45 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
||
46 | |||
47 | namespace OpenSim.Region.CoreModules.Avatar.Friends |
||
48 | { |
||
49 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HGFriendsModule")] |
||
50 | public class HGFriendsModule : FriendsModule, ISharedRegionModule, IFriendsModule, IFriendsSimConnector |
||
51 | { |
||
52 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
53 | |||
54 | private int m_levelHGFriends = 0; |
||
55 | |||
56 | IUserManagement m_uMan; |
||
57 | public IUserManagement UserManagementModule |
||
58 | { |
||
59 | get |
||
60 | { |
||
61 | if (m_uMan == null) |
||
62 | m_uMan = m_Scenes[0].RequestModuleInterface<IUserManagement>(); |
||
63 | return m_uMan; |
||
64 | } |
||
65 | } |
||
66 | |||
67 | protected HGFriendsServicesConnector m_HGFriendsConnector = new HGFriendsServicesConnector(); |
||
68 | protected HGStatusNotifier m_StatusNotifier; |
||
69 | |||
70 | #region ISharedRegionModule |
||
71 | public override string Name |
||
72 | { |
||
73 | get { return "HGFriendsModule"; } |
||
74 | } |
||
75 | |||
76 | public override void AddRegion(Scene scene) |
||
77 | { |
||
78 | if (!m_Enabled) |
||
79 | return; |
||
80 | |||
81 | base.AddRegion(scene); |
||
82 | scene.RegisterModuleInterface<IFriendsSimConnector>(this); |
||
83 | } |
||
84 | |||
85 | public override void RegionLoaded(Scene scene) |
||
86 | { |
||
87 | if (!m_Enabled) |
||
88 | return; |
||
89 | if (m_StatusNotifier == null) |
||
90 | m_StatusNotifier = new HGStatusNotifier(this); |
||
91 | } |
||
92 | |||
93 | protected override void InitModule(IConfigSource config) |
||
94 | { |
||
95 | base.InitModule(config); |
||
96 | |||
97 | // Additionally to the base method |
||
98 | IConfig friendsConfig = config.Configs["HGFriendsModule"]; |
||
99 | if (friendsConfig != null) |
||
100 | { |
||
101 | m_levelHGFriends = friendsConfig.GetInt("LevelHGFriends", 0); |
||
102 | |||
103 | // TODO: read in all config variables pertaining to |
||
104 | // HG friendship permissions |
||
105 | } |
||
106 | } |
||
107 | |||
108 | #endregion |
||
109 | |||
110 | #region IFriendsSimConnector |
||
111 | |||
112 | /// <summary> |
||
113 | /// Notify the user that the friend's status changed |
||
114 | /// </summary> |
||
115 | /// <param name="userID">user to be notified</param> |
||
116 | /// <param name="friendID">friend whose status changed</param> |
||
117 | /// <param name="online">status</param> |
||
118 | /// <returns></returns> |
||
119 | public bool StatusNotify(UUID friendID, UUID userID, bool online) |
||
120 | { |
||
121 | return LocalStatusNotification(friendID, userID, online); |
||
122 | } |
||
123 | |||
124 | #endregion |
||
125 | |||
126 | protected override void OnInstantMessage(IClientAPI client, GridInstantMessage im) |
||
127 | { |
||
128 | if ((InstantMessageDialog)im.dialog == InstantMessageDialog.FriendshipOffered) |
||
129 | { |
||
130 | // we got a friendship offer |
||
131 | UUID principalID = new UUID(im.fromAgentID); |
||
132 | UUID friendID = new UUID(im.toAgentID); |
||
133 | |||
134 | // Check if friendID is foreigner and if principalID has the permission |
||
135 | // to request friendships with foreigners. If not, return immediately. |
||
136 | if (!UserManagementModule.IsLocalGridUser(friendID)) |
||
137 | { |
||
138 | ScenePresence avatar = null; |
||
139 | ((Scene)client.Scene).TryGetScenePresence(principalID, out avatar); |
||
140 | |||
141 | if (avatar == null) |
||
142 | return; |
||
143 | |||
144 | if (avatar.UserLevel < m_levelHGFriends) |
||
145 | { |
||
146 | client.SendAgentAlertMessage("Unable to send friendship invitation to foreigner. Insufficient permissions.", false); |
||
147 | return; |
||
148 | } |
||
149 | } |
||
150 | } |
||
151 | |||
152 | base.OnInstantMessage(client, im); |
||
153 | } |
||
154 | |||
155 | protected override void OnApproveFriendRequest(IClientAPI client, UUID friendID, List<UUID> callingCardFolders) |
||
156 | { |
||
157 | // Update the local cache. Yes, we need to do it right here |
||
158 | // because the HGFriendsService placed something on the DB |
||
159 | // from under the sim |
||
160 | base.OnApproveFriendRequest(client, friendID, callingCardFolders); |
||
161 | } |
||
162 | |||
163 | protected override bool CacheFriends(IClientAPI client) |
||
164 | { |
||
165 | // m_log.DebugFormat("[HGFRIENDS MODULE]: Entered CacheFriends for {0}", client.Name); |
||
166 | |||
167 | if (base.CacheFriends(client)) |
||
168 | { |
||
169 | UUID agentID = client.AgentId; |
||
170 | // we do this only for the root agent |
||
171 | if (m_Friends[agentID].Refcount == 1) |
||
172 | { |
||
173 | // We need to preload the user management cache with the names |
||
174 | // of foreign friends, just like we do with SOPs' creators |
||
175 | foreach (FriendInfo finfo in m_Friends[agentID].Friends) |
||
176 | { |
||
177 | if (finfo.TheirFlags != -1) |
||
178 | { |
||
179 | UUID id; |
||
180 | if (!UUID.TryParse(finfo.Friend, out id)) |
||
181 | { |
||
182 | string url = string.Empty, first = string.Empty, last = string.Empty, tmp = string.Empty; |
||
183 | if (Util.ParseUniversalUserIdentifier(finfo.Friend, out id, out url, out first, out last, out tmp)) |
||
184 | { |
||
185 | IUserManagement uMan = m_Scenes[0].RequestModuleInterface<IUserManagement>(); |
||
186 | m_log.DebugFormat("[HGFRIENDS MODULE]: caching {0}", finfo.Friend); |
||
187 | uMan.AddUser(id, url + ";" + first + " " + last); |
||
188 | } |
||
189 | } |
||
190 | } |
||
191 | } |
||
192 | |||
193 | // m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting CacheFriends for {0} since detected root agent", client.Name); |
||
194 | return true; |
||
195 | } |
||
196 | } |
||
197 | |||
198 | // m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting CacheFriends for {0} since detected not root agent", client.Name); |
||
199 | return false; |
||
200 | } |
||
201 | |||
202 | public override bool SendFriendsOnlineIfNeeded(IClientAPI client) |
||
203 | { |
||
204 | // m_log.DebugFormat("[HGFRIENDS MODULE]: Entering SendFriendsOnlineIfNeeded for {0}", client.Name); |
||
205 | |||
206 | if (base.SendFriendsOnlineIfNeeded(client)) |
||
207 | { |
||
208 | AgentCircuitData aCircuit = ((Scene)client.Scene).AuthenticateHandler.GetAgentCircuitData(client.AgentId); |
||
209 | if (aCircuit != null && (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0) |
||
210 | { |
||
211 | UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(client.Scene.RegionInfo.ScopeID, client.AgentId); |
||
212 | if (account == null) // foreign |
||
213 | { |
||
214 | FriendInfo[] friends = GetFriendsFromCache(client.AgentId); |
||
215 | foreach (FriendInfo f in friends) |
||
216 | { |
||
217 | client.SendChangeUserRights(new UUID(f.Friend), client.AgentId, f.TheirFlags); |
||
218 | } |
||
219 | } |
||
220 | } |
||
221 | } |
||
222 | |||
223 | // m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting SendFriendsOnlineIfNeeded for {0}", client.Name); |
||
224 | return false; |
||
225 | } |
||
226 | |||
227 | protected override void GetOnlineFriends(UUID userID, List<string> friendList, /*collector*/ List<UUID> online) |
||
228 | { |
||
229 | // m_log.DebugFormat("[HGFRIENDS MODULE]: Entering GetOnlineFriends for {0}", userID); |
||
230 | |||
231 | List<string> fList = new List<string>(); |
||
232 | foreach (string s in friendList) |
||
233 | { |
||
234 | if (s.Length < 36) |
||
235 | m_log.WarnFormat( |
||
236 | "[HGFRIENDS MODULE]: Ignoring friend {0} ({1} chars) for {2} since identifier too short", |
||
237 | s, s.Length, userID); |
||
238 | else |
||
239 | fList.Add(s.Substring(0, 36)); |
||
240 | } |
||
241 | |||
242 | PresenceInfo[] presence = PresenceService.GetAgents(fList.ToArray()); |
||
243 | foreach (PresenceInfo pi in presence) |
||
244 | { |
||
245 | UUID presenceID; |
||
246 | if (UUID.TryParse(pi.UserID, out presenceID)) |
||
247 | online.Add(presenceID); |
||
248 | } |
||
249 | |||
250 | // m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting GetOnlineFriends for {0}", userID); |
||
251 | } |
||
252 | |||
253 | protected override void StatusNotify(List<FriendInfo> friendList, UUID userID, bool online) |
||
254 | { |
||
255 | //m_log.DebugFormat("[HGFRIENDS MODULE]: Entering StatusNotify for {0}", userID); |
||
256 | |||
257 | // First, let's divide the friends on a per-domain basis |
||
258 | Dictionary<string, List<FriendInfo>> friendsPerDomain = new Dictionary<string, List<FriendInfo>>(); |
||
259 | foreach (FriendInfo friend in friendList) |
||
260 | { |
||
261 | UUID friendID; |
||
262 | if (UUID.TryParse(friend.Friend, out friendID)) |
||
263 | { |
||
264 | if (!friendsPerDomain.ContainsKey("local")) |
||
265 | friendsPerDomain["local"] = new List<FriendInfo>(); |
||
266 | friendsPerDomain["local"].Add(friend); |
||
267 | } |
||
268 | else |
||
269 | { |
||
270 | // it's a foreign friend |
||
271 | string url = string.Empty, tmp = string.Empty; |
||
272 | if (Util.ParseUniversalUserIdentifier(friend.Friend, out friendID, out url, out tmp, out tmp, out tmp)) |
||
273 | { |
||
274 | // Let's try our luck in the local sim. Who knows, maybe it's here |
||
275 | if (LocalStatusNotification(userID, friendID, online)) |
||
276 | continue; |
||
277 | |||
278 | if (!friendsPerDomain.ContainsKey(url)) |
||
279 | friendsPerDomain[url] = new List<FriendInfo>(); |
||
280 | friendsPerDomain[url].Add(friend); |
||
281 | } |
||
282 | } |
||
283 | } |
||
284 | |||
285 | // For the local friends, just call the base method |
||
286 | // Let's do this first of all |
||
287 | if (friendsPerDomain.ContainsKey("local")) |
||
288 | base.StatusNotify(friendsPerDomain["local"], userID, online); |
||
289 | |||
290 | m_StatusNotifier.Notify(userID, friendsPerDomain, online); |
||
291 | |||
292 | // m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting StatusNotify for {0}", userID); |
||
293 | } |
||
294 | |||
295 | protected override bool GetAgentInfo(UUID scopeID, string fid, out UUID agentID, out string first, out string last) |
||
296 | { |
||
297 | first = "Unknown"; last = "UserHGGAI"; |
||
298 | if (base.GetAgentInfo(scopeID, fid, out agentID, out first, out last)) |
||
299 | return true; |
||
300 | |||
301 | // fid is not a UUID... |
||
302 | string url = string.Empty, tmp = string.Empty, f = string.Empty, l = string.Empty; |
||
303 | if (Util.ParseUniversalUserIdentifier(fid, out agentID, out url, out f, out l, out tmp)) |
||
304 | { |
||
305 | if (!agentID.Equals(UUID.Zero)) |
||
306 | { |
||
307 | m_uMan.AddUser(agentID, f, l, url); |
||
308 | |||
309 | string name = m_uMan.GetUserName(agentID); |
||
310 | string[] parts = name.Trim().Split(new char[] { ' ' }); |
||
311 | if (parts.Length == 2) |
||
312 | { |
||
313 | first = parts[0]; |
||
314 | last = parts[1]; |
||
315 | } |
||
316 | else |
||
317 | { |
||
318 | first = f; |
||
319 | last = l; |
||
320 | } |
||
321 | return true; |
||
322 | } |
||
323 | } |
||
324 | return false; |
||
325 | } |
||
326 | |||
327 | protected override string GetFriendshipRequesterName(UUID agentID) |
||
328 | { |
||
329 | return m_uMan.GetUserName(agentID); |
||
330 | } |
||
331 | |||
332 | protected override string FriendshipMessage(string friendID) |
||
333 | { |
||
334 | UUID id; |
||
335 | if (UUID.TryParse(friendID, out id)) |
||
336 | return base.FriendshipMessage(friendID); |
||
337 | |||
338 | return "Please confirm this friendship you made while you were away."; |
||
339 | } |
||
340 | |||
341 | protected override FriendInfo GetFriend(FriendInfo[] friends, UUID friendID) |
||
342 | { |
||
343 | foreach (FriendInfo fi in friends) |
||
344 | { |
||
345 | if (fi.Friend.StartsWith(friendID.ToString())) |
||
346 | return fi; |
||
347 | } |
||
348 | return null; |
||
349 | } |
||
350 | |||
351 | public override FriendInfo[] GetFriendsFromService(IClientAPI client) |
||
352 | { |
||
353 | // m_log.DebugFormat("[HGFRIENDS MODULE]: Entering GetFriendsFromService for {0}", client.Name); |
||
354 | Boolean agentIsLocal = true; |
||
355 | if (UserManagementModule != null) |
||
356 | agentIsLocal = UserManagementModule.IsLocalGridUser(client.AgentId); |
||
357 | |||
358 | if (agentIsLocal) |
||
359 | return base.GetFriendsFromService(client); |
||
360 | |||
361 | FriendInfo[] finfos = new FriendInfo[0]; |
||
362 | // Foreigner |
||
363 | AgentCircuitData agentClientCircuit = ((Scene)(client.Scene)).AuthenticateHandler.GetAgentCircuitData(client.CircuitCode); |
||
364 | if (agentClientCircuit != null) |
||
365 | { |
||
366 | // Note that this is calling a different interface than base; this one calls with a string param! |
||
367 | finfos = FriendsService.GetFriends(client.AgentId.ToString()); |
||
368 | m_log.DebugFormat("[HGFRIENDS MODULE]: Fetched {0} local friends for visitor {1}", finfos.Length, client.AgentId.ToString()); |
||
369 | } |
||
370 | |||
371 | // m_log.DebugFormat("[HGFRIENDS MODULE]: Exiting GetFriendsFromService for {0}", client.Name); |
||
372 | |||
373 | return finfos; |
||
374 | } |
||
375 | |||
376 | protected override bool StoreRights(UUID agentID, UUID friendID, int rights) |
||
377 | { |
||
378 | Boolean agentIsLocal = true; |
||
379 | Boolean friendIsLocal = true; |
||
380 | if (UserManagementModule != null) |
||
381 | { |
||
382 | agentIsLocal = UserManagementModule.IsLocalGridUser(agentID); |
||
383 | friendIsLocal = UserManagementModule.IsLocalGridUser(friendID); |
||
384 | } |
||
385 | |||
386 | // Are they both local users? |
||
387 | if (agentIsLocal && friendIsLocal) |
||
388 | { |
||
389 | // local grid users |
||
390 | return base.StoreRights(agentID, friendID, rights); |
||
391 | } |
||
392 | |||
393 | if (agentIsLocal) // agent is local, friend is foreigner |
||
394 | { |
||
395 | FriendInfo[] finfos = GetFriendsFromCache(agentID); |
||
396 | FriendInfo finfo = GetFriend(finfos, friendID); |
||
397 | if (finfo != null) |
||
398 | { |
||
399 | FriendsService.StoreFriend(agentID.ToString(), finfo.Friend, rights); |
||
400 | return true; |
||
401 | } |
||
402 | } |
||
403 | |||
404 | if (friendIsLocal) // agent is foreigner, friend is local |
||
405 | { |
||
406 | string agentUUI = GetUUI(friendID, agentID); |
||
407 | if (agentUUI != string.Empty) |
||
408 | { |
||
409 | FriendsService.StoreFriend(agentUUI, friendID.ToString(), rights); |
||
410 | return true; |
||
411 | } |
||
412 | } |
||
413 | |||
414 | return false; |
||
415 | } |
||
416 | |||
417 | protected override void StoreBackwards(UUID friendID, UUID agentID) |
||
418 | { |
||
419 | bool agentIsLocal = true; |
||
420 | // bool friendIsLocal = true; |
||
421 | |||
422 | if (UserManagementModule != null) |
||
423 | { |
||
424 | agentIsLocal = UserManagementModule.IsLocalGridUser(agentID); |
||
425 | // friendIsLocal = UserManagementModule.IsLocalGridUser(friendID); |
||
426 | } |
||
427 | |||
428 | // Is the requester a local user? |
||
429 | if (agentIsLocal) |
||
430 | { |
||
431 | // local grid users |
||
432 | m_log.DebugFormat("[HGFRIENDS MODULE]: Friendship requester is local. Storing backwards."); |
||
433 | |||
434 | base.StoreBackwards(friendID, agentID); |
||
435 | return; |
||
436 | } |
||
437 | |||
438 | // no provision for this temporary friendship state when user is not local |
||
439 | //FriendsService.StoreFriend(friendID.ToString(), agentID.ToString(), 0); |
||
440 | } |
||
441 | |||
442 | protected override void StoreFriendships(UUID agentID, UUID friendID) |
||
443 | { |
||
444 | Boolean agentIsLocal = true; |
||
445 | Boolean friendIsLocal = true; |
||
446 | if (UserManagementModule != null) |
||
447 | { |
||
448 | agentIsLocal = UserManagementModule.IsLocalGridUser(agentID); |
||
449 | friendIsLocal = UserManagementModule.IsLocalGridUser(friendID); |
||
450 | } |
||
451 | |||
452 | // Are they both local users? |
||
453 | if (agentIsLocal && friendIsLocal) |
||
454 | { |
||
455 | // local grid users |
||
456 | m_log.DebugFormat("[HGFRIENDS MODULE]: Users are both local"); |
||
457 | base.StoreFriendships(agentID, friendID); |
||
458 | return; |
||
459 | } |
||
460 | |||
461 | // ok, at least one of them is foreigner, let's get their data |
||
462 | IClientAPI agentClient = LocateClientObject(agentID); |
||
463 | IClientAPI friendClient = LocateClientObject(friendID); |
||
464 | AgentCircuitData agentClientCircuit = null; |
||
465 | AgentCircuitData friendClientCircuit = null; |
||
466 | string agentUUI = string.Empty; |
||
467 | string friendUUI = string.Empty; |
||
468 | string agentFriendService = string.Empty; |
||
469 | string friendFriendService = string.Empty; |
||
470 | |||
471 | if (agentClient != null) |
||
472 | { |
||
473 | agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode); |
||
474 | agentUUI = Util.ProduceUserUniversalIdentifier(agentClientCircuit); |
||
475 | agentFriendService = agentClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); |
||
476 | RecacheFriends(agentClient); |
||
477 | } |
||
478 | if (friendClient != null) |
||
479 | { |
||
480 | friendClientCircuit = ((Scene)(friendClient.Scene)).AuthenticateHandler.GetAgentCircuitData(friendClient.CircuitCode); |
||
481 | friendUUI = Util.ProduceUserUniversalIdentifier(friendClientCircuit); |
||
482 | friendFriendService = friendClientCircuit.ServiceURLs["FriendsServerURI"].ToString(); |
||
483 | RecacheFriends(friendClient); |
||
484 | } |
||
485 | |||
486 | m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}", |
||
487 | agentUUI, friendUUI, agentFriendService, friendFriendService); |
||
488 | |||
489 | // Generate a random 8-character hex number that will sign this friendship |
||
490 | string secret = UUID.Random().ToString().Substring(0, 8); |
||
491 | |||
492 | string theFriendUUID = friendUUI + ";" + secret; |
||
493 | string agentUUID = agentUUI + ";" + secret; |
||
494 | |||
495 | if (agentIsLocal) // agent is local, 'friend' is foreigner |
||
496 | { |
||
497 | // This may happen when the agent returned home, in which case the friend is not there |
||
498 | // We need to look for its information in the friends list itself |
||
499 | FriendInfo[] finfos = null; |
||
500 | bool confirming = false; |
||
501 | if (friendUUI == string.Empty) |
||
502 | { |
||
503 | finfos = GetFriendsFromCache(agentID); |
||
504 | foreach (FriendInfo finfo in finfos) |
||
505 | { |
||
506 | if (finfo.TheirFlags == -1) |
||
507 | { |
||
508 | if (finfo.Friend.StartsWith(friendID.ToString())) |
||
509 | { |
||
510 | friendUUI = finfo.Friend; |
||
511 | theFriendUUID = friendUUI; |
||
512 | UUID utmp = UUID.Zero; |
||
513 | string url = String.Empty; |
||
514 | string first = String.Empty; |
||
515 | string last = String.Empty; |
||
516 | |||
517 | // If it's confirming the friendship, we already have the full UUI with the secret |
||
518 | if (Util.ParseUniversalUserIdentifier(theFriendUUID, out utmp, out url, out first, out last, out secret)) |
||
519 | { |
||
520 | agentUUID = agentUUI + ";" + secret; |
||
521 | m_uMan.AddUser(utmp, first, last, url); |
||
522 | } |
||
523 | confirming = true; |
||
524 | break; |
||
525 | } |
||
526 | } |
||
527 | } |
||
528 | if (!confirming) |
||
529 | { |
||
530 | friendUUI = m_uMan.GetUserUUI(friendID); |
||
531 | theFriendUUID = friendUUI + ";" + secret; |
||
532 | } |
||
533 | |||
534 | friendFriendService = m_uMan.GetUserServerURL(friendID, "FriendsServerURI"); |
||
535 | |||
536 | // m_log.DebugFormat("[HGFRIENDS MODULE] HG Friendship! thisUUI={0}; friendUUI={1}; foreignThisFriendService={2}; foreignFriendFriendService={3}", |
||
537 | // agentUUI, friendUUI, agentFriendService, friendFriendService); |
||
538 | |||
539 | } |
||
540 | |||
541 | // Delete any previous friendship relations |
||
542 | DeletePreviousRelations(agentID, friendID); |
||
543 | |||
544 | // store in the local friends service a reference to the foreign friend |
||
545 | FriendsService.StoreFriend(agentID.ToString(), theFriendUUID, 1); |
||
546 | // and also the converse |
||
547 | FriendsService.StoreFriend(theFriendUUID, agentID.ToString(), 1); |
||
548 | |||
549 | //if (!confirming) |
||
550 | //{ |
||
551 | // store in the foreign friends service a reference to the local agent |
||
552 | HGFriendsServicesConnector friendsConn = null; |
||
553 | if (friendClientCircuit != null) // the friend is here, validate session |
||
554 | friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID); |
||
555 | else // the friend is not here, he initiated the request in his home world |
||
556 | friendsConn = new HGFriendsServicesConnector(friendFriendService); |
||
557 | |||
558 | friendsConn.NewFriendship(friendID, agentUUID); |
||
559 | //} |
||
560 | } |
||
561 | else if (friendIsLocal) // 'friend' is local, agent is foreigner |
||
562 | { |
||
563 | // Delete any previous friendship relations |
||
564 | DeletePreviousRelations(agentID, friendID); |
||
565 | |||
566 | // store in the local friends service a reference to the foreign agent |
||
567 | FriendsService.StoreFriend(friendID.ToString(), agentUUI + ";" + secret, 1); |
||
568 | // and also the converse |
||
569 | FriendsService.StoreFriend(agentUUI + ";" + secret, friendID.ToString(), 1); |
||
570 | |||
571 | if (agentClientCircuit != null) |
||
572 | { |
||
573 | // store in the foreign friends service a reference to the local agent |
||
574 | HGFriendsServicesConnector friendsConn = new HGFriendsServicesConnector(agentFriendService, agentClientCircuit.SessionID, agentClientCircuit.ServiceSessionID); |
||
575 | friendsConn.NewFriendship(agentID, friendUUI + ";" + secret); |
||
576 | } |
||
577 | } |
||
578 | else // They're both foreigners! |
||
579 | { |
||
580 | HGFriendsServicesConnector friendsConn; |
||
581 | if (agentClientCircuit != null) |
||
582 | { |
||
583 | friendsConn = new HGFriendsServicesConnector(agentFriendService, agentClientCircuit.SessionID, agentClientCircuit.ServiceSessionID); |
||
584 | friendsConn.NewFriendship(agentID, friendUUI + ";" + secret); |
||
585 | } |
||
586 | if (friendClientCircuit != null) |
||
587 | { |
||
588 | friendsConn = new HGFriendsServicesConnector(friendFriendService, friendClientCircuit.SessionID, friendClientCircuit.ServiceSessionID); |
||
589 | friendsConn.NewFriendship(friendID, agentUUI + ";" + secret); |
||
590 | } |
||
591 | } |
||
592 | // my brain hurts now |
||
593 | } |
||
594 | |||
595 | private void DeletePreviousRelations(UUID a1, UUID a2) |
||
596 | { |
||
597 | // Delete any previous friendship relations |
||
598 | FriendInfo[] finfos = null; |
||
599 | FriendInfo f = null; |
||
600 | finfos = GetFriendsFromCache(a1); |
||
601 | if (finfos != null) |
||
602 | { |
||
603 | f = GetFriend(finfos, a2); |
||
604 | if (f != null) |
||
605 | { |
||
606 | FriendsService.Delete(a1, f.Friend); |
||
607 | // and also the converse |
||
608 | FriendsService.Delete(f.Friend, a1.ToString()); |
||
609 | } |
||
610 | } |
||
611 | |||
612 | finfos = GetFriendsFromCache(a2); |
||
613 | if (finfos != null) |
||
614 | { |
||
615 | f = GetFriend(finfos, a1); |
||
616 | if (f != null) |
||
617 | { |
||
618 | FriendsService.Delete(a2, f.Friend); |
||
619 | // and also the converse |
||
620 | FriendsService.Delete(f.Friend, a2.ToString()); |
||
621 | } |
||
622 | } |
||
623 | } |
||
624 | |||
625 | protected override bool DeleteFriendship(UUID agentID, UUID exfriendID) |
||
626 | { |
||
627 | Boolean agentIsLocal = true; |
||
628 | Boolean friendIsLocal = true; |
||
629 | if (UserManagementModule != null) |
||
630 | { |
||
631 | agentIsLocal = UserManagementModule.IsLocalGridUser(agentID); |
||
632 | friendIsLocal = UserManagementModule.IsLocalGridUser(exfriendID); |
||
633 | } |
||
634 | |||
635 | // Are they both local users? |
||
636 | if (agentIsLocal && friendIsLocal) |
||
637 | { |
||
638 | // local grid users |
||
639 | return base.DeleteFriendship(agentID, exfriendID); |
||
640 | } |
||
641 | |||
642 | // ok, at least one of them is foreigner, let's get their data |
||
643 | string agentUUI = string.Empty; |
||
644 | string friendUUI = string.Empty; |
||
645 | |||
646 | if (agentIsLocal) // agent is local, 'friend' is foreigner |
||
647 | { |
||
648 | // We need to look for its information in the friends list itself |
||
649 | FriendInfo[] finfos = GetFriendsFromCache(agentID); |
||
650 | FriendInfo finfo = GetFriend(finfos, exfriendID); |
||
651 | if (finfo != null) |
||
652 | { |
||
653 | friendUUI = finfo.Friend; |
||
654 | |||
655 | // delete in the local friends service the reference to the foreign friend |
||
656 | FriendsService.Delete(agentID, friendUUI); |
||
657 | // and also the converse |
||
658 | FriendsService.Delete(friendUUI, agentID.ToString()); |
||
659 | |||
660 | // notify the exfriend's service |
||
661 | Util.FireAndForget(delegate { Delete(exfriendID, agentID, friendUUI); }); |
||
662 | |||
663 | m_log.DebugFormat("[HGFRIENDS MODULE]: {0} terminated {1}", agentID, friendUUI); |
||
664 | return true; |
||
665 | } |
||
666 | } |
||
667 | else if (friendIsLocal) // agent is foreigner, 'friend' is local |
||
668 | { |
||
669 | agentUUI = GetUUI(exfriendID, agentID); |
||
670 | |||
671 | if (agentUUI != string.Empty) |
||
672 | { |
||
673 | // delete in the local friends service the reference to the foreign agent |
||
674 | FriendsService.Delete(exfriendID, agentUUI); |
||
675 | // and also the converse |
||
676 | FriendsService.Delete(agentUUI, exfriendID.ToString()); |
||
677 | |||
678 | // notify the agent's service? |
||
679 | Util.FireAndForget(delegate { Delete(agentID, exfriendID, agentUUI); }); |
||
680 | |||
681 | m_log.DebugFormat("[HGFRIENDS MODULE]: {0} terminated {1}", agentUUI, exfriendID); |
||
682 | return true; |
||
683 | } |
||
684 | } |
||
685 | //else They're both foreigners! Can't handle this |
||
686 | |||
687 | return false; |
||
688 | } |
||
689 | |||
690 | private string GetUUI(UUID localUser, UUID foreignUser) |
||
691 | { |
||
692 | // Let's see if the user is here by any chance |
||
693 | FriendInfo[] finfos = GetFriendsFromCache(localUser); |
||
694 | if (finfos != EMPTY_FRIENDS) // friend is here, cool |
||
695 | { |
||
696 | FriendInfo finfo = GetFriend(finfos, foreignUser); |
||
697 | if (finfo != null) |
||
698 | { |
||
699 | return finfo.Friend; |
||
700 | } |
||
701 | } |
||
702 | else // user is not currently on this sim, need to get from the service |
||
703 | { |
||
704 | finfos = FriendsService.GetFriends(localUser); |
||
705 | foreach (FriendInfo finfo in finfos) |
||
706 | { |
||
707 | if (finfo.Friend.StartsWith(foreignUser.ToString())) // found it! |
||
708 | { |
||
709 | return finfo.Friend; |
||
710 | } |
||
711 | } |
||
712 | } |
||
713 | return string.Empty; |
||
714 | } |
||
715 | |||
716 | private void Delete(UUID foreignUser, UUID localUser, string uui) |
||
717 | { |
||
718 | UUID id; |
||
719 | string url = string.Empty, secret = string.Empty, tmp = string.Empty; |
||
720 | if (Util.ParseUniversalUserIdentifier(uui, out id, out url, out tmp, out tmp, out secret)) |
||
721 | { |
||
722 | m_log.DebugFormat("[HGFRIENDS MODULE]: Deleting friendship from {0}", url); |
||
723 | HGFriendsServicesConnector friendConn = new HGFriendsServicesConnector(url); |
||
724 | friendConn.DeleteFriendship(foreignUser, localUser, secret); |
||
725 | } |
||
726 | } |
||
727 | |||
728 | protected override bool ForwardFriendshipOffer(UUID agentID, UUID friendID, GridInstantMessage im) |
||
729 | { |
||
730 | if (base.ForwardFriendshipOffer(agentID, friendID, im)) |
||
731 | return true; |
||
732 | |||
733 | // OK, that didn't work, so let's try to find this user somewhere |
||
734 | if (!m_uMan.IsLocalGridUser(friendID)) |
||
735 | { |
||
736 | string friendsURL = m_uMan.GetUserServerURL(friendID, "FriendsServerURI"); |
||
737 | if (friendsURL != string.Empty) |
||
738 | { |
||
739 | m_log.DebugFormat("[HGFRIENDS MODULE]: Forwading friendship from {0} to {1} @ {2}", agentID, friendID, friendsURL); |
||
740 | GridRegion region = new GridRegion(); |
||
741 | region.ServerURI = friendsURL; |
||
742 | |||
743 | string name = im.fromAgentName; |
||
744 | if (m_uMan.IsLocalGridUser(agentID)) |
||
745 | { |
||
746 | IClientAPI agentClient = LocateClientObject(agentID); |
||
747 | AgentCircuitData agentClientCircuit = ((Scene)(agentClient.Scene)).AuthenticateHandler.GetAgentCircuitData(agentClient.CircuitCode); |
||
748 | string agentHomeService = string.Empty; |
||
749 | try |
||
750 | { |
||
751 | agentHomeService = agentClientCircuit.ServiceURLs["HomeURI"].ToString(); |
||
752 | string lastname = "@" + new Uri(agentHomeService).Authority; |
||
753 | string firstname = im.fromAgentName.Replace(" ", "."); |
||
754 | name = firstname + lastname; |
||
755 | } |
||
756 | catch (KeyNotFoundException) |
||
757 | { |
||
758 | m_log.DebugFormat("[HGFRIENDS MODULE]: Key HomeURI not found for user {0}", agentID); |
||
759 | return false; |
||
760 | } |
||
761 | catch (NullReferenceException) |
||
762 | { |
||
763 | m_log.DebugFormat("[HGFRIENDS MODULE]: Null HomeUri for local user {0}", agentID); |
||
764 | return false; |
||
765 | } |
||
766 | catch (UriFormatException) |
||
767 | { |
||
768 | m_log.DebugFormat("[HGFRIENDS MODULE]: Malformed HomeUri {0} for local user {1}", agentHomeService, agentID); |
||
769 | return false; |
||
770 | } |
||
771 | } |
||
772 | |||
773 | m_HGFriendsConnector.FriendshipOffered(region, agentID, friendID, im.message, name); |
||
774 | |||
775 | return true; |
||
776 | } |
||
777 | } |
||
778 | |||
779 | return false; |
||
780 | } |
||
781 | |||
782 | public override bool LocalFriendshipOffered(UUID toID, GridInstantMessage im) |
||
783 | { |
||
784 | if (base.LocalFriendshipOffered(toID, im)) |
||
785 | { |
||
786 | if (im.fromAgentName.Contains("@")) |
||
787 | { |
||
788 | string[] parts = im.fromAgentName.Split(new char[] { '@' }); |
||
789 | if (parts.Length == 2) |
||
790 | { |
||
791 | string[] fl = parts[0].Trim().Split(new char[] { '.' }); |
||
792 | if (fl.Length == 2) |
||
793 | m_uMan.AddUser(new UUID(im.fromAgentID), fl[0], fl[1], "http://" + parts[1]); |
||
794 | else |
||
795 | m_uMan.AddUser(new UUID(im.fromAgentID), fl[0], "", "http://" + parts[1]); |
||
796 | } |
||
797 | } |
||
798 | return true; |
||
799 | } |
||
800 | return false; |
||
801 | } |
||
802 | } |
||
803 | } |