mirror of
https://github.com/opensim/opensim.git
synced 2026-05-27 12:26:01 +08:00
* We now have CloseAllAgents( circuit ) and CloseAllCircuits( agentId ) for great justice ( but alas, still only closing on one single scene - be brave! ) * Login and ConnectionClosed now eventified and moveified awayified * Killed off unused NullClientAPI * Now the client is almost only responsible for its own closing. ( I will get that scene out of there ) * Lookin' good!
105 lines
2.8 KiB
C#
105 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using libsecondlife.Packets;
|
|
using OpenSim.Framework.Interfaces;
|
|
using libsecondlife;
|
|
|
|
namespace OpenSim.Framework
|
|
{
|
|
public delegate void ForEachClientDelegate(IClientAPI client);
|
|
public class ClientManager
|
|
{
|
|
private Dictionary<uint, IClientAPI> m_clients;
|
|
|
|
public void ForEachClient(ForEachClientDelegate whatToDo)
|
|
{
|
|
foreach (IClientAPI client in m_clients.Values)
|
|
{
|
|
whatToDo(client);
|
|
}
|
|
}
|
|
|
|
public ClientManager()
|
|
{
|
|
m_clients = new Dictionary<uint, IClientAPI>();
|
|
}
|
|
|
|
private void Remove(uint id)
|
|
{
|
|
m_clients.Remove(id);
|
|
}
|
|
|
|
public void Add(uint id, IClientAPI client)
|
|
{
|
|
m_clients.Add(id, client);
|
|
}
|
|
|
|
public void InPacket(uint circuitCode, libsecondlife.Packets.Packet packet)
|
|
{
|
|
IClientAPI client;
|
|
|
|
if (m_clients.TryGetValue(circuitCode, out client))
|
|
{
|
|
client.InPacket(packet);
|
|
}
|
|
}
|
|
|
|
public void CloseAllAgents(uint circuitCode)
|
|
{
|
|
IClientAPI client;
|
|
|
|
if (m_clients.TryGetValue(circuitCode, out client))
|
|
{
|
|
CloseAllCircuits(client.AgentId);
|
|
}
|
|
}
|
|
|
|
public void CloseAllCircuits( LLUUID agentId )
|
|
{
|
|
uint[] circuits = GetAllCircuits(agentId);
|
|
foreach (uint circuit in circuits )
|
|
{
|
|
IClientAPI client;
|
|
if (m_clients.TryGetValue(circuit, out client))
|
|
{
|
|
Remove(circuit);
|
|
client.Close();
|
|
}
|
|
}
|
|
}
|
|
|
|
private uint[] GetAllCircuits(LLUUID agentId)
|
|
{
|
|
List<uint> circuits = new List<uint>();
|
|
|
|
foreach (KeyValuePair<uint, IClientAPI> pair in m_clients)
|
|
{
|
|
if( pair.Value.AgentId == agentId )
|
|
{
|
|
circuits.Add( pair.Key );
|
|
}
|
|
}
|
|
|
|
return circuits.ToArray();
|
|
}
|
|
|
|
|
|
public void ViewerEffectHandler(IClientAPI sender, ViewerEffectPacket.EffectBlock[] effectBlock)
|
|
{
|
|
ViewerEffectPacket packet = new ViewerEffectPacket();
|
|
packet.Effect = effectBlock;
|
|
|
|
foreach (IClientAPI client in m_clients.Values)
|
|
{
|
|
if (client.AgentId != sender.AgentId)
|
|
{
|
|
packet.AgentData.AgentID = client.AgentId;
|
|
packet.AgentData.SessionID = client.SessionId;
|
|
client.OutPacket(packet);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|