예제 #1
0
        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);
        }
예제 #2
0
        /*
         * 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());
            }
        }
예제 #3
0
        /*
         * Look for some input from the server
         */
        public string readMessage()
        {
            string message = null;

            try
            {
                message = inputStream.ReadLine();
                if (Channel.DebugLevel > 8)
                {
                    Channel.WriteDebug("<-" + message);
                }
            }
            catch (Exception ex)
            {
                if (Channel.DebugLevel > 0)
                {
                    Channel.WriteDebug("Irc ReadMessage failure: " + ex.Message);
                }
            }

            return(message);
        }
예제 #4
0
        /*
         * 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());
                }
            }
        }
예제 #5
0
        /*
         * 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.Substring(0, 1).Equals("/") && message.Length > 1)
            {
                if (Channel.DebugLevel > 0)
                {
                    Channel.WriteDebug("Processing command " + message);
                }

                if (message.IndexOf(' ') > 0)
                {
                    cmd = message.Substring(1, message.IndexOf(' ')).Trim().ToUpper();
                    msg = message.Substring(message.IndexOf(' ')).Trim();
                }
                else
                {
                    cmd = message.Substring(1).Trim().ToUpper();
                }

                message = string.Empty;

                switch (cmd)
                {
                case "ACTION":
                    message = ((char)1).ToString() + "ACTION " + msg + ((char)1).ToString();
                    break;

                case "JOIN":
                    joinRoom(msg);
                    break;

                case "KICK":
                    SendOutput("KICK #" + this.ircChannel + " " + msg);
                    outputStream.Flush();
                    break;

                case "MODE":
                    SendOutput("MODE :" + msg);
                    break;

                case "NAMES":
                    SendOutput("NAMES");
                    outputStream.Flush();
                    break;

                case "NICK":
                    SendOutput("NICK :" + msg);
                    outputStream.Flush();
                    break;

                case "PART":
                    SendOutput("PART #" + this.ircChannel);
                    outputStream.Flush();
                    break;

                case "QUIT":
                    SendOutput("QUIT " + msg);
                    outputStream.Flush();
                    break;
                }
            }

            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;
                    }
                }

                // Put together the formatted chat message
                sendIrcMessage(":" + userName + "!" + userName + "@" + Channel.UserHost + " PRIVMSG #" + ircChannel + " :" + message);
            }
        }