HGEntityTransferModule.cs 26 KB

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