Ejemplo n.º 1
0
        private static void Irc_MessageReceived(object sender, string e)
        {
            Irc irc = (Irc)sender;

            // ping pong response
            if (e.IndexOf("PING") == 0)
            {
                irc.Send("PONG " + e.Substring(e.IndexOf(':')));
            }
            int index = e.IndexOf("PRIVMSG");

            if (index != -1)
            {
                int message_start = e.IndexOf(':', index) + 1;
                if (message_start == -1)
                {
                    return;
                }

                int sender_nickname_start = e.IndexOf(':') + 1;
                if (sender_nickname_start == -1)
                {
                    return;
                }

                int sender_nickname_end = e.IndexOf('!', sender_nickname_start);
                if (sender_nickname_end == -1)
                {
                    return;
                }

                string sender_nickname = e.Substring(sender_nickname_start, sender_nickname_end - sender_nickname_start);
                string message         = e.Substring(message_start);

                Log("[Private Message]", ConsoleColor.Red);
                Log("Sender:  " + sender_nickname, ConsoleColor.Red);
                Log("Message: " + message, ConsoleColor.Red);

                if (sender_nickname == owner_nick && message.IndexOf("!download") == 0)
                {
                    string url = message.Substring(
                        message.IndexOf(' ') + 1
                        );
                    irc.Send(string.Format("PRIVMSG {0} :{1}", channels, "Now downloading " + url));
                }
            }

            // print it out
            Log(e, ConsoleColor.Gray);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Irc irc = new Irc
            {
                ThrowExceptions = false
            };

            irc.MessageReceived += Irc_MessageReceived;
            irc.MessageSent     += Irc_MessageSent;
            irc.StateChanged    += Irc_StateChanged;
            irc.Connect("irc.freenode.net", 6667);

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        private static void Irc_StateChanged(object sender, bool e)
        {
            Irc irc = (Irc)sender;

            if (e)
            {
                Log("Connected", ConsoleColor.Cyan);
                irc.Ident(nickname, realname);
                irc.Join(channels);
            }
            else
            {
                Log("Disconnected", ConsoleColor.Red);
            }
        }
Ejemplo n.º 4
0
        protected static void ConnectCallback(IAsyncResult ar)
        {
            Irc irc = (Irc)ar.AsyncState;
            List <Exception> exceptions = new List <Exception>();

            try
            {
                irc.m_Socket.EndConnect(ar);
            }
            catch (Exception e)
            {
                exceptions.Add(e);
                irc.OnStateChanged(false);
            }

            if (irc.ThrowExceptions && exceptions.Count > 0)
            {
                throw new AggregateException(exceptions);
            }

            irc.OnStateChanged(irc.m_Socket.Connected);
        }
Ejemplo n.º 5
0
        private void GetData()
        {
            #region Lade Konfiguration wenn vorhanden. Ansonsten nutze Standartwerte
            if (!string.IsNullOrWhiteSpace(ConfigFile))
            {
                try
                {
                    clientConfig  = ClientConfiguration.LoadConfig(ConfigFile);
                    IrcConnection = new Irc(clientConfig);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Fehler beim Laden der Konfiguration: " + ex.Message);
                    Console.ReadKey();
                    return; // return beendet die Methode und damit das Programm.
                }
            }


            #endregion

            // Verbindung zum IRC-Server aufbauen
            IrcConnection.Connect();

            while (IrcConnection.Connected)
            {
                string Data = IrcConnection.readData();

                if (!string.IsNullOrWhiteSpace(Data))
                {
                    Console.WriteLine("> " + Data);

                    #region PING
                    if (Data.Substring(0, 6) == "PING :")
                    {
                        string[] tPing = Data.Split(Convert.ToChar(":"));
                        IrcConnection.sendData("PONG :" + tPing[1]);
                    }
                    #endregion

                    #region Server Messages
                    if (Regex.IsMatch(Data, @":(.+) ([\d]{3}) (.+) :(.+)"))
                    {
                        string[] tRegEx = Regex.Split(Data, @":(.+) ([\d]{3}) (.+) (:)?(.+)");
                        // tRegEx[0] = null
                        // tRegEx[1] = Server-Hostname
                        // tRegEx[2] = Numeric Response
                        // tRegEx[3] = Client Username
                        // tRegEx[4] = Server Message
                        // tRegEx[5] = null


                        switch (int.Parse(tRegEx[2]))
                        {
                        case (int)NumericResponses.RPL_WELCOME:
                            IrcConnection.ServerAdress = tRegEx[1];
                            break;

                        case (int)NumericResponses.RPL_ENDOFMOTD:
                            AutoJoinChannels(clientConfig.Channels);
                            break;

                        case (int)NumericResponses.ERR_NICKNAMEINUSE:     // Wenn Nickname bereits verwendet, eine zufällige dreistellige Ziffer hintendranhängen.
                            IrcConnection.ChangeNickname(clientConfig.ServerDetails.Nick + new Random().Next(100, 1000));
                            break;

                        case (int)NumericResponses.ERR_YOUWILLBEBANNED:
                            Console.WriteLine("IMPORTANT: Server is going to deny your access.");
                            break;

                            // ToDo: Weitere wichtige NumericReplies einbinden und verarbeiten.
                        }
                    }
                    #endregion

                    #region PRIVMSG
                    if (Regex.IsMatch(Data, @":([^@!\ ]*)(.)*PRIVMSG\ ([^@!\ ]*)\ :"))
                    {
                        // :|54H|DamianRyse!~|54H|[email protected] PRIVMSG #DamiansTestRoom :test
                        IrcMessage Message = new IrcMessage(Data);
                        Actions(Message);
                    }
                    #endregion
                }
            }
            Console.WriteLine("Reconnect in 5 Minuten...");
            System.Threading.Thread.Sleep(60000);
            Console.WriteLine("Reconnect in 4 Minuten...");
            System.Threading.Thread.Sleep(60000);
            Console.WriteLine("Reconnect in 3 Minuten...");
            System.Threading.Thread.Sleep(60000);
            Console.WriteLine("Reconnect in 2 Minuten...");
            System.Threading.Thread.Sleep(60000);
            Console.WriteLine("Reconnect in 1 Minute...");
            System.Threading.Thread.Sleep(60000);
            GetData();
        }