HGEntityTransferModule.cs 26 KB

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