aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/Hypergrid
diff options
context:
space:
mode:
authorDiva Canto2010-01-15 15:11:58 -0800
committerDiva Canto2010-01-15 15:11:58 -0800
commitf1c30784ac767bf5f62e81748984b76d85d71f6a (patch)
tree5aa635eadb534f30cd8aa2b9a1803f637e9b95a6 /OpenSim/Region/Framework/Scenes/Hypergrid
parentAdded a UserAccountCache to the UserAccountServiceConnectors. Uses a CenomeCa... (diff)
downloadopensim-SC-f1c30784ac767bf5f62e81748984b76d85d71f6a.zip
opensim-SC-f1c30784ac767bf5f62e81748984b76d85d71f6a.tar.gz
opensim-SC-f1c30784ac767bf5f62e81748984b76d85d71f6a.tar.bz2
opensim-SC-f1c30784ac767bf5f62e81748984b76d85d71f6a.tar.xz
* General cleanup of Teleports, Crossings and Child agents. They are now in the new AgentTransferModule, in line with what MW started implementing back in May -- ITeleportModule. This has been renamed IAgentTransferModule, to be more generic.
* HGSceneCommunicationService has been deleted * SceneCommunicationService will likely be deleted soon too
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Hypergrid')
-rw-r--r--OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs387
1 files changed, 0 insertions, 387 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs b/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs
deleted file mode 100644
index b27be80..0000000
--- a/OpenSim/Region/Framework/Scenes/Hypergrid/HGSceneCommunicationService.cs
+++ /dev/null
@@ -1,387 +0,0 @@
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 System.Net;
31using System.Reflection;
32using System.Threading;
33using log4net;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Framework.Client;
37using OpenSim.Framework.Communications;
38using OpenSim.Framework.Capabilities;
39using OpenSim.Region.Framework.Interfaces;
40using OpenSim.Services.Interfaces;
41using GridRegion = OpenSim.Services.Interfaces.GridRegion;
42
43namespace OpenSim.Region.Framework.Scenes.Hypergrid
44{
45 public class HGSceneCommunicationService : SceneCommunicationService
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private IHyperlinkService m_hg;
50 IHyperlinkService HyperlinkService
51 {
52 get
53 {
54 if (m_hg == null)
55 m_hg = m_scene.RequestModuleInterface<IHyperlinkService>();
56 return m_hg;
57 }
58 }
59
60 public HGSceneCommunicationService() : base()
61 {
62 }
63
64
65 /// <summary>
66 /// Try to teleport an agent to a new region.
67 /// </summary>
68 /// <param name="remoteClient"></param>
69 /// <param name="RegionHandle"></param>
70 /// <param name="position"></param>
71 /// <param name="lookAt"></param>
72 /// <param name="flags"></param>
73 public override void RequestTeleportToLocation(ScenePresence avatar, ulong regionHandle, Vector3 position,
74 Vector3 lookAt, uint teleportFlags)
75 {
76 if (!avatar.Scene.Permissions.CanTeleport(avatar.UUID))
77 return;
78
79 bool destRegionUp = true;
80
81 IEventQueue eq = avatar.Scene.RequestModuleInterface<IEventQueue>();
82
83 // Reset animations; the viewer does that in teleports.
84 avatar.Animator.ResetAnimations();
85
86 if (regionHandle == m_regionInfo.RegionHandle)
87 {
88 // Teleport within the same region
89 if (IsOutsideRegion(avatar.Scene, position) || position.Z < 0)
90 {
91 Vector3 emergencyPos = new Vector3(128, 128, 128);
92
93 m_log.WarnFormat(
94 "[HGSceneCommService]: RequestTeleportToLocation() was given an illegal position of {0} for avatar {1}, {2}. Substituting {3}",
95 position, avatar.Name, avatar.UUID, emergencyPos);
96 position = emergencyPos;
97 }
98 // TODO: Get proper AVG Height
99 float localAVHeight = 1.56f;
100
101 float posZLimit = 22;
102
103 if (position.X > 0 && position.X <= (int)Constants.RegionSize && position.Y > 0 && position.Y <= (int)Constants.RegionSize)
104 {
105 posZLimit = (float) avatar.Scene.Heightmap[(int) position.X, (int) position.Y];
106 }
107
108 float newPosZ = posZLimit + localAVHeight;
109 if (posZLimit >= (position.Z - (localAVHeight / 2)) && !(Single.IsInfinity(newPosZ) || Single.IsNaN(newPosZ)))
110 {
111 position.Z = newPosZ;
112 }
113
114 // Only send this if the event queue is null
115 if (eq == null)
116 avatar.ControllingClient.SendTeleportLocationStart();
117
118
119 avatar.ControllingClient.SendLocalTeleport(position, lookAt, teleportFlags);
120 avatar.Teleport(position);
121 }
122 else
123 {
124 uint x = 0, y = 0;
125 Utils.LongToUInts(regionHandle, out x, out y);
126 GridRegion reg = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
127
128 if (reg != null)
129 {
130
131 uint newRegionX = (uint)(reg.RegionHandle >> 40);
132 uint newRegionY = (((uint)(reg.RegionHandle)) >> 8);
133 uint oldRegionX = (uint)(m_regionInfo.RegionHandle >> 40);
134 uint oldRegionY = (((uint)(m_regionInfo.RegionHandle)) >> 8);
135
136 ///
137 /// Hypergrid mod start
138 ///
139 ///
140 bool isHyperLink = (HyperlinkService.GetHyperlinkRegion(reg.RegionHandle) != null);
141 bool isHomeUser = true;
142 ulong realHandle = regionHandle;
143 isHomeUser = HyperlinkService.IsLocalUser(avatar.UUID);
144 realHandle = m_hg.FindRegionHandle(regionHandle);
145 m_log.Debug("XXX ---- home user? " + isHomeUser + " --- hyperlink? " + isHyperLink + " --- real handle: " + realHandle.ToString());
146 ///
147 /// Hypergrid mod stop
148 ///
149 ///
150
151 if (eq == null)
152 avatar.ControllingClient.SendTeleportLocationStart();
153
154
155 // Let's do DNS resolution only once in this process, please!
156 // This may be a costly operation. The reg.ExternalEndPoint field is not a passive field,
157 // it's actually doing a lot of work.
158 IPEndPoint endPoint = reg.ExternalEndPoint;
159 if (endPoint.Address == null)
160 {
161 // Couldn't resolve the name. Can't TP, because the viewer wants IP addresses.
162 destRegionUp = false;
163 }
164
165 if (destRegionUp)
166 {
167 // Fixing a bug where teleporting while sitting results in the avatar ending up removed from
168 // both regions
169 if (avatar.ParentID != (uint)0)
170 avatar.StandUp();
171
172 if (!avatar.ValidateAttachments())
173 {
174 avatar.ControllingClient.SendTeleportFailed("Inconsistent attachment state");
175 return;
176 }
177
178 // the avatar.Close below will clear the child region list. We need this below for (possibly)
179 // closing the child agents, so save it here (we need a copy as it is Clear()-ed).
180 //List<ulong> childRegions = new List<ulong>(avatar.GetKnownRegionList());
181 // Compared to ScenePresence.CrossToNewRegion(), there's no obvious code to handle a teleport
182 // failure at this point (unlike a border crossing failure). So perhaps this can never fail
183 // once we reach here...
184 //avatar.Scene.RemoveCapsHandler(avatar.UUID);
185
186 string capsPath = String.Empty;
187 AgentCircuitData agentCircuit = avatar.ControllingClient.RequestClientInfo();
188 agentCircuit.BaseFolder = UUID.Zero;
189 agentCircuit.InventoryFolder = UUID.Zero;
190 agentCircuit.startpos = position;
191 agentCircuit.child = true;
192 agentCircuit.Appearance = avatar.Appearance;
193
194 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY))
195 {
196 // brand new agent, let's create a new caps seed
197 agentCircuit.CapsPath = CapsUtil.GetRandomCapsObjectPath();
198 }
199
200 string reason = String.Empty;
201
202 if (!m_scene.SimulationService.CreateAgent(reg, agentCircuit, teleportFlags, out reason))
203 {
204 avatar.ControllingClient.SendTeleportFailed(String.Format("Destination is not accepting teleports: {0}",
205 reason));
206 return;
207 }
208
209 // Let's close some agents
210 if (isHyperLink) // close them all except this one
211 {
212 List<ulong> regions = new List<ulong>(avatar.KnownChildRegionHandles);
213 regions.Remove(avatar.Scene.RegionInfo.RegionHandle);
214 SendCloseChildAgentConnections(avatar.UUID, regions);
215 }
216 else // close just a few
217 avatar.CloseChildAgents(newRegionX, newRegionY);
218
219 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY) || isHyperLink)
220 {
221 capsPath
222 = "http://"
223 + reg.ExternalHostName
224 + ":"
225 + reg.HttpPort
226 + CapsUtil.GetCapsSeedPath(agentCircuit.CapsPath);
227
228 if (eq != null)
229 {
230 #region IP Translation for NAT
231 IClientIPEndpoint ipepClient;
232 if (avatar.ClientView.TryGet(out ipepClient))
233 {
234 endPoint.Address = NetworkUtil.GetIPFor(ipepClient.EndPoint, endPoint.Address);
235 }
236 #endregion
237
238 eq.EnableSimulator(realHandle, endPoint, avatar.UUID);
239
240 // ES makes the client send a UseCircuitCode message to the destination,
241 // which triggers a bunch of things there.
242 // So let's wait
243 Thread.Sleep(2000);
244
245 eq.EstablishAgentCommunication(avatar.UUID, endPoint, capsPath);
246 }
247 else
248 {
249 avatar.ControllingClient.InformClientOfNeighbour(realHandle, endPoint);
250 // TODO: make Event Queue disablable!
251 }
252 }
253 else
254 {
255 // child agent already there
256 agentCircuit.CapsPath = avatar.Scene.CapsModule.GetChildSeed(avatar.UUID, reg.RegionHandle);
257 capsPath = "http://" + reg.ExternalHostName + ":" + reg.HttpPort
258 + "/CAPS/" + agentCircuit.CapsPath + "0000/";
259 }
260
261 //m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId,
262 // position, false);
263
264 //if (!m_commsProvider.InterRegion.ExpectAvatarCrossing(reg.RegionHandle, avatar.ControllingClient.AgentId,
265 // position, false))
266 //{
267 // avatar.ControllingClient.SendTeleportFailed("Problem with destination.");
268 // // We should close that agent we just created over at destination...
269 // List<ulong> lst = new List<ulong>();
270 // lst.Add(realHandle);
271 // SendCloseChildAgentAsync(avatar.UUID, lst);
272 // return;
273 //}
274
275 SetInTransit(avatar.UUID);
276 // Let's send a full update of the agent. This is a synchronous call.
277 AgentData agent = new AgentData();
278 avatar.CopyTo(agent);
279 agent.Position = position;
280 agent.CallbackURI = "http://" + m_regionInfo.ExternalHostName + ":" + m_regionInfo.HttpPort +
281 "/agent/" + avatar.UUID.ToString() + "/" + avatar.Scene.RegionInfo.RegionID.ToString() + "/release/";
282
283 m_scene.SimulationService.UpdateAgent(reg, agent);
284
285 m_log.DebugFormat(
286 "[CAPS]: Sending new CAPS seed url {0} to client {1}", capsPath, avatar.UUID);
287
288
289 ///
290 /// Hypergrid mod: realHandle instead of reg.RegionHandle
291 ///
292 ///
293 if (eq != null)
294 {
295 eq.TeleportFinishEvent(realHandle, 13, endPoint,
296 4, teleportFlags, capsPath, avatar.UUID);
297 }
298 else
299 {
300 avatar.ControllingClient.SendRegionTeleport(realHandle, 13, endPoint, 4,
301 teleportFlags, capsPath);
302 }
303 ///
304 /// Hypergrid mod stop
305 ///
306
307
308 // TeleportFinish makes the client send CompleteMovementIntoRegion (at the destination), which
309 // trigers a whole shebang of things there, including MakeRoot. So let's wait for confirmation
310 // that the client contacted the destination before we send the attachments and close things here.
311 if (!WaitForCallback(avatar.UUID))
312 {
313 // Client never contacted destination. Let's restore everything back
314 avatar.ControllingClient.SendTeleportFailed("Problems connecting to destination.");
315
316 ResetFromTransit(avatar.UUID);
317 // Yikes! We should just have a ref to scene here.
318 avatar.Scene.InformClientOfNeighbours(avatar);
319
320 // Finally, kill the agent we just created at the destination.
321 m_scene.SimulationService.CloseAgent(reg, avatar.UUID);
322 return;
323 }
324
325 // Can't go back from here
326 if (KiPrimitive != null)
327 {
328 KiPrimitive(avatar.LocalId);
329 }
330
331 avatar.MakeChildAgent();
332
333 // CrossAttachmentsIntoNewRegion is a synchronous call. We shouldn't need to wait after it
334 avatar.CrossAttachmentsIntoNewRegion(reg, true);
335
336
337 // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone
338 ///
339 /// Hypergrid mod: extra check for isHyperLink
340 ///
341 if (Util.IsOutsideView(oldRegionX, newRegionX, oldRegionY, newRegionY) || isHyperLink)
342 {
343 Thread.Sleep(5000);
344 avatar.Close();
345 CloseConnection(avatar.UUID);
346 }
347 // if (teleport success) // seems to be always success here
348 // the user may change their profile information in other region,
349 // so the userinfo in UserProfileCache is not reliable any more, delete it
350 if (avatar.Scene.NeedSceneCacheClear(avatar.UUID) || isHyperLink)
351 {
352 // REFACTORING PROBLEM!!!!
353 //m_commsProvider.UserProfileCacheService.RemoveUser(avatar.UUID);
354 m_log.DebugFormat(
355 "[HGSceneCommService]: User {0} is going to another region, profile cache removed",
356 avatar.UUID);
357 }
358 }
359 else
360 {
361 avatar.ControllingClient.SendTeleportFailed("Remote Region appears to be down");
362 }
363 }
364 else
365 {
366 // TP to a place that doesn't exist (anymore)
367 // Inform the viewer about that
368 avatar.ControllingClient.SendTeleportFailed("The region you tried to teleport to doesn't exist anymore");
369
370 // and set the map-tile to '(Offline)'
371 uint regX, regY;
372 Utils.LongToUInts(regionHandle, out regX, out regY);
373
374 MapBlockData block = new MapBlockData();
375 block.X = (ushort)(regX / Constants.RegionSize);
376 block.Y = (ushort)(regY / Constants.RegionSize);
377 block.Access = 254; // == not there
378
379 List<MapBlockData> blocks = new List<MapBlockData>();
380 blocks.Add(block);
381 avatar.ControllingClient.SendMapBlock(blocks, 0);
382 }
383 }
384 }
385
386 }
387}