aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs185
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs155
2 files changed, 282 insertions, 58 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
index 7e7d9e9..cc3a3ee 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
@@ -115,6 +115,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
115 } 115 }
116 } 116 }
117 117
118 public IScene Scene
119 {
120 get
121 {
122 if (m_Scenes.Count > 0)
123 return m_Scenes[0];
124 else
125 return null;
126 }
127 }
128
118 public void Initialise(IConfigSource config) 129 public void Initialise(IConfigSource config)
119 { 130 {
120 IConfig friendsConfig = config.Configs["Friends"]; 131 IConfig friendsConfig = config.Configs["Friends"];
@@ -276,6 +287,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
276 287
277 private void SendPresence(UUID agentID) 288 private void SendPresence(UUID agentID)
278 { 289 {
290 // Inform the friends that this user is online
291 StatusChange(agentID, true);
292
293 // Now send the list of online friends to this user
279 if (!m_Friends.ContainsKey(agentID)) 294 if (!m_Friends.ContainsKey(agentID))
280 { 295 {
281 m_log.DebugFormat("[FRIENDS MODULE]: agent {0} not found in local cache", agentID); 296 m_log.DebugFormat("[FRIENDS MODULE]: agent {0} not found in local cache", agentID);
@@ -291,11 +306,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
291 306
292 List<UUID> online = GetOnlineFriends(agentID); 307 List<UUID> online = GetOnlineFriends(agentID);
293 308
294 m_log.DebugFormat("[FRIENDS]: User {0} has {1} friends online", agentID, online.Count); 309 m_log.DebugFormat("[FRIENDS]: User {0} in region {1} has {2} friends online", client.AgentId, client.Scene.RegionInfo.RegionName, online.Count);
295 client.SendAgentOnline(online.ToArray()); 310 client.SendAgentOnline(online.ToArray());
296 311
297 // Now inform the friends that this user is online
298 StatusChange(agentID, true);
299 } 312 }
300 313
301 List<UUID> GetOnlineFriends(UUID userID) 314 List<UUID> GetOnlineFriends(UUID userID)
@@ -315,7 +328,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
315 foreach (PresenceInfo pi in presence) 328 foreach (PresenceInfo pi in presence)
316 { 329 {
317 if (pi.Online) 330 if (pi.Online)
331 {
318 online.Add(new UUID(pi.UserID)); 332 online.Add(new UUID(pi.UserID));
333 //m_log.DebugFormat("[XXX] {0} friend online {1}", userID, pi.UserID);
334 }
319 } 335 }
320 336
321 return online; 337 return online;
@@ -324,13 +340,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
324 // 340 //
325 // Find the client for a ID 341 // Find the client for a ID
326 // 342 //
327 private IClientAPI LocateClientObject(UUID agentID) 343 public IClientAPI LocateClientObject(UUID agentID)
328 { 344 {
329 Scene scene=GetClientScene(agentID); 345 Scene scene = GetClientScene(agentID);
330 if(scene == null) 346 if(scene == null)
331 return null; 347 return null;
332 348
333 ScenePresence presence=scene.GetScenePresence(agentID); 349 ScenePresence presence = scene.GetScenePresence(agentID);
334 if(presence == null) 350 if(presence == null)
335 return null; 351 return null;
336 352
@@ -386,19 +402,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
386 402
387 if (UUID.TryParse(friend.Friend, out friendID)) 403 if (UUID.TryParse(friend.Friend, out friendID))
388 { 404 {
389 IClientAPI friendClient = LocateClientObject(friendID); 405 // Try local
390 if (friendClient != null) 406 if (LocalStatusNotification(userID, friendID, online))
391 {
392 //m_log.DebugFormat("[FRIENDS]: Notify {0} that user {1} is {2}", friend.Friend, userID, online);
393 // the friend in this sim as root agent
394 if (online)
395 friendClient.SendAgentOnline(new UUID[] { userID });
396 else
397 friendClient.SendAgentOffline(new UUID[] { userID });
398 // we're done
399 return; 407 return;
400 } 408
401
402 // The friend is not here [as root]. Let's forward. 409 // The friend is not here [as root]. Let's forward.
403 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); 410 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
404 PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); 411 PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions);
@@ -438,14 +445,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
438 // We stick this agent's ID as imSession, so that it's directly available on the receiving end 445 // We stick this agent's ID as imSession, so that it's directly available on the receiving end
439 im.imSessionID = im.fromAgentID; 446 im.imSessionID = im.fromAgentID;
440 447
441 IClientAPI friendClient = LocateClientObject(friendID); 448 // Try the local sim
442 if (friendClient != null) 449 if (LocalFriendshipOffered(friendID, im))
443 { 450 return;
444 // the prospective friend in this sim as root agent
445 friendClient.SendInstantMessage(im);
446 // we're done
447 return ;
448 }
449 451
450 // The prospective friend is not here [as root]. Let's forward. 452 // The prospective friend is not here [as root]. Let's forward.
451 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); 453 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
@@ -471,26 +473,20 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
471 // Notify the friend 473 // Notify the friend
472 // 474 //
473 475
474 IClientAPI friendClient = LocateClientObject(friendID); 476 // Try Local
475 if (friendClient != null) 477 if (LocalFriendshipApproved(agentID, client.Name, friendID))
476 { 478 {
477 // the prospective friend in this sim as root agent
478 GridInstantMessage im = new GridInstantMessage(client.Scene, client.AgentId, client.Name, friendID,
479 (byte)OpenMetaverse.InstantMessageDialog.FriendshipAccepted, client.AgentId.ToString(), false, Vector3.Zero);
480 friendClient.SendInstantMessage(im);
481 client.SendAgentOnline(new UUID[] { friendID }); 479 client.SendAgentOnline(new UUID[] { friendID });
482 // update the local cache
483 m_Friends[friendID].Friends = FriendsService.GetFriends(friendID);
484 // we're done
485 return; 480 return;
486 } 481 }
487 482
483 // The friend is not here
488 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); 484 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
489 PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); 485 PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions);
490 if (friendSession != null) 486 if (friendSession != null)
491 { 487 {
492 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); 488 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
493 m_FriendsSimConnector.FriendshipApproved(region, agentID, friendID); 489 m_FriendsSimConnector.FriendshipApproved(region, agentID, client.Name, friendID);
494 client.SendAgentOnline(new UUID[] { friendID }); 490 client.SendAgentOnline(new UUID[] { friendID });
495 } 491 }
496 492
@@ -507,24 +503,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
507 // Notify the friend 503 // Notify the friend
508 // 504 //
509 505
510 IClientAPI friendClient = LocateClientObject(friendID); 506 // Try local
511 if (friendClient != null) 507 if (LocalFriendshipDenied(agentID, client.Name, friendID))
512 {
513 // the prospective friend in this sim as root agent
514
515 GridInstantMessage im = new GridInstantMessage(client.Scene, client.AgentId, client.Name, friendID,
516 (byte)OpenMetaverse.InstantMessageDialog.FriendshipDeclined, client.AgentId.ToString(), false, Vector3.Zero);
517 friendClient.SendInstantMessage(im);
518 // we're done
519 return; 508 return;
520 }
521 509
522 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); 510 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() });
523 PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); 511 PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions);
524 if (friendSession != null) 512 if (friendSession != null)
525 { 513 {
526 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); 514 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
527 m_FriendsSimConnector.FriendshipDenied(region, agentID, friendID); 515 m_FriendsSimConnector.FriendshipDenied(region, agentID, client.Name, friendID);
528 } 516 }
529 } 517 }
530 518
@@ -542,16 +530,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
542 // Notify the friend 530 // Notify the friend
543 // 531 //
544 532
545 IClientAPI friendClient = LocateClientObject(exfriendID); 533 // Try local
546 if (friendClient != null) 534 if (LocalFriendshipTerminated(exfriendID))
547 {
548 // the friend in this sim as root agent
549 friendClient.SendTerminateFriend(exfriendID);
550 // update local cache
551 m_Friends[exfriendID].Friends = FriendsService.GetFriends(exfriendID);
552 // we're done
553 return; 535 return;
554 }
555 536
556 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { exfriendID.ToString() }); 537 PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { exfriendID.ToString() });
557 PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); 538 PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions);
@@ -587,5 +568,97 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
587 m_FriendsSimConnector.GrantRights(region, requester, target); 568 m_FriendsSimConnector.GrantRights(region, requester, target);
588 } 569 }
589 } 570 }
571
572 #region Local
573
574 public bool LocalFriendshipOffered(UUID toID, GridInstantMessage im)
575 {
576 IClientAPI friendClient = LocateClientObject(toID);
577 if (friendClient != null)
578 {
579 // the prospective friend in this sim as root agent
580 friendClient.SendInstantMessage(im);
581 // we're done
582 return true;
583 }
584 return false;
585 }
586
587 public bool LocalFriendshipApproved(UUID userID, string userName, UUID friendID)
588 {
589 IClientAPI friendClient = LocateClientObject(friendID);
590 if (friendClient != null)
591 {
592 // the prospective friend in this sim as root agent
593 GridInstantMessage im = new GridInstantMessage(Scene, userID, userName, friendID,
594 (byte)OpenMetaverse.InstantMessageDialog.FriendshipAccepted, userID.ToString(), false, Vector3.Zero);
595 friendClient.SendInstantMessage(im);
596 // update the local cache
597 m_Friends[friendID].Friends = FriendsService.GetFriends(friendID);
598 // we're done
599 return true;
600 }
601
602 return false;
603 }
604
605 public bool LocalFriendshipDenied(UUID userID, string userName, UUID friendID)
606 {
607 IClientAPI friendClient = LocateClientObject(friendID);
608 if (friendClient != null)
609 {
610 // the prospective friend in this sim as root agent
611
612 GridInstantMessage im = new GridInstantMessage(Scene, userID, userName, friendID,
613 (byte)OpenMetaverse.InstantMessageDialog.FriendshipDeclined, userID.ToString(), false, Vector3.Zero);
614 friendClient.SendInstantMessage(im);
615 // we're done
616 return true;
617 }
618
619 return false;
620 }
621
622 public bool LocalFriendshipTerminated(UUID exfriendID)
623 {
624 IClientAPI friendClient = LocateClientObject(exfriendID);
625 if (friendClient != null)
626 {
627 // the friend in this sim as root agent
628 friendClient.SendTerminateFriend(exfriendID);
629 // update local cache
630 m_Friends[exfriendID].Friends = FriendsService.GetFriends(exfriendID);
631 // we're done
632 return true;
633 }
634
635 return false;
636 }
637
638 public bool LocalGrantRights()
639 {
640 // TODO
641 return true;
642 }
643
644 public bool LocalStatusNotification(UUID userID, UUID friendID, bool online)
645 {
646 IClientAPI friendClient = LocateClientObject(friendID);
647 if (friendClient != null)
648 {
649 //m_log.DebugFormat("[FRIENDS]: Notify {0} that user {1} is {2}", friend.Friend, userID, online);
650 // the friend in this sim as root agent
651 if (online)
652 friendClient.SendAgentOnline(new UUID[] { userID });
653 else
654 friendClient.SendAgentOffline(new UUID[] { userID });
655 // we're done
656 return true;
657 }
658
659 return false;
660 }
661 #endregion
662
590 } 663 }
591} 664}
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs
index cde54ed..e7b74a9 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsRequestHandler.cs
@@ -75,8 +75,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
75 75
76 switch (method) 76 switch (method)
77 { 77 {
78 case "TEST": 78 case "friendship_offered":
79 break; 79 return FriendshipOffered(request);
80 case "friendship_approved":
81 return FriendshipApproved(request);
82 case "friendship_denied":
83 return FriendshipDenied(request);
84 case "friendship_terminated":
85 return FriendshipTerminated(request);
86 case "grant_rights":
87 return GrantRights(request);
88 case "status":
89 return StatusNotification(request);
80 } 90 }
81 } 91 }
82 catch (Exception e) 92 catch (Exception e)
@@ -87,6 +97,146 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
87 return FailureResult(); 97 return FailureResult();
88 } 98 }
89 99
100 byte[] FriendshipOffered(Dictionary<string, object> request)
101 {
102 UUID fromID = UUID.Zero;
103 UUID toID = UUID.Zero;
104 string message = string.Empty;
105
106 if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID"))
107 return FailureResult();
108
109 message = request["Message"].ToString();
110
111 if (!UUID.TryParse(request["FromID"].ToString(), out fromID))
112 return FailureResult();
113
114 if (!UUID.TryParse(request["ToID"].ToString(), out toID))
115 return FailureResult();
116
117 GridInstantMessage im = new GridInstantMessage(m_FriendsModule.Scene, fromID, "", toID,
118 (byte)InstantMessageDialog.FriendshipOffered, message, false, Vector3.Zero);
119
120 if (m_FriendsModule.LocalFriendshipOffered(toID, im))
121 return SuccessResult();
122
123 return FailureResult();
124 }
125
126 byte[] FriendshipApproved(Dictionary<string, object> request)
127 {
128 UUID fromID = UUID.Zero;
129 UUID toID = UUID.Zero;
130 string fromName = string.Empty;
131
132 if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID"))
133 return FailureResult();
134
135 if (!UUID.TryParse(request["FromID"].ToString(), out fromID))
136 return FailureResult();
137
138 if (!UUID.TryParse(request["ToID"].ToString(), out toID))
139 return FailureResult();
140
141 if (request.ContainsKey("FromName"))
142 fromName = request["FromName"].ToString();
143
144 if (m_FriendsModule.LocalFriendshipApproved(fromID, fromName, toID))
145 return SuccessResult();
146
147 return FailureResult();
148 }
149
150 byte[] FriendshipDenied(Dictionary<string, object> request)
151 {
152 UUID fromID = UUID.Zero;
153 UUID toID = UUID.Zero;
154 string fromName = string.Empty;
155
156 if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID"))
157 return FailureResult();
158
159 if (!UUID.TryParse(request["FromID"].ToString(), out fromID))
160 return FailureResult();
161
162 if (!UUID.TryParse(request["ToID"].ToString(), out toID))
163 return FailureResult();
164
165 if (request.ContainsKey("FromName"))
166 fromName = request["FromName"].ToString();
167
168 if (m_FriendsModule.LocalFriendshipDenied(fromID, fromName, toID))
169 return SuccessResult();
170
171 return FailureResult();
172 }
173
174 byte[] FriendshipTerminated(Dictionary<string, object> request)
175 {
176 UUID fromID = UUID.Zero;
177 UUID toID = UUID.Zero;
178
179 if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID"))
180 return FailureResult();
181
182 if (!UUID.TryParse(request["FromID"].ToString(), out fromID))
183 return FailureResult();
184
185 if (!UUID.TryParse(request["ToID"].ToString(), out toID))
186 return FailureResult();
187
188 if (m_FriendsModule.LocalFriendshipTerminated(toID))
189 return SuccessResult();
190
191 return FailureResult();
192 }
193
194 byte[] GrantRights(Dictionary<string, object> request)
195 {
196 UUID fromID = UUID.Zero;
197 UUID toID = UUID.Zero;
198
199 if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID"))
200 return FailureResult();
201
202 if (!UUID.TryParse(request["FromID"].ToString(), out fromID))
203 return FailureResult();
204
205 if (!UUID.TryParse(request["ToID"].ToString(), out toID))
206 return FailureResult();
207
208 if (m_FriendsModule.LocalGrantRights(/* ??? */))
209 return SuccessResult();
210
211 return FailureResult();
212 }
213
214 byte[] StatusNotification(Dictionary<string, object> request)
215 {
216 UUID fromID = UUID.Zero;
217 UUID toID = UUID.Zero;
218 bool online = false;
219
220 if (!request.ContainsKey("FromID") || !request.ContainsKey("ToID") || !request.ContainsKey("Online"))
221 return FailureResult();
222
223 if (!UUID.TryParse(request["FromID"].ToString(), out fromID))
224 return FailureResult();
225
226 if (!UUID.TryParse(request["ToID"].ToString(), out toID))
227 return FailureResult();
228
229 if (!Boolean.TryParse(request["Online"].ToString(), out online))
230 return FailureResult();
231
232 if (m_FriendsModule.LocalStatusNotification(fromID, toID, online))
233 return SuccessResult();
234
235 return FailureResult();
236 }
237
238 #region Misc
239
90 private byte[] FailureResult() 240 private byte[] FailureResult()
91 { 241 {
92 return BoolResult(false); 242 return BoolResult(false);
@@ -130,5 +280,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
130 return ms.ToArray(); 280 return ms.ToArray();
131 } 281 }
132 282
283 #endregion
133 } 284 }
134} 285}