aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar
diff options
context:
space:
mode:
authorMelanie2011-11-14 20:03:47 +0000
committerMelanie2011-11-14 20:03:47 +0000
commitafca742392e30748de13a125f932046949af0bcb (patch)
tree34e9dd92533abe446e356d9fb1ad8625cb28c9bc /OpenSim/Region/CoreModules/Avatar
parentMerge branch 'master' into bigmerge (diff)
parentminor: remove some mono compiler warnings (diff)
downloadopensim-SC-afca742392e30748de13a125f932046949af0bcb.zip
opensim-SC-afca742392e30748de13a125f932046949af0bcb.tar.gz
opensim-SC-afca742392e30748de13a125f932046949af0bcb.tar.bz2
opensim-SC-afca742392e30748de13a125f932046949af0bcb.tar.xz
Merge branch 'master' into bigmerge
Conflicts: OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs28
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/HGFriendsModule.cs9
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs97
-rw-r--r--OpenSim/Region/CoreModules/Avatar/InstantMessage/HGMessageTransferModule.cs3
4 files changed, 121 insertions, 16 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs
index a5131ec..74f32e7 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,20 +354,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
352 continue; 354 continue;
353 } 355 }
354 356
355 PresenceInfo presence = null; 357 im.offline = 0;
356 PresenceInfo[] presences = PresenceService.GetAgents(new string[] { fid });
357 if (presences != null && presences.Length > 0)
358 presence = presences[0];
359 if (presence != null)
360 im.offline = 0;
361
362 im.fromAgentID = fromAgentID.Guid; 358 im.fromAgentID = fromAgentID.Guid;
363 im.fromAgentName = firstname + " " + lastname; 359 im.fromAgentName = firstname + " " + lastname;
364 im.offline = (byte)((presence == null) ? 1 : 0); 360 im.offline = (byte)((presence == null) ? 1 : 0);
365 im.imSessionID = im.fromAgentID; 361 im.imSessionID = im.fromAgentID;
366 im.message = FriendshipMessage(fid); 362 im.message = FriendshipMessage(fid);
367 363
368 // Finally
369 LocalFriendshipOffered(agentID, im); 364 LocalFriendshipOffered(agentID, im);
370 } 365 }
371 366
@@ -576,9 +571,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
576 571
577 private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders) 572 private void OnApproveFriendRequest(IClientAPI client, UUID agentID, UUID friendID, List<UUID> callingCardFolders)
578 { 573 {
579 m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", agentID, friendID); 574 m_log.DebugFormat("[FRIENDS]: {0} accepted friendship from {1}", client.AgentId, friendID);
580 575
581 StoreFriendships(agentID, friendID); 576 AddFriend(client, friendID);
577 }
578
579 public void AddFriend(IClientAPI client, UUID friendID)
580 {
581 StoreFriendships(client.AgentId, friendID);
582 582
583 ICallingCardModule ccm = client.Scene.RequestModuleInterface<ICallingCardModule>(); 583 ICallingCardModule ccm = client.Scene.RequestModuleInterface<ICallingCardModule>();
584 if (ccm != null) 584 if (ccm != null)
@@ -594,7 +594,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
594 // 594 //
595 595
596 // Try Local 596 // Try Local
597 if (LocalFriendshipApproved(agentID, client.Name, friendID)) 597 if (LocalFriendshipApproved(client.AgentId, client.Name, friendID))
598 { 598 {
599 client.SendAgentOnline(new UUID[] { friendID }); 599 client.SendAgentOnline(new UUID[] { friendID });
600 return; 600 return;
@@ -608,7 +608,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
608 if (friendSession != null) 608 if (friendSession != null)
609 { 609 {
610 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); 610 GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID);
611 m_FriendsSimConnector.FriendshipApproved(region, agentID, client.Name, friendID); 611 m_FriendsSimConnector.FriendshipApproved(region, client.AgentId, client.Name, friendID);
612 client.SendAgentOnline(new UUID[] { friendID }); 612 client.SendAgentOnline(new UUID[] { friendID });
613 } 613 }
614 } 614 }
@@ -882,7 +882,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
882 } 882 }
883 883
884 /// <summary> 884 /// <summary>
885 /// Update loca cache only 885 /// Update local cache only
886 /// </summary> 886 /// </summary>
887 /// <param name="userID"></param> 887 /// <param name="userID"></param>
888 /// <param name="friendID"></param> 888 /// <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..942091c
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/Tests/FriendModuleTests.cs
@@ -0,0 +1,97 @@
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 friendship is currently only one-way, which might be pathalogical in Second Life.
91 m_fm.AddFriend(sp.ControllingClient, user2Id);
92
93 Assert.That(((TestClient)sp.ControllingClient).OfflineNotificationsReceived.Count, Is.EqualTo(0));
94 Assert.That(((TestClient)sp.ControllingClient).OnlineNotificationsReceived.Count, Is.EqualTo(1));
95 }
96 }
97} \ 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