diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Chat')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs | 30 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Chat/Tests/ChatModuleTests.cs | 285 |
2 files changed, 314 insertions, 1 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs index 9d70063..2801ef0 100644 --- a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs | |||
@@ -214,10 +214,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat | |||
214 | UUID destination = c.Destination; | 214 | UUID destination = c.Destination; |
215 | Vector3 fromPos = c.Position; | 215 | Vector3 fromPos = c.Position; |
216 | Vector3 regionPos = new Vector3(scene.RegionInfo.WorldLocX, scene.RegionInfo.WorldLocY, 0); | 216 | Vector3 regionPos = new Vector3(scene.RegionInfo.WorldLocX, scene.RegionInfo.WorldLocY, 0); |
217 | <<<<<<< HEAD | ||
218 | ======= | ||
217 | 219 | ||
218 | bool checkParcelHide = false; | 220 | bool checkParcelHide = false; |
219 | UUID sourceParcelID = UUID.Zero; | 221 | UUID sourceParcelID = UUID.Zero; |
220 | Vector3 hidePos = fromPos; | 222 | Vector3 hidePos = fromPos; |
223 | >>>>>>> avn/ubitvar | ||
221 | 224 | ||
222 | if (c.Channel == DEBUG_CHANNEL) c.Type = ChatTypeEnum.DebugChannel; | 225 | if (c.Channel == DEBUG_CHANNEL) c.Type = ChatTypeEnum.DebugChannel; |
223 | 226 | ||
@@ -355,22 +358,46 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat | |||
355 | string fromName = c.From; | 358 | string fromName = c.From; |
356 | 359 | ||
357 | UUID fromID = UUID.Zero; | 360 | UUID fromID = UUID.Zero; |
361 | UUID ownerID = UUID.Zero; | ||
358 | ChatSourceType sourceType = ChatSourceType.Object; | 362 | ChatSourceType sourceType = ChatSourceType.Object; |
359 | if (null != c.Sender) | 363 | if (null != c.Sender) |
360 | { | 364 | { |
361 | ScenePresence avatar = (c.Scene as Scene).GetScenePresence(c.Sender.AgentId); | 365 | ScenePresence avatar = (c.Scene as Scene).GetScenePresence(c.Sender.AgentId); |
362 | fromID = c.Sender.AgentId; | 366 | fromID = c.Sender.AgentId; |
363 | fromName = avatar.Name; | 367 | fromName = avatar.Name; |
368 | ownerID = c.Sender.AgentId; | ||
364 | sourceType = ChatSourceType.Agent; | 369 | sourceType = ChatSourceType.Agent; |
365 | } | 370 | } |
366 | else if (c.SenderUUID != UUID.Zero) | 371 | else if (c.SenderUUID != UUID.Zero) |
367 | { | 372 | { |
368 | fromID = c.SenderUUID; | 373 | fromID = c.SenderUUID; |
374 | ownerID = ((SceneObjectPart)c.SenderObject).OwnerID; | ||
369 | } | 375 | } |
370 | 376 | ||
371 | // m_log.DebugFormat("[CHAT] Broadcast: fromID {0} fromName {1}, cType {2}, sType {3}", fromID, fromName, cType, sourceType); | 377 | // m_log.DebugFormat("[CHAT] Broadcast: fromID {0} fromName {1}, cType {2}, sType {3}", fromID, fromName, cType, sourceType); |
372 | HashSet<UUID> receiverIDs = new HashSet<UUID>(); | 378 | HashSet<UUID> receiverIDs = new HashSet<UUID>(); |
373 | 379 | ||
380 | <<<<<<< HEAD | ||
381 | ((Scene)c.Scene).ForEachRootClient( | ||
382 | delegate(IClientAPI client) | ||
383 | { | ||
384 | // don't forward SayOwner chat from objects to | ||
385 | // non-owner agents | ||
386 | if ((c.Type == ChatTypeEnum.Owner) && | ||
387 | (null != c.SenderObject) && | ||
388 | (((SceneObjectPart)c.SenderObject).OwnerID != client.AgentId)) | ||
389 | return; | ||
390 | |||
391 | client.SendChatMessage( | ||
392 | c.Message, (byte)cType, CenterOfRegion, fromName, fromID, ownerID, | ||
393 | (byte)sourceType, (byte)ChatAudibleLevel.Fully); | ||
394 | |||
395 | receiverIDs.Add(client.AgentId); | ||
396 | }); | ||
397 | |||
398 | (c.Scene as Scene).EventManager.TriggerOnChatToClients( | ||
399 | fromID, receiverIDs, c.Message, cType, CenterOfRegion, fromName, sourceType, ChatAudibleLevel.Fully); | ||
400 | ======= | ||
374 | if (c.Scene != null) | 401 | if (c.Scene != null) |
375 | { | 402 | { |
376 | ((Scene)c.Scene).ForEachRootClient | 403 | ((Scene)c.Scene).ForEachRootClient |
@@ -392,6 +419,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat | |||
392 | (c.Scene as Scene).EventManager.TriggerOnChatToClients( | 419 | (c.Scene as Scene).EventManager.TriggerOnChatToClients( |
393 | fromID, receiverIDs, c.Message, cType, CenterOfRegion, fromName, sourceType, ChatAudibleLevel.Fully); | 420 | fromID, receiverIDs, c.Message, cType, CenterOfRegion, fromName, sourceType, ChatAudibleLevel.Fully); |
394 | } | 421 | } |
422 | >>>>>>> avn/ubitvar | ||
395 | } | 423 | } |
396 | 424 | ||
397 | /// <summary> | 425 | /// <summary> |
diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/Tests/ChatModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Chat/Tests/ChatModuleTests.cs new file mode 100644 index 0000000..3018d94 --- /dev/null +++ b/OpenSim/Region/CoreModules/Avatar/Chat/Tests/ChatModuleTests.cs | |||
@@ -0,0 +1,285 @@ | |||
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.Generic; | ||
30 | using log4net.Config; | ||
31 | using Nini.Config; | ||
32 | using NUnit.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Servers; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Region.CoreModules.Avatar.Chat; | ||
38 | using OpenSim.Region.CoreModules.Framework; | ||
39 | using OpenSim.Region.CoreModules.Framework.EntityTransfer; | ||
40 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | using OpenSim.Services.Interfaces; | ||
43 | using OpenSim.Tests.Common; | ||
44 | |||
45 | namespace OpenSim.Region.CoreModules.Avatar.Chat.Tests | ||
46 | { | ||
47 | [TestFixture] | ||
48 | public class ChatModuleTests : OpenSimTestCase | ||
49 | { | ||
50 | [TestFixtureSetUp] | ||
51 | public void FixtureInit() | ||
52 | { | ||
53 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. | ||
54 | // We must do this here so that child agent positions are updated in a predictable manner. | ||
55 | Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest; | ||
56 | } | ||
57 | |||
58 | [TestFixtureTearDown] | ||
59 | public void TearDown() | ||
60 | { | ||
61 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple | ||
62 | // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression | ||
63 | // tests really shouldn't). | ||
64 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; | ||
65 | } | ||
66 | |||
67 | private void SetupNeighbourRegions(TestScene sceneA, TestScene sceneB) | ||
68 | { | ||
69 | // XXX: HTTP server is not (and should not be) necessary for this test, though it's absence makes the | ||
70 | // CapabilitiesModule complain when it can't set up HTTP endpoints. | ||
71 | // BaseHttpServer httpServer = new BaseHttpServer(99999); | ||
72 | // MainServer.AddHttpServer(httpServer); | ||
73 | // MainServer.Instance = httpServer; | ||
74 | |||
75 | // We need entity transfer modules so that when sp2 logs into the east region, the region calls | ||
76 | // EntityTransferModuleto set up a child agent on the west region. | ||
77 | // XXX: However, this is not an entity transfer so is misleading. | ||
78 | EntityTransferModule etmA = new EntityTransferModule(); | ||
79 | EntityTransferModule etmB = new EntityTransferModule(); | ||
80 | LocalSimulationConnectorModule lscm = new LocalSimulationConnectorModule(); | ||
81 | |||
82 | IConfigSource config = new IniConfigSource(); | ||
83 | config.AddConfig("Chat"); | ||
84 | IConfig modulesConfig = config.AddConfig("Modules"); | ||
85 | modulesConfig.Set("EntityTransferModule", etmA.Name); | ||
86 | modulesConfig.Set("SimulationServices", lscm.Name); | ||
87 | |||
88 | SceneHelpers.SetupSceneModules(new Scene[] { sceneA, sceneB }, config, lscm); | ||
89 | SceneHelpers.SetupSceneModules(sceneA, config, new CapabilitiesModule(), etmA, new ChatModule()); | ||
90 | SceneHelpers.SetupSceneModules(sceneB, config, new CapabilitiesModule(), etmB, new ChatModule()); | ||
91 | } | ||
92 | |||
93 | /// <summary> | ||
94 | /// Tests chat between neighbour regions on the east-west axis | ||
95 | /// </summary> | ||
96 | /// <remarks> | ||
97 | /// Really, this is a combination of a child agent position update test and a chat range test. These need | ||
98 | /// to be separated later on. | ||
99 | /// </remarks> | ||
100 | [Test] | ||
101 | public void TestInterRegionChatDistanceEastWest() | ||
102 | { | ||
103 | TestHelpers.InMethod(); | ||
104 | // TestHelpers.EnableLogging(); | ||
105 | |||
106 | UUID sp1Uuid = TestHelpers.ParseTail(0x11); | ||
107 | UUID sp2Uuid = TestHelpers.ParseTail(0x12); | ||
108 | |||
109 | Vector3 sp1Position = new Vector3(6, 128, 20); | ||
110 | Vector3 sp2Position = new Vector3(250, 128, 20); | ||
111 | |||
112 | SceneHelpers sh = new SceneHelpers(); | ||
113 | TestScene sceneWest = sh.SetupScene("sceneWest", TestHelpers.ParseTail(0x1), 1000, 1000); | ||
114 | TestScene sceneEast = sh.SetupScene("sceneEast", TestHelpers.ParseTail(0x2), 1001, 1000); | ||
115 | |||
116 | SetupNeighbourRegions(sceneWest, sceneEast); | ||
117 | |||
118 | ScenePresence sp1 = SceneHelpers.AddScenePresence(sceneEast, sp1Uuid); | ||
119 | TestClient sp1Client = (TestClient)sp1.ControllingClient; | ||
120 | |||
121 | // If we don't set agents to flying, test will go wrong as they instantly fall to z = 0. | ||
122 | // TODO: May need to create special complete no-op test physics module rather than basic physics, since | ||
123 | // physics is irrelevant to this test. | ||
124 | sp1.Flying = true; | ||
125 | |||
126 | // When sp1 logs in to sceneEast, it sets up a child agent in sceneWest and informs the sp2 client to | ||
127 | // make the connection. For this test, will simplify this chain by making the connection directly. | ||
128 | ScenePresence sp1Child = SceneHelpers.AddChildScenePresence(sceneWest, sp1Uuid); | ||
129 | TestClient sp1ChildClient = (TestClient)sp1Child.ControllingClient; | ||
130 | |||
131 | sp1.AbsolutePosition = sp1Position; | ||
132 | |||
133 | ScenePresence sp2 = SceneHelpers.AddScenePresence(sceneWest, sp2Uuid); | ||
134 | TestClient sp2Client = (TestClient)sp2.ControllingClient; | ||
135 | sp2.Flying = true; | ||
136 | |||
137 | ScenePresence sp2Child = SceneHelpers.AddChildScenePresence(sceneEast, sp2Uuid); | ||
138 | TestClient sp2ChildClient = (TestClient)sp2Child.ControllingClient; | ||
139 | |||
140 | sp2.AbsolutePosition = sp2Position; | ||
141 | |||
142 | // We must update the scenes in order to make the root new root agents trigger position updates in their | ||
143 | // children. | ||
144 | sceneWest.Update(1); | ||
145 | sceneEast.Update(1); | ||
146 | |||
147 | // Check child positions are correct. | ||
148 | Assert.AreEqual( | ||
149 | new Vector3(sp1Position.X + sceneEast.RegionInfo.RegionSizeX, sp1Position.Y, sp1Position.Z), | ||
150 | sp1ChildClient.SceneAgent.AbsolutePosition); | ||
151 | |||
152 | Assert.AreEqual( | ||
153 | new Vector3(sp2Position.X - sceneWest.RegionInfo.RegionSizeX, sp2Position.Y, sp2Position.Z), | ||
154 | sp2ChildClient.SceneAgent.AbsolutePosition); | ||
155 | |||
156 | string receivedSp1ChatMessage = ""; | ||
157 | string receivedSp2ChatMessage = ""; | ||
158 | |||
159 | sp1ChildClient.OnReceivedChatMessage | ||
160 | += (message, type, fromPos, fromName, fromAgentID, ownerID, source, audible) => receivedSp1ChatMessage = message; | ||
161 | sp2ChildClient.OnReceivedChatMessage | ||
162 | += (message, type, fromPos, fromName, fromAgentID, ownerID, source, audible) => receivedSp2ChatMessage = message; | ||
163 | |||
164 | TestUserInRange(sp1Client, "ello darling", ref receivedSp2ChatMessage); | ||
165 | TestUserInRange(sp2Client, "fantastic cats", ref receivedSp1ChatMessage); | ||
166 | |||
167 | sp1Position = new Vector3(30, 128, 20); | ||
168 | sp1.AbsolutePosition = sp1Position; | ||
169 | sceneEast.Update(1); | ||
170 | |||
171 | // Check child position is correct. | ||
172 | Assert.AreEqual( | ||
173 | new Vector3(sp1Position.X + sceneEast.RegionInfo.RegionSizeX, sp1Position.Y, sp1Position.Z), | ||
174 | sp1ChildClient.SceneAgent.AbsolutePosition); | ||
175 | |||
176 | TestUserOutOfRange(sp1Client, "beef", ref receivedSp2ChatMessage); | ||
177 | TestUserOutOfRange(sp2Client, "lentils", ref receivedSp1ChatMessage); | ||
178 | } | ||
179 | |||
180 | /// <summary> | ||
181 | /// Tests chat between neighbour regions on the north-south axis | ||
182 | /// </summary> | ||
183 | /// <remarks> | ||
184 | /// Really, this is a combination of a child agent position update test and a chat range test. These need | ||
185 | /// to be separated later on. | ||
186 | /// </remarks> | ||
187 | [Test] | ||
188 | public void TestInterRegionChatDistanceNorthSouth() | ||
189 | { | ||
190 | TestHelpers.InMethod(); | ||
191 | // TestHelpers.EnableLogging(); | ||
192 | |||
193 | UUID sp1Uuid = TestHelpers.ParseTail(0x11); | ||
194 | UUID sp2Uuid = TestHelpers.ParseTail(0x12); | ||
195 | |||
196 | Vector3 sp1Position = new Vector3(128, 250, 20); | ||
197 | Vector3 sp2Position = new Vector3(128, 6, 20); | ||
198 | |||
199 | SceneHelpers sh = new SceneHelpers(); | ||
200 | TestScene sceneNorth = sh.SetupScene("sceneNorth", TestHelpers.ParseTail(0x1), 1000, 1000); | ||
201 | TestScene sceneSouth = sh.SetupScene("sceneSouth", TestHelpers.ParseTail(0x2), 1000, 1001); | ||
202 | |||
203 | SetupNeighbourRegions(sceneNorth, sceneSouth); | ||
204 | |||
205 | ScenePresence sp1 = SceneHelpers.AddScenePresence(sceneNorth, sp1Uuid); | ||
206 | TestClient sp1Client = (TestClient)sp1.ControllingClient; | ||
207 | |||
208 | // If we don't set agents to flying, test will go wrong as they instantly fall to z = 0. | ||
209 | // TODO: May need to create special complete no-op test physics module rather than basic physics, since | ||
210 | // physics is irrelevant to this test. | ||
211 | sp1.Flying = true; | ||
212 | |||
213 | // When sp1 logs in to sceneEast, it sets up a child agent in sceneNorth and informs the sp2 client to | ||
214 | // make the connection. For this test, will simplify this chain by making the connection directly. | ||
215 | ScenePresence sp1Child = SceneHelpers.AddChildScenePresence(sceneSouth, sp1Uuid); | ||
216 | TestClient sp1ChildClient = (TestClient)sp1Child.ControllingClient; | ||
217 | |||
218 | sp1.AbsolutePosition = sp1Position; | ||
219 | |||
220 | ScenePresence sp2 = SceneHelpers.AddScenePresence(sceneSouth, sp2Uuid); | ||
221 | TestClient sp2Client = (TestClient)sp2.ControllingClient; | ||
222 | sp2.Flying = true; | ||
223 | |||
224 | ScenePresence sp2Child = SceneHelpers.AddChildScenePresence(sceneNorth, sp2Uuid); | ||
225 | TestClient sp2ChildClient = (TestClient)sp2Child.ControllingClient; | ||
226 | |||
227 | sp2.AbsolutePosition = sp2Position; | ||
228 | |||
229 | // We must update the scenes in order to make the root new root agents trigger position updates in their | ||
230 | // children. | ||
231 | sceneNorth.Update(1); | ||
232 | sceneSouth.Update(1); | ||
233 | |||
234 | // Check child positions are correct. | ||
235 | Assert.AreEqual( | ||
236 | new Vector3(sp1Position.X, sp1Position.Y - sceneNorth.RegionInfo.RegionSizeY, sp1Position.Z), | ||
237 | sp1ChildClient.SceneAgent.AbsolutePosition); | ||
238 | |||
239 | Assert.AreEqual( | ||
240 | new Vector3(sp2Position.X, sp2Position.Y + sceneSouth.RegionInfo.RegionSizeY, sp2Position.Z), | ||
241 | sp2ChildClient.SceneAgent.AbsolutePosition); | ||
242 | |||
243 | string receivedSp1ChatMessage = ""; | ||
244 | string receivedSp2ChatMessage = ""; | ||
245 | |||
246 | sp1ChildClient.OnReceivedChatMessage | ||
247 | += (message, type, fromPos, fromName, fromAgentID, ownerID, source, audible) => receivedSp1ChatMessage = message; | ||
248 | sp2ChildClient.OnReceivedChatMessage | ||
249 | += (message, type, fromPos, fromName, fromAgentID, ownerID, source, audible) => receivedSp2ChatMessage = message; | ||
250 | |||
251 | TestUserInRange(sp1Client, "ello darling", ref receivedSp2ChatMessage); | ||
252 | TestUserInRange(sp2Client, "fantastic cats", ref receivedSp1ChatMessage); | ||
253 | |||
254 | sp1Position = new Vector3(30, 128, 20); | ||
255 | sp1.AbsolutePosition = sp1Position; | ||
256 | sceneNorth.Update(1); | ||
257 | |||
258 | // Check child position is correct. | ||
259 | Assert.AreEqual( | ||
260 | new Vector3(sp1Position.X, sp1Position.Y - sceneNorth.RegionInfo.RegionSizeY, sp1Position.Z), | ||
261 | sp1ChildClient.SceneAgent.AbsolutePosition); | ||
262 | |||
263 | TestUserOutOfRange(sp1Client, "beef", ref receivedSp2ChatMessage); | ||
264 | TestUserOutOfRange(sp2Client, "lentils", ref receivedSp1ChatMessage); | ||
265 | } | ||
266 | |||
267 | private void TestUserInRange(TestClient speakClient, string testMessage, ref string receivedMessage) | ||
268 | { | ||
269 | receivedMessage = ""; | ||
270 | |||
271 | speakClient.Chat(0, ChatTypeEnum.Say, testMessage); | ||
272 | |||
273 | Assert.AreEqual(testMessage, receivedMessage); | ||
274 | } | ||
275 | |||
276 | private void TestUserOutOfRange(TestClient speakClient, string testMessage, ref string receivedMessage) | ||
277 | { | ||
278 | receivedMessage = ""; | ||
279 | |||
280 | speakClient.Chat(0, ChatTypeEnum.Say, testMessage); | ||
281 | |||
282 | Assert.AreNotEqual(testMessage, receivedMessage); | ||
283 | } | ||
284 | } | ||
285 | } \ No newline at end of file | ||