opensim-development – Blame information for rev 1

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