Esempio n. 1
0
        /// <summary>
        /// Adds a "special" message to the send queue that replaces
        /// previous messages of the same type in the queue.
        /// </summary>
        /// <param name="qm">The message to queue.</param>
        private void AddSpecialQueuedMessage(QueuedMessage qm)
        {
            int broadcastingMessageIndex = MessageQueue.FindIndex(m => m.MessageType == qm.MessageType);

            if (broadcastingMessageIndex > -1)
            {
                if (ProgramConstants.LOG_LEVEL > 1)
                {
                    Logger.Log("QM Replace: " + qm.Command + " " + broadcastingMessageIndex);
                }
                MessageQueue[broadcastingMessageIndex] = qm;
            }
            else
            {
                int placeInQueue = MessageQueue.FindIndex(m => m.Priority < qm.Priority);
                if (ProgramConstants.LOG_LEVEL > 1)
                {
                    Logger.Log("QM: " + qm.Command + " " + placeInQueue);
                }
                if (placeInQueue == -1)
                {
                    MessageQueue.Add(qm);
                }
                else
                {
                    MessageQueue.Insert(placeInQueue, qm);
                }
            }
        }
Esempio n. 2
0
        public void QueueMessage(QueuedMessageType type, int priority, int delay, string message)
        {
            QueuedMessage qm = new QueuedMessage(message, type, priority, delay);

            QueueMessage(qm);
            Logger.Log("Setting delay to " + delay + "ms for " + qm.ID);
        }
Esempio n. 3
0
        /// <summary>
        /// Adds a message to the send queue.
        /// </summary>
        /// <param name="qm">The message to queue.</param>
        /// <param name="replace">If true, attempt to replace a previous message of the same type</param>
        public void QueueMessage(QueuedMessage qm)
        {
            if (!_isConnected)
            {
                return;
            }

            if (qm.Replace && ReplaceMessage(qm))
            {
                return;
            }

            qm.ID = NextQueueID++;

            lock (messageQueueLocker)
            {
                switch (qm.MessageType)
                {
                case QueuedMessageType.GAME_BROADCASTING_MESSAGE:
                case QueuedMessageType.GAME_PLAYERS_MESSAGE:
                case QueuedMessageType.GAME_SETTINGS_MESSAGE:
                case QueuedMessageType.GAME_PLAYERS_READY_STATUS_MESSAGE:
                case QueuedMessageType.GAME_LOCKED_MESSAGE:
                case QueuedMessageType.GAME_GET_READY_MESSAGE:
                case QueuedMessageType.GAME_NOTIFICATION_MESSAGE:
                case QueuedMessageType.GAME_HOSTING_MESSAGE:
                case QueuedMessageType.WHOIS_MESSAGE:
                case QueuedMessageType.GAME_CHEATER_MESSAGE:
                    AddSpecialQueuedMessage(qm);
                    break;

                case QueuedMessageType.INSTANT_MESSAGE:
                    SendMessage(qm.Command);
                    break;

                default:
                    int placeInQueue = MessageQueue.FindIndex(m => m.Priority < qm.Priority);
                    if (ProgramConstants.LOG_LEVEL > 1)
                    {
                        Logger.Log("QM Undefined: " + qm.Command + " " + placeInQueue);
                    }
                    if (placeInQueue == -1)
                    {
                        MessageQueue.Add(qm);
                    }
                    else
                    {
                        MessageQueue.Insert(placeInQueue, qm);
                    }
                    break;
                }
            }
        }
Esempio n. 4
0
        private void RunSendQueue()
        {
            while (_isConnected)
            {
                string message = String.Empty;

                lock (messageQueueLocker)
                {
                    for (int i = 0; i < MessageQueue.Count; i++)
                    {
                        QueuedMessage qm = MessageQueue[i];
                        if (qm.Delay > 0)
                        {
                            if (qm.SendAt < DateTime.Now)
                            {
                                message = qm.Command;

                                Logger.Log("Delayed message sent: " + qm.ID);

                                MessageQueue.RemoveAt(i);
                                break;
                            }
                        }
                        else
                        {
                            message = qm.Command;
                            MessageQueue.RemoveAt(i);
                            break;
                        }
                    }
                }

                if (String.IsNullOrEmpty(message))
                {
                    Thread.Sleep(10);
                    continue;
                }

                SendMessage(message);

                Thread.Sleep(MessageQueueDelay);
            }

            lock (messageQueueLocker)
            {
                MessageQueue.Clear();
            }

            sendQueueExited = true;
        }
Esempio n. 5
0
        /// <summary>
        /// This will attempt to replace a previously queued message of the same type.
        /// </summary>
        /// <param name="qm">The new message to replace with</param>
        /// <returns>Whether or not a replace occurred</returns>
        private bool ReplaceMessage(QueuedMessage qm)
        {
            lock (messageQueueLocker)
            {
                var previousMessageIndex = MessageQueue.FindIndex(m => m.MessageType == qm.MessageType);
                if (previousMessageIndex == -1)
                {
                    return(false);
                }

                MessageQueue[previousMessageIndex] = qm;
                return(true);
            }
        }
Esempio n. 6
0
 public void SendCustomMessage(QueuedMessage qm)
 {
     connection.QueueMessage(qm);
 }
Esempio n. 7
0
        public void QueueMessage(QueuedMessageType type, int priority, string message)
        {
            QueuedMessage qm = new QueuedMessage(message, type, priority);

            QueueMessage(qm);
        }
Esempio n. 8
0
        public void QueueMessage(QueuedMessageType type, int priority, string message, bool replace = false)
        {
            QueuedMessage qm = new QueuedMessage(message, type, priority, replace);

            QueueMessage(qm);
        }