Jump to content

OpenSimulator Internals/Code Map/EntityTransferModule

From Open Simulator Technical Help

OpenSimulator Internals/Code Map/EntityTransferModule

[edit]

Overview

[edit]
OpenSim/Region/CoreModules/Framework/EntityTransfer/EntityTransferModule.cs

INonSharedRegionModule. Handles all agent movement between regions: teleport (within region and to other regions), region crossing, child agent management, and object crossing. One instance per region.

Registered as IEntityTransferModule. Extended by HGEntityTransferModule for HyperGrid.


Configuration

[edit]
[EntityTransfer] section
Key Default Purpose
wait_for_callback true Source region waits for destination to confirm arrival before closing agent
DisableInterRegionTeleportCancellation false If true, tells viewer to disable cancel button

Event Wiring

[edit]

OnNewClient() hooks per client:

Event Handler
OnTeleportHomeRequest TriggerTeleportHome()
OnTeleportLandmarkRequest RequestTeleportLandmark()
OnTeleportCancel OnClientCancelTeleport() (if cancellation enabled)
OnConnectionClosed OnConnectionClosed()

OnConnectionClosed(): if client IsLoggingOut while in transit, updates transfer state to Aborting.


Transfer State Machine

[edit]

EntityTransferStateMachine tracks per-agent transfer state:

State Meaning
(none) Not in transit
Transferring Transfer initiated, past point of no clean abort
ReceivedAtDestination Destination confirmed arrival
CleaningUp Closing child agents and source agent
Cancelling Client requested cancel
Aborting Client disconnected during transfer

SetInTransit() / ResetFromTransit() bracket the full operation. UpdateInTransit() moves through states. Failed transitions are logged and abort the operation.


Teleport Entry Point

[edit]
Teleport(ScenePresence sp, ulong regionHandle, Vector3 position, Vector3 lookAt, uint teleportFlags)
  1. Checks permissions (CanTeleport). Adds Godlike flag if grid god.
  2. Calls SetInTransit() -- rejects if already in transit.
  3. If destination handle matches current region after offset check: calls TeleportAgentWithinRegion().
  4. Otherwise: calls TeleportAgentToDifferentRegion().
  5. ResetFromTransit() in finally block.

TeleportAgentWithinRegion()

[edit]

Local teleport within the same region.

  1. Validates position is within region bounds; substitutes emergency pos (128,128,128) if not.
  2. Raises Z to ground height + avatar half-height.
  3. Sends TeleportStart to viewer.
  4. Sends SendLocalTeleport to viewer.
  5. Sets sp.TeleportFlags, rotates avatar, zeros velocity.
  6. Calls sp.Teleport(position) -- moves physics actor.
  7. Fires CHANGED_TELEPORT script event on all attachment SOGs.

TeleportAgentToDifferentRegion()

[edit]
  1. Calls GetTeleportDestinationRegion() -- GridService.GetRegionByPosition() accounting for varregion offsets.
  2. Calls GetFinalDestination() (HG hook -- returns same region for normal grid).
  3. Calls ValidateGenericConditions() (override point).
  4. Calls DoTeleportInternal().

DoTeleportInternal()

[edit]

Core cross-simulator teleport sequence.

  1. DNS resolution: finalDestination.ExternalEndPoint.
  2. Calls SimulationService.QueryAccess() -- destination region confirms it will accept the agent. Returns reason string on refusal.
  3. Checks sp.Appearance.CanTeleport(ctx.OutboundVersion) -- rejects if outfit incompatible with destination protocol version.
  4. If avatar sitting: calls sp.StandUp().
  5. Sets sp.IsInTransit = true.
  6. Sends TeleportStart to viewer.
  7. Builds AgentCircuitData for the destination.
  8. Determines OutSideViewRange -- whether destination already has a child agent or needs a new one.
  9. Selects protocol version: V2 (>= 0.2) or V1 fallback.

TransferAgent_V2()

[edit]

Current protocol path.

  1. If OutSideViewRange: removes current region handle from ChildrenCapSeeds.
  2. Calls CreateAgent() -- SimulationService.CreateAgent() to destination. Fires TeleportStart event.
  3. Checks cancel/abort state.
  4. Sets sp.IsChildAgent = true.
  5. Sends TeleportFinishEvent to viewer immediately (V2 difference from V1: no prior EnableSimulator/EstablishAgentCommunication).
  6. Builds full AgentData via sp.CopyTo() including appearance, animations, attachments, script states.
  7. Sets SenderWantsToWaitForRoot = true in AgentData.
  8. Calls UpdateAgent() -- SimulationService.UpdateAgent() sends full agent state to destination. Blocks until destination's CompleteMovement() fires and returns.
  9. On UpdateAgent success: calls sp.HasMovedAway(), sp.MakeChildAgent(), CloseChildAgents().
  10. If NeedsClosing (OutSideViewRange): waits up to 15 seconds for sp.IsInTransit to clear, then calls m_scene.CloseAgent().

