private void CoarseLocationHandler(Packet packet, Simulator simulator) { CoarseLocationUpdatePacket coarse = (CoarseLocationUpdatePacket)packet; lock (simulator.avatarPositions) { simulator.avatarPositions.Clear(); for (int i = 0; i < coarse.Location.Length; i++) { if (i == coarse.Index.You) { simulator.positionIndexYou = i; } else if (i == coarse.Index.Prey) { simulator.positionIndexPrey = i; } simulator.avatarPositions.Add(new LLVector3(coarse.Location[i].X, coarse.Location[i].Y, coarse.Location[i].Z)); } if (OnCoarseLocationUpdate != null) { try { OnCoarseLocationUpdate(simulator); } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } } }
void CoarseLocationTimer_Elapsed(object sender) { lock (Server.Agents) { List<Vector3> avatarPositions = new List<Vector3>(); CoarseLocationUpdatePacket update = new CoarseLocationUpdatePacket(); update.AgentData = new CoarseLocationUpdatePacket.AgentDataBlock[Server.Agents.Count]; update.Location = new CoarseLocationUpdatePacket.LocationBlock[Server.Agents.Count]; short i = 0; foreach (Agent agent in Server.Agents.Values) { update.AgentData[i] = new CoarseLocationUpdatePacket.AgentDataBlock(); update.AgentData[i].AgentID = agent.AgentID; update.Location[i] = new CoarseLocationUpdatePacket.LocationBlock(); update.Location[i].X = (byte)((int)agent.Avatar.Position.X); update.Location[i].Y = (byte)((int)agent.Avatar.Position.Y); update.Location[i].Z = (byte)((int)agent.Avatar.Position.Z / 4); update.Index.Prey = -1; i++; } i = 0; foreach (Agent recipient in Server.Agents.Values) { update.Index.You = i; recipient.SendPacket(update); i++; } } }
/// <summary>Process an incoming packet and raise the appropriate events</summary> /// <param name="sender">The sender</param> /// <param name="e">The EventArgs object containing the packet data</param> protected void CoarseLocationHandler(object sender, PacketReceivedEventArgs e) { CoarseLocationUpdatePacket coarse = (CoarseLocationUpdatePacket)e.Packet; // populate a dictionary from the packet, for local use Dictionary <UUID, Vector3> coarseEntries = new Dictionary <UUID, Vector3>(); for (int i = 0; i < coarse.AgentData.Length; i++) { if (coarse.Location.Length > 0) { coarseEntries[coarse.AgentData[i].AgentID] = new Vector3((int)coarse.Location[i].X, (int)coarse.Location[i].Y, (int)coarse.Location[i].Z * 4); } // the friend we are tracking on radar if (i == coarse.Index.Prey) { e.Simulator.preyID = coarse.AgentData[i].AgentID; } } // find stale entries (people who left the sim) List <UUID> removedEntries = e.Simulator.avatarPositions.FindAll( findID => !coarseEntries.ContainsKey(findID)); // anyone who was not listed in the previous update List <UUID> newEntries = new List <UUID>(); lock (e.Simulator.avatarPositions.Dictionary) { // remove stale entries foreach (UUID trackedID in removedEntries) { e.Simulator.avatarPositions.Dictionary.Remove(trackedID); } // add or update tracked info, and record who is new foreach (KeyValuePair <UUID, Vector3> entry in coarseEntries) { if (!e.Simulator.avatarPositions.Dictionary.ContainsKey(entry.Key)) { newEntries.Add(entry.Key); } e.Simulator.avatarPositions.Dictionary[entry.Key] = entry.Value; } } if (m_CoarseLocationUpdate != null) { ThreadPool.QueueUserWorkItem(delegate(object o) { OnCoarseLocationUpdate(new CoarseLocationUpdateEventArgs(e.Simulator, newEntries, removedEntries)); }); } }
private void CoarseLocationHandler(Packet packet, Simulator simulator) { CoarseLocationUpdatePacket coarse = (CoarseLocationUpdatePacket)packet; // populate a dictionary from the packet, for local use Dictionary <UUID, Vector3> coarseEntries = new Dictionary <UUID, Vector3>(); for (int i = 0; i < coarse.AgentData.Length; i++) { coarseEntries[coarse.AgentData[i].AgentID] = new Vector3((int)coarse.Location[i].X, (int)coarse.Location[i].Y, (int)coarse.Location[i].Z * 4); // the friend we are tracking on radar if (i == coarse.Index.Prey) { simulator.preyID = coarse.AgentData[i].AgentID; } } // find stale entries (people who left the sim) List <UUID> removedEntries = simulator.avatarPositions.FindAll(delegate(UUID findID) { return(!coarseEntries.ContainsKey(findID)); }); // anyone who was not listed in the previous update List <UUID> newEntries = new List <UUID>(); lock (simulator.avatarPositions) { // remove stale entries foreach (UUID trackedID in removedEntries) { simulator.avatarPositions.Dictionary.Remove(trackedID); } // add or update tracked info, and record who is new foreach (KeyValuePair <UUID, Vector3> entry in coarseEntries) { if (!simulator.avatarPositions.Dictionary.ContainsKey(entry.Key)) { newEntries.Add(entry.Key); } simulator.avatarPositions.Dictionary[entry.Key] = entry.Value; } } if (OnCoarseLocationUpdate != null) { try { OnCoarseLocationUpdate(simulator, newEntries, removedEntries); } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } }
void CoarseLocationTimer_Elapsed(object sender) { lock (server.Agents) { foreach (Agent recipient in server.Agents.Values) { int i = 0; CoarseLocationUpdatePacket update = new CoarseLocationUpdatePacket(); update.Index.Prey = -1; update.Index.You = 0; update.AgentData = new CoarseLocationUpdatePacket.AgentDataBlock[server.Agents.Count]; update.Location = new CoarseLocationUpdatePacket.LocationBlock[server.Agents.Count]; // Fill in this avatar update.AgentData[0] = new CoarseLocationUpdatePacket.AgentDataBlock(); update.AgentData[0].AgentID = recipient.AgentID; update.Location[0] = new CoarseLocationUpdatePacket.LocationBlock(); update.Location[0].X = (byte)((int)recipient.Avatar.Position.X); update.Location[0].Y = (byte)((int)recipient.Avatar.Position.Y); update.Location[0].Z = (byte)((int)recipient.Avatar.Position.Z / 4); ++i; foreach (Agent agent in server.Agents.Values) { if (agent != recipient) { update.AgentData[i] = new CoarseLocationUpdatePacket.AgentDataBlock(); update.AgentData[i].AgentID = agent.AgentID; update.Location[i] = new CoarseLocationUpdatePacket.LocationBlock(); update.Location[i].X = (byte)((int)agent.Avatar.Position.X); update.Location[i].Y = (byte)((int)agent.Avatar.Position.Y); update.Location[i].Z = (byte)((int)agent.Avatar.Position.Z / 4); ++i; } } server.UDP.SendPacket(recipient.AgentID, update, PacketCategory.State); } } }
private void CoarseLocationHandler(Packet packet, Simulator simulator) { CoarseLocationUpdatePacket coarse = (CoarseLocationUpdatePacket)packet; lock (simulator.avatarPositions) { simulator.avatarPositions.Clear(); for (int i = 0; i < coarse.Location.Length; i++) { if (i == coarse.Index.You) { simulator.positionIndexYou = i; } else if (i == coarse.Index.Prey) { simulator.positionIndexPrey = i; } simulator.avatarPositions.Add(new LLVector3(coarse.Location[i].X, coarse.Location[i].Y, coarse.Location[i].Z)); } } }
private void SendCoarseLocations(object sender, System.Timers.ElapsedEventArgs e) { const int MAX_LOCATIONS = 60; const int INTERVAL_SECONDS = 3; if (++m_coarseLocationSeconds >= INTERVAL_SECONDS) { m_coarseLocationSeconds = 0; IScenePresence[] presences = m_scene.GetPresences(); if (presences.Length == 0) { return; } // Prune out child agents List <IScenePresence> rootPresences = new List <IScenePresence>(presences.Length); for (int i = 0; i < presences.Length; i++) { if (!presences[i].IsChildPresence) { rootPresences.Add(presences[i]); } } // Clamp the maximum locations to put in this packet int count = Math.Min(rootPresences.Count, MAX_LOCATIONS); if (count == 0) { return; } // Create the location and agentID blocks CoarseLocationUpdatePacket.AgentDataBlock[] uuids = new CoarseLocationUpdatePacket.AgentDataBlock[count]; CoarseLocationUpdatePacket.LocationBlock[] locations = new CoarseLocationUpdatePacket.LocationBlock[count]; for (int i = 0; i < count; i++) { IScenePresence presence = rootPresences[i]; Vector3 pos = presence.ScenePosition; uuids[i] = new CoarseLocationUpdatePacket.AgentDataBlock { AgentID = presence.ID }; locations[i] = new CoarseLocationUpdatePacket.LocationBlock { X = (byte)pos.X, Y = (byte)pos.Y, Z = (byte)pos.Z }; } for (int i = 0; i < rootPresences.Count; i++) { if (rootPresences[i] is LLAgent) { LLAgent agent = (LLAgent)rootPresences[i]; CoarseLocationUpdatePacket packet = new CoarseLocationUpdatePacket(); packet.Header.Reliable = false; packet.AgentData = uuids; packet.Location = locations; // Only the first MAX_COUNT avatars are in the list int you = (i < count) ? i : -1; packet.Index.You = (short)you; // TODO: Support Prey packet.Index.Prey = -1; m_udp.SendPacket(agent, packet, ThrottleCategory.Task, false); } } } }
private Packet LocationIN(Packet p, IPEndPoint sim) { //if (sim.Address != shared.ip || sim.Port != shared.port) return p; if (sim.ToString() != proxy.activeCircuit.ToString()) { return(p); } CoarseLocationUpdatePacket c = (CoarseLocationUpdatePacket)p; List <UUID> temp = new List <UUID>(); bool say = false; if (c.AgentData.Length < 1) { return(p); } lock (avs) { foreach (CoarseLocationUpdatePacket.AgentDataBlock a in c.AgentData) { if (!avs.Contains(a.AgentID)) { say = true; form.listBox1.Items.Add(a.AgentID.ToString()); if (shared.key2name.ContainsKey(a.AgentID)) { form.listBox2.Items.Add(shared.key2name[a.AgentID]); } else { plugin.RequestNameFromKey(a.AgentID); pending.Add(a.AgentID); } } temp.Add(a.AgentID); } foreach (UUID u in avs) { if (!temp.Contains(u)) { say = true; form.listBox1.Items.Remove(u.ToString()); if (shared.key2name.ContainsKey(u)) { if (form.listBox2.Items.Contains(shared.key2name[u])) { form.listBox2.Items.Remove(shared.key2name[u]); } } } } } avs = temp; if (say) { if (form.checkBox1.Checked) { sendUpdate(); } } return(p); }
private void SendCoarseLocations(object sender, System.Timers.ElapsedEventArgs e) { const int MAX_LOCATIONS = 60; const int INTERVAL_SECONDS = 3; if (++m_coarseLocationSeconds >= INTERVAL_SECONDS) { m_coarseLocationSeconds = 0; IScenePresence[] presences = m_scene.GetPresences(); if (presences.Length == 0) return; // Prune out child agents List<IScenePresence> rootPresences = new List<IScenePresence>(presences.Length); for (int i = 0; i < presences.Length; i++) { if (!presences[i].IsChildPresence) rootPresences.Add(presences[i]); } // Clamp the maximum locations to put in this packet int count = Math.Min(rootPresences.Count, MAX_LOCATIONS); if (count == 0) return; // Create the location and agentID blocks CoarseLocationUpdatePacket.AgentDataBlock[] uuids = new CoarseLocationUpdatePacket.AgentDataBlock[count]; CoarseLocationUpdatePacket.LocationBlock[] locations = new CoarseLocationUpdatePacket.LocationBlock[count]; for (int i = 0; i < count; i++) { IScenePresence presence = rootPresences[i]; Vector3 pos = presence.ScenePosition; uuids[i] = new CoarseLocationUpdatePacket.AgentDataBlock { AgentID = presence.ID }; locations[i] = new CoarseLocationUpdatePacket.LocationBlock { X = (byte)pos.X, Y = (byte)pos.Y, Z = (byte)pos.Z }; } for (int i = 0; i < rootPresences.Count; i++) { if (rootPresences[i] is LLAgent) { LLAgent agent = (LLAgent)rootPresences[i]; CoarseLocationUpdatePacket packet = new CoarseLocationUpdatePacket(); packet.Header.Reliable = false; packet.AgentData = uuids; packet.Location = locations; // Only the first MAX_COUNT avatars are in the list int you = (i < count) ? i : -1; packet.Index.You = (short)you; // TODO: Support Prey packet.Index.Prey = -1; m_udp.SendPacket(agent, packet, ThrottleCategory.Task, false); } } } }