public void Log(int db, bool makeend = false) { if (db == 0) { return; } if (!Directory.Exists(GlobalManager.SettingsPath + @"\Logs\" + Name)) { Directory.CreateDirectory(GlobalManager.SettingsPath + @"\Logs\" + Name); } string logpath = GlobalManager.SettingsPath + @"\Logs\" + Name + "\\" + DateRegex.Replace(DateTime.Now.ToString("d"), "-") + ".log"; using (StreamWriter writer = new StreamWriter(logpath, true)) { for (int i = 0; i < db && Messages.Count > 0; i++) { MessageClass msg = Messages[0]; writer.WriteLine("(" + msg.Style.Type.ToString() + ") " + msg.Time.ToString("G") + " " + msg.Sender.Name + ": " + msg.Message); Messages.RemoveAt(0); } if (makeend) { writer.WriteLine(DateTime.Now.ToString("G") + " - Channel closed."); writer.WriteLine("-----------------------------------------------------------------------------------------"); writer.WriteLine(Environment.NewLine + Environment.NewLine); } } }
public void AddMessage(MessageClass msg) { if (Messages.Count + 1 > GlobalManager.MaxMessagesInMemory) { Log(GlobalManager.NumOfOldMessagesToBeLoaded); } Messages.Add(msg); if (!msg.Sender.IsBanned || !IsPrivMsgChannel && Properties.Settings.Default.ShowBannedMessages) { if (mw.EnergySaveModeOn) { this.MessageReloadNeeded = true; } else { mw.AddNewMessage(this, msg, false); } } }
private void ChangeMessageColorForClient(Client c, SolidColorBrush color) { bool italic = c.Group.ID != UserGroups.SystemGroupID; for (int i = 0; i < Servers.Count; i++) { if (Servers[i].IsRunning) { foreach (var item in Servers[i].ChannelList) { Channel ch = item.Value; if (ch.Joined && ch.TheFlowDocument.Blocks.Count > 0) { Paragraph p = (Paragraph)ch.TheFlowDocument.Blocks.FirstBlock; while (p != null) { MessageClass msg = (MessageClass)p.Tag; if (msg.Sender == c) { if (Properties.Settings.Default.MessageTime) { p.Inlines.FirstInline.NextInline.Foreground = (color != null) ? color : msg.Style.NickColor; p.Inlines.FirstInline.NextInline.FontStyle = (italic) ? FontStyles.Italic : FontStyles.Normal; } else { p.Inlines.FirstInline.Foreground = (color != null) ? color : msg.Style.NickColor; p.Inlines.FirstInline.FontStyle = (italic) ? FontStyles.Italic : FontStyles.Normal; } } p = (Paragraph)p.NextBlock; } } } } } }
public override void DoTask(MainWindow mw) { Client c = null; Channel ch = null; string fromLow = ClientName.ToLower(); // If the message arrived in a closed channel if (Sender.ChannelList.TryGetValue(ChannelHash, out ch) && !ch.Joined) { return; } // If the user doesn't exists we create one if (!Sender.Clients.TryGetValue(fromLow, out c)) { c = new Client(ClientName, Sender); } if (ch == null) // New private message arrived for us { ch = new Channel(mw, Sender, ChannelHash, "Chat with " + c.Name, c); } if (!ch.IsPrivMsgChannel) { MessageClass msg = new MessageClass(c, Message, Setting); bool LookForLeague = Setting.Type == MessageTypes.Channel && mw.SearchHere == ch; // Search for league or hightlight or notification if (LookForLeague || Setting.Type == MessageTypes.Channel) { bool notificationSearch = false; // Is there any notificator for messages bool notif = true; // to ensure that only one notification will be sent if (mw.Notifications.Count > 0) { foreach (NotificatorClass nc in mw.Notifications) { if (notif && nc.InMessages) { notificationSearch = true; } if (nc.InMessageSenders && nc.TryMatch(c.LowerName)) { notif = false; mw.NotificatorFound(c.Name + ": " + Message, ch); break; } } } string[] words = Message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); msg.Words = words; for (int i = 0; i < words.Length; i++) { // Highlight if (words[i].StartsWith(Sender.User.Name) && !nickRegex.IsMatch(words[i].Substring(Sender.User.Name.Length))) { msg.AddHighlightWord(i, HightLightTypes.Highlight); Channel selectedCH = null; if (mw.Channels.SelectedItem != null) { selectedCH = (Channel)((TabItem)mw.Channels.SelectedItem).DataContext; } if (!mw.IsActive || ch != selectedCH) { ch.NewMessages = true; if (Properties.Settings.Default.TrayFlashing && !mw.IsActive) { mw.FlashWindow(); } if (Properties.Settings.Default.TrayNotifications) { mw.NotifyIcon.ShowBalloonTip(null, "You have been highlighted!", Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Info); } if (ch.BeepSoundPlay && Properties.Settings.Default.HBeepEnabled) { Sounds.PlaySound("HBeep"); ch.BeepSoundPlay = false; } } } else if (LookForLeague) { // foundUsers.ContainsKey(lower) == league name we are looking for // foundUsers[lower].Contains(c.LowerName) == the user we found for league lower foreach (var item in mw.FoundUsers) { if (words[i].IndexOf(item.Key, StringComparison.OrdinalIgnoreCase) != -1) { msg.AddHighlightWord(i, HightLightTypes.LeagueFound); if (!mw.FoundUsers[item.Key].Contains(c.LowerName)) { mw.FoundUsers[item.Key].Add(c.LowerName); if (Properties.Settings.Default.TrayFlashing && !mw.IsActive) { mw.FlashWindow(); } if (Properties.Settings.Default.TrayNotifications) { mw.NotifyIcon.ShowBalloonTip(null, c.Name + ": " + Message, Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Info); } if (Properties.Settings.Default.LeagueFoundBeepEnabled) { Sounds.PlaySound("LeagueFoundBeep"); } } break; } } } else if (notif && notificationSearch) { foreach (NotificatorClass nc in mw.Notifications) { if (nc.InMessages && nc.TryMatch(words[i])) { msg.AddHighlightWord(i, HightLightTypes.NotificatorFound); mw.NotificatorFound(c.Name + ": " + Message, ch); break; } } } } } ch.AddMessage(msg); } // Beep user that new private message arrived else { // If user was removed from conversation and then added to it again but the channel tab remaint open if (ch.Disabled) { ch.Disabled = false; } // This way away message will be added to the channel later than the arrived message ch.AddMessage(c, Message, Setting); if (!c.IsBanned) { Channel selectedCH = null; if (mw.Channels.SelectedItem != null) { selectedCH = (Channel)((TabItem)mw.Channels.SelectedItem).DataContext; } // Private message arrived notification if (!mw.IsActive || ch != selectedCH) { ch.NewMessages = true; if (Properties.Settings.Default.TrayFlashing && !mw.IsActive) { mw.FlashWindow(); } if (Properties.Settings.Default.TrayNotifications) { mw.NotifyIcon.ShowBalloonTip(null, c.Name + ": " + Message, Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Info); } if (ch.BeepSoundPlay && Properties.Settings.Default.PMBeepEnabled) { Sounds.PlaySound("PMBeep"); ch.BeepSoundPlay = false; } // Send away message if needed if (mw.AwayText != string.Empty && ch.SendAway && ch.Messages.Count > 0) { mw.SendMessageToChannel(mw.AwayText, ch); ch.SendAway = false; ch.SendBack = true; } } } } }
public bool AddNewMessage(Channel ch, MessageClass message, bool insert = false) { if (Properties.Settings.Default.ChatMode && ( message.Style.Type == MessageTypes.Part || message.Style.Type == MessageTypes.Join || message.Style.Type == MessageTypes.Quit) ) { return(false); } try { Paragraph p = new Paragraph(); MessageSettings.LoadSettingsFor(p, message.Style); p.Foreground = message.Style.MessageColor; p.Margin = new Thickness(0, 2, 0, 2); p.Tag = message; p.MouseRightButtonDown += InstantColorMenu; // Time when the message arrived if (Properties.Settings.Default.MessageTime) { Run word = new Run(message.Time.ToString("T") + " "); MessageSettings.LoadSettingsFor(word, MessageSettings.MessageTimeStyle); word.Foreground = MessageSettings.MessageTimeStyle.NickColor; p.Inlines.Add(word); } // Sender of the message Run nick = (message.Style.Type == MessageTypes.Action) ? new Run(message.Sender.Name + " ") : new Run(message.Sender.Name + ": "); SolidColorBrush b; // Instant color if (InstantColors.TryGetValue(message.Sender.LowerName, out b)) { nick.Foreground = b; } // Group color else if (message.Sender.Group.ID != UserGroups.SystemGroupID) { nick.Foreground = message.Sender.Group.TextColor; nick.FontStyle = FontStyles.Italic; } else { nick.Foreground = message.Style.NickColor; } nick.FontWeight = FontWeights.Bold; p.Inlines.Add(nick); // Message content if (message.Style.IsFixedText) { p.Inlines.Add(new Run(message.Message)); } else { string[] words; if (message.Words != null) { words = message.Words; } else { words = message.Message.Split(' '); } Uri uri = null; HightLightTypes highlightType; sb.Clear(); // this StringBuilder is for minimizing the number on Runs in a paragraph for (int i = 0; i < words.Length; i++) { if (message.HighlightWords != null && message.HighlightWords.TryGetValue(i, out highlightType)) { // Flush the sb content if (sb.Length > 0) { p.Inlines.Add(new Run(sb.ToString())); sb.Clear(); } Run word = new Run(words[i]); if (highlightType == HightLightTypes.Highlight) { word.FontStyle = FontStyles.Italic; } else { MessageSettings.LoadSettingsFor(word, MessageSettings.LeagueFoundMessage); word.Foreground = MessageSettings.LeagueFoundMessage.NickColor; } p.Inlines.Add(word); } // Links else if ( ( words[i].StartsWith("ftp://", StringComparison.OrdinalIgnoreCase) || words[i].StartsWith("http://", StringComparison.OrdinalIgnoreCase) || words[i].StartsWith("https://", StringComparison.OrdinalIgnoreCase) ) && Uri.TryCreate(words[i], UriKind.RelativeOrAbsolute, out uri) ) { // Flush the sb content if (sb.Length > 0) { p.Inlines.Add(new Run(sb.ToString())); sb.Clear(); } Hyperlink word = new Hyperlink(new Run(words[i])); MessageSettings.LoadSettingsFor(word, MessageSettings.HyperLinkStyle); word.Foreground = MessageSettings.HyperLinkStyle.NickColor; word.NavigateUri = new Uri(words[i]); word.RequestNavigate += OpenURLInBrowser; p.Inlines.Add(word); } else { sb.Append(words[i]); } if (i + 1 < words.Length) { sb.Append(' '); } } // Flush the sb content if (sb.Length > 0) { p.Inlines.Add(new Run(sb.ToString())); } } // Insert the new paragraph if (insert) { ch.TheFlowDocument.Blocks.InsertBefore(ch.TheFlowDocument.Blocks.FirstBlock, p); } else { ch.TheFlowDocument.Blocks.Add(p); } while (ch.TheFlowDocument.Blocks.Count > GlobalManager.MaxMessagesInMemory) { ch.TheFlowDocument.Blocks.Remove(ch.TheFlowDocument.Blocks.FirstBlock); } return(true); } catch (Exception e) { ErrorLog.Log(e); } return(false); }