/// <summary> /// Sends a message to the queue /// </summary> /// <param name="raw">the message text</param> /// <param name="limiter">the message limiter to use with this message, can be null if no limits are in place</param> /// <param name="priority">the priority the message has</param> /// <example> /// A client that automatically replies to pings with an appropriate pong, /// the pong message has critical priority and is not limited or validated /// <code> /// public class TmiPing : TmiConnection /// { /// [IrcCommand("PING")] /// protected virtual void OnPing(IrcMessage msg) /// { /// Send($"PONG {msg.RawPrefix}", null, MessagePriority.Critical); /// } /// } /// </code> /// </example> protected void Send(string raw, IMessageLimiter limiter, MessagePriority priority = MessagePriority.Default) { if (!limiter?.Validate(raw) ?? false) { MessageDropped?.Invoke(this, new MessageDroppedEventArgs(raw, MessageDropReason.Validation)); return; } if (sendQueue.Count >= QueueSize) { MessageDropped?.Invoke(this, new MessageDroppedEventArgs(raw, MessageDropReason.QueueOverflow)); return; } lock (sendSyncRoot) { sendQueue.Enqueue(new QueuedMessage(raw, priority, limiter)); sender.Signal(); } }
/// <summary> /// Called when a message was dropped. /// </summary> /// <param name="e">the event arguments.</param> protected virtual void OnMessageDropped(MessageDroppedEventArgs e) { MessageDropped?.Invoke(this, e); }