/* * Send everything from the outbound message queue * */ public override int SendMessage() { int Result = 0; for (int i = 0; i < OutMsgQueue.Count; i++) { try { string m = OutMsgQueue[0].Message; if (m != null && m.Length > 0) { irc.sendChatMessage(m); } else { WriteDebug(GetType().Name + ".SENDMESSAGE - OutMsgQueue[0].Message is " + (m == null ? "null" : "empty")); } } catch (Exception ex) { AddError(Result = 12, ex.Message, GetType().Name + ".SENDMESSAGE"); break; } // if the message was sent, remove the old message OutMsgQueue.RemoveAt(0); MsgCount++; } return(Result); }
/* * Create a message and put it onto the FIFO OutMsgQueue */ public override int CreateMessage(string contact, string body, string subject) { CommunicationMessage msg = new CommunicationMessage(); msg.Sender.Name = UserName; msg.Sender.NickName = UserNick; msg.Sender.IP4Address = LocalIP; msg.Sender.MachineID = MachineName; body = body.Trim(); if (isEncrypted) { // we need to encrypt the message body = "[CRYPTOR]" + cryptor.EncryptString(body); } msg.Message = body.Trim(); if (contact.Length > 0) { CommunicationRecipient s = new CommunicationRecipient(); s.Name = UserName; msg.Recipient.Add(s); } OutMsgQueue.Add(msg); if (DebugLevel > 8) { WriteDebug(string.Format("Saving Name '{0}' and body '{1}'", msg.Sender.Name, msg.Message)); } return(0); }
public override int CreateMessage(string contact, string body, string subject) { try { //WriteDebug(string.Format("Createmsg - Connected={0}", clientSocket.Connected)); CommunicationMessage Msg = new CommunicationMessage(); Msg.Message = body; OutMsgQueue.Add(Msg); } catch (Exception ex) { AddError(703, ex.Message, "GETMESSAGE"); } return(0); }
public override int SendMessage() { while (OutMsgQueue.Count > 0) { try { //WriteDebug(string.Format("sendmsg - Connected={0}", clientSocket.Connected)); byte[] outStream = System.Text.Encoding.ASCII.GetBytes(OutMsgQueue[0].Message); OutMsgQueue.RemoveAt(0); serverStream.Write(outStream, 0, outStream.Length); serverStream.Flush(); } catch (Exception ex) { AddError(905, ex.Message, ".SENDMESSAGE", "Failed to send message from outbound queue"); } } return(0); }
/* * Pop the oldest message off the FIFO stack and * send it out to the receiving IP */ public override int SendMessage() { int Result = 0; for (int i = 0; i < OutMsgQueue.Count; i++) { try { // converts from string to byte[] System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); byte[] msg = new byte[1500]; string m = OutMsgQueue[0].Sender.NickName + "|" + OutMsgQueue[0].Sender.Name + "|" + OutMsgQueue[0].Sender.IP4Address + "|" + OutMsgQueue[0].Sender.MachineID + "|" + (OutMsgQueue[0].Recipient.Count > 0 ? "[" + OutMsgQueue[0].Recipient[0].Name + "]" : "") + "|" + "{" + DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK") + "}" + "# " + OutMsgQueue[0].Message; // FROM: MSG msg = enc.GetBytes(m); if (DebugLevel > 5) { WriteDebug(string.Format("-> {0}", m)); } // sending the message string sck.Send(msg); } catch (Exception ex) { AddError(Result = 802, ex.Message, GetType().Name + ".SENDMESSAGE", string.Format("Failed to send message: {0}", OutMsgQueue[0].Message)); } finally { OutMsgQueue.RemoveAt(0); } } return(Result); }
/* * Create a message for outbound and add it to the out queue * * THOUGHTS * If address len>0 then it's private message * If subject len>0 then it's a message to another channel? Is that allowed? * */ public override int CreateMessage(string address, string body, string subject) { int Result = 0; try { CommunicationMessage msg = new CommunicationMessage(); CommunicationRecipient r = new CommunicationRecipient(); msg.Message = body; r.Name = address; msg.Recipient.Add(r); OutMsgQueue.Add(msg); } catch (Exception ex) { AddError(Result = 16, ex.Message, GetType().Name + ".CREATEMESSAGE", "Failed to create message -> " + body); } return(Result); }