Beispiel #1
0
        private void SendCoarseLocationUpdateToSpecificAgent(IAgent agent, Dictionary <UUID, Vector3> data)
        {
            const int            NUM_OF_ENTRIES = 50;
            CoarseLocationUpdate upd            = null;
            UUID ownId   = agent.ID;
            UUID trackId = agent.TracksAgentID;
            /* var region scaling */
            double scaleX = 256 / SizeX;
            double scaleY = 256 / SizeY;

            foreach (KeyValuePair <UUID, Vector3> kvp in data)
            {
                if (upd == null)
                {
                    upd = new CoarseLocationUpdate
                    {
                        Prey = -1,
                        You  = -1
                    };
                }

                int count = upd.AgentData.Count;

                if (kvp.Key == ownId)
                {
                    upd.You = (short)count;
                }
                if (kvp.Key == trackId)
                {
                    upd.Prey = (short)count;
                }

                upd.AgentData.Add(new CoarseLocationUpdate.AgentDataEntry
                {
                    AgentID = kvp.Key,
                    X       = (byte)(kvp.Value.X * scaleX).Clamp(0, 255),
                    Y       = (byte)(kvp.Value.Y * scaleY).Clamp(0, 255),
                    Z       = (byte)(kvp.Value.Z / 4).Clamp(0, 255)
                });

                if (count + 1 == NUM_OF_ENTRIES)
                {
                    agent.SendMessageAlways(upd, ID);
                    upd = null;
                }
            }

            if (upd != null)
            {
                agent.SendMessageAlways(upd, ID);
            }
        }
        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);
                }
            }
        }