TransferAgent_V1()

[edit]

Legacy protocol path (destination protocol < 0.2).

  1. Calls CreateAgent().
  2. If OutSideViewRange: sends EnableSimulator + EstablishAgentCommunication via event queue, then sleeps 200ms.
  3. Sends full AgentData via UpdateAgent().
  4. Sends TeleportFinishEvent.
  5. Waits for WaitForAgentArrivedAtDestination() callback -- blocks up to 10 seconds.
  6. On success: CloseChildAgents(), MakeChildAgent(), CloseAgent() after 2-second sleep (viewer compatibility).

Region Crossing

[edit]

Cross(ScenePresence, isFlying):

  • Fires async via WorkManager.RunInThreadPool.
  • Calls CrossAsync() → CrossAgentToNewRegionAsync() → CrossAgentIntoNewRegionMain().

CrossAgentIntoNewRegionMain():

  1. Calls sp.CopyTo(cAgent, isCrossUpdate=true) -- full agent state including cross flags.
  2. Sets position to projected crossing position.
  3. Calls SimulationService.UpdateAgent() -- sends state to destination. Destination's IncomingUpdateChildAgent() fires, sets m_originRegionID.
  4. On success: sets sp.IsChildAgent = true, sends CrossRegion event queue message to viewer.
  5. CloseChildAgents() for out-of-range neighbours.
  6. Calls sp.HasMovedAway(), sp.MakeChildAgent().

CrossAsync() detects crossing by projecting position + velocity * 0.2s and calling GetDestination() → GridService.GetRegionByPosition().


Child Agent Management

[edit]

EnableChildAgents(ScenePresence sp):

  • Computes neighbours within RegionViewDistance via RegionsInSPView().
  • For new neighbours: builds AgentCircuitData, calls CreateAgent() + EnableSimulator + EstablishAgentCommunication.
  • For regions no longer in view: calls sp.CloseChildAgents().
  • Updates KnownRegions and cap seeds.
  • Sends AgentPosition updates to existing known neighbours.
  • Neighbour list cached for 30 seconds.

EnableChildAgent(sp, region): single-region version, used when a new neighbour comes online.

CloseOldChildAgents(sp): called from SendInitialData() on login. Closes any child agents not in current view range.


Failure Handling

[edit]

Fail():

  • Calls CleanupFailedInterRegionTeleport() -- sets IsChildAgent=false, ReInstantiateScripts(), calls SimulationService.CloseAgent() on destination.
  • Sends TeleportFailed to viewer.
  • Fires TriggerTeleportFail event.

BannedRegionCache: ExpiringCacheOS keyed by region handle → Dictionary<UUID, expiry>. Regions that refuse QueryAccess are cached for 60 seconds to avoid hammering.

NotFoundLocationCache: Caches region handle positions that returned null from GridService for 30 seconds.


Key Virtual Methods (HG Override Points)

[edit]
Method Purpose
GetFinalDestination() Returns destination region (HG overrides to resolve HG address)
CreateAgent() Calls SimulationService.CreateAgent() (HG overrides to set logout flag)
UpdateAgent() Calls SimulationService.UpdateAgent()
AgentHasMovedAway() Hook after agent departs (HG deletes attachments from scene)
NeedsClosing() Whether to close source agent (HG uses different logic)
ValidateGenericConditions() Additional pre-flight checks (base returns true)

Object Crossing

[edit]

CrossPrimGroupIntoNewRegion():

  • Calls SimulationService.CreateObject() on destination.
  • On success: calls scene.DeleteSceneObject() on source.

GetObjectDestination(): projects object position into world coordinates, calls GridService.GetRegionByPosition().


Statistics

[edit]

Four stats registered per region under "entitytransfer" category:

  • InterRegionTeleportAttempts
  • InterRegionTeleportAborts (simultaneous logout)
  • InterRegionTeleportCancels (client cancel)
  • InterRegionTeleportFailures (network/server problems)

See Also

[edit]