clockwerk-opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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 System.Reflection; |
||
31 | |||
32 | using OpenSim.Framework; |
||
33 | using OpenSim.Framework.Client; |
||
34 | using OpenSim.Region.Framework.Interfaces; |
||
35 | using OpenSim.Region.Framework.Scenes; |
||
36 | using OpenSim.Services.Connectors.Hypergrid; |
||
37 | using OpenSim.Services.Interfaces; |
||
38 | using OpenSim.Server.Base; |
||
39 | |||
40 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
||
41 | |||
42 | using OpenMetaverse; |
||
43 | using log4net; |
||
44 | using Nini.Config; |
||
45 | using Mono.Addins; |
||
46 | |||
47 | namespace OpenSim.Region.CoreModules.Framework.EntityTransfer |
||
48 | { |
||
49 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HGEntityTransferModule")] |
||
50 | public class HGEntityTransferModule |
||
51 | : EntityTransferModule, INonSharedRegionModule, IEntityTransferModule, IUserAgentVerificationModule |
||
52 | { |
||
53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
54 | |||
55 | private int m_levelHGTeleport = 0; |
||
56 | |||
57 | private GatekeeperServiceConnector m_GatekeeperConnector; |
||
58 | private IUserAgentService m_UAS; |
||
59 | |||
60 | protected bool m_RestrictAppearanceAbroad; |
||
61 | protected string m_AccountName; |
||
62 | protected List<AvatarAppearance> m_ExportedAppearances; |
||
63 | protected List<AvatarAttachment> m_Attachs; |
||
64 | |||
65 | protected List<AvatarAppearance> ExportedAppearance |
||
66 | { |
||
67 | get |
||
68 | { |
||
69 | if (m_ExportedAppearances != null) |
||
70 | return m_ExportedAppearances; |
||
71 | |||
72 | m_ExportedAppearances = new List<AvatarAppearance>(); |
||
73 | m_Attachs = new List<AvatarAttachment>(); |
||
74 | |||
75 | string[] names = m_AccountName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); |
||
76 | |||
77 | foreach (string name in names) |
||
78 | { |
||
79 | string[] parts = name.Trim().Split(); |
||
80 | if (parts.Length != 2) |
||
81 | { |
||
82 | m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: Wrong user account name format {0}. Specify 'First Last'", name); |
||
83 | return null; |
||
84 | } |
||
85 | UserAccount account = Scene.UserAccountService.GetUserAccount(UUID.Zero, parts[0], parts[1]); |
||
86 | if (account == null) |
||
87 | { |
||
88 | m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: Unknown account {0}", m_AccountName); |
||
89 | return null; |
||
90 | } |
||
91 | AvatarAppearance a = Scene.AvatarService.GetAppearance(account.PrincipalID); |
||
92 | if (a != null) |
||
93 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Successfully retrieved appearance for {0}", name); |
||
94 | |||
95 | foreach (AvatarAttachment att in a.GetAttachments()) |
||
96 | { |
||
97 | InventoryItemBase item = new InventoryItemBase(att.ItemID, account.PrincipalID); |
||
98 | item = Scene.InventoryService.GetItem(item); |
||
99 | if (item != null) |
||
100 | a.SetAttachment(att.AttachPoint, att.ItemID, item.AssetID); |
||
101 | else |
||
102 | m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: Unable to retrieve item {0} from inventory {1}", att.ItemID, name); |
||
103 | } |
||
104 | |||
105 | m_ExportedAppearances.Add(a); |
||
106 | m_Attachs.AddRange(a.GetAttachments()); |
||
107 | } |
||
108 | |||
109 | return m_ExportedAppearances; |
||
110 | } |
||
111 | } |
||
112 | |||
113 | #region ISharedRegionModule |
||
114 | |||
115 | public override string Name |
||
116 | { |
||
117 | get { return "HGEntityTransferModule"; } |
||
118 | } |
||
119 | |||
120 | public override void Initialise(IConfigSource source) |
||
121 | { |
||
122 | IConfig moduleConfig = source.Configs["Modules"]; |
||
123 | |||
124 | if (moduleConfig != null) |
||
125 | { |
||
126 | string name = moduleConfig.GetString("EntityTransferModule", ""); |
||
127 | if (name == Name) |
||
128 | { |
||
129 | IConfig transferConfig = source.Configs["EntityTransfer"]; |
||
130 | if (transferConfig != null) |
||
131 | { |
||
132 | m_levelHGTeleport = transferConfig.GetInt("LevelHGTeleport", 0); |
||
133 | |||
134 | m_RestrictAppearanceAbroad = transferConfig.GetBoolean("RestrictAppearanceAbroad", false); |
||
135 | if (m_RestrictAppearanceAbroad) |
||
136 | { |
||
137 | m_AccountName = transferConfig.GetString("AccountForAppearance", string.Empty); |
||
138 | if (m_AccountName == string.Empty) |
||
139 | m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: RestrictAppearanceAbroad is on, but no account has been given for avatar appearance!"); |
||
140 | } |
||
141 | } |
||
142 | |||
143 | InitialiseCommon(source); |
||
144 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: {0} enabled.", Name); |
||
145 | } |
||
146 | } |
||
147 | } |
||
148 | |||
149 | public override void AddRegion(Scene scene) |
||
150 | { |
||
151 | base.AddRegion(scene); |
||
152 | |||
153 | if (m_Enabled) |
||
154 | { |
||
155 | scene.RegisterModuleInterface<IUserAgentVerificationModule>(this); |
||
156 | scene.EventManager.OnIncomingSceneObject += OnIncomingSceneObject; |
||
157 | } |
||
158 | } |
||
159 | |||
160 | void OnIncomingSceneObject(SceneObjectGroup so) |
||
161 | { |
||
162 | if (!so.IsAttachment) |
||
163 | return; |
||
164 | |||
165 | if (so.AttachedAvatar == UUID.Zero || Scene.UserManagementModule.IsLocalGridUser(so.AttachedAvatar)) |
||
166 | return; |
||
167 | |||
168 | // foreign user |
||
169 | AgentCircuitData aCircuit = Scene.AuthenticateHandler.GetAgentCircuitData(so.AttachedAvatar); |
||
170 | if (aCircuit != null && (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0) |
||
171 | { |
||
172 | if (aCircuit.ServiceURLs != null && aCircuit.ServiceURLs.ContainsKey("AssetServerURI")) |
||
173 | { |
||
174 | string url = aCircuit.ServiceURLs["AssetServerURI"].ToString(); |
||
175 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Incoming attachment {0} for HG user {1} with asset server {2}", so.Name, so.AttachedAvatar, url); |
||
176 | Dictionary<UUID, sbyte> ids = new Dictionary<UUID, sbyte>(); |
||
177 | HGUuidGatherer uuidGatherer = new HGUuidGatherer(Scene.AssetService, url); |
||
178 | uuidGatherer.GatherAssetUuids(so, ids); |
||
179 | |||
180 | foreach (KeyValuePair<UUID, sbyte> kvp in ids) |
||
181 | uuidGatherer.FetchAsset(kvp.Key); |
||
182 | } |
||
183 | } |
||
184 | } |
||
185 | |||
186 | protected override void OnNewClient(IClientAPI client) |
||
187 | { |
||
188 | client.OnTeleportHomeRequest += TriggerTeleportHome; |
||
189 | client.OnTeleportLandmarkRequest += RequestTeleportLandmark; |
||
190 | client.OnConnectionClosed += new Action<IClientAPI>(OnConnectionClosed); |
||
191 | } |
||
192 | |||
193 | public override void RegionLoaded(Scene scene) |
||
194 | { |
||
195 | base.RegionLoaded(scene); |
||
196 | |||
197 | if (m_Enabled) |
||
198 | { |
||
199 | m_GatekeeperConnector = new GatekeeperServiceConnector(scene.AssetService); |
||
200 | m_UAS = scene.RequestModuleInterface<IUserAgentService>(); |
||
201 | if (m_UAS == null) |
||
202 | m_UAS = new UserAgentServiceConnector(m_ThisHomeURI); |
||
203 | |||
204 | } |
||
205 | } |
||
206 | |||
207 | public override void RemoveRegion(Scene scene) |
||
208 | { |
||
209 | base.RemoveRegion(scene); |
||
210 | |||
211 | if (m_Enabled) |
||
212 | scene.UnregisterModuleInterface<IUserAgentVerificationModule>(this); |
||
213 | } |
||
214 | |||
215 | #endregion |
||
216 | |||
217 | #region HG overrides of IEntiryTransferModule |
||
218 | |||
219 | protected override GridRegion GetFinalDestination(GridRegion region, UUID agentID, string agentHomeURI, out string message) |
||
220 | { |
||
221 | int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, region.RegionID); |
||
222 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: region {0} flags: {1}", region.RegionName, flags); |
||
223 | message = null; |
||
224 | |||
225 | if ((flags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0) |
||
226 | { |
||
227 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Destination region is hyperlink"); |
||
228 | GridRegion real_destination = m_GatekeeperConnector.GetHyperlinkRegion(region, region.RegionID, agentID, agentHomeURI, out message); |
||
229 | if (real_destination != null) |
||
230 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: GetFinalDestination: ServerURI={0}", real_destination.ServerURI); |
||
231 | else |
||
232 | m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: GetHyperlinkRegion of region {0} from Gatekeeper {1} failed: {2}", region.RegionID, region.ServerURI, message); |
||
233 | return real_destination; |
||
234 | } |
||
235 | |||
236 | return region; |
||
237 | } |
||
238 | |||
239 | protected override bool NeedsClosing(float drawdist, uint oldRegionX, uint newRegionX, uint oldRegionY, uint newRegionY, GridRegion reg) |
||
240 | { |
||
241 | if (base.NeedsClosing(drawdist, oldRegionX, newRegionX, oldRegionY, newRegionY, reg)) |
||
242 | return true; |
||
243 | |||
244 | int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, reg.RegionID); |
||
245 | if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0) |
||
246 | return true; |
||
247 | |||
248 | return false; |
||
249 | } |
||
250 | |||
251 | protected override void AgentHasMovedAway(ScenePresence sp, bool logout) |
||
252 | { |
||
253 | base.AgentHasMovedAway(sp, logout); |
||
254 | if (logout) |
||
255 | { |
||
256 | // Log them out of this grid |
||
257 | Scene.PresenceService.LogoutAgent(sp.ControllingClient.SessionId); |
||
258 | string userId = Scene.UserManagementModule.GetUserUUI(sp.UUID); |
||
259 | Scene.GridUserService.LoggedOut(userId, UUID.Zero, Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat); |
||
260 | } |
||
261 | } |
||
262 | |||
263 | protected override bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, out string reason, out bool logout) |
||
264 | { |
||
265 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: CreateAgent {0} {1}", reg.ServerURI, finalDestination.ServerURI); |
||
266 | reason = string.Empty; |
||
267 | logout = false; |
||
268 | int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, reg.RegionID); |
||
269 | if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0) |
||
270 | { |
||
271 | // this user is going to another grid |
||
272 | // for local users, check if HyperGrid teleport is allowed, based on user level |
||
273 | if (Scene.UserManagementModule.IsLocalGridUser(sp.UUID) && sp.UserLevel < m_levelHGTeleport) |
||
274 | { |
||
275 | m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: Unable to HG teleport agent due to insufficient UserLevel."); |
||
276 | reason = "Hypergrid teleport not allowed"; |
||
277 | return false; |
||
278 | } |
||
279 | |||
280 | if (agentCircuit.ServiceURLs.ContainsKey("HomeURI")) |
||
281 | { |
||
282 | string userAgentDriver = agentCircuit.ServiceURLs["HomeURI"].ToString(); |
||
283 | IUserAgentService connector; |
||
284 | |||
285 | if (userAgentDriver.Equals(m_ThisHomeURI) && m_UAS != null) |
||
286 | connector = m_UAS; |
||
287 | else |
||
288 | connector = new UserAgentServiceConnector(userAgentDriver); |
||
289 | |||
290 | GridRegion source = new GridRegion(Scene.RegionInfo); |
||
291 | source.RawServerURI = m_GatekeeperURI; |
||
292 | |||
293 | bool success = connector.LoginAgentToGrid(source, agentCircuit, reg, finalDestination, false, out reason); |
||
294 | logout = success; // flag for later logout from this grid; this is an HG TP |
||
295 | |||
296 | if (success) |
||
297 | sp.Scene.EventManager.TriggerTeleportStart(sp.ControllingClient, reg, finalDestination, teleportFlags, logout); |
||
298 | |||
299 | return success; |
||
300 | } |
||
301 | else |
||
302 | { |
||
303 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent does not have a HomeURI address"); |
||
304 | return false; |
||
305 | } |
||
306 | } |
||
307 | |||
308 | return base.CreateAgent(sp, reg, finalDestination, agentCircuit, teleportFlags, out reason, out logout); |
||
309 | } |
||
310 | |||
311 | protected override bool ValidateGenericConditions(ScenePresence sp, GridRegion reg, GridRegion finalDestination, uint teleportFlags, out string reason) |
||
312 | { |
||
313 | reason = "Please wear your grid's allowed appearance before teleporting to another grid"; |
||
314 | if (!m_RestrictAppearanceAbroad) |
||
315 | return true; |
||
316 | |||
317 | // The rest is only needed for controlling appearance |
||
318 | |||
319 | int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, reg.RegionID); |
||
320 | if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0) |
||
321 | { |
||
322 | // this user is going to another grid |
||
323 | if (Scene.UserManagementModule.IsLocalGridUser(sp.UUID)) |
||
324 | { |
||
325 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: RestrictAppearanceAbroad is ON. Checking generic appearance"); |
||
326 | |||
327 | // Check wearables |
||
328 | for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++) |
||
329 | { |
||
330 | for (int j = 0; j < sp.Appearance.Wearables[i].Count; j++) |
||
331 | { |
||
332 | if (sp.Appearance.Wearables[i] == null) |
||
333 | continue; |
||
334 | |||
335 | bool found = false; |
||
336 | foreach (AvatarAppearance a in ExportedAppearance) |
||
337 | if (a.Wearables[i] != null) |
||
338 | { |
||
339 | found = true; |
||
340 | break; |
||
341 | } |
||
342 | |||
343 | if (!found) |
||
344 | { |
||
345 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Wearable not allowed to go outside {0}", i); |
||
346 | return false; |
||
347 | } |
||
348 | |||
349 | found = false; |
||
350 | foreach (AvatarAppearance a in ExportedAppearance) |
||
351 | if (sp.Appearance.Wearables[i][j].AssetID == a.Wearables[i][j].AssetID) |
||
352 | { |
||
353 | found = true; |
||
354 | break; |
||
355 | } |
||
356 | |||
357 | if (!found) |
||
358 | { |
||
359 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Wearable not allowed to go outside {0}", i); |
||
360 | return false; |
||
361 | } |
||
362 | } |
||
363 | } |
||
364 | |||
365 | // Check attachments |
||
366 | foreach (AvatarAttachment att in sp.Appearance.GetAttachments()) |
||
367 | { |
||
368 | bool found = false; |
||
369 | foreach (AvatarAttachment att2 in m_Attachs) |
||
370 | { |
||
371 | if (att2.AssetID == att.AssetID) |
||
372 | { |
||
373 | found = true; |
||
374 | break; |
||
375 | } |
||
376 | } |
||
377 | if (!found) |
||
378 | { |
||
379 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Attachment not allowed to go outside {0}", att.AttachPoint); |
||
380 | return false; |
||
381 | } |
||
382 | } |
||
383 | } |
||
384 | } |
||
385 | |||
386 | reason = string.Empty; |
||
387 | return true; |
||
388 | } |
||
389 | |||
390 | |||
391 | //protected override bool UpdateAgent(GridRegion reg, GridRegion finalDestination, AgentData agentData, ScenePresence sp) |
||
392 | //{ |
||
393 | // int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, reg.RegionID); |
||
394 | // if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Data.RegionFlags.Hyperlink) != 0) |
||
395 | // { |
||
396 | // // this user is going to another grid |
||
397 | // if (m_RestrictAppearanceAbroad && Scene.UserManagementModule.IsLocalGridUser(agentData.AgentID)) |
||
398 | // { |
||
399 | // // We need to strip the agent off its appearance |
||
400 | // m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: RestrictAppearanceAbroad is ON. Sending generic appearance"); |
||
401 | |||
402 | // // Delete existing npc attachments |
||
403 | // Scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, false); |
||
404 | |||
405 | // // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet since it doesn't transfer attachments |
||
406 | // AvatarAppearance newAppearance = new AvatarAppearance(ExportedAppearance, true); |
||
407 | // sp.Appearance = newAppearance; |
||
408 | |||
409 | // // Rez needed npc attachments |
||
410 | // Scene.AttachmentsModule.RezAttachments(sp); |
||
411 | |||
412 | |||
413 | // IAvatarFactoryModule module = Scene.RequestModuleInterface<IAvatarFactoryModule>(); |
||
414 | // //module.SendAppearance(sp.UUID); |
||
415 | // module.RequestRebake(sp, false); |
||
416 | |||
417 | // Scene.AttachmentsModule.CopyAttachments(sp, agentData); |
||
418 | // agentData.Appearance = sp.Appearance; |
||
419 | // } |
||
420 | // } |
||
421 | |||
422 | // foreach (AvatarAttachment a in agentData.Appearance.GetAttachments()) |
||
423 | // m_log.DebugFormat("[XXX]: {0}-{1}", a.ItemID, a.AssetID); |
||
424 | |||
425 | |||
426 | // return base.UpdateAgent(reg, finalDestination, agentData, sp); |
||
427 | //} |
||
428 | |||
429 | public override void TriggerTeleportHome(UUID id, IClientAPI client) |
||
430 | { |
||
431 | TeleportHome(id, client); |
||
432 | } |
||
433 | |||
434 | public override bool TeleportHome(UUID id, IClientAPI client) |
||
435 | { |
||
436 | m_log.DebugFormat( |
||
437 | "[ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.Name, client.AgentId); |
||
438 | |||
439 | // Let's find out if this is a foreign user or a local user |
||
440 | IUserManagement uMan = Scene.RequestModuleInterface<IUserManagement>(); |
||
441 | if (uMan != null && uMan.IsLocalGridUser(id)) |
||
442 | { |
||
443 | // local grid user |
||
444 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is local"); |
||
445 | return base.TeleportHome(id, client); |
||
446 | } |
||
447 | |||
448 | // Foreign user wants to go home |
||
449 | // |
||
450 | AgentCircuitData aCircuit = ((Scene)(client.Scene)).AuthenticateHandler.GetAgentCircuitData(client.CircuitCode); |
||
451 | if (aCircuit == null || (aCircuit != null && !aCircuit.ServiceURLs.ContainsKey("HomeURI"))) |
||
452 | { |
||
453 | client.SendTeleportFailed("Your information has been lost"); |
||
454 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Unable to locate agent's gateway information"); |
||
455 | return false; |
||
456 | } |
||
457 | |||
458 | IUserAgentService userAgentService = new UserAgentServiceConnector(aCircuit.ServiceURLs["HomeURI"].ToString()); |
||
459 | Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY; |
||
460 | |||
461 | GridRegion finalDestination = null; |
||
462 | try |
||
463 | { |
||
464 | finalDestination = userAgentService.GetHomeRegion(aCircuit.AgentID, out position, out lookAt); |
||
465 | } |
||
466 | catch (Exception e) |
||
467 | { |
||
468 | m_log.Debug("[HG ENTITY TRANSFER MODULE]: GetHomeRegion call failed ", e); |
||
469 | } |
||
470 | |||
471 | if (finalDestination == null) |
||
472 | { |
||
473 | client.SendTeleportFailed("Your home region could not be found"); |
||
474 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent's home region not found"); |
||
475 | return false; |
||
476 | } |
||
477 | |||
478 | ScenePresence sp = ((Scene)(client.Scene)).GetScenePresence(client.AgentId); |
||
479 | if (sp == null) |
||
480 | { |
||
481 | client.SendTeleportFailed("Internal error"); |
||
482 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent not found in the scene where it is supposed to be"); |
||
483 | return false; |
||
484 | } |
||
485 | |||
486 | GridRegion homeGatekeeper = MakeRegion(aCircuit); |
||
487 | |||
488 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: teleporting user {0} {1} home to {2} via {3}:{4}", |
||
489 | aCircuit.firstname, aCircuit.lastname, finalDestination.RegionName, homeGatekeeper.ServerURI, homeGatekeeper.RegionName); |
||
490 | |||
491 | DoTeleport( |
||
492 | sp, homeGatekeeper, finalDestination, |
||
493 | position, lookAt, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome)); |
||
494 | return true; |
||
495 | } |
||
496 | |||
497 | /// <summary> |
||
498 | /// Tries to teleport agent to landmark. |
||
499 | /// </summary> |
||
500 | /// <param name="remoteClient"></param> |
||
501 | /// <param name="regionHandle"></param> |
||
502 | /// <param name="position"></param> |
||
503 | public override void RequestTeleportLandmark(IClientAPI remoteClient, AssetLandmark lm) |
||
504 | { |
||
505 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Teleporting agent via landmark to {0} region {1} position {2}", |
||
506 | (lm.Gatekeeper == string.Empty) ? "local" : lm.Gatekeeper, lm.RegionID, lm.Position); |
||
507 | |||
508 | if (lm.Gatekeeper == string.Empty) |
||
509 | { |
||
510 | base.RequestTeleportLandmark(remoteClient, lm); |
||
511 | return; |
||
512 | } |
||
513 | |||
514 | GridRegion info = Scene.GridService.GetRegionByUUID(UUID.Zero, lm.RegionID); |
||
515 | |||
516 | // Local region? |
||
517 | if (info != null) |
||
518 | { |
||
519 | ((Scene)(remoteClient.Scene)).RequestTeleportLocation(remoteClient, info.RegionHandle, lm.Position, |
||
520 | Vector3.Zero, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaLandmark)); |
||
521 | } |
||
522 | else |
||
523 | { |
||
524 | // Foreign region |
||
525 | Scene scene = (Scene)(remoteClient.Scene); |
||
526 | GatekeeperServiceConnector gConn = new GatekeeperServiceConnector(); |
||
527 | GridRegion gatekeeper = new GridRegion(); |
||
528 | gatekeeper.ServerURI = lm.Gatekeeper; |
||
529 | string homeURI = Scene.GetAgentHomeURI(remoteClient.AgentId); |
||
530 | |||
531 | string message; |
||
532 | GridRegion finalDestination = gConn.GetHyperlinkRegion(gatekeeper, new UUID(lm.RegionID), remoteClient.AgentId, homeURI, out message); |
||
533 | |||
534 | if (finalDestination != null) |
||
535 | { |
||
536 | ScenePresence sp = scene.GetScenePresence(remoteClient.AgentId); |
||
537 | IEntityTransferModule transferMod = scene.RequestModuleInterface<IEntityTransferModule>(); |
||
538 | |||
539 | if (transferMod != null && sp != null) |
||
540 | { |
||
541 | if (message != null) |
||
542 | sp.ControllingClient.SendAgentAlertMessage(message, true); |
||
543 | |||
544 | transferMod.DoTeleport( |
||
545 | sp, gatekeeper, finalDestination, lm.Position, Vector3.UnitX, |
||
546 | (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaLandmark)); |
||
547 | } |
||
548 | } |
||
549 | else |
||
550 | { |
||
551 | remoteClient.SendTeleportFailed(message); |
||
552 | } |
||
553 | |||
554 | } |
||
555 | } |
||
556 | |||
557 | #endregion |
||
558 | |||
559 | #region IUserAgentVerificationModule |
||
560 | |||
561 | public bool VerifyClient(AgentCircuitData aCircuit, string token) |
||
562 | { |
||
563 | if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) |
||
564 | { |
||
565 | string url = aCircuit.ServiceURLs["HomeURI"].ToString(); |
||
566 | IUserAgentService security = new UserAgentServiceConnector(url); |
||
567 | return security.VerifyClient(aCircuit.SessionID, token); |
||
568 | } |
||
569 | else |
||
570 | { |
||
571 | m_log.DebugFormat( |
||
572 | "[HG ENTITY TRANSFER MODULE]: Agent {0} {1} does not have a HomeURI OH NO!", |
||
573 | aCircuit.firstname, aCircuit.lastname); |
||
574 | } |
||
575 | |||
576 | return false; |
||
577 | } |
||
578 | |||
579 | void OnConnectionClosed(IClientAPI obj) |
||
580 | { |
||
581 | if (obj.SceneAgent.IsChildAgent) |
||
582 | return; |
||
583 | |||
584 | // Let's find out if this is a foreign user or a local user |
||
585 | IUserManagement uMan = Scene.RequestModuleInterface<IUserManagement>(); |
||
586 | // UserAccount account = Scene.UserAccountService.GetUserAccount(Scene.RegionInfo.ScopeID, obj.AgentId); |
||
587 | |||
588 | if (uMan != null && uMan.IsLocalGridUser(obj.AgentId)) |
||
589 | { |
||
590 | // local grid user |
||
591 | m_UAS.LogoutAgent(obj.AgentId, obj.SessionId); |
||
592 | return; |
||
593 | } |
||
594 | |||
595 | AgentCircuitData aCircuit = ((Scene)(obj.Scene)).AuthenticateHandler.GetAgentCircuitData(obj.CircuitCode); |
||
596 | if (aCircuit != null && aCircuit.ServiceURLs != null && aCircuit.ServiceURLs.ContainsKey("HomeURI")) |
||
597 | { |
||
598 | string url = aCircuit.ServiceURLs["HomeURI"].ToString(); |
||
599 | IUserAgentService security = new UserAgentServiceConnector(url); |
||
600 | security.LogoutAgent(obj.AgentId, obj.SessionId); |
||
601 | //m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Sent logout call to UserAgentService @ {0}", url); |
||
602 | } |
||
603 | else |
||
604 | { |
||
605 | m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: HomeURI not found for agent {0} logout", obj.AgentId); |
||
606 | } |
||
607 | } |
||
608 | |||
609 | #endregion |
||
610 | |||
611 | private GridRegion MakeRegion(AgentCircuitData aCircuit) |
||
612 | { |
||
613 | GridRegion region = new GridRegion(); |
||
614 | |||
615 | Uri uri = null; |
||
616 | if (!aCircuit.ServiceURLs.ContainsKey("HomeURI") || |
||
617 | (aCircuit.ServiceURLs.ContainsKey("HomeURI") && !Uri.TryCreate(aCircuit.ServiceURLs["HomeURI"].ToString(), UriKind.Absolute, out uri))) |
||
618 | return null; |
||
619 | |||
620 | region.ExternalHostName = uri.Host; |
||
621 | region.HttpPort = (uint)uri.Port; |
||
622 | region.ServerURI = aCircuit.ServiceURLs["HomeURI"].ToString(); |
||
623 | region.RegionName = string.Empty; |
||
624 | region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), (int)0); |
||
625 | return region; |
||
626 | } |
||
627 | } |
||
628 | } |