OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
HGEntityTransferModule.cs
Go to the documentation of this file.
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.Framework.Monitoring;
35 using OpenSim.Region.Framework.Interfaces;
36 using OpenSim.Region.Framework.Scenes;
37 using OpenSim.Services.Connectors.Hypergrid;
38 using OpenSim.Services.Interfaces;
39 using OpenSim.Server.Base;
40 
42 
43 using OpenMetaverse;
44 using log4net;
45 using Nini.Config;
46 using Mono.Addins;
47 
48 namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
49 {
50  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "HGEntityTransferModule")]
53  {
54  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
55 
56  private int m_levelHGTeleport = 0;
57 
58  private GatekeeperServiceConnector m_GatekeeperConnector;
59  private IUserAgentService m_UAS;
60 
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 
117  private JobEngine m_incomingSceneObjectEngine;
118 
119  #region ISharedRegionModule
120 
121  public override string Name
122  {
123  get { return "HGEntityTransferModule"; }
124  }
125 
126  public override void Initialise(IConfigSource source)
127  {
128  IConfig moduleConfig = source.Configs["Modules"];
129 
130  if (moduleConfig != null)
131  {
132  string name = moduleConfig.GetString("EntityTransferModule", "");
133  if (name == Name)
134  {
135  IConfig transferConfig = source.Configs["EntityTransfer"];
136  if (transferConfig != null)
137  {
138  m_levelHGTeleport = transferConfig.GetInt("LevelHGTeleport", 0);
139 
140  m_RestrictAppearanceAbroad = transferConfig.GetBoolean("RestrictAppearanceAbroad", false);
141  if (m_RestrictAppearanceAbroad)
142  {
143  m_AccountName = transferConfig.GetString("AccountForAppearance", string.Empty);
144  if (m_AccountName == string.Empty)
145  m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: RestrictAppearanceAbroad is on, but no account has been given for avatar appearance!");
146  }
147  }
148 
149  InitialiseCommon(source);
150  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: {0} enabled.", Name);
151  }
152  }
153  }
154 
155  public override void AddRegion(Scene scene)
156  {
157  base.AddRegion(scene);
158 
159  if (m_Enabled)
160  {
161  scene.RegisterModuleInterface<IUserAgentVerificationModule>(this);
162  //scene.EventManager.OnIncomingSceneObject += OnIncomingSceneObject;
163 
164  m_incomingSceneObjectEngine
165  = new JobEngine(
166  string.Format("HG Incoming Scene Object Engine ({0})", scene.Name),
167  "HG INCOMING SCENE OBJECT ENGINE");
168 
169  StatsManager.RegisterStat(
170  new Stat(
171  "HGIncomingAttachmentsWaiting",
172  "Number of incoming attachments waiting for processing.",
173  "",
174  "",
175  "entitytransfer",
176  Name,
177  StatType.Pull,
178  MeasuresOfInterest.None,
179  stat => stat.Value = m_incomingSceneObjectEngine.JobsWaiting,
180  StatVerbosity.Debug));
181 
182  m_incomingSceneObjectEngine.Start();
183  }
184  }
185 
186  protected override void OnNewClient(IClientAPI client)
187  {
188  client.OnTeleportHomeRequest += TriggerTeleportHome;
189  client.OnTeleportLandmarkRequest += RequestTeleportLandmark;
190  client.OnConnectionClosed += new Action<IClientAPI>(OnConnectionClosed);
191  }
192 
193  public override void RegionLoaded(Scene scene)
194  {
195  base.RegionLoaded(scene);
196 
197  if (m_Enabled)
198  {
199  m_GatekeeperConnector = new GatekeeperServiceConnector(scene.AssetService);
200  m_UAS = scene.RequestModuleInterface<IUserAgentService>();
201  if (m_UAS == null)
202  m_UAS = new UserAgentServiceConnector(m_ThisHomeURI);
203 
204  }
205  }
206 
207  public override void RemoveRegion(Scene scene)
208  {
209  base.RemoveRegion(scene);
210 
211  if (m_Enabled)
212  {
213  scene.UnregisterModuleInterface<IUserAgentVerificationModule>(this);
214  m_incomingSceneObjectEngine.Stop();
215  }
216  }
217 
218  #endregion
219 
220  #region HG overrides of IEntityTransferModule
221 
222  protected override GridRegion GetFinalDestination(GridRegion region, UUID agentID, string agentHomeURI, out string message)
223  {
224  int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, region.RegionID);
225  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: region {0} flags: {1}", region.RegionName, flags);
226  message = null;
227 
228  if ((flags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0)
229  {
230  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Destination region is hyperlink");
231  GridRegion real_destination = m_GatekeeperConnector.GetHyperlinkRegion(region, region.RegionID, agentID, agentHomeURI, out message);
232  if (real_destination != null)
233  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: GetFinalDestination: ServerURI={0}", real_destination.ServerURI);
234  else
235  m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: GetHyperlinkRegion of region {0} from Gatekeeper {1} failed: {2}", region.RegionID, region.ServerURI, message);
236  return real_destination;
237  }
238 
239  return region;
240  }
241 
242  protected override bool NeedsClosing(GridRegion reg, bool OutViewRange)
243  {
244  if (OutViewRange)
245  return true;
246 
247  int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, reg.RegionID);
248  if (flags == -1 || (flags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0)
249  return true;
250 
251  return false;
252  }
253 
254  protected override void AgentHasMovedAway(ScenePresence sp, bool logout)
255  {
256  base.AgentHasMovedAway(sp, logout);
257  if (logout)
258  {
259  // Log them out of this grid
260  Scene.PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
261  string userId = Scene.UserManagementModule.GetUserUUI(sp.UUID);
262  Scene.GridUserService.LoggedOut(userId, UUID.Zero, Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
263  }
264  }
265 
266  protected override bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, EntityTransferContext ctx, out string reason, out bool logout)
267  {
268  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: CreateAgent {0} {1}", reg.ServerURI, finalDestination.ServerURI);
269  reason = string.Empty;
270  logout = false;
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  // for local users, check if HyperGrid teleport is allowed, based on user level
276  if (Scene.UserManagementModule.IsLocalGridUser(sp.UUID) && sp.UserLevel < m_levelHGTeleport)
277  {
278  m_log.WarnFormat("[HG ENTITY TRANSFER MODULE]: Unable to HG teleport agent due to insufficient UserLevel.");
279  reason = "Hypergrid teleport not allowed";
280  return false;
281  }
282 
283  if (agentCircuit.ServiceURLs.ContainsKey("HomeURI"))
284  {
285  string userAgentDriver = agentCircuit.ServiceURLs["HomeURI"].ToString();
286  IUserAgentService connector;
287 
288  if (userAgentDriver.Equals(m_ThisHomeURI) && m_UAS != null)
289  connector = m_UAS;
290  else
291  connector = new UserAgentServiceConnector(userAgentDriver);
292 
293  GridRegion source = new GridRegion(Scene.RegionInfo);
294  source.RawServerURI = m_GatekeeperURI;
295 
296  bool success = connector.LoginAgentToGrid(source, agentCircuit, reg, finalDestination, false, out reason);
297  logout = success; // flag for later logout from this grid; this is an HG TP
298 
299  if (success)
300  Scene.EventManager.TriggerTeleportStart(sp.ControllingClient, reg, finalDestination, teleportFlags, logout);
301 
302  return success;
303  }
304  else
305  {
306  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent does not have a HomeURI address");
307  return false;
308  }
309  }
310 
311  return base.CreateAgent(sp, reg, finalDestination, agentCircuit, teleportFlags, ctx, out reason, out logout);
312  }
313 
314  public override void TriggerTeleportHome(UUID id, IClientAPI client)
315  {
316  TeleportHome(id, client);
317  }
318 
319  protected override bool ValidateGenericConditions(ScenePresence sp, GridRegion reg, GridRegion finalDestination, uint teleportFlags, out string reason)
320  {
321  reason = "Please wear your grid's allowed appearance before teleporting to another grid";
322  if (!m_RestrictAppearanceAbroad)
323  return true;
324 
325  // The rest is only needed for controlling appearance
326 
327  int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, reg.RegionID);
328  if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Framework.RegionFlags.Hyperlink) != 0)
329  {
330  // this user is going to another grid
332  {
333  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: RestrictAppearanceAbroad is ON. Checking generic appearance");
334 
335  // Check wearables
336  for (int i = 0; i < sp.Appearance.Wearables.Length ; i++)
337  {
338  for (int j = 0; j < sp.Appearance.Wearables[i].Count; j++)
339  {
340  if (sp.Appearance.Wearables[i] == null)
341  continue;
342 
343  bool found = false;
344  foreach (AvatarAppearance a in ExportedAppearance)
345  if (i < a.Wearables.Length && a.Wearables[i] != null)
346  {
347  found = true;
348  break;
349  }
350 
351  if (!found)
352  {
353  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Wearable not allowed to go outside {0}", i);
354  return false;
355  }
356 
357  found = false;
358  foreach (AvatarAppearance a in ExportedAppearance)
359  if (i < a.Wearables.Length && sp.Appearance.Wearables[i][j].AssetID == a.Wearables[i][j].AssetID)
360  {
361  found = true;
362  break;
363  }
364 
365  if (!found)
366  {
367  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Wearable not allowed to go outside {0}", i);
368  return false;
369  }
370  }
371  }
372 
373  // Check attachments
374  foreach (AvatarAttachment att in sp.Appearance.GetAttachments())
375  {
376  bool found = false;
377  foreach (AvatarAttachment att2 in m_Attachs)
378  {
379  if (att2.AssetID == att.AssetID)
380  {
381  found = true;
382  break;
383  }
384  }
385  if (!found)
386  {
387  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Attachment not allowed to go outside {0}", att.AttachPoint);
388  return false;
389  }
390  }
391  }
392  }
393 
394  reason = string.Empty;
395  return true;
396  }
397 
398 
399  //protected override bool UpdateAgent(GridRegion reg, GridRegion finalDestination, AgentData agentData, ScenePresence sp)
400  //{
401  // int flags = Scene.GridService.GetRegionFlags(Scene.RegionInfo.ScopeID, reg.RegionID);
402  // if (flags == -1 /* no region in DB */ || (flags & (int)OpenSim.Data.RegionFlags.Hyperlink) != 0)
403  // {
404  // // this user is going to another grid
405  // if (m_RestrictAppearanceAbroad && Scene.UserManagementModule.IsLocalGridUser(agentData.AgentID))
406  // {
407  // // We need to strip the agent off its appearance
408  // m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: RestrictAppearanceAbroad is ON. Sending generic appearance");
409 
410  // // Delete existing npc attachments
411  // Scene.AttachmentsModule.DeleteAttachmentsFromScene(sp, false);
412 
413  // // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet since it doesn't transfer attachments
414  // AvatarAppearance newAppearance = new AvatarAppearance(ExportedAppearance, true);
415  // sp.Appearance = newAppearance;
416 
417  // // Rez needed npc attachments
418  // Scene.AttachmentsModule.RezAttachments(sp);
419 
420 
421  // IAvatarFactoryModule module = Scene.RequestModuleInterface<IAvatarFactoryModule>();
422  // //module.SendAppearance(sp.UUID);
423  // module.RequestRebake(sp, false);
424 
425  // Scene.AttachmentsModule.CopyAttachments(sp, agentData);
426  // agentData.Appearance = sp.Appearance;
427  // }
428  // }
429 
430  // foreach (AvatarAttachment a in agentData.Appearance.GetAttachments())
431  // m_log.DebugFormat("[XXX]: {0}-{1}", a.ItemID, a.AssetID);
432 
433 
434  // return base.UpdateAgent(reg, finalDestination, agentData, sp);
435  //}
436 
437 
438  public override bool TeleportHome(UUID id, IClientAPI client)
439  {
440  m_log.DebugFormat(
441  "[ENTITY TRANSFER MODULE]: Request to teleport {0} {1} home", client.Name, client.AgentId);
442 
443  // Let's find out if this is a foreign user or a local user
444  IUserManagement uMan = Scene.RequestModuleInterface<IUserManagement>();
445  if (uMan != null && uMan.IsLocalGridUser(id))
446  {
447  // local grid user
448  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: User is local");
449  return base.TeleportHome(id, client);
450  }
451 
452  // Foreign user wants to go home
453  //
454  AgentCircuitData aCircuit = ((Scene)(client.Scene)).AuthenticateHandler.GetAgentCircuitData(client.CircuitCode);
455  if (aCircuit == null || (aCircuit != null && !aCircuit.ServiceURLs.ContainsKey("HomeURI")))
456  {
457  client.SendTeleportFailed("Your information has been lost");
458  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Unable to locate agent's gateway information");
459  return false;
460  }
461 
462  IUserAgentService userAgentService = new UserAgentServiceConnector(aCircuit.ServiceURLs["HomeURI"].ToString());
463  Vector3 position = Vector3.UnitY, lookAt = Vector3.UnitY;
464 
465  GridRegion finalDestination = null;
466  try
467  {
468  finalDestination = userAgentService.GetHomeRegion(aCircuit.AgentID, out position, out lookAt);
469  }
470  catch (Exception e)
471  {
472  m_log.Debug("[HG ENTITY TRANSFER MODULE]: GetHomeRegion call failed ", e);
473  }
474 
475  if (finalDestination == null)
476  {
477  client.SendTeleportFailed("Your home region could not be found");
478  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent's home region not found");
479  return false;
480  }
481 
482  ScenePresence sp = ((Scene)(client.Scene)).GetScenePresence(client.AgentId);
483  if (sp == null)
484  {
485  client.SendTeleportFailed("Internal error");
486  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Agent not found in the scene where it is supposed to be");
487  return false;
488  }
489 
490  GridRegion homeGatekeeper = MakeRegion(aCircuit);
491 
492  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: teleporting user {0} {1} home to {2} via {3}:{4}",
493  aCircuit.firstname, aCircuit.lastname, finalDestination.RegionName, homeGatekeeper.ServerURI, homeGatekeeper.RegionName);
494 
495  DoTeleport(sp, homeGatekeeper, finalDestination, position, lookAt, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaHome));
496  return true;
497  }
498 
505  public override void RequestTeleportLandmark(IClientAPI remoteClient, AssetLandmark lm)
506  {
507  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Teleporting agent via landmark to {0} region {1} position {2}",
508  (lm.Gatekeeper == string.Empty) ? "local" : lm.Gatekeeper, lm.RegionID, lm.Position);
509 
510  if (lm.Gatekeeper == string.Empty)
511  {
512  base.RequestTeleportLandmark(remoteClient, lm);
513  return;
514  }
515 
516  GridRegion info = Scene.GridService.GetRegionByUUID(UUID.Zero, lm.RegionID);
517 
518  // Local region?
519  if (info != null)
520  {
521  Scene.RequestTeleportLocation(
522  remoteClient, info.RegionHandle, lm.Position,
523  Vector3.Zero, (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaLandmark));
524  }
525  else
526  {
527  // Foreign region
529  GridRegion gatekeeper = new GridRegion();
530  gatekeeper.ServerURI = lm.Gatekeeper;
531  string homeURI = Scene.GetAgentHomeURI(remoteClient.AgentId);
532 
533  string message;
534  GridRegion finalDestination = gConn.GetHyperlinkRegion(gatekeeper, new UUID(lm.RegionID), remoteClient.AgentId, homeURI, out message);
535 
536  if (finalDestination != null)
537  {
538  ScenePresence sp = Scene.GetScenePresence(remoteClient.AgentId);
539 
540  if (sp != null)
541  {
542  if (message != null)
543  sp.ControllingClient.SendAgentAlertMessage(message, true);
544 
545  // Validate assorted conditions
546  string reason = string.Empty;
547  if (!ValidateGenericConditions(sp, gatekeeper, finalDestination, 0, out reason))
548  {
549  sp.ControllingClient.SendTeleportFailed(reason);
550  return;
551  }
552 
553  DoTeleport(
554  sp, gatekeeper, finalDestination, lm.Position, Vector3.UnitX,
555  (uint)(Constants.TeleportFlags.SetLastToTarget | Constants.TeleportFlags.ViaLandmark));
556  }
557  }
558  else
559  {
560  remoteClient.SendTeleportFailed(message);
561  }
562 
563  }
564  }
565 
566  private void RemoveIncomingSceneObjectJobs(string commonIdToRemove)
567  {
568  List<JobEngine.Job> jobsToReinsert = new List<JobEngine.Job>();
569  int jobsRemoved = 0;
570 
571  JobEngine.Job job;
572  while ((job = m_incomingSceneObjectEngine.RemoveNextJob()) != null)
573  {
574  if (job.CommonId != commonIdToRemove)
575  jobsToReinsert.Add(job);
576  else
577  jobsRemoved++;
578  }
579 
580  m_log.DebugFormat(
581  "[HG ENTITY TRANSFER]: Removing {0} jobs with common ID {1} and reinserting {2} other jobs",
582  jobsRemoved, commonIdToRemove, jobsToReinsert.Count);
583 
584  if (jobsToReinsert.Count > 0)
585  {
586  foreach (JobEngine.Job jobToReinsert in jobsToReinsert)
587  m_incomingSceneObjectEngine.QueueJob(jobToReinsert);
588  }
589  }
590 
591  public override bool HandleIncomingSceneObject(SceneObjectGroup so, Vector3 newPosition)
592  {
593  // FIXME: We must make it so that we can use SOG.IsAttachment here. At the moment it is always null!
594  if (!so.IsAttachmentCheckFull())
595  return base.HandleIncomingSceneObject(so, newPosition);
596 
597  // Equally, we can't use so.AttachedAvatar here.
599  return base.HandleIncomingSceneObject(so, newPosition);
600 
601  // foreign user
602  AgentCircuitData aCircuit = Scene.AuthenticateHandler.GetAgentCircuitData(so.OwnerID);
603  if (aCircuit != null)
604  {
605  if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) == 0)
606  {
607  // We have already pulled the necessary attachments from the source grid.
608  base.HandleIncomingSceneObject(so, newPosition);
609  }
610  else
611  {
612  if (aCircuit.ServiceURLs != null && aCircuit.ServiceURLs.ContainsKey("AssetServerURI"))
613  {
614  m_incomingSceneObjectEngine.QueueJob(
615  string.Format("HG UUID Gather for attachment {0} for {1}", so.Name, aCircuit.Name),
616  () =>
617  {
618  string url = aCircuit.ServiceURLs["AssetServerURI"].ToString();
619  // m_log.DebugFormat(
620  // "[HG ENTITY TRANSFER MODULE]: Incoming attachment {0} for HG user {1} with asset service {2}",
621  // so.Name, so.AttachedAvatar, url);
622 
623  IDictionary<UUID, sbyte> ids = new Dictionary<UUID, sbyte>();
624  HGUuidGatherer uuidGatherer
625  = new HGUuidGatherer(Scene.AssetService, url, ids);
626  uuidGatherer.AddForInspection(so);
627 
628  while (!uuidGatherer.Complete)
629  {
630  int tickStart = Util.EnvironmentTickCount();
631 
632  UUID? nextUuid = uuidGatherer.NextUuidToInspect;
633  uuidGatherer.GatherNext();
634 
635  // m_log.DebugFormat(
636  // "[HG ENTITY TRANSFER]: Gathered attachment asset uuid {0} for object {1} for HG user {2} took {3} ms with asset service {4}",
637  // nextUuid, so.Name, so.OwnerID, Util.EnvironmentTickCountSubtract(tickStart), url);
638 
639  int ticksElapsed = Util.EnvironmentTickCountSubtract(tickStart);
640 
641  if (ticksElapsed > 30000)
642  {
643  m_log.WarnFormat(
644  "[HG ENTITY TRANSFER]: Removing incoming scene object jobs for HG user {0} as gather of {1} from {2} took {3} ms to respond (> {4} ms)",
645  so.OwnerID, so.Name, url, ticksElapsed, 30000);
646 
647  RemoveIncomingSceneObjectJobs(so.OwnerID.ToString());
648 
649  return;
650  }
651  }
652 
653  // m_log.DebugFormat(
654  // "[HG ENTITY TRANSFER]: Fetching {0} assets for attachment {1} for HG user {2} with asset service {3}",
655  // ids.Count, so.Name, so.OwnerID, url);
656 
657  foreach (KeyValuePair<UUID, sbyte> kvp in ids)
658  {
659  int tickStart = Util.EnvironmentTickCount();
660 
661  uuidGatherer.FetchAsset(kvp.Key);
662 
663  int ticksElapsed = Util.EnvironmentTickCountSubtract(tickStart);
664 
665  if (ticksElapsed > 30000)
666  {
667  m_log.WarnFormat(
668  "[HG ENTITY TRANSFER]: Removing incoming scene object jobs for HG user {0} as fetch of {1} from {2} took {3} ms to respond (> {4} ms)",
669  so.OwnerID, kvp.Key, url, ticksElapsed, 30000);
670 
671  RemoveIncomingSceneObjectJobs(so.OwnerID.ToString());
672 
673  return;
674  }
675  }
676 
677  base.HandleIncomingSceneObject(so, newPosition);
678 
679  // m_log.DebugFormat(
680  // "[HG ENTITY TRANSFER MODULE]: Completed incoming attachment {0} for HG user {1} with asset server {2}",
681  // so.Name, so.OwnerID, url);
682  },
683  so.OwnerID.ToString());
684  }
685  }
686  }
687 
688  return true;
689  }
690 
691  #endregion
692 
693  #region IUserAgentVerificationModule
694 
695  public bool VerifyClient(AgentCircuitData aCircuit, string token)
696  {
697  if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
698  {
699  string url = aCircuit.ServiceURLs["HomeURI"].ToString();
700  IUserAgentService security = new UserAgentServiceConnector(url);
701  return security.VerifyClient(aCircuit.SessionID, token);
702  }
703  else
704  {
705  m_log.DebugFormat(
706  "[HG ENTITY TRANSFER MODULE]: Agent {0} {1} does not have a HomeURI OH NO!",
707  aCircuit.firstname, aCircuit.lastname);
708  }
709 
710  return false;
711  }
712 
713  void OnConnectionClosed(IClientAPI obj)
714  {
715  if (obj.SceneAgent.IsChildAgent)
716  return;
717 
718  // Let's find out if this is a foreign user or a local user
719  IUserManagement uMan = Scene.RequestModuleInterface<IUserManagement>();
720 // UserAccount account = Scene.UserAccountService.GetUserAccount(Scene.RegionInfo.ScopeID, obj.AgentId);
721 
722  if (uMan != null && uMan.IsLocalGridUser(obj.AgentId))
723  {
724  // local grid user
725  m_UAS.LogoutAgent(obj.AgentId, obj.SessionId);
726  return;
727  }
728 
729  AgentCircuitData aCircuit = ((Scene)(obj.Scene)).AuthenticateHandler.GetAgentCircuitData(obj.CircuitCode);
730  if (aCircuit != null && aCircuit.ServiceURLs != null && aCircuit.ServiceURLs.ContainsKey("HomeURI"))
731  {
732  string url = aCircuit.ServiceURLs["HomeURI"].ToString();
733  IUserAgentService security = new UserAgentServiceConnector(url);
734  security.LogoutAgent(obj.AgentId, obj.SessionId);
735  //m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Sent logout call to UserAgentService @ {0}", url);
736  }
737  else
738  {
739  m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: HomeURI not found for agent {0} logout", obj.AgentId);
740  }
741  }
742 
743  #endregion
744 
745  private GridRegion MakeRegion(AgentCircuitData aCircuit)
746  {
747  GridRegion region = new GridRegion();
748 
749  Uri uri = null;
750  if (!aCircuit.ServiceURLs.ContainsKey("HomeURI") ||
751  (aCircuit.ServiceURLs.ContainsKey("HomeURI") && !Uri.TryCreate(aCircuit.ServiceURLs["HomeURI"].ToString(), UriKind.Absolute, out uri)))
752  return null;
753 
754  region.ExternalHostName = uri.Host;
755  region.HttpPort = (uint)uri.Port;
756  region.ServerURI = aCircuit.ServiceURLs["HomeURI"].ToString();
757  region.RegionName = string.Empty;
758  region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), (int)0);
759  return region;
760  }
761  }
762 }
Contains the Avatar's Appearance and methods to manipulate the appearance.
IUserManagement UserManagementModule
Definition: Scene.cs:774
OpenSim.Services.Interfaces.GridRegion GridRegion
Holds individual statistic details
Definition: Stat.cs:41
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
bool IsChildAgent
If true, then the agent has no avatar in the scene. The agent exists to relay data from a region that...
Definition: ISceneAgent.cs:56
Dictionary< string, object > ServiceURLs
override void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
ISceneAgent SceneAgent
The scene agent for this client. This will only be set if the client has an agent in a scene (i...
Definition: IClientAPI.cs:724
override bool HandleIncomingSceneObject(SceneObjectGroup so, Vector3 newPosition)
bool IsAttachmentCheckFull()
Check both the attachment property and the relevant properties of the underlying root part...
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
Inventory Item - contains all the properties associated with an individual inventory piece...
override GridRegion GetFinalDestination(GridRegion region, UUID agentID, string agentHomeURI, out string message)
virtual AvatarWearable[] Wearables
StatVerbosity
Verbosity of stat.
List< AvatarAttachment > GetAttachments()
Get a list of the attachments.
string ServerURI
A well-formed URI for the host region server (namely "http://" + ExternalHostName) ...
Interactive OpenSim region server
Definition: OpenSim.cs:55
override void RequestTeleportLandmark(IClientAPI remoteClient, AssetLandmark lm)
Tries to teleport agent to landmark.
override bool CreateAgent(ScenePresence sp, GridRegion reg, GridRegion finalDestination, AgentCircuitData agentCircuit, uint teleportFlags, EntityTransferContext ctx, out string reason, out bool logout)
override void AgentHasMovedAway(ScenePresence sp, bool logout)
Clean up operations once an agent has moved away through cross or teleport.
override void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
override void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
override void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
override bool ValidateGenericConditions(ScenePresence sp, GridRegion reg, GridRegion finalDestination, uint teleportFlags, out string reason)
uint teleportFlags
How this agent got here
override bool TeleportHome(UUID id, IClientAPI client)
Teleports the agent for the given client to their home destination.
This maintains the relationship between a UUID and a user name.
MeasuresOfInterest
Measures of interest for this stat.