/// <summary> /// Applies the spam delay. If the delay wasn't respected, <see cref="Fail"/> them. /// </summary> /// <param name="message">The message to analyze.</param> private static void ApplySpamDelay(Entites.Message message) { Debug.Assert(message.UserToChannel.Privileges.Rules.SpamDelay != null, "message.UserToChannel.Privileges.Rules.SpamDelay != null"); if (message.SentOn - UserToChannel.GetMessageBefore(message.UserToChannel, message.SentOn).SentOn < message.UserToChannel.Privileges.Rules.SpamDelay.Value) { Fail(message, "You are sending messages too quickly. Be careful or you will be kicked."); } }
/// <summary> /// Fails the user due to the specified message. Warn them if they weren't muted, kick them otherwise. /// </summary> /// <param name="message">The message.</param> /// <param name="reason">The reason.</param> private static void Fail(Entites.Message message, string reason) { message.UserToChannel.NbSilences++; TimeSpan muteTime = GetMuteTime(message.UserToChannel.NbSilences); // Someone abusing the system in some way or if someone gets failed while already muted if (muteTime > TimeoutLimit || message.UserToChannel.SilencedTo - DateTime.UtcNow > TimeSpan.FromSeconds(1)) { Kick(message.UserToChannel); return; } message.UserToChannel.SilencedTo = DateTime.UtcNow + muteTime; UserToChannel.Update(message.UserToChannel); DAL.UserToChannel.LoadChannel(message.UserToChannel); Entites.Message.SendMessage(Message.Answer(message, reason)); }
/// <summary> /// Creates the specified message. /// </summary> /// <param name="iMessage">The imessage.</param> /// <returns>The newly created message.</returns> public static Entites.Message Create(IMessage iMessage) { //TODO: Actually process the real message types. Entites.Message message = DAL.Message.Create( new Entites.Message(Application.UpdateOrCreate(iMessage.Channel.Application), iMessage.ApplicationId, iMessage.SentDate, UserToChannel.UpdateOrCreate(iMessage.Channel.Application, iMessage.From, iMessage.Channel), MessageType.Get("Text"), iMessage.RepliesTo != null ? GetOrCreate(iMessage.RepliesTo) : null, false, iMessage.JoinedUser == null ? null : UserToChannel.GetOrCreate(iMessage.Channel.Application, iMessage.JoinedUser, iMessage.Channel))); if (!string.IsNullOrEmpty(iMessage.Text)) { message.Texts = new List <Entites.Text> { Text.Create(new Entites.Text(iMessage.Text, iMessage.SentDate, message, string.IsNullOrEmpty(iMessage.Text) ? null : Rules.ToR9KText(iMessage.Text))) }; } // If the user was invited back, we make sure to reboot their consequences. if (message.JoinedUserToChannel != null && (message.JoinedUserToChannel.NbSilences != 0 || message.JoinedUserToChannel.SilencedTo != null)) { message.JoinedUserToChannel.NbSilences = 0; message.JoinedUserToChannel.SilencedTo = null; UserToChannel.Update(message.JoinedUserToChannel); } return(message); }