[Request]Broadcast timer O.O

10/21/2008 02:36 BlooD-BoY#1
umm could any one help me with a broadcast timer...i want it to go like that "if "Broadcast timer = #" then it would send your msg O.O lets say person #1 send a msg then person #2 sends a msg right after him....the timer will stop it for like 10 secs and then release it O.O any ideas? thx =)
10/21/2008 04:28 InfamousNoone#2
So you want a queued broadcast? Like after 10 seconds (or more) if a message is pending, the next message gets appended to (sent)? If so...

Code:
//requires
//using System.Threading;
//using System.Collections.Generic;

// call BroadcastQueue.Init() when the server starts up

    public class BroadcastQueue
    {
        private static Queue<byte[]> Queue;

        private static void ExportGlobalPacket(byte[] Packet)
        {
            // method to send the packet to everyone on the server
        }
        public static void Init()
        {
            Queue = new Queue<byte[]>();
            new Thread(
                delegate()
                {
                    while (true)
                    {
                        const int Ten_Seconds = 10 * 1000;
                        byte[] Outgoing;
                        lock (Queue)
                        {
                            Outgoing = Queue.Dequeue();
                        }
                        ExportGlobalPacket(Outgoing);
                        Thread.Sleep(Ten_Seconds);
                    }
                }
            ).Start();
        }
        public static void Add(byte[] BroadcastMsgPacket)
        {
            lock (Queue)
            {
                Queue.Enqueue(BroadcastMsgPacket);
            }
        }
    }