/// <summary> /// Expires a message, making it invalid and recycling its ID. /// </summary> /// <param name="message">Message to expire.</param> public static void ExpireMessage(Message message) { lock (message) { _availableIds.Enqueue(message.Id); message.Id = expiredId; } }
/// <summary> /// Posts the provided <see cref="Message"/> instance to the message board. /// </summary> /// <param name="message"><see cref="Message"/> instance to post.</param> public void PostMessage(Message message) { _messageTable.AddOrUpdate(message.Id, message, (key, existingValue) => { if (message.Code != existingValue.Code) { throw new ArgumentException("Duplicate unexpired messages with the same ID are not allowed"); } return message; }); int expiration = (_gameTick + message.TimeToLive + 1) % Message.MaxTimeToLive; if (_messagesByExpiration[expiration] == null) { _messagesByExpiration[expiration] = new List<Message>(); } _messagesByExpiration[expiration].Add(message); }