public void HandleRequestGodlikePowers(Message p)
        {
            var m = (RequestGodlikePowers)p;

            if (m.AgentID != ID || m.SessionID != m.CircuitSessionID)
            {
                return;
            }

            if (m.IsGodlike && !m_IsActiveGod)
            {
                /* request god powers */
                if (CheckForGodPowers(m.CircuitSceneID, ID))
                {
                    var r = new GrantGodlikePowers
                    {
                        AgentID   = m.AgentID,
                        SessionID = m.SessionID,

                        GodLevel = 255,
                        Token    = UUID.Zero
                    };
                    m_IsActiveGod = true;
                    SendMessageIfRootAgent(r, m.CircuitSceneID);
                }
                else
                {
                    var r = new AlertMessage
                    {
                        Message = "NOTIFY: GodlikeRequestFailed"
                    };
                    SendMessageIfRootAgent(r, m.CircuitSceneID);
                }
            }
            else if (!m.IsGodlike && m_IsActiveGod)
            {
                var r = new GrantGodlikePowers
                {
                    AgentID   = m.AgentID,
                    SessionID = m.SessionID,

                    GodLevel = 0,
                    Token    = UUID.Zero
                };
                m_IsActiveGod = false;
                SendMessageAlways(r, m.CircuitSceneID);
            }
        }
        public void HandleCompleteAgentMovement(Message m)
        {
            var          cam = (CompleteAgentMovement)m;
            AgentCircuit circuit;

            if (cam.SessionID != cam.CircuitSessionID ||
                cam.AgentID != cam.CircuitAgentID)
            {
                m_Log.InfoFormat("Unexpected CompleteAgentMovement with invalid details");
            }
            else if (Circuits.TryGetValue(cam.CircuitSceneID, out circuit))
            {
                var scene = circuit.Scene;
                if (scene == null)
                {
                    return;
                }

                /* switch agent region */
                if (m_IsActiveGod && !scene.IsPossibleGod(Owner))
                {
                    /* revoke god powers when changing region and new region has a different owner */
                    var gm = new GrantGodlikePowers
                    {
                        AgentID   = ID,
                        SessionID = circuit.SessionID,
                        GodLevel  = 0,
                        Token     = UUID.Zero
                    };
                    SendMessageIfRootAgent(gm, SceneID);
                    m_IsActiveGod = false;
                }
                SceneID = scene.ID;
                scene.TriggerAgentChangedScene(this);

                if (circuit.LastTeleportFlags.NeedsInitialPosition())
                {
                    try
                    {
                        scene.DetermineInitialAgentLocation(this, circuit.LastTeleportFlags, GlobalPosition, LookAt);
                    }
                    catch
                    {
                        /* TODO: how to do this? */
                        return;
                    }
                }

                var amc = new AgentMovementComplete
                {
                    AgentID        = cam.AgentID,
                    ChannelVersion = VersionInfo.SimulatorVersion,
                    LookAt         = circuit.Agent.LookAt,
                    Position       = GlobalPosition,
                    SessionID      = cam.SessionID,
                    GridPosition   = circuit.Scene.GridPosition,
                    Timestamp      = (uint)Date.GetUnixTime()
                };

                amc.OnSendCompletion += (bool success) =>
                {
                    if (success)
                    {
                        HandleChildAgentChanges(circuit);
                    }
                };
                circuit.SendMessage(amc);

                SendAgentDataUpdate(circuit);
                scene.SendAgentObjectToAllAgents(this);

                var clu = new CoarseLocationUpdate
                {
                    You  = 0,
                    Prey = -1
                };
                var ad = new CoarseLocationUpdate.AgentDataEntry
                {
                    X       = (byte)(uint)GlobalPosition.X,
                    Y       = (byte)(uint)GlobalPosition.Y,
                    Z       = (byte)(uint)GlobalPosition.Z,
                    AgentID = ID
                };
                clu.AgentData.Add(ad);
                circuit.SendMessage(clu);

                scene.Environment.UpdateWindlightProfileToClientNoReset(this);
                scene.Environment.SendSimulatorTimeMessageToClient(this);

                foreach (var action in circuit.m_TriggerOnRootAgentActions)
                {
                    action.TriggerOnRootAgent(ID, scene);
                }
            }
        }