aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs25
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs9
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs98
-rw-r--r--OpenSim/Region/CoreModules/Avatar/InstantMessage/HGMessageTransferModule.cs3
4 files changed, 121 insertions, 14 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
index c952ebf..7a2a46e 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
@@ -165,7 +165,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
165 165
166 // Instantiate the request handler 166 // Instantiate the request handler
167 IHttpServer server = MainServer.GetHttpServer((uint)mPort); 167 IHttpServer server = MainServer.GetHttpServer((uint)mPort);
168 server.AddStreamHandler(new FriendsRequestHandler(this)); 168
169 if (server != null)
170 server.AddStreamHandler(new FriendsRequestHandler(this));
169 } 171 }
170 172
171 if (m_FriendsService == null) 173 if (m_FriendsService == null)
@@ -352,18 +354,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
352 continue; 354 continue;
353 } 355 }
354 356
355 PresenceInfo presence = null;
356 PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid });
357 if (presences != null && presences.Length > 0)
358 presence = presences[0];
359 im.offline = 0; 357 im.offline = 0;
360
361 im.fromAgentID = fromAgentID.Guid; 358 im.fromAgentID = fromAgentID.Guid;
362 im.fromAgentName = firstname + " " + lastname; 359 im.fromAgentName = firstname + " " + lastname;
363 im.imSessionID = im.fromAgentID; 360 im.imSessionID = im.fromAgentID;
364 im.message = FriendshipMessage(fid); 361 im.message = FriendshipMessage(fid);
365 362
366 // Finally
367 LocalFriendshipOffered(agentID, im); 363 LocalFriendshipOffered(agentID, im);
368 } 364 }
369 365
@@ -574,9 +570,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
574 570
575 private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) 571 private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders)
576 { 572 {
577 m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", agentID, friendID); 573 m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", client.AgentId, friendID);
578 574
579 StoreFriendships(agentID, friendID); 575 AddFriendship(client, friendID);
576 }
577
578 public void AddFriendship(IClientAPI client, UUID friendID)
579 {
580 StoreFriendships(client.AgentId, friendID);
580 581
581 // Update the local cache 582 // Update the local cache
582 RefetchFriends(client); 583 RefetchFriends(client);
@@ -586,7 +587,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
586 // 587 //
587 588
588 // Try Local 589 // Try Local
589 if (LocalFriendshipApproved(agentID, client.Name, friendID)) 590 if (LocalFriendshipApproved(client.AgentId, client.Name, friendID))
590 { 591 {
591 client.SendAgentOnline(new UUID[] { friendID }); 592 client.SendAgentOnline(new UUID[] { friendID });
592 return; 593 return;
@@ -600,7 +601,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
600 if (friendSession != null) 601 if (friendSession != null)
601 { 602 {
602 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); 603 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
603 m_FriendsSimConnector.FriendshipApproved(region, agentID, client.Name, friendID); 604 m_FriendsSimConnector.FriendshipApproved(region, client.AgentId, client.Name, friendID);
604 client.SendAgentOnline(new UUID[] { friendID }); 605 client.SendAgentOnline(new UUID[] { friendID });
605 } 606 }
606 } 607 }
@@ -867,7 +868,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
867 } 868 }
868 869
869 /// <summary> 870 /// <summary>
870 /// Update loca cache only 871 /// Update local cache only
871 /// </summary> 872 /// </summary>
872 /// <param name="userID"></param> 873 /// <param name="userID"></param>
873 /// <param name="friendID"></param> 874 /// <param name="friendID"></param>
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
index dda67f9..02b417f 100644
--- a/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs
@@ -141,7 +141,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
141 { 141 {
142 List<string> fList = new List<string>(); 142 List<string> fList = new List<string>();
143 foreach (string s in friendList) 143 foreach (string s in friendList)
144 fList.Add(s.Substring(0, 36)); 144 {
145 if (s.Length < 36)
146 m_log.WarnFormat(
147 "[HGFRIENDS MODULE]: Ignoring friend {0} ({1} chars) for {2} since identifier too short",
148 s, s.Length, userID);
149 else
150 fList.Add(s.Substring(0, 36));
151 }
145 152
146 PresenceInfo[] presence = PresenceService.GetAgents(fList.ToArray()); 153 PresenceInfo[] presence = PresenceService.GetAgents(fList.ToArray());
147 foreach (PresenceInfo pi in presence) 154 foreach (PresenceInfo pi in presence)
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs
new file mode 100644
index 0000000..c945dcf
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs
@@ -0,0 +1,98 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using Nini.Config;
31using NUnit.Framework;
32using OpenMetaverse;
33using OpenSim.Framework;
34using OpenSim.Region.CoreModules.Avatar.Friends;
35using OpenSim.Region.Framework.Scenes;
36using OpenSim.Tests.Common;
37using OpenSim.Tests.Common.Mock;
38
39namespace OpenSim.Region.CoreModules.Avatar.Friends.Tests
40{
41 [TestFixture]
42 public class FriendsModuleTests
43 {
44 private FriendsModule m_fm;
45 private TestScene m_scene;
46
47 [SetUp]
48 public void Init()
49 {
50 IConfigSource config = new IniConfigSource();
51 config.AddConfig("Modules");
52 // Not strictly necessary since FriendsModule assumes it is the default (!)
53 config.Configs["Modules"].Set("FriendsModule", "FriendsModule");
54 config.AddConfig("Friends");
55 config.Configs["Friends"].Set("Connector", "OpenSim.Services.FriendsService.dll");
56 config.AddConfig("FriendsService");
57 config.Configs["FriendsService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
58
59 m_scene = SceneHelpers.SetupScene();
60 m_fm = new FriendsModule();
61 SceneHelpers.SetupSceneModules(m_scene, config, m_fm);
62 }
63
64 [Test]
65 public void TestNoFriends()
66 {
67 TestHelpers.InMethod();
68// log4net.Config.XmlConfigurator.Configure();
69
70 UUID userId = TestHelpers.ParseTail(0x1);
71
72 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
73
74 Assert.That(((TestClient)sp.ControllingClient).OfflineNotificationsReceived.Count, Is.EqualTo(0));
75 Assert.That(((TestClient)sp.ControllingClient).OnlineNotificationsReceived.Count, Is.EqualTo(0));
76 }
77
78 [Test]
79 public void TestAddFriendWhileOnline()
80 {
81 TestHelpers.InMethod();
82// log4net.Config.XmlConfigurator.Configure();
83
84 UUID userId = TestHelpers.ParseTail(0x1);
85 UUID user2Id = TestHelpers.ParseTail(0x2);
86
87 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
88 SceneHelpers.AddScenePresence(m_scene, user2Id);
89
90 // This fiendship is two-way but without a connector, only the first user will receive the online
91 // notification.
92 m_fm.AddFriendship(sp.ControllingClient, user2Id);
93
94 Assert.That(((TestClient)sp.ControllingClient).OfflineNotificationsReceived.Count, Is.EqualTo(0));
95 Assert.That(((TestClient)sp.ControllingClient).OnlineNotificationsReceived.Count, Is.EqualTo(1));
96 }
97 }
98} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/HGMessageTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/HGMessageTransferModule.cs
index 321a705..560d913 100644
--- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/HGMessageTransferModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/HGMessageTransferModule.cs
@@ -225,12 +225,13 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
225 foreach (Scene scene in m_Scenes) 225 foreach (Scene scene in m_Scenes)
226 { 226 {
227 ScenePresence sp = scene.GetScenePresence(toAgentID); 227 ScenePresence sp = scene.GetScenePresence(toAgentID);
228 if(!sp.IsChildAgent) 228 if(sp != null && !sp.IsChildAgent)
229 { 229 {
230 scene.EventManager.TriggerIncomingInstantMessage(gim); 230 scene.EventManager.TriggerIncomingInstantMessage(gim);
231 successful = true; 231 successful = true;
232 } 232 }
233 } 233 }
234
234 if (!successful) 235 if (!successful)
235 { 236 {
236 // If the message can't be delivered to an agent, it 237 // If the message can't be delivered to an agent, it