private void Send(BasePacket packet, IEnumerable <ConnectedClient> clients) { List <SocketPacketPair> listOfPacketsToSend = new List <SocketPacketPair>(); foreach (var client in clients)// this should be improved. I try to save the results and then do them all at once. Prevents locks. { BasePacket bp = IntrepidSerialize.ReplicatePacket(packet); listOfPacketsToSend.Add(new SocketPacketPair(client.SocketId, bp)); } lock (containersLock) { foreach (var item in listOfPacketsToSend) { containers.outgoingPackets.Enqueue(item); } } IntrepidSerialize.ReturnToPool(packet); }
private void SendChangeBehavior(ServerPlayer[] playerInRange, Behavior behavior) { if (playerInRange.Length > 0) { NPC_BTState packet = IntrepidSerialize.TakeFromPool(PacketType.NPC_BTState) as NPC_BTState; packet.guid.Copy(behavior.id); if (packet == null) { return; } packet.entityId = EntityId; previousState = (NPC_BTState)IntrepidSerialize.ReplicatePacket(packet); Server.Send(packet, playerInRange.Select(e => e.EntityId)); } }