aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Avatar/Friends
diff options
context:
space:
mode:
authorAdam Frisby2008-04-30 21:43:47 +0000
committerAdam Frisby2008-04-30 21:43:47 +0000
commitbe20f41637b6c06ce3ab16bc25851b6e43468e12 (patch)
treec41081329891f4c24de704fc760fb9012954ac9d /OpenSim/Region/Environment/Modules/Avatar/Friends
parent* Sometimes you know, you do something really stupid. (diff)
downloadopensim-SC_OLD-be20f41637b6c06ce3ab16bc25851b6e43468e12.zip
opensim-SC_OLD-be20f41637b6c06ce3ab16bc25851b6e43468e12.tar.gz
opensim-SC_OLD-be20f41637b6c06ce3ab16bc25851b6e43468e12.tar.bz2
opensim-SC_OLD-be20f41637b6c06ce3ab16bc25851b6e43468e12.tar.xz
* Cruft removal step #1. Cleaning Modules directory.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Avatar/Friends')
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs165
1 files changed, 81 insertions, 84 deletions
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs
index 3b0cc4c..db38d87 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs
@@ -42,13 +42,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
42 { 42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 44
45 private Dictionary<LLUUID, List<FriendListItem>> FriendLists = new Dictionary<LLUUID, List<FriendListItem>>();
46 private Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>();
47 private Dictionary<LLUUID, ulong> m_rootAgents = new Dictionary<LLUUID, ulong>();
45 private List<Scene> m_scene = new List<Scene>(); 48 private List<Scene> m_scene = new List<Scene>();
46 49
47 Dictionary<LLUUID, ulong> m_rootAgents = new Dictionary<LLUUID, ulong>(); 50 #region IRegionModule Members
48
49 Dictionary<LLUUID, LLUUID> m_pendingFriendRequests = new Dictionary<LLUUID, LLUUID>();
50
51 Dictionary<LLUUID, List<FriendListItem>> FriendLists = new Dictionary<LLUUID, List<FriendListItem>>();
52 51
53 public void Initialise(Scene scene, IConfigSource config) 52 public void Initialise(Scene scene, IConfigSource config)
54 { 53 {
@@ -68,11 +67,33 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
68 scene.EventManager.OnMakeChildAgent += MakeChildAgent; 67 scene.EventManager.OnMakeChildAgent += MakeChildAgent;
69 scene.EventManager.OnClientClosed += ClientLoggedOut; 68 scene.EventManager.OnClientClosed += ClientLoggedOut;
70 } 69 }
70
71 public void PostInitialise()
72 {
73 }
74
75 public void Close()
76 {
77 }
78
79 public string Name
80 {
81 get { return "FriendsModule"; }
82 }
83
84 public bool IsSharedModule
85 {
86 get { return true; }
87 }
88
89 #endregion
90
71 public XmlRpcResponse processPresenceUpdate(XmlRpcRequest req) 91 public XmlRpcResponse processPresenceUpdate(XmlRpcRequest req)
72 { 92 {
73 m_log.Info("[FRIENDS]: Got Notification about a user! OMG"); 93 m_log.Info("[FRIENDS]: Got Notification about a user! OMG");
74 return new XmlRpcResponse(); 94 return new XmlRpcResponse();
75 } 95 }
96
76 private void OnNewClient(IClientAPI client) 97 private void OnNewClient(IClientAPI client)
77 { 98 {
78 // All friends establishment protocol goes over instant message 99 // All friends establishment protocol goes over instant message
@@ -83,7 +104,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
83 // Generated by LoginService. The friends are retreived from the database by the UserManager 104 // Generated by LoginService. The friends are retreived from the database by the UserManager
84 105
85 // Subscribe to instant messages 106 // Subscribe to instant messages
86 107
87 client.OnInstantMessage += OnInstantMessage; 108 client.OnInstantMessage += OnInstantMessage;
88 client.OnApproveFriendRequest += OnApprovedFriendRequest; 109 client.OnApproveFriendRequest += OnApprovedFriendRequest;
89 client.OnDenyFriendRequest += OnDenyFriendRequest; 110 client.OnDenyFriendRequest += OnDenyFriendRequest;
@@ -99,10 +120,10 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
99 { 120 {
100 fl = FriendLists[client.AgentId]; 121 fl = FriendLists[client.AgentId];
101 } 122 }
102 else 123 else
103 { 124 {
104 fl = m_scene[0].GetFriendList(client.AgentId); 125 fl = m_scene[0].GetFriendList(client.AgentId);
105 126
106 //lock (FriendLists) 127 //lock (FriendLists)
107 //{ 128 //{
108 if (!FriendLists.ContainsKey(client.AgentId)) 129 if (!FriendLists.ContainsKey(client.AgentId))
@@ -110,11 +131,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
110 //} 131 //}
111 } 132 }
112 } 133 }
113 134
114 List<LLUUID> UpdateUsers = new List<LLUUID>(); 135 List<LLUUID> UpdateUsers = new List<LLUUID>();
115 136
116 foreach (FriendListItem f in fl) 137 foreach (FriendListItem f in fl)
117 { 138 {
118 if (m_rootAgents.ContainsKey(f.Friend)) 139 if (m_rootAgents.ContainsKey(f.Friend))
119 { 140 {
120 if (f.onlinestatus == false) 141 if (f.onlinestatus == false)
@@ -169,10 +190,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
169 onp.AgentBlock = onpb; 190 onp.AgentBlock = onpb;
170 client.OutPacket(onp, ThrottleOutPacketType.Task); 191 client.OutPacket(onp, ThrottleOutPacketType.Task);
171 } 192 }
172
173
174
175
176 } 193 }
177 194
178 private void ClientLoggedOut(LLUUID AgentId) 195 private void ClientLoggedOut(LLUUID AgentId)
@@ -182,7 +199,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
182 if (m_rootAgents.ContainsKey(AgentId)) 199 if (m_rootAgents.ContainsKey(AgentId))
183 { 200 {
184 m_rootAgents.Remove(AgentId); 201 m_rootAgents.Remove(AgentId);
185 m_log.Info("[FRIEND]: Removing " + AgentId + ". Agent logged out."); 202 m_log.Info("[FRIEND]: Removing " + AgentId + ". Agent logged out.");
186 } 203 }
187 } 204 }
188 List<FriendListItem> lfli = new List<FriendListItem>(); 205 List<FriendListItem> lfli = new List<FriendListItem>();
@@ -208,7 +225,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
208 List<FriendListItem> flfli = new List<FriendListItem>(); 225 List<FriendListItem> flfli = new List<FriendListItem>();
209 try 226 try
210 { 227 {
211
212 lock (FriendLists) 228 lock (FriendLists)
213 { 229 {
214 if (FriendLists.ContainsKey(updateUsers[i])) 230 if (FriendLists.ContainsKey(updateUsers[i]))
@@ -231,9 +247,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
231 { 247 {
232 flfli[i].onlinestatus = false; 248 flfli[i].onlinestatus = false;
233 } 249 }
234
235 } 250 }
236 251
237 catch (IndexOutOfRangeException) 252 catch (IndexOutOfRangeException)
238 { 253 {
239 // Ignore the index out of range exception. 254 // Ignore the index out of range exception.
@@ -242,15 +257,13 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
242 m_log.Info("[FRIEND]: Unable to enumerate last friendlist user. User logged off"); 257 m_log.Info("[FRIEND]: Unable to enumerate last friendlist user. User logged off");
243 } 258 }
244 } 259 }
245
246 } 260 }
247 261
248 for (int i = 0; i < updateUsers.Count; i++) 262 for (int i = 0; i < updateUsers.Count; i++)
249 { 263 {
250 ScenePresence av = GetPresenceFromAgentID(updateUsers[i]); 264 ScenePresence av = GetPresenceFromAgentID(updateUsers[i]);
251 if (av != null) 265 if (av != null)
252 { 266 {
253
254 OfflineNotificationPacket onp = new OfflineNotificationPacket(); 267 OfflineNotificationPacket onp = new OfflineNotificationPacket();
255 OfflineNotificationPacket.AgentBlockBlock[] onpb = new OfflineNotificationPacket.AgentBlockBlock[1]; 268 OfflineNotificationPacket.AgentBlockBlock[] onpb = new OfflineNotificationPacket.AgentBlockBlock[1];
256 OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock(); 269 OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock();
@@ -265,7 +278,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
265 { 278 {
266 FriendLists.Remove(AgentId); 279 FriendLists.Remove(AgentId);
267 } 280 }
268
269 } 281 }
270 282
271 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID) 283 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID)
@@ -282,7 +294,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
282 { 294 {
283 JId avatarID = new JId(avatar.JID); 295 JId avatarID = new JId(avatar.JID);
284 // REST Post XMPP Stanzas! 296 // REST Post XMPP Stanzas!
285
286 } 297 }
287 // Claim User! my user! Mine mine mine! 298 // Claim User! my user! Mine mine mine!
288 } 299 }
@@ -295,9 +306,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
295 } 306 }
296 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); 307 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
297 } 308 }
309
298 private void MakeChildAgent(ScenePresence avatar) 310 private void MakeChildAgent(ScenePresence avatar)
299 { 311 {
300
301 lock (m_rootAgents) 312 lock (m_rootAgents)
302 { 313 {
303 if (m_rootAgents.ContainsKey(avatar.UUID)) 314 if (m_rootAgents.ContainsKey(avatar.UUID))
@@ -307,30 +318,53 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
307 m_rootAgents.Remove(avatar.UUID); 318 m_rootAgents.Remove(avatar.UUID);
308 m_log.Info("[FRIEND]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent"); 319 m_log.Info("[FRIEND]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent");
309 } 320 }
310
311 } 321 }
312 } 322 }
323 }
313 324
325 private ScenePresence GetPresenceFromAgentID(LLUUID AgentID)
326 {
327 ScenePresence returnAgent = null;
328 lock (m_scene)
329 {
330 ScenePresence queryagent = null;
331 for (int i = 0; i < m_scene.Count; i++)
332 {
333 queryagent = m_scene[i].GetScenePresence(AgentID);
334 if (queryagent != null)
335 {
336 if (!queryagent.IsChildAgent)
337 {
338 returnAgent = queryagent;
339 break;
340 }
341 }
342 }
343 }
344 return returnAgent;
314 } 345 }
346
315 #region FriendRequestHandling 347 #region FriendRequestHandling
316 private void OnInstantMessage(IClientAPI client,LLUUID fromAgentID, 348
349 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID,
317 LLUUID fromAgentSession, LLUUID toAgentID, 350 LLUUID fromAgentSession, LLUUID toAgentID,
318 LLUUID imSessionID, uint timestamp, string fromAgentName, 351 LLUUID imSessionID, uint timestamp, string fromAgentName,
319 string message, byte dialog, bool fromGroup, byte offline, 352 string message, byte dialog, bool fromGroup, byte offline,
320 uint ParentEstateID, LLVector3 Position, LLUUID RegionID, 353 uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
321 byte[] binaryBucket) 354 byte[] binaryBucket)
322 { 355 {
323 // Friend Requests go by Instant Message.. using the dialog param 356 // Friend Requests go by Instant Message.. using the dialog param
324 // https://wiki.secondlife.com/wiki/ImprovedInstantMessage 357 // https://wiki.secondlife.com/wiki/ImprovedInstantMessage
325 358
326 // 38 == Offer friendship 359 // 38 == Offer friendship
327 if (dialog == (byte)38) 360 if (dialog == (byte) 38)
328 { 361 {
329 LLUUID friendTransactionID = LLUUID.Random(); 362 LLUUID friendTransactionID = LLUUID.Random();
330 363
331 m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); 364 m_pendingFriendRequests.Add(friendTransactionID, fromAgentID);
332 365
333 m_log.Info("[FRIEND]: 38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); 366 m_log.Info("[FRIEND]: 38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" +
367 message);
334 GridInstantMessage msg = new GridInstantMessage(); 368 GridInstantMessage msg = new GridInstantMessage();
335 msg.fromAgentID = fromAgentID.UUID; 369 msg.fromAgentID = fromAgentID.UUID;
336 msg.fromAgentSession = fromAgentSession.UUID; 370 msg.fromAgentSession = fromAgentSession.UUID;
@@ -340,11 +374,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
340 msg.timestamp = timestamp; 374 msg.timestamp = timestamp;
341 if (client != null) 375 if (client != null)
342 { 376 {
343 msg.fromAgentName = client.FirstName + " " + client.LastName;// fromAgentName; 377 msg.fromAgentName = client.FirstName + " " + client.LastName; // fromAgentName;
344 } 378 }
345 else 379 else
346 { 380 {
347 msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it 381 msg.fromAgentName = "(hippos)"; // Added for posterity. This means that we can't figure out who sent it
348 } 382 }
349 msg.message = message; 383 msg.message = message;
350 msg.dialog = dialog; 384 msg.dialog = dialog;
@@ -359,15 +393,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
359 } 393 }
360 394
361 // 39 == Accept Friendship 395 // 39 == Accept Friendship
362 if (dialog == (byte)39) 396 if (dialog == (byte) 39)
363 { 397 {
364 m_log.Info("[FRIEND]: 39 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); 398 m_log.Info("[FRIEND]: 39 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" +
399 message);
365 } 400 }
366 401
367 // 40 == Decline Friendship 402 // 40 == Decline Friendship
368 if (dialog == (byte)40) 403 if (dialog == (byte) 40)
369 { 404 {
370 m_log.Info("[FRIEND]: 40 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); 405 m_log.Info("[FRIEND]: 40 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" +
406 message);
371 } 407 }
372 } 408 }
373 409
@@ -395,16 +431,16 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
395 msg.imSessionID = transactionID.UUID; 431 msg.imSessionID = transactionID.UUID;
396 msg.message = agentID.UUID.ToString(); 432 msg.message = agentID.UUID.ToString();
397 msg.ParentEstateID = 0; 433 msg.ParentEstateID = 0;
398 msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); 434 msg.timestamp = (uint) Util.UnixTimeSinceEpoch();
399 msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; 435 msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID;
400 msg.dialog = (byte)39;// Approved friend request 436 msg.dialog = (byte) 39; // Approved friend request
401 msg.Position = new sLLVector3(); 437 msg.Position = new sLLVector3();
402 msg.offline = (byte)0; 438 msg.offline = (byte) 0;
403 msg.binaryBucket = new byte[0]; 439 msg.binaryBucket = new byte[0];
404 // We don't really care which scene we pipe it through, it goes to the shared IM Module and/or the database 440 // We don't really care which scene we pipe it through, it goes to the shared IM Module and/or the database
405 441
406 SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); 442 SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
407 SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint)1); 443 SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint) 1);
408 m_pendingFriendRequests.Remove(transactionID); 444 m_pendingFriendRequests.Remove(transactionID);
409 445
410 // TODO: Inform agent that the friend is online 446 // TODO: Inform agent that the friend is online
@@ -433,11 +469,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
433 msg.imSessionID = transactionID.UUID; 469 msg.imSessionID = transactionID.UUID;
434 msg.message = agentID.UUID.ToString(); 470 msg.message = agentID.UUID.ToString();
435 msg.ParentEstateID = 0; 471 msg.ParentEstateID = 0;
436 msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); 472 msg.timestamp = (uint) Util.UnixTimeSinceEpoch();
437 msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; 473 msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID;
438 msg.dialog = (byte)40;// Deny friend request 474 msg.dialog = (byte) 40; // Deny friend request
439 msg.Position = new sLLVector3(); 475 msg.Position = new sLLVector3();
440 msg.offline = (byte)0; 476 msg.offline = (byte) 0;
441 msg.binaryBucket = new byte[0]; 477 msg.binaryBucket = new byte[0];
442 SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); 478 SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule);
443 m_pendingFriendRequests.Remove(transactionID); 479 m_pendingFriendRequests.Remove(transactionID);
@@ -453,52 +489,13 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
453 private void OnGridInstantMessage(GridInstantMessage msg) 489 private void OnGridInstantMessage(GridInstantMessage msg)
454 { 490 {
455 // Trigger the above event handler 491 // Trigger the above event handler
456 OnInstantMessage(null,new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession), 492 OnInstantMessage(null, new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession),
457 new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName, 493 new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName,
458 msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID, 494 msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID,
459 new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID), 495 new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID),
460 msg.binaryBucket); 496 msg.binaryBucket);
461 } 497 }
462 #endregion
463 private ScenePresence GetPresenceFromAgentID(LLUUID AgentID)
464 {
465 ScenePresence returnAgent = null;
466 lock (m_scene)
467 {
468 ScenePresence queryagent = null;
469 for (int i = 0; i < m_scene.Count; i++)
470 {
471 queryagent = m_scene[i].GetScenePresence(AgentID);
472 if (queryagent != null)
473 {
474 if (!queryagent.IsChildAgent)
475 {
476 returnAgent = queryagent;
477 break;
478 }
479 }
480 }
481 }
482 return returnAgent;
483
484 }
485
486 public void PostInitialise()
487 {
488 }
489
490 public void Close()
491 {
492 }
493 498
494 public string Name 499 #endregion
495 {
496 get { return "FriendsModule"; }
497 }
498
499 public bool IsSharedModule
500 {
501 get { return true; }
502 }
503 } 500 }
504} \ No newline at end of file 501} \ No newline at end of file