using System.Collections.Generic; using Arrowgene.Services.Buffers; using Arrowgene.Services.Logging; using Mhf.Server.Logging; using Mhf.Server.Model; namespace Mhf.Server.Packet { public class PacketRouter { private readonly MhfLogger _logger; public PacketRouter() { _logger = LogProvider.Logger(this); } /// /// Send a packet to a client. /// public void Send(ISender client, MhfPacket packet) { client.Send(packet); } /// /// Send a packet to a client. /// public void Send(ISender client, ushort id, IBuffer data) { MhfPacket packet = new MhfPacket(id, data); Send(client, packet); } /// /// Send a packet to multiple clients. /// /// clients to exclude public void Send(List clients, MhfPacket packet, params ISender[] excepts) { clients = GetClients(clients, excepts); foreach (MhfClient client in clients) { Send(client, packet); } } /// /// Send a packet to multiple clients. /// /// clients to exclude public void Send(List clients, ushort id, IBuffer data, params ISender[] excepts) { Send(clients, new MhfPacket(id, data), excepts); } /// /// Send a specific packet response. /// public void Send(PacketResponse response) { foreach (ISender client in response.Receiver) { Send(client, response.ToPacket()); } } /// /// Send a specific packet response. /// public void Send(PacketResponse response, params ISender[] clients) { response.AddReceiver(clients); Send(response); } private List GetClients(List clients, params ISender[] excepts) { if (excepts.Length == 0) { return clients; } foreach (ISender except in excepts) { clients.Remove(except); } return clients; } } }