public void IncomingMessage(ref Message_Private IncomingMessage, ref bool DisplayMessage) { //WE NEED TO SCAN THE INCOMING MESSAGE VIA REGEX FOR URL'S WE NEED TO CONVERT TO <A></A> //TODO: EMAIL LINKS ACTUALLY CAUSE AN ERROR SO WE HANDLE BY BREAKING THE LINK SO IT WONT WORK string hostregex = @"([a-z\d][-a-z\d]+[a-z\d]\.)+[a-z][-a-z\d]+[a-z]"; string portregex = @"(:\d{1,})?"; string pathregex = @"(/[^\s]+)?"; string queryregex = "(\\?[^<>#\"\\string]+)?"; string fullregex = @"(?:(?<=^)|(?<=\s))(((ht|f)tps?://)?" + hostregex + portregex + pathregex + queryregex + ")"; //IF THE MENU ITEM IS NOT CHECKED THEN WE DONT NEED TO RUN THIS ITEM if (!this.MainMenu.Checked) { return; } //REPLACE URL STRINGS WITH ACTUAL LINKS SO THEY CAN BE NAVIGATED TO Regex tmpScan = new Regex(fullregex, RegexOptions.IgnoreCase); foreach (Match tmpMatch in tmpScan.Matches(IncomingMessage.Message)) { string newValue = (tmpMatch.Value.Contains("://") ? tmpMatch.Value : "http://" + tmpMatch.Value); IncomingMessage.Message = IncomingMessage.Message.Replace(tmpMatch.Value, string.Format("<a href=\"{0}\" target=\"_new\">{1}</a>", newValue, tmpMatch.Value)); } }
public void OutgoingMessage(ref Message_Private OutgoingMessage, ref bool ContinueToSend) { if (this.EnabledMenu.Checked) { //ENCRYPT THE MESSAGE WITH THE KEYS WE HAVE BEEN PROVIDED EncryptedWrapper tmpMessage = EncryptedWrapper.EncryptMessage(OutgoingMessage.Message, this.PublicKeys); OutgoingMessage.Message = Convert.ToBase64String(EncryptedWrapper.Serialize(tmpMessage)); } }
public void IncomingMessage(ref Message_Private IncomingMessage, ref bool DisplayMessage) { //IF THERE IS A DEBUG WINDOW THEN UPDATE THE TEXT if (DebugWindow != null) { DebugWindow.txtMessages.Text += string.Format("Incoming Message: {0} - {1}\n\n", IncomingMessage.TimeStamp.ToString("m/d/yy HH:mm:ss"), IncomingMessage.Message); } //TODO: CHECK TO SEE IF THE MESSAGE WHICH JUST CAME IN WAS A SECURITY KEY AND IF SO PARSE IT AND USE IT if (IncomingMessage.Message.Contains("Begin Key ---->")) { //GET THE KEY VIA REGEX EnabledMenu.Checked = true; string Key = Regex.Match(IncomingMessage.Message, "Begin Key ---->(?<Key>.*)<---- End Key", RegexOptions.IgnoreCase).Groups["Key"].Value; //ADD THE KEY TO THE LIST OF PUBLIC KEYS if (!PublicKeys.Keys.Contains(IncomingMessage.SenderID)) { PublicKeys.Add(IncomingMessage.SenderID, Convert.FromBase64String(Key)); } //IF THIS MESSAGE CAME FROM US THEN JUST LET THE USER KNOW IT WORKED OTHERWISE TELL THE USER WE RECEIVED A KEY if (IncomingMessage.SenderID != this.Connection.UserID) { this.EnabledMenu.Checked = true; IncomingMessage.Message = string.Format("Public Key Received From {0}", IncomingMessage.Sender); IncomingMessage.Sender = this.Name; } else { //LET THE USER KNOW THE KEY WAS SUCCEFULLY PLACED IN THE CONVERSATION BECAUSE WE GOT OUR MESSAGE BACK IncomingMessage.Message = "Key sent successfully!"; IncomingMessage.Sender = this.Name; } } else { if (EnabledMenu.Checked) { try { EncryptedWrapper tmpMessage = EncryptedWrapper.Deserialize(Convert.FromBase64String(IncomingMessage.Message)); IncomingMessage.Message = EncryptedWrapper.DecryptMessage(tmpMessage, this.MyPrivateKey); } catch { //DO NOTHING BECAUSE IT MUST BE VALID } } } }
private void btnSend_Click(object sender, EventArgs e) { //MAKE SURE THE USER IS NOT JUST CLICKING THE SEND BUTTON BUT THEY ACTUALLY HAVE ENTERED SOMETHING if (!string.IsNullOrEmpty(txtSend.Text)) { //CREATE A NEW PRIVATE MESSAGE AND SEND IT USING THISCONNECTION Message_Private tmpMessage = new Message_Private() { Message = txtSend.Text, ConversationID = this.ConversationID, TimeStamp = DateTime.Now, Sender = ThisConnection.DisplayName, SenderID = ThisConnection.UserID }; //RUN THE MESSAGE THROUGH ALL OUTBOUND PLUGINS bool ContinueToSend = true; foreach (IConversationPlugin tmpPlugin in (from a in Plugins.Values where a.SupportsSending == true orderby a.SendOrder select a)) { tmpPlugin.OutgoingMessage(ref tmpMessage, ref ContinueToSend); } //SEND THIS MESSAGE tmpMessage.Send(ThisConnection); //CLEAR THE TEXT SINCE THE MESSAGE WAS SENT txtSend.Text = ""; } //HIDE THE EMOTICONS WINDOW AFTER A MESSAGE HAS BEEN SENT if (emoticonsToolStripButton.Checked) { emoticonsToolStripButton.Checked = false; EmoticonsDisplay.Visible = false; } //RESET THE FOCUS ON THE SEND TEXT BOX SO THE USER CAN KEEP TYPING txtSend.Focus(); //REMEMBER WE HAVE NOT SENT AN UPDATE FOR THE NEW MESSAGE IF THERE IS ONE HasUpdateBeenSent = false; }
public void ReceiveMessage(Message_Private IncomingMessage) { string SelfMessageWithTimeStamp = @"<b style=""color: #0066B3"">{0}</b> ({1}): {2}<br/>"; string SelfMessageWithoutTimeStamp = @"<b style=""color: #0066B3"">{0}</b>: {2}<br/>"; string OtherMessageWithTimeStamp = @"<b style=""color: #990099"">{0}</b> ({1}): {2}<br/>"; string OtherMessageWithoutTimeStamp = @"<b style=""color: #990099"">{0}</b>: {2}<br/>"; //RUN THROUGH THE LIST OF PLUGINS WHICH SUPPORT RECEIVING OF DATA bool DisplayMessage = true; foreach (IConversationPlugin tmpPlugin in (from a in Plugins.Values where a.SupportsReceiving == true orderby a.ReceiveOrder select a)) { tmpPlugin.IncomingMessage(ref IncomingMessage, ref DisplayMessage); } //IF THE MESSAGE IS NOT GOING TO BE DISPLAYED THEN WE DO NOT NEED TO GO ANY FURTHER if (!DisplayMessage) { return; } //CONVERT KNOWN EMOTICON VALUES TO THEIR IMAGE EQUIV foreach (Dictionary <string, string> tmpEmoticon in Emoticons.OrderBy(a => a["text"].Length).Reverse()) { IncomingMessage.Message = Regex.Replace(IncomingMessage.Message, tmpEmoticon["text"], string.Format(@"<img src=""file://{0}/{1}"" height=20 width=20 border=0 style=""vertical-align: middle;"" />", Path.Combine(Application.StartupPath, "Images\\Emoticons\\"), tmpEmoticon["image"])); } //APPEND THE RECEIVED MESSAGE TO THE DISPLAY WINDOW BY INVOKING THE CONTROL if (IncomingMessage.SenderID == ThisConnection.UserID) { webDisplay.Document.Write(string.Format((timestampToolStripMenuItem.Checked ? SelfMessageWithTimeStamp : SelfMessageWithoutTimeStamp), IncomingMessage.Sender, IncomingMessage.TimeStamp.ToString("M/d/yy h:mm tt"), IncomingMessage.Message)); } else { webDisplay.Document.Write(string.Format((timestampToolStripMenuItem.Checked ? OtherMessageWithTimeStamp : OtherMessageWithoutTimeStamp), IncomingMessage.Sender, IncomingMessage.TimeStamp.ToString("M/d/yy h:mm tt"), IncomingMessage.Message)); } //TODO: THIS CAN PROBABLY BE MADE TO NOT HAVE TO LOOP THROUGH THE ENTIRE CONVERSATION EVERY TIME //INTERCEPT LINK CLICKS BY ADDING AN EVENT HANDLER TO EVERY ONE OF THEM for (int i = 0; i < webDisplay.Document.Links.Count; i++) { webDisplay.Document.Links[i].Click -= ClickHandler; webDisplay.Document.Links[i].Click += ClickHandler; webDisplay.Document.Links[i].MouseDown -= MouseDownHandler; webDisplay.Document.Links[i].MouseDown += MouseDownHandler; } //ONLY PLAY THE SOUND IF THE SENDER IS NOT YOURSELF if (IncomingMessage.Sender != ThisConnection.DisplayName && (!IncomingMessage.IsArchive || FirstMessage)) { Sounds tmpSound = new Sounds(); tmpSound.Play(Path.Combine(Application.StartupPath, @"Sounds\notify.wav")); FirstMessage = false; } //TODO: LOOK AT HOW SCROLL WORKS WHEN SELECTING TEXT AND STUFF OF THAT NATURE //CHECK TO SEE WHERE WE ARE SCROLL WISE AND IF WE NEED TO MOVE THE WINDOW DOWN webDisplay.Document.Window.ScrollTo(0, webDisplay.Document.Body.ScrollRectangle.Bottom); //IF THE SEND BOX IS NOT FOCUSED THEN START THE WINDOW FLASHING BY INVOKING ACROSS THE THREAD if (!txtSend.Focused && !IncomingMessage.IsArchive) { Common.Windows.FlashWindow.Flash(this, Common.Windows.FLASHWFlags.FLASHW_ALL); } //CLEAR THE TEXT FROM THE STATUS LABEL lblUserEnteredText.Text = ""; }
public void OutgoingMessage(ref Message_Private OutgoingMessage, ref bool ContinueToSend) { throw new NotImplementedException(); }
public void IncomingMessage(ref Message_Private IncomingMessage, ref bool DisplayMessage) { throw new NotImplementedException(); }