HGEntityTransferModule.cs 27 KB

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