예제 #1
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());
            }
        }
예제 #2
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());
                }
            }
        }
예제 #3
0
        /*
         * Set up the channel by simply traversing the XML node and calling
         * the Settings method for each entry.  Example XML file will look
         * like the following:
         *
         * <Table>
         *   <Channel>
         *     <Type>1</Type>
         *   </Channel>
         *   <Setup>
         *     <Server>c:\temp</Server>
         *     <Debug>9</Debug>
         *   </Setup>
         * </Table>
         *
         */
        private void SetUpChannel(string ConfigFileUNC, string SectionName)
        {
            Channel = null;

            XmlDocument xmldoc = new XmlDocument();
            XmlNodeList xmlnode;
            FileStream  fs = new FileStream(ConfigFileUNC, FileMode.Open, FileAccess.Read);

            if (startupDebug)
            {
                dbug("In SetUpChannel");
            }

            xmldoc.Load(fs);

            xmlnode = xmldoc.GetElementsByTagName("Channel");
            for (int i = 0; i <= xmlnode.Count - 1; i++)
            {
                for (int j = 0; j < xmlnode[i].ChildNodes.Count; j++)
                {
                    try
                    {
                        // Fill it up
                        switch (xmlnode[i].ChildNodes.Item(j).Name.Trim().ToUpper())
                        {
                        case "TYPE":
                            switch (xmlnode[i].ChildNodes.Item(j).InnerText.Trim().ToUpper())
                            {
                            case "COMFILE":
                                Channel = null;
                                Channel = new ComFile();
                                break;

                            case "COMIRC":
                                Channel = null;
                                Channel = new ComIRC();
                                break;

                            case "COMCHAT":
                                Channel = null;
                                Channel = new ComChat();
                                break;

                            case "COMTCP":
                                Channel = null;
                                Channel = new ComTCP();
                                break;
                            }
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        dbug("SetUpChannel Error: " + ex.Message + "\r\nFrom " + ex.Source);
                    }
                }
            }

            if (Channel != null)
            {
                xmlnode = xmldoc.GetElementsByTagName(SectionName);
                for (int i = 0; i <= xmlnode.Count - 1; i++)
                {
                    for (int j = 0; j < xmlnode[i].ChildNodes.Count; j++)
                    {
                        if (startupDebug)
                        {
                            dbug(string.Format("Setting {0} to {1}", xmlnode[i].ChildNodes.Item(j).Name.Trim(), xmlnode[i].ChildNodes.Item(j).InnerText.Trim()));
                        }
                        Channel.Setting(xmlnode[i].ChildNodes.Item(j).Name.Trim(), xmlnode[i].ChildNodes.Item(j).InnerText.Trim());
                    }
                }

                if (Channel.SetEncrypt)
                {
                    SetChannelEncryption(Channel.EncryptInfo);
                }

                if (startupDebug)
                {
                    dbug("Running " + Channel.Name + "\r\n-----------------------------------------------------------------------\r\n");
                }
            }

            fs.Close();
        }