Exemplo n.º 1
0
        public bool Login(string username, string password)
        {
            mylogin = username;
            LogFile.WriteLine(this.GetType().ToString() + " Login()");
            //InformClient( "test inform" );
            try
            {
                Config.Coordination coordinationconfig = Config.GetInstance().coordination;
                string[]            serverlist         = new string[] { coordinationconfig.ircserver };
                int port = coordinationconfig.ircport;
                _channel = coordinationconfig.ircchannel;

                LogFile.WriteLine("ircchat connecting to " + coordinationconfig.ircserver);
                ircclient.Connect(serverlist, port);
                ircclient.Login(username, username);
                ircclient.RfcJoin(_channel);
                if (password != "")
                {
                    ircclient.SendMessage(SendType.Message, "nickserv", "identify " + password);
                }
                IsConnected = true;
            }
            catch (ConnectionException e)
            {
                OnMessage(ChatMessageType.Error, "", "IRC Error: " + e.Message + ". Irc chat will not be available in this session");
            }
            return(IsConnected);
        }
Exemplo n.º 2
0
        public IRCBot()
        {
            // The IRC Bot must run in a seperate thread, or else the server will freeze.
            ircThread = new Thread(new ThreadStart(delegate
            {
                // Attach event handlers
                irc.OnConnecting     += new EventHandler(OnConnecting);
                irc.OnConnected      += new EventHandler(OnConnected);
                irc.OnChannelMessage += new IrcEventHandler(OnChanMessage);
                irc.OnJoin           += new JoinEventHandler(OnJoin);
                irc.OnPart           += new PartEventHandler(OnPart);
                irc.OnQuit           += new QuitEventHandler(OnQuit);
                irc.OnNickChange     += new NickChangeEventHandler(OnNickChange);
                irc.OnDisconnected   += new EventHandler(OnDisconnected);
                irc.OnQueryMessage   += new IrcEventHandler(OnPrivMsg);
                irc.OnNames          += new NamesEventHandler(OnNames);
                irc.OnChannelAction  += new ActionEventHandler(OnAction);
                irc.OnKick           += new KickEventHandler(OnKick);

                // Attempt to connect to the IRC server
                try { irc.Connect(server, Server.ircPort); }
                catch (Exception ex) { Server.s.Log("Unable to connect to IRC server: " + ex.Message); }
            }));
            ircThread.Start();
        }
Exemplo n.º 3
0
        public GlobalChatBot()
        {
            // The IRC Bot must run in a seperate thread, or else the server will freeze.
            globalThread = new Thread(new ThreadStart(delegate
            {
                // Attach event handlers
                globalchat.OnConnecting     += new EventHandler(OnConnecting);
                globalchat.OnConnected      += new EventHandler(OnConnected);
                globalchat.OnChannelMessage += new IrcEventHandler(OnChanMessage);
                globalchat.OnJoin           += new JoinEventHandler(OnJoin);
                globalchat.OnPart           += new PartEventHandler(OnPart);
                globalchat.OnQuit           += new QuitEventHandler(OnQuit);
                globalchat.OnNickChange     += new NickChangeEventHandler(OnNickChange);
                globalchat.OnDisconnected   += new EventHandler(OnDisconnected);
                globalchat.OnQueryMessage   += new IrcEventHandler(OnPrivMsg);
                globalchat.OnNames          += new NamesEventHandler(OnNames);
                globalchat.OnChannelAction  += new ActionEventHandler(OnAction);

                // Attempt to connect to the IRC server
                try { globalchat.Connect(server, 6667); }
                catch (Exception ex) { if (Server.useglobal)
                                       {
                                           Server.s.Log("Unable to connect to MCDawn Global Chat Server: " + ex.Message);
                                       }
                }
            }));
            globalThread.Start();
        }
Exemplo n.º 4
0
 public void Connect()
 {
     if (server.server.Contains(":"))
     {
         client.Connect(server.server.Split(':')[0], Convert.ToInt32(server.server.Split(':')[1]), false, regInfo);
         return;
     }
     client.Connect(server.server, false, regInfo);
 }
Exemplo n.º 5
0
        private void Reconnect()
        {
            if (IrcClient != null)
            {
                IrcClient.Disconnect();
                IrcClient = null;
            }

            IrcClient = new IrcClient();

            IrcClient.ClientId = "TWITCHCLIENT 2";

            IrcClient.Connected          += IrcClient_Connected;
            IrcClient.ProtocolError      += IrcClient_ProtocolError;
            IrcClient.Error              += IrcClient_Error;
            IrcClient.Disconnected       += IrcClient_Disconnected;
            IrcClient.RawMessageReceived += IrcClient_RawMessageReceived;
            IrcClient.ConnectFailed      += IrcClient_ConnectFailed;

            IrcClient.MotdReceived += IrcClient_MotdReceived;

            Random rnd = new Random();
            string s   = "justinfan" + rnd.Next(100000000);

            regInfo = new IrcUserRegistrationInfo()
            {
                NickName = s,
                UserName = s,
                Password = "******",
                RealName = s
            };

            Header = "http://twitch.tv, Подключаемся к " + StreamerNick;

            if (!string.IsNullOrEmpty(_directAdress))
            {
                string[] dat = _directAdress.Split(':');
                try {
                    int port = int.Parse(dat[1]);
                    IrcClient.Connect(dat[0], port, false, regInfo);
                } catch {
                    Header = "http://twitch.tv, Ошибка " + StreamerNick;
                }
            }
            else
            {
                IrcClient.Connect(StreamerNick + ".jtvirc.com", 6667, false, regInfo);
            }
        }
Exemplo n.º 6
0
        public void Create(User user, CountdownEvent countdownEvent, bool shouldChat)
        {
            _user           = user;
            _countdownEvent = countdownEvent;

            _irc.Encoding             = System.Text.Encoding.UTF8;
            _irc.SendDelay            = 1000;
            _irc.ActiveChannelSyncing = true;
            _irc.AutoReconnect        = true;
            _irc.AutoRejoinOnKick     = true;
            _irc.AutoRetry            = true;
            _irc.AutoRetryDelay       = 30000;
            _irc.AutoRelogin          = true;

            _irc.OnError      += new ErrorEventHandler(OnError);
            _irc.OnRawMessage += new IrcEventHandler(OnRawMessage);

            try
            {
                _irc.Connect(Settings.Server, Settings.Port);
            }
            catch (Exception e)
            {
                Log.AddErrorMessage(e.Message);
                _countdownEvent.Signal();
                System.Environment.Exit(1);
            }

            try
            {
                _irc.Login(_user.Username, _user.Username, 0, _user.Username, _user.Password);

                foreach (var channel in Settings.Channels)
                {
                    _irc.RfcJoin(channel);
                }

                if (shouldChat)
                {
                    _timer = new Timer(streamTimer, null,
                                       TimeSpan.FromSeconds(Math.Max(Settings.UserInitialWait + (StaticRandom.Rand() % (Settings.UserChatVariance * 2)) - Settings.UserChatVariance, 0)),
                                       TimeSpan.FromSeconds(Math.Max(Settings.UserChatInterval + (StaticRandom.Rand() % (Settings.UserChatVariance * 2)) - Settings.UserChatVariance, 0)));
                }

                while (!_shouldDisconnect)
                {
                    _irc.ListenOnce();
                }
            }
            catch (Exception e)
            {
                Log.AddErrorMessage(e.Message);
                //System.Environment.Exit(2);
            }
            finally
            {
                _countdownEvent.Signal();
                _irc.Disconnect();
            }
        }
Exemplo n.º 7
0
        static void InitIrcClient()
        {
            Thread.CurrentThread.Name = "Main";
            irc.Encoding = System.Text.Encoding.UTF8;

            // wait time between messages, we can set this lower on own irc servers
            irc.SendDelay = 200;
            // we use channel sync, means we can use irc.GetChannel() and so on
            irc.ActiveChannelSyncing = true;
            irc.AutoReconnect        = true;
            irc.AutoRejoin           = true;
            irc.AutoRejoinOnKick     = true;
            irc.SupportNonRfc        = true;

            // here we connect the events of the API to our written methods
            // most have own event handler types, because they ship different data
            irc.OnQueryMessage   += new IrcEventHandler(OnPrivateMessage);
            irc.OnError          += new Meebey.SmartIrc4net.ErrorEventHandler(OnError);
            irc.OnRawMessage     += new IrcEventHandler(OnRawMessage);
            irc.OnChannelMessage += new IrcEventHandler(OnChannelMessage);
            irc.OnJoin           += new JoinEventHandler(OnUserJoin);
            irc.OnPart           += new PartEventHandler(OnUserPartChannel);

            string[] serverlist;
            // the server we want to connect to, could be also a simple string
            serverlist = new string[] { "irc.miners-zone.net" };
            int port = 6667;

            try
            {
                // here we try to connect to the server and exceptions get handled
                irc.Connect(serverlist, port);
            }
            catch (ConnectionException e)
            {
                // something went wrong, the reason will be shown
                System.Console.WriteLine("couldn't connect! Reason: " + e.Message);
            }

            try
            {
                // here we logon and register our nickname and so on
                irc.Login(Program.BotName, Program.BotDescription);
                // join the channel
                irc.RfcJoin(Program.PublicChannel);
                irc.RfcJoin(Program.AdminChannel);
            }
            catch (ConnectionException)
            {
                // this exception is handled because Disconnect() can throw a not
                // connected exception
            }
            catch (Exception e)
            {
                // this should not happen by just in case we handle it nicely
                System.Console.WriteLine("Error occurred! Message: " + e.Message);
                System.Console.WriteLine("Exception: " + e.StackTrace);
                irc.Disconnect();
            }
        }
Exemplo n.º 8
0
        public void Connect()
        {
            try
            {
                irc.Connect(server, port);
            }
            catch (ConnectionException e)
            {
                Console.WriteLine("Could not connect: " + e.Message);
                return;
            }
            try
            {
                irc.Login("testuser889", "testing the goonite irc client");
                irc.RfcJoin(channel);
                _listenThread = new Thread(new ThreadStart(irc.Listen));
                _listenThread.Start();

                // here we send just 3 different types of messages, 3 times for
                // testing the delay and flood protection (messagebuffer work)
                //irc.SendMessage(SendType.Message, channel, "test message (" + i.ToString() + ")");
                //irc.SendMessage(SendType.Action, channel, "thinks this is cool (" + i.ToString() + ")");
                //irc.SendMessage(SendType.Notice, channel, "SmartIrc4net rocks (" + i.ToString() + ")");
            }
            catch (ConnectionException e)
            {
                Console.WriteLine("Error at Login / Listen" + e.Message);
                return;
            }
        }
Exemplo n.º 9
0
        bool ConnectIRC(object[] Params)
        {
            if (!Session.Safe || (!Session.InSpace && !Session.InStation))
            {
                return(false);
            }

            if (Config.UseIRC)
            {
                try
                {
                    IrcUserRegistrationInfo reginfo = new IrcUserRegistrationInfo();
                    reginfo.NickName   = Me.Name.Replace(" ", string.Empty).Replace("'", string.Empty);
                    reginfo.RealName   = Me.Name.Replace(" ", string.Empty).Replace("'", string.Empty);
                    reginfo.UserName   = Me.Name.Replace(" ", string.Empty).Replace("'", string.Empty);
                    IRC.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
                    IRC.Connect(new Uri("irc://" + Config.Server), reginfo);
                }
                catch
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 10
0
        public bool Connect(string server)
        {
            connectedEvent.Reset();
            client.Connect(server, false, RegistrationInfo);

            return(connectedEvent.Wait(10000));
        }
Exemplo n.º 11
0
        public void Connect()
        {
            try
            {
                IrcClientConnectionOptions options = null;

                if (Settings.Current.IRC.Ssl)
                {
                    options             = new IrcClientConnectionOptions();
                    options.Ssl         = true;
                    options.SslHostname = Settings.Current.IRC.Server;

                    if (Settings.Current.IRC.SslAcceptInvalid)
                    {
                        options.SslCertificateValidationCallback = (sender, certificate, chain, policyErrors) => true;
                    }
                }

                Client.Connect(Settings.Current.IRC.Server, Settings.Current.IRC.Port, options);
            }
            catch (Exception e)
            {
                Log.WriteError("IRC", "Failed to connect: {0}\n{1}", e.Message, e.StackTrace);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// See interface.
        /// </summary>
        /// <param name="network"></param>
        public void Connect(INetwork network)
        {
            // Create client
            Client = new IrcClient
            {
                Encoding             = Encoding.UTF8,
                SendDelay            = 200,
                ActiveChannelSyncing = true,
            };

            Network = network;


            // Hook up to events
            Client.OnList            += OnChannelListReceived;
            Client.OnConnected       += OnConnected;
            Client.OnConnectionError += OnError;
            Client.OnDisconnected    += OnDisconnected;
            Client.OnError           += OnError;
            Client.OnErrorMessage    += OnErrorMessage;
            Client.OnMotd            += OnMotd; // << USED AS *CONNECTED* FOR NOW
            Client.OnChannelMessage  += OnChannelMessage;
            Client.OnQueryMessage    += OnQueryMessage;


            Client.OnRawMessage += OnRawMessage;
            Client.OnRegistered += OnRegistered;

            Client.Connect(network.Address, network.Port);
            Task.Run(() => Client.Listen());
        }
Exemplo n.º 13
0
        void Listen()
        {
            int    port    = 6667;
            string channel = "#" + Settings.Default.Language + ".wikipedia";

            try
            {
                _irc.Connect("irc.wikimedia.org", port);
            }
            catch (ConnectionException err)
            {
                System.Console.WriteLine("couldn't connect! Reason: " + err.Message);
                return;
            }

            try
            {
                _autoEvent.Reset();
                _irc.Login(Settings.Default.IrcUser, Settings.Default.IrcDescription);
                _irc.RfcJoin(channel);
                _stop = false;
                while (!_stop)
                {
                    _irc.ListenOnce();
                }
                _irc.Disconnect();
                _autoEvent.Set();
            }
            catch (ConnectionException)
            {
            }
        }
Exemplo n.º 14
0
 static void Connect()
 {
     Irc.Connect(ip, port);
     Irc.Login(nick, realname);
     Irc.RfcJoin(channel);
     new Thread(new ThreadStart(Irc.Listen)).Start();
 }
Exemplo n.º 15
0
        public void Connect()
        {
            irc.Encoding             = System.Text.Encoding.UTF8;
            irc.SendDelay            = 200;
            irc.ActiveChannelSyncing = true;
            RegisterEvents();

            string[] serverlist = new string[] { "irc.ppy.sh" };
            int      port       = 6667;

            try
            {
                irc.Connect(serverlist, port);
            }
            catch (ConnectionException e)
            {
                System.Console.WriteLine("couldn't connect! Reason: " + e.Message);
                return;
            }

            try
            {
                irc.Login(name, name, 4, name, password);
                irc.RfcJoin("#korean");
                StartLoop();
            }
            catch (Exception e)
            {
                // this should not happen by just in case we handle it nicely
                System.Console.WriteLine("Error occurred! Message: " + e.Message);
                System.Console.WriteLine("Exception: " + e.StackTrace);
                return;
            }
        }
Exemplo n.º 16
0
        private void Reconnect(ConfigPlugin config)
        {
            if (ircClient.IsConnected)
            {
                ircClient.Disconnect();
            }

            threadRunning = false;

            try
            {
                ircThread.Abort();
            }
            catch (Exception)
            {
            }


            ircClient.Connect(config.Host, config.Port);
            ircClient.Login(config.IrcNick, config.IrcNick);
            ircClient.RfcJoin(config.Channel);

            if (!threadRunning)
            {
                ircThread = new Thread(new ThreadStart(IrcThread));
            }
            threadRunning = true;
            ircThread.Start();
        }
Exemplo n.º 17
0
        public void SpawnBot()
        {
            new Thread(() =>
            {
                try
                {
                    ircClient.Connect(server, port);

                    ircClient.Login(nick, loginName);

                    if (authstring.Length != 0)
                    {
                        ircClient.SendMessage(SendType.Message, authuser, authstring);

                        Thread.Sleep(1000); // login delay
                    }

                    ircClient.RfcJoin(channel);

                    ircClient.Listen();

                    timer.Start();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return;
                }
            }).Start();
        }
Exemplo n.º 18
0
        public void Connect()
        {
            if (client.IsConnected)
            {
                return;
            }

            new Thread(() =>
            {
                try
                {
                    client.Connect(Game.Settings.Chat.Hostname, Game.Settings.Chat.Port);
                }
                catch (Exception e)
                {
                    connectionStatus = ChatConnectionStatus.Error;
                    AddNotification(e.Message);
                    Game.RunAfterTick(() => Log.Write("irc", e.ToString()));

                    return;
                }

                client.Listen();
            })
            {
                Name = "IrcListenThread", IsBackground = true
            }.Start();
        }
Exemplo n.º 19
0
        public override void Loop()
        {
            while (true)
            {
                _client = new IrcClient
                {
                    AutoJoinOnInvite = true,
                    AutoReconnect    = true,
                    AutoRejoin       = true,
                    AutoRejoinOnKick = true,
                    AutoRelogin      = true,
                    AutoRetry        = true
                };
                var mre = new ManualResetEvent(false);
                _client.OnJoin += (sender, args) =>
                                  Output("I have joined " + args.Channel);
                _client.OnChannelMessage += (sender, args) =>
                                            Handle(args.Data.Message);
                _client.OnConnected += (sender, args) =>
                {
                    mre.Set();
                    _client.RfcJoin("#jarvis");
                };

                _client.Connect("irc.clossit.com", 6668);
                _client.Login("Jarvis", "Jarvis");
                new Thread(() => _client.Listen()).Start();
                mre.WaitOne(30.Seconds());
                while (_client.IsConnected)
                {
                    5.Seconds().Sleep();
                }
                Output("I have lost connection to I.R.C");
            }
        }
Exemplo n.º 20
0
        //
        // Connecting, Joining, Listening
        //

        public void Connect(string server, int port, string botName, string pass)
        {
            try
            {
                // here we try to connect to the server and exceptions get handled
                mainIRCClient.Connect(server, port);
            }
            catch (ConnectionException e)
            {
                // something went wrong, the reason will be shown
                System.Console.WriteLine("couldn't connect! Reason: " + e.Message);
            }

            try
            {
                // here we logon and register our nickname and so on
                mainIRCClient.Login(botName, botName);
            }
            catch (ConnectionException)
            {
                // this exception is handled because Disconnect() can throw a not
                // connected exception
            }
            catch (Exception e)
            {
                // this should not happen by just in case we handle it nicely
                System.Console.WriteLine("Error occurred! Message: " + e.Message);
                System.Console.WriteLine("Exception: " + e.StackTrace);
            }
        }
Exemplo n.º 21
0
        public static void Main(string[] args)
        {
            sessions = new Dictionary <string, ChatterBotSession>();
            ChatterBotFactory factory = new ChatterBotFactory();

            bot1 = factory.Create(ChatterBotType.CLEVERBOT);

            //ChatterBot bot2 = factory.Create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477");
            //ChatterBotSession bot2session = bot2.CreateSession();

            //string s = "Hi";
            irc                = new IrcClient();
            irc.Connected     += irc_Connected;
            irc.Registered    += irc_Registered;
            irc.Error         += irc_Error;
            irc.ConnectFailed += irc_ConnectFailed;
            irc.Connect("chat.freenode.net", false, new IrcUserRegistrationInfo()
            {
                NickName = name, RealName = name, UserName = name
            });
            while (true)
            {
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 22
0
 void Listen()
 {
     try
     {
         _irc                    = new IrcClient();
         _irc.AutoRejoin         = true;
         _irc.SendDelay          = 500;
         _irc.OnConnecting      += new EventHandler(_irc_OnConnecting);
         _irc.OnConnected       += new EventHandler(_irc_OnConnected);
         _irc.OnConnectionError += new EventHandler(_irc_OnConnectionError);
         _irc.OnDisconnected    += new EventHandler(_irc_OnDisconnected);
         _irc.OnChannelMessage  += new IrcEventHandler(_irc_OnChannelMessage);
         _irc.OnRawMessage      += new IrcEventHandler(_irc_OnRawMessage);
         _irc.OnError           += new ErrorEventHandler(_irc_OnError);
         _irc.OnErrorMessage    += new IrcEventHandler(_irc_OnErrorMessage);
         _irc.Connect(_server, _port);
         _irc.Login(_nick, _realName);
         _irc.RfcJoin(_channel);
         _irc.Listen();
     }
     catch (Exception ex)
     {
         OutputMessage("Fatal Error: " + ex.Message);
     }
 }
Exemplo n.º 23
0
        private void Connect()
        {
            Console.WriteLine("Connecting to {0} port {1}",
                              hostname,
                              port);
            while (!m_IrcClient.Connected)
            {
                try
                {
                    m_IrcClient.Connect(hostname, port);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Thread.Sleep(10000);
                }
            }

            m_IrcClient.Register(botname, password, null);
            Console.WriteLine("Registered as {0}...", m_IrcClient.Nickname);

            /* Did we get the nick we wanted? */
            if (m_IrcClient.Nickname != botname)
            {
                /* there must have been an existing one, kill it */
                m_IrcClient.GhostNick(botname, password);;
            }

            JoinChannels();
        }
Exemplo n.º 24
0
        private void IRCMessenger_Load(object sender, EventArgs e)
        {
            m_IRCClient = new IrcClient();

            // UTF-8 test
            m_IRCClient.Encoding = System.Text.Encoding.UTF8;
            // wait time between messages, we can set this lower on own irc servers
            m_IRCClient.SendDelay = 200;
            // we use channel sync, means we can use irc.GetChannel() and so on
            m_IRCClient.ActiveChannelSyncing = true;

            // Setup Events
            m_IRCClient.OnConnected += new EventHandler(ircClient_OnConnect);
            m_IRCClient.OnJoin      += new JoinEventHandler(ircClient_OnJoin);
            m_IRCClient.OnNames     += new NamesEventHandler(ircClient_OnNames);
            // Leave room
            m_IRCClient.OnPart         += new PartEventHandler(ircClient_OnPart);
            m_IRCClient.OnQuit         += new QuitEventHandler(ircClient_OnQuit);
            m_IRCClient.OnKick         += new KickEventHandler(ircClient_OnKick);
            m_IRCClient.OnQueryMessage += new IrcEventHandler(ircClient_OnPrivMsg);
            m_IRCClient.OnErrorMessage += new IrcEventHandler(ircClient_OnError);
            //m_IRCClient.OnRawMessage += new IrcEventHandler(OnRawMessage);

            m_IRCClient.Connect(m_IRCServer, m_IRCPort);

            // here we logon and register our nickname and so on
            m_IRCClient.Login(m_Nick, "SmartIrc4net Test Bot");

            // Setup listen thread
            m_IrcThread = new Thread(ListenThread);
            m_IrcThread.Start();
        }
Exemplo n.º 25
0
        public void Connect()
        {
            try
            {
                IrcClientConnectionOptions options = null;

                if (Settings.Current.IRC.Ssl)
                {
                    options = new IrcClientConnectionOptions
                    {
                        Ssl         = true,
                        SslHostname = Settings.Current.IRC.Server
                    };

                    if (Settings.Current.IRC.SslAcceptInvalid)
                    {
                        options.SslCertificateValidationCallback = (sender, certificate, chain, policyErrors) => true;
                    }
                }

                Client.Connect(Settings.Current.IRC.Server, Settings.Current.IRC.Port, options);
            }
            catch (Exception e)
            {
                ErrorReporter.Notify("IRC", e);
            }
        }
Exemplo n.º 26
0
        public void Tick()
        {
            if (DateTime.Now >= nextConnect)
            {
                nextConnect = DateTime.MaxValue;

                Log.WriteInfo("IRC", "Connecting...");

                if (client.IsConnected)
                {
                    client.Disconnect();
                }

                client.Connect(Settings.Current.IRCServer, Settings.Current.IRCPort);

                var nickList = new string[] { Settings.Current.IRCNick, Settings.Current.IRCNick + "_" };

                if (!string.IsNullOrEmpty(Settings.Current.IRCPassword))
                {
                    client.Login(nickList, Settings.Current.IRCNick, 4, "steamircbot", Settings.Current.IRCPassword);
                }
                else
                {
                    client.Login(nickList, Settings.Current.IRCNick, 4, "steamircbot");
                }
            }

            client.ListenOnce(false);

            CommandManager.Tick();
        }
Exemplo n.º 27
0
        private void IrcThread(object param)
        {
            object[] args   = (object[])param;
            string   server = (string)args[0];
            int      port   = (int)args[1];
            string   nick   = (string)args[2];
            string   chan   = (string)args[3];

            connecting = true;
            PrintMsg("System", "Connecting...");

            try
            {
                irc.Connect(server, port);
                PrintMsg("System", "Logging in...");
                irc.Login(nick, "Radegast SL Relay", 0, nick);
                irc.RfcJoin(chan);
                connecting = false;
            }
            catch (Exception ex)
            {
                PrintMsg("System", "An error has occured: " + ex.Message);
            }

            try
            {
                irc.Listen();
                if (irc.IsConnected)
                {
                    irc.AutoReconnect = false;
                    irc.Disconnect();
                }
            }
            catch { }
        }
Exemplo n.º 28
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            lstLog.Items.Clear();

            nummsg    = 0;
            oldnummsg = 0;

            if (_ircClient.IsConnected)
            {
                _ircClient.Disconnect();
            }
            _ircClient.SendDelay            = 200;
            _ircClient.ActiveChannelSyncing = true;

            AddItemToLog("Connecting to " + txtServer.Text);
            try
            {
                _ircClient.Connect(txtServer.Text, 6667);
                grpIRCCONFIG.Enabled = false;
                grpLOGCONFIG.Enabled = false;
                StatsTimer.Interval  = Convert.ToInt32(txtLogInterval.Text);
            }
            catch (ConnectionException ex)
            {
                AddItemToLog("couldn't connect! Reason: " + ex.Message);
            }
        }
Exemplo n.º 29
0
        protected void Connect(string server, IrcRegistrationInfo registrationInfo)
        {
            // Create new IRC client and connect to given server.
            var client = new IrcClient();

            client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
            client.Connected     += IrcClient_Connected;
            client.Disconnected  += IrcClient_Disconnected;
            client.Registered    += IrcClient_Registered;

            // Wait until connection has succeeded or timed out.
            using (var connectedEvent = new ManualResetEventSlim(false))
            {
                client.Connected += (sender2, e2) => connectedEvent.Set();
                client.Connect(server, false, registrationInfo);
                if (!connectedEvent.Wait(10000))
                {
                    client.Dispose();
                    ConsoleUtilities.WriteError("Connection to '{0}' timed out.", server);
                    return;
                }
            }

            // Add new client to collection.
            this.allClients.Add(client);

            Console.Out.WriteLine("Now connected to '{0}'.", server);
        }
Exemplo n.º 30
0
        private void IRCApp_Load(object sender, EventArgs e)
        {
            // Show connection dialog
            ConnectForm connectDialog = new ConnectForm();

            connectDialog.ShowDialog();

            // Fetch the client object...
            client = connectDialog.client;

            // Register client events...
            client.SelfJoinedChannel += Client_SelfJoinedChannel;
            client.GotGeneralMessage += Client_GotGeneralMessage;

            // And get connected.
            client.Connect();

            // Initialize the status tab...
            StatusTabControl          = new TabLayout(client, null);
            StatusTabControl.TopLevel = false;
            StatusTab.Controls.Add(StatusTabControl);

            // And make it visible.
            StatusTabControl.Dock = DockStyle.Fill;
            StatusTabControl.Show();
        }
Exemplo n.º 31
0
 public static void IrcClientList()
 {
     IrcClient irc = new IrcClient();
     irc.OnRawMessage += new EventHandler<IrcEventArgs>(IrcClientListCallback);
     irc.Connect(SERVER, PORT);
     irc.Login(NICK, REALNAME);
     irc.RfcList(CHANNEL);
     irc.Listen();
 }
Exemplo n.º 32
0
        private void menuItemConnect_Click(object sender, System.EventArgs e)
        {
            try
            {
                AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Attempting connection to " + User.server + ":" + User.port.ToString() + "\n");

                if (File.Exists("ignore"))
                {
                    using (StreamReader sr = new StreamReader("ignore"))
                    {
                        string line = null;

                        while ((line = sr.ReadLine()) != null)
                        {
                            alIgnoredHosts.Add(line.ToString());
                        }
                    }
                }

                irc = new IrcClient();
                irc.SendDelay = 200;
                irc.AutoRetry = false;
                irc.ChannelSyncing = true;

                irc.OnTopic += new TopicEventHandler(irc_OnTopic);
                irc.OnDisconnected += new SimpleEventHandler(irc_OnDisconnected);
                irc.OnDeop += new DeopEventHandler(irc_OnDeop);
                irc.OnOp += new OpEventHandler(irc_OnOp);
                irc.OnOwner += new OwnerEventHandler(irc_OnOwner);
                irc.OnHalfOp += new HalfOpEventHandler(irc_OnHalfOp);
                irc.OnProtect += new ProtectEventHandler(irc_OnProtect);
                irc.OnDeOwner += new DeOwnerEventHandler(irc_OnDeOwner);
                irc.OnDeHalfOp += new DeHalfOpEventHandler(irc_OnDeHalfOp);
                irc.OnDeProtect += new DeProtectEventHandler(irc_OnDeProtect);
                irc.OnDevoice += new DevoiceEventHandler(irc_OnDevoice);
                irc.OnVoice += new VoiceEventHandler(irc_OnVoice);
                irc.OnWho += new WhoEventHandler(irc_OnWho);
                irc.OnModeChange += new MessageEventHandler(irc_OnModeChange);
                irc.OnUserModeChange += new MessageEventHandler(irc_OnUserModeChange);
                irc.OnUnban += new UnbanEventHandler(irc_OnUnban);
                irc.OnBan += new BanEventHandler(irc_OnBan);
                irc.OnKick += new KickEventHandler(irc_OnKick);
                irc.OnQueryAction += new ActionEventHandler(irc_OnQueryAction);
                irc.OnQuit += new QuitEventHandler(irc_OnQuit);
                irc.OnNickChange += new NickChangeEventHandler(irc_OnNickChange);
                irc.OnChannelAction += new ActionEventHandler(irc_OnChannelAction);
                irc.OnReadLine += new ReadLineEventHandler(irc_OnReadLine);
                irc.OnJoin += new JoinEventHandler(irc_OnJoin);
                irc.OnPart += new PartEventHandler(irc_OnPart);
                irc.OnQueryNotice += new MessageEventHandler(irc_OnQueryNotice);
                irc.OnChannelMessage += new MessageEventHandler(irc_OnChannelMessage);
                irc.OnQueryMessage += new MessageEventHandler(irc_OnQueryMessage);

                if (irc.Connect(User.server, User.port))
                {
                    irc.Login(User.username, Application.Name + " " + Application.Version);
                    irc.Join(User.channel);

                    if (irc.Connected)
                    {
                        menuItemConnect.Enabled = false;
                        menuItemDisconnect.Enabled = true;

                        threadIrcConnection = new Thread(new ThreadStart(IRCListenThread));
                        threadIrcConnection.Start();
                    }
                    else
                    {
                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                        AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                        AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                        AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- Unable to connect to " + User.server + ":" + User.port.ToString() + "\n");
                    }
                }
                else
                {
                    AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "[");
                    AppendText(tabControlChatTabs.SelectedTab.Text, "time", DateTime.Now.ToShortTimeString().ToString());
                    AppendText(tabControlChatTabs.SelectedTab.Text, "tag", "] ");
                    AppendText(tabControlChatTabs.SelectedTab.Text, "notice", " -!- A connection to " + User.server + ":" + User.port.ToString() + " could not be established.\n");
                }
            }
            catch (Exception ex)
            {
                User.ErrorLog(ex.ToString());
            }
        }
Exemplo n.º 33
0
        public static void ClassInitialize(TestContext testContext)
        {
            stateManager = new TestStateManager<IrcClientTestState>();

            // Create IRC clients.
            ircClient1 = new IrcClient();
#if DEBUG
            ircClient1.ClientId = "1";
#endif
            ircClient1.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
            ircClient1.Connected += ircClient1_Connected;
            ircClient1.ConnectFailed += ircClient1_ConnectFailed;
            ircClient1.Disconnected += ircClient1_Disconnected;
            ircClient1.Error += ircClient1_Error;
            ircClient1.ProtocolError += ircClient1_ProtocolError;
            ircClient1.Registered += ircClient1_Registered;
            ircClient1.MotdReceived += ircClient1_MotdReceived;
            ircClient1.NetworkInformationReceived += ircClient1_NetworkInformationReceived;
            ircClient1.ServerVersionInfoReceived += ircClient1_ServerVersionInfoReceived;
            ircClient1.ServerTimeReceived += ircClient1_ServerTimeReceived;
            ircClient1.ServerLinksListReceived += ircClient1_ServerLinksListReceived;
            ircClient1.ServerStatsReceived += ircClient1_ServerStatsReceived;
            ircClient1.WhoReplyReceived += ircClient1_WhoReplyReceived;
            ircClient1.WhoIsReplyReceived += ircClient1_WhoIsReplyReceived;
            ircClient1.WhoWasReplyReceived += ircClient1_WhoWasReplyReceived;
            ircClient1.ChannelListReceived += ircClient1_ChannelListReceived;

            ircClient2 = new IrcClient();
#if DEBUG
            ircClient2.ClientId = "2";
#endif
            ircClient2.Connected += ircClient2_Connected;
            ircClient2.ConnectFailed += ircClient2_ConnectFailed;
            ircClient2.Disconnected += ircClient2_Disconnected;
            ircClient2.Error += ircClient2_Error;
            ircClient2.ProtocolError += ircClient2_ProtocolError;
            ircClient2.Registered += ircClient2_Registered;

            // Create CTCP clients over IRC clients.
            ctcpClient1 = new CtcpClient(ircClient1);
            ctcpClient1.ClientVersion = clientVersionInfo;
            ctcpClient1.PingResponseReceived += ctcpClient1_PingResponseReceived;
            ctcpClient1.VersionResponseReceived += ctcpClient1_VersionResponseReceived;
            ctcpClient1.TimeResponseReceived += ctcpClient1_TimeResponseReceived;
            ctcpClient1.ActionReceived += ctcpClient1_ActionReceived;

            ctcpClient2 = new CtcpClient(ircClient2);
            ctcpClient2.ClientVersion = clientVersionInfo;
            ctcpClient2.PingResponseReceived += ctcpClient2_PingResponseReceived;
            ctcpClient2.VersionResponseReceived += ctcpClient2_VersionResponseReceived;
            ctcpClient2.TimeResponseReceived += ctcpClient2_TimeResponseReceived;
            ctcpClient2.ActionReceived += ctcpClient2_ActionReceived;

            // Initialize wait handles for all events.
            GetAllWaitHandlesFields().ForEach(fieldInfo => fieldInfo.SetValue(null, new AutoResetEvent(false)));

            // Nick name length limit on irc.freenode.net is 16 chars.
            Func<string> getRandomUserId = () => Guid.NewGuid().ToString().Substring(0, 8);

            serverPassword = Properties.Resources.ServerPassword;
            if (string.IsNullOrEmpty(serverPassword))
                serverPassword = null;
            nickName1 = userName1 = string.Format(Properties.Resources.NickNameFormat, getRandomUserId());
            nickName2 = userName2 = string.Format(Properties.Resources.NickNameFormat, getRandomUserId());
            realName = Properties.Resources.RealName;

            Debug.WriteLine("Client users have real name '{0}'", realName);
            Debug.WriteLine("Client 1 user has nick name '{0}' and user name '{1}'.", nickName1, userName1);
            Debug.WriteLine("Client 2 user has nick name '{0}' and user name '{1}'.", nickName2, userName2);

            stateManager.SetStates(IrcClientTestState.Client1Initialized, IrcClientTestState.Client2Initialized);
            ircClient1.Connect(Properties.Resources.ServerHostName, false, new IrcUserRegistrationInfo()
                {
                    Password = serverPassword,
                    NickName = nickName1,
                    UserName = userName1,
                    RealName = realName,
                });
            ircClient2.Connect(Properties.Resources.ServerHostName, false, new IrcUserRegistrationInfo()
                {
                    Password = serverPassword,
                    NickName = nickName2,
                    UserName = userName2,
                    RealName = realName,
                });
        }
Exemplo n.º 34
0
        public void Connect(string server, IrcRegistrationInfo registrationInfo)
        {
            // Create new IRC client and connect to given server.
            var client = new IrcClient();
            client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
            client.Connected += IrcClient_Connected;
            client.Disconnected += IrcClient_Disconnected;
            client.Registered += IrcClient_Registered;

            // Wait until connection has succeeded or timed out.
            using (var connectedEvent = new ManualResetEventSlim(false))
            {
                client.Connected += (sender2, e2) => connectedEvent.Set();
                client.Connect(server, false, registrationInfo);
                if (!connectedEvent.Wait(10000))
                {
                    client.Dispose();
                    ConsoleUtilities.WriteError("Connection to '{0}' timed out.", server);
                    return;
                }
            }

            // Add new client to collection.
            this.allClients.Add(client);

            Console.Out.WriteLine("Now connected to '{0}'.", server);
        }