public bool SetChannelEncryption(string pinfo) { bool Results = false; int locinfo = -1; string setinfo = string.Empty; string einfo = pinfo; try { if (einfo.Length > 4) { if (einfo.Substring(0, 4).Equals("KEY:")) { setinfo = einfo.Substring(4).Trim(); Results = Channel.SetEncryption(setinfo); } else if (einfo.Substring(0, 4).Equals("LOC:")) { setinfo = einfo.Substring(4).Trim(); int.TryParse(setinfo, out locinfo); Results = Channel.SetEncryption(setinfo); } } } catch (Exception ex) { Channel.AddError(903, ex.Message, GetType().Name + ".SETCHANNELENCRYPTTION", "Failed to set encryption from parameter " + pinfo); } Channel.WriteDebug(string.Format("SetChannelEncryption('{0}') set encryption using {1}", pinfo, setinfo)); Channel.SetEncrypt = false; Channel.EncryptInfo = string.Empty; Channel.isEncrypted = Results; return(Results); }
/* * Send a chat message from the user and intercept any commands that we might support * */ public void sendChatMessage(string message) { string cmd = string.Empty; string msg = string.Empty; if (message.Length > 0) { // Do we encrypt the message? if (Channel.isEncrypted) { try { // Create the formatted message message = "[CRYPTOR]" + Channel.cryptor.EncryptString(message); } catch (Exception ex) { message = "<Failed CRYPTOR message> Error: " + ex.Message; Channel.AddError(101, ex.Message, GetType().Name + ".SENDCHATMESSAGE", "Failed to encrypt message -> " + message); } } // Put together the formatted chat message sendMessage("#" + userName + ":" + message); } }
/* * Constructor to connect to a server and log in */ public IrcClient(CommunicationChannel chan) { Channel = chan; this.userName = Channel.UserName; this.address = Channel.Server; this.port = Channel.PortOut; // Set up tcp client try { tcpClient = new TcpClient(address, port); address = ((IPEndPoint)tcpClient.Client.LocalEndPoint).Address.ToString(); if (Channel.DebugLevel > 3) { Channel.WriteDebug("Connected to " + address + " on port " + port.ToString()); } } catch (Exception ex) { Channel.AddError(1, "IrcClient.IRCCLIENT", ex.Message, "Attempted to connect to " + address + ":" + port.ToString()); } // Set up the streams and set up user/nick try { inputStream = new StreamReader(tcpClient.GetStream()); outputStream = new StreamWriter(tcpClient.GetStream()); } catch (Exception ex) { Channel.AddError(2, "IrcClient.IRCCLIENT", ex.Message, "Attempted to authorize user at " + address + ":" + port.ToString()); } }
/* * TODO - learn about IRC login w/ password and implement * */ public int IrcLogIn(string user, string pw) { int Result = 0; if (Connected()) { SendOutput(string.Format("NICK {0}", userName)); SendOutput(string.Format("USER {0} 8 * {1}", userName, userName)); outputStream.Flush(); } else { Channel.AddError(Result = 1, "IRC Channel not connected", GetType().Name + ".IRCLOGIN"); } return(Result); }
/* * Constructor to connect to a server and log in */ public TCPClient2(CommunicationChannel chan) { Channel = chan; tcpSet(); // Set up tcp client try { tcpClient = new TcpClient(address, port); address = ((IPEndPoint)tcpClient.Client.LocalEndPoint).Address.ToString(); if (Channel.DebugLevel > 3) { Channel.WriteDebug("Connected to " + address + " on port " + port.ToString()); } } catch (Exception ex) { Channel.AddError(1, ex.Message, GetType().Name + ".TCPHELPER", "Attempted to connect to " + address + ":" + port.ToString()); tcpClient = null; address = null; } // Set up the streams and set up user/nick if (tcpClient != null) { try { inputStream = new StreamReader(tcpClient.GetStream()); outputStream = new StreamWriter(tcpClient.GetStream()); SendOutput(string.Format("NICK {0}", userName)); SendOutput(string.Format("USER {0} 8 * {1}", userName, userName)); outputStream.Flush(); } catch (Exception ex) { Channel.AddError(2, ex.Message, GetType().Name + ".TCPHELPER", "Attempted to authorize user at " + address + ":" + port.ToString()); } } }