aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/Hypergrid/HGSceneCommunicationService.cs
diff options
context:
space:
mode:
authorDr Scofield2009-02-06 16:55:34 +0000
committerDr Scofield2009-02-06 16:55:34 +0000
commit9b66108081a8c8cf79faaa6c541554091c40850e (patch)
tree095a232ae5a9de3a9244bcd34da08294f61eeea5 /OpenSim/Region/Environment/Scenes/Hypergrid/HGSceneCommunicationService.cs
parent* removed superfluous constants class (diff)
downloadopensim-SC_OLD-9b66108081a8c8cf79faaa6c541554091c40850e.zip
opensim-SC_OLD-9b66108081a8c8cf79faaa6c541554091c40850e.tar.gz
opensim-SC_OLD-9b66108081a8c8cf79faaa6c541554091c40850e.tar.bz2
opensim-SC_OLD-9b66108081a8c8cf79faaa6c541554091c40850e.tar.xz
This changeset is the step 1 of 2 in refactoring
OpenSim.Region.Environment into a "framework" part and a modules only part. This first changeset refactors OpenSim.Region.Environment.Scenes, OpenSim.Region.Environment.Interfaces, and OpenSim.Region.Interfaces into OpenSim.Region.Framework.{Interfaces,Scenes} leaving only region modules in OpenSim.Region.Environment. The next step will be to move region modules up from OpenSim.Region.Environment.Modules to OpenSim.Region.CoreModules and then sort out which modules are really core modules and which should move out to forge. I've been very careful to NOT BREAK anything. i hope i've succeeded. as this is the work of a whole week i hope i managed to keep track with the applied patches of the last week --- could any of you that did check in stuff have a look at whether it survived? thx!
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/Hypergrid/HGSceneCommunicationService.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/Hypergrid/HGSceneCommunicationService.cs363
1 files changed, 0 insertions, 363 deletions
diff --git a/OpenSim/Region/Environment/Scenes/Hypergrid/HGSceneCommunicationService.cs b/OpenSim/Region/Environment/Scenes/Hypergrid/HGSceneCommunicationService.cs
deleted file mode 100644
index 5e3e03f..0000000
--- a/OpenSim/Region/Environment/Scenes/Hypergrid/HGSceneCommunicationService.cs
+++ /dev/null
@@ -1,363 +0,0 @@
1/**
2 * Copyright (c) 2008, Contributors. All rights reserved.
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the Organizations nor the names of Individual
14 * Contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25 * OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29using System;
30using System.Collections.Generic;
31using System.Net;
32using System.Reflection;
33using System.Threading;
34using log4net;
35using OpenMetaverse;
36using OSD = OpenMetaverse.StructuredData.OSD;
37using OpenSim.Framework;
38using OpenSim.Framework.Communications;
39using OpenSim.Framework.Communications.Cache;
40using OpenSim.Framework.Communications.Capabilities;
41using OpenSim.Region.Environment.Scenes;
42using OpenSim.Region.Environment;
43using OpenSim.Region.Interfaces;
44
45namespace OpenSim.Region.Environment.Scenes.Hypergrid
46{
47 public class HGSceneCommunicationService : SceneCommunicationService
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 public readonly IHyperlink m_hg;
52
53 public HGSceneCommunicationService(CommunicationsManager commsMan, IHyperlink hg) : base(commsMan)
54 {
55 m_hg = hg;
56 }
57
58
59 /// <summary>
60 /// Try to teleport an agent to a new region.
61 /// </summary>
62 /// <param name="remoteClient"></param>
63 /// <param name="RegionHandle"></param>
64 /// <param name="position"></param>
65 /// <param name="lookAt"></param>
66 /// <param name="flags"></param>
67 public override void RequestTeleportToLocation(ScenePresence avatar, ulong regionHandle, Vector3 position,
68 Vector3 lookAt, uint teleportFlags)
69 {
70 if (!avatar.Scene.Permissions.CanTeleport(avatar.UUID))
71 return;
72
73 bool destRegionUp = true;
74
75 IEventQueue eq = avatar.Scene.RequestModuleInterface<IEventQueue>();
76
77 if (regionHandle == m_regionInfo.RegionHandle)
78 {
79 // Teleport within the same region
80 if (position.X < 0 || position.X > Constants.RegionSize || position.Y < 0 || position.Y > Constants.RegionSize || position.Z < 0)
81 {
82 Vector3 emergencyPos = new Vector3(128, 128, 128);
83
84 m_log.WarnFormat(
85 "[HGSceneCommService]: RequestTeleportToLocation() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}",
86 position, avatar.Name, avatar.UUID, emergencyPos);
87 position = emergencyPos;
88 }
89 // TODO: Get proper AVG Height
90 float localAVHeight = 1.56f;
91 float posZLimit = (float)avatar.Scene.GetLandHeight((int)position.X, (int)position.Y);
92 float newPosZ = posZLimit + localAVHeight;
93 if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
94 {
95 position.Z = newPosZ;
96 }
97
98 // Only send this if the event queue is null
99 if (eq == null)
100 avatar.ControllingClient.SendTeleportLocationStart();
101
102
103 avatar.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags);
104 avatar.Teleport(position);
105 }
106 else
107 {
108 RegionInfo reg = RequestNeighbouringRegionInfo(regionHandle);
109 if (reg != null)
110 {
111
112 uint newRegionX = (uint)(reg.RegionHandle >> 40);
113 uint newRegionY = (((uint)(reg.RegionHandle)) >> 8);
114 uint oldRegionX = (uint)(m_regionInfo.RegionHandle >> 40);
115 uint oldRegionY = (((uint)(m_regionInfo.RegionHandle)) >> 8);
116
117 ///
118 /// Hypergrid mod start
119 ///
120 ///
121 bool isHyperLink = m_hg.IsHyperlinkRegion(reg.RegionHandle);
122 bool isHomeUser = true;
123 ulong realHandle = regionHandle;
124 CachedUserInfo uinfo = m_commsProvider.UserProfileCacheService.GetUserDetails(avatar.UUID);
125 if (uinfo != null)
126 {
127 isHomeUser = HGNetworkServersInfo.Singleton.IsLocalUser(uinfo.UserProfile);
128 realHandle = m_hg.FindRegionHandle(regionHandle);
129 Console.WriteLine("XXX ---- home user? " + isHomeUser + " --- hyperlink? " + isHyperLink + " --- real handle: " + realHandle.ToString());
130 }
131 ///
132 /// Hypergrid mod stop
133 ///
134 ///
135
136 if (eq == null)
137 avatar.ControllingClient.SendTeleportLocationStart();
138
139
140 // Let's do DNS resolution only once in this process, please!
141 // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field,
142 // it's actually doing a lot of work.
143 IPEndPoint endPoint = reg.ExternalEndPoint;
144 if (endPoint.Address == null)
145 {
146 // Couldn't resolve the name. Can't TP, because the viewer wants IP addresses.
147 destRegionUp = false;
148 }
149
150 if (destRegionUp)
151 {
152 // Fixing a bug where teleporting while sitting results in the avatar ending up removed from
153 // both regions
154 if (avatar.ParentID != (uint)0)
155 avatar.StandUp();
156
157 if (!avatar.ValidateAttachments())
158 {
159 avatar.ControllingClient.SendTeleportFailed("Inconsistent attachment state");
160 return;
161 }
162
163 // the avatar.Close below will clear the child region list. We need this below for (possibly)
164 // closing the child agents, so save it here (we need a copy as it is Clear()-ed).
165 //List<ulong> childRegions = new List<ulong>(avatar.GetKnownRegionList());
166 // Compared to ScenePresence.CrossToNewRegion(), there's no obvious code to handle a teleport
167 // failure at this point (unlike a border crossing failure). So perhaps this can never fail
168 // once we reach here...
169 //avatar.Scene.RemoveCapsHandler(avatar.UUID);
170
171 string capsPath = String.Empty;
172 AgentCircuitData agentCircuit = avatar.ControllingClient.RequestClientInfo();
173 agentCircuit.BaseFolder = UUID.Zero;
174 agentCircuit.InventoryFolder = UUID.Zero;
175 agentCircuit.startpos = position;
176 agentCircuit.child = true;
177 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY))
178 {
179 // brand new agent, let's create a new caps seed
180 agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
181 }
182
183 //if (!m_commsProvider.InterRegion.InformRegionOfChildAgent(reg.RegionHandle, agentCircuit))
184 if (!m_interregionCommsOut.SendCreateChildAgent(reg.RegionHandle, agentCircuit))
185 {
186 avatar.ControllingClient.SendTeleportFailed("Destination is not accepting teleports.");
187 return;
188 }
189
190 // Let's close some agents
191 if (isHyperLink) // close them all except this one
192 {
193 List<ulong> regions = new List<ulong>(avatar.KnownChildRegionHandles);
194 regions.Remove(avatar.Scene.RegionInfo.RegionHandle);
195 SendCloseChildAgentConnections(avatar.UUID, regions);
196 }
197 else // close just a few
198 avatar.CloseChildAgents(newRegionX, newRegionY);
199
200 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY) || isHyperLink)
201 {
202 capsPath
203 = "http://"
204 + reg.ExternalHostName
205 + ":"
206 + reg.HttpPort
207 + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
208
209 if (eq != null)
210 {
211 OSD Item = EventQueueHelper.EnableSimulator(realHandle, endPoint);
212 eq.Enqueue(Item, avatar.UUID);
213
214 // ES makes the client send a UseCircuitCode message to the destination,
215 // which triggers a bunch of things there.
216 // So let's wait
217 Thread.Sleep(2000);
218
219 Item = EventQueueHelper.EstablishAgentCommunication(avatar.UUID, endPoint.ToString(), capsPath);
220 eq.Enqueue(Item, avatar.UUID);
221 }
222 else
223 {
224 avatar.ControllingClient.InformClientOfNeighbour(realHandle, endPoint);
225 // TODO: make Event Queue disablable!
226 }
227 }
228 else
229 {
230 // child agent already there
231 agentCircuit.CapsPath = avatar.Scene.CapsModule.GetChildSeed(avatar.UUID, reg.RegionHandle);
232 capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort
233 + "/CAPS/" + agentCircuit.CapsPath + "0000/";
234 }
235
236 //m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId,
237 // position, false);
238
239 //if (!m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId,
240 // position, false))
241 //{
242 // avatar.ControllingClient.SendTeleportFailed("Problem with destination.");
243 // // We should close that agent we just created over at destination...
244 // List<ulong> lst = new List<ulong>();
245 // lst.Add(realHandle);
246 // SendCloseChildAgentAsync(avatar.UUID, lst);
247 // return;
248 //}
249
250 SetInTransit(avatar.UUID);
251 // Let's send a full update of the agent. This is a synchronous call.
252 AgentData agent = new AgentData();
253 avatar.CopyTo(agent);
254 agent.Position = position;
255 agent.CallbackURI = "http://" + m_regionInfo.ExternalHostName + ":" + m_regionInfo.HttpPort +
256 "/agent/" + avatar.UUID.ToString() + "/" + avatar.Scene.RegionInfo.RegionHandle.ToString() + "/release/";
257
258 m_interregionCommsOut.SendChildAgentUpdate(reg.RegionHandle, agent);
259
260 m_log.DebugFormat(
261 "[CAPS]: Sending new CAPS seed url {0} to client {1}", agentCircuit.CapsPath, avatar.UUID);
262
263
264 ///
265 /// Hypergrid mod: realHandle instead of reg.RegionHandle
266 ///
267 ///
268 if (eq != null)
269 {
270 OSD Item = EventQueueHelper.TeleportFinishEvent(realHandle, 13, endPoint,
271 4, teleportFlags, capsPath, avatar.UUID);
272 eq.Enqueue(Item, avatar.UUID);
273 }
274 else
275 {
276 avatar.ControllingClient.SendRegionTeleport(realHandle, 13, endPoint, 4,
277 teleportFlags, capsPath);
278 }
279 ///
280 /// Hypergrid mod stop
281 ///
282
283
284 // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which
285 // trigers a whole shebang of things there, including MakeRoot. So let's wait for confirmation
286 // that the client contacted the destination before we send the attachments and close things here.
287 if (!WaitForCallback(avatar.UUID))
288 {
289 // Client never contacted destination. Let's restore everything back
290 avatar.ControllingClient.SendTeleportFailed("Problems connecting to destination.");
291
292 ResetFromTransit(avatar.UUID);
293 // Yikes! We should just have a ref to scene here.
294 avatar.Scene.InformClientOfNeighbours(avatar);
295
296 // Finally, kill the agent we just created at the destination.
297 m_interregionCommsOut.SendCloseAgent(reg.RegionHandle, avatar.UUID);
298
299 return;
300 }
301
302 // Can't go back from here
303 if (KiPrimitive != null)
304 {
305 KiPrimitive(avatar.LocalId);
306 }
307
308 avatar.MakeChildAgent();
309
310 // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it
311 avatar.CrossAttachmentsIntoNewRegion(reg.RegionHandle, true);
312
313
314 // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone
315 ///
316 /// Hypergrid mod: extra check for isHyperLink
317 ///
318 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY) || isHyperLink)
319 {
320 Thread.Sleep(5000);
321 avatar.Close();
322 CloseConnection(avatar.UUID);
323 }
324 // if (teleport success) // seems to be always success here
325 // the user may change their profile information in other region,
326 // so the userinfo in UserProfileCache is not reliable any more, delete it
327 if (avatar.Scene.NeedSceneCacheClear(avatar.UUID) || isHyperLink)
328 {
329 m_commsProvider.UserProfileCacheService.RemoveUser(avatar.UUID);
330 m_log.DebugFormat(
331 "[HGSceneCommService]: User {0} is going to another region, profile cache removed",
332 avatar.UUID);
333 }
334 }
335 else
336 {
337 avatar.ControllingClient.SendTeleportFailed("Remote Region appears to be down");
338 }
339 }
340 else
341 {
342 // TP to a place that doesn't exist (anymore)
343 // Inform the viewer about that
344 avatar.ControllingClient.SendTeleportFailed("The region you tried to teleport to doesn't exist anymore");
345
346 // and set the map-tile to '(Offline)'
347 uint regX, regY;
348 Utils.LongToUInts(regionHandle, out regX, out regY);
349
350 MapBlockData block = new MapBlockData();
351 block.X = (ushort)(regX / Constants.RegionSize);
352 block.Y = (ushort)(regY / Constants.RegionSize);
353 block.Access = 254; // == not there
354
355 List<MapBlockData> blocks = new List<MapBlockData>();
356 blocks.Add(block);
357 avatar.ControllingClient.SendMapBlock(blocks, 0);
358 }
359 }
360 }
361
362 }
363}