当前位置: 首页>>代码示例>>C#>>正文


C# IrcClient.Connect方法代码示例

本文整理汇总了C#中Meebey.SmartIrc4net.IrcClient.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# IrcClient.Connect方法的具体用法?C# IrcClient.Connect怎么用?C# IrcClient.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Meebey.SmartIrc4net.IrcClient的用法示例。


在下文中一共展示了IrcClient.Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Connect

        public void Connect()
        {
            IrcClient = new IrcClient();
            IrcClient.OnConnected += OnConnected;
            IrcClient.OnConnecting += OnConnecting;
            IrcClient.OnDisconnected += OnDisconnected;
            //IrcClient.OnReadLine += OnReadLine;
            IrcClient.OnPing += OnPing;
            IrcClient.OnRawMessage += OnRawMessage;

            IrcClient.AutoRetry = Convert.ToBoolean(Connection.auto_retry);
            IrcClient.AutoRetryDelay = Convert.ToInt32(Connection.auto_retry_delay);
            IrcClient.AutoReconnect = Convert.ToBoolean(Connection.auto_reconnect);
            IrcClient.AutoRelogin = Convert.ToBoolean(Connection.auto_relogin);
            IrcClient.AutoRejoin = Convert.ToBoolean(Connection.auto_rejoin);
            IrcClient.AutoRejoinOnKick = Convert.ToBoolean(Connection.auto_rejoin_on_kick);
            IrcClient.AutoNickHandling = Convert.ToBoolean(Connection.auto_nick_handling);

            try
            {
                IrcClient.Connect(Connection.hostname, Convert.ToInt32(Connection.port));
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to connect: " + e.Message);
            }
        }
开发者ID:soend,项目名称:Glucodyn,代码行数:27,代码来源:IdentityConnection.cs

示例2: IrcClientList

 public static void IrcClientList()
 {
     IrcClient irc = new IrcClient();
     irc.OnRawMessage += new IrcEventHandler(IrcClientListCallback);
     irc.Connect(SERVER, PORT);
     irc.Login(NICK, REALNAME);
     irc.RfcList(CHANNEL);
     irc.Listen();
 }
开发者ID:garrafote,项目名称:SmartIrc4net,代码行数:9,代码来源:benchmark.cs

示例3: Client

        public Client()
        {
            instance = new IrcClient();

            instance.OnConnected += clientInstance_OnConnected;
            instance.OnRegistered += clientInstance_OnRegistered;

            instance.Connect(Server, Port);

            Timer timer = new Timer(15 * 1000);
            timer.Elapsed += saveGlobalStorage;
            timer.Start();
        }
开发者ID:undeclared,项目名称:nullbot,代码行数:13,代码来源:Client.cs

示例4: Connect

        private void Connect()
        {
            _ircClient = new SIRC4N.IrcClient();

            _ircClient.OnDisconnected += _ircClient_OnDisconnected;
            _ircClient.OnRawMessage += _ircClient_OnRawMessage;
            _ircClient.OnRegistered += _ircClient_OnRegistered;
            _ircClient.OnChannelAction += _ircClient_OnChannelAction;
            _ircClient.OnChannelMessage += _ircClient_OnChannelMessage;
            _ircClient.OnQueryAction += _ircClient_OnQueryAction;
            _ircClient.OnQueryMessage += _ircClient_OnQueryMessage;
            _ircClient.OnQueryNotice += _ircClient_OnQueryNotice;

            _ircClient.Connect(Server.Host, Server.Port ?? 6667);
            _ircClient.Login(Network.BotNickname, Network.BotRealname);

            listenThread = new Thread(_ircClient.Listen);
            listenThread.Start();
        }
开发者ID:KAmaia,项目名称:SpikeLite,代码行数:19,代码来源:IrcClient.cs

示例5: BetWorker

        public BetWorker(MainViewModel viewModel)
        {
            _viewModel = viewModel;
            _bets = new List<Bet>();
            _users = new List<User>();

            _ircClient = new IrcClient();
            _ircClient.Connect(_server, _port);
            _ircClient.WriteLine(Rfc2812.Nick(_botName), Priority.Critical);
            _ircClient.WriteLine(Rfc2812.User(_botName, 0, _botName), Priority.Critical);
            _ircClient.WriteLine(Rfc2812.Join(_channel));
            _listenThread = new Thread(() =>
            {
                _ircClient.OnChannelMessage += _ircClient_OnChannelMessage;
                _ircClient.OnJoin += _ircClient_OnJoin;
                _ircClient.OnPart += _ircClient_OnPart;
                _ircClient.OnQuit += _ircClient_OnQuit;
                _ircClient.Listen();
            });
            _listenThread.Start();
        }
开发者ID:Booom3,项目名称:CreditBot,代码行数:21,代码来源:BetWorker.cs

示例6: Run

 private static void Run()
 {
     while( !stopRequested ) {
         try {
             irc = new IrcClient();
             irc.Encoding = System.Text.Encoding.UTF8;
             irc.SendDelay = 200;
             irc.ActiveChannelSyncing = true;
             irc.OnRawMessage += new IrcEventHandler( irc_OnRawMessage );
             irc.Connect( settings.IrcHost, settings.IrcPort );
             irc.Login( NICK, NICK, 0, NICK, settings.IrcPassword );
             irc.RfcJoin( settings.IrcChannelName );
             irc.Listen();
             if( irc.IsConnected ) {
                 irc.Disconnect();
             }
         } catch( Exception e ) {
             Console.WriteLine( e.Message );
         }
         if( !stopRequested ) {
             Thread.Sleep( TimeSpan.FromSeconds( 10 ) );
         }
     }
 }
开发者ID:kbinani,项目名称:fez-trade-bot,代码行数:24,代码来源:Irc.cs

示例7: IrcMaster

        public IrcMaster(string host, int port)
        {
            // Init IRC client
            client = new IrcClient();
            client.Encoding = Encoding.UTF8;
            client.ActiveChannelSyncing = true;
            client.SendDelay = 1;

            Log.Info("Connecting to "+host+":"+port+".");
            client.Connect(host, port);

            if(!client.IsConnected) {
                throw new Exception("Could not connect to the server.");
            }

            // Hook up events
            client.OnChannelMessage += new IrcEventHandler(OnChannelMessage);
            client.OnQueryMessage += new IrcEventHandler(OnQueryMessage);
            client.OnKick += new KickEventHandler(OnKick);
            client.OnDisconnected += new EventHandler(OnDisconnect);
            client.OnJoin += new JoinEventHandler(OnJoin);
            client.OnPart += new PartEventHandler(OnPart);
            client.OnQuit += new QuitEventHandler(OnQuit);
        }
开发者ID:JamesBondski,项目名称:mafiabot,代码行数:24,代码来源:IrcMaster.cs

示例8: Loop

        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");
            }
        }
开发者ID:csyolen,项目名称:Jarvis,代码行数:36,代码来源:IRCListener.cs

示例9: Main

    static void Main()
    {
        var client = new IrcClient() {
            ActiveChannelSyncing = true
        };
        client.Connect("irc.oftc.net", 6667);
        client.Login("smuxi-bot", "smuxi bot");
        client.OnRegistered += delegate {
            client.RfcJoin("#smuxi");
        };

        var client2 = new IrcClient() {
            ActiveChannelSyncing = true
        };
        client2.Connect("irc.freenode.net", 6667);
        client2.Login("smuxi-bot", "smuxi bot");
        client2.OnRegistered += delegate {
            client2.RfcJoin("#smuxi");
        };

        var timer = new Timer(delegate {
            var chan = client.GetChannel("#smuxi");
            var chan2 = client2.GetChannel("#smuxi");
            if (chan == null) {
                client.RfcJoin("#smuxi");
                return;
            }
            if (chan2 == null) {
                client2.RfcJoin("#smuxi");
                return;
            }
            // filter duplicates and clones
            var users = new List<string>();
            foreach (string user in chan.Users.Keys) {
                var nick = user.TrimEnd('_');
                users.Add(nick);
            };
            foreach (string user in chan2.Users.Keys) {
                var nick = user.TrimEnd('_');
                if (users.Contains(nick)) {
                    continue;
                }
                users.Add(nick);
            }
            Console.WriteLine("{0} #smuxi user count: {1}",
                            DateTime.Now.ToString("s"), users.Count);
        }, null, TimeSpan.Zero, TimeSpan.FromMinutes(1));

        var thread = new Thread(new ThreadStart(delegate {
            while (client.IsConnected) {
                client.Listen();
                Thread.Sleep(1000);
            }
        }));
        thread.Start();

        var thread2 = new Thread(new ThreadStart(delegate {
            while (client2.IsConnected) {
                client2.Listen();
                Thread.Sleep(1000);
            }
        }));
        thread2.Start();

        thread.Join();
        thread2.Join();
    }
开发者ID:grendello,项目名称:smuxi,代码行数:67,代码来源:smuxi-channel-stats.cs

示例10: Main

        static void Main(string[] args)
        {
            string confFile = "bot.conf";

            // accept some console arguments
            if (args.Length > 0)
            {
                foreach (string arg in args)
                {
                    string[] nv = arg.Split(new char[] { '=' });
                    switch (nv[0])
                    {
                        //config file
                        case "-c":
                        case "-config":
                            confFile = nv[1];
                            break;
                    }
                }
            }

            // load the configuration information first
            // since other things will rely on it.
            try
            {
                System.Console.WriteLine("Using config: " + confFile);
                conf = new IniConfigSource(Path.Combine(Environment.CurrentDirectory,confFile));
            }
            catch (IOException ioe)
            {
                FatalError(ioe.Message);
            }
            catch (Exception ex)
            {
                FatalError(ex.Message);
            }

            // initialise our functions (the IRC commands).
            // let them set up and initialise before we connect
            functions = new List<IFunction>();
            InitFunctions();

            // and begin to handle their outputs now
            foreach (var f in functions)
            {
                f.FunctionOutputHandler += new FunctionOutput(f_FunctionOutputHandler);
            }

            // load the irc stuff
            irc = new IrcClient();

            // and handle some irc events
            irc.OnRawMessage += new IrcEventHandler(irc_OnRawMessage);
            irc.OnConnected += new EventHandler(irc_OnConnected);

            // listen for commands in the console
            // (but we don't do anything with it yet)
            new Thread(new ThreadStart(ReadLine)).Start();

            // now set up IRC and connect
            try
            {

                irc.SendDelay = Convert.ToInt32(GetConf("bot", "delay"));
                irc.ActiveChannelSyncing = true;
                irc.Encoding = System.Text.Encoding.UTF8;
                irc.AutoNickHandling = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("IRC Initialisation error: ");
                FatalError(ex.Message);
            }

            try
            {
                string network = (string)GetConf("bot", "network");
                int port = Convert.ToInt32(GetConf("bot", "port"));
                irc.Connect(network, port);
            }
            catch (ConnectionException e)
            {
                Console.WriteLine("Connection error: ");
                FatalError(e.Message);
            }

            string nick = "", realName = "", ident = "";

            try
            {
                nick = (string)GetConf("bot", "nick");
                realName = (string)GetConf("bot", "real_name");
                ident = (string)GetConf("bot", "ident");
            }
            catch (Exception e)
            {
                Console.WriteLine("Configuration error.");
                FatalError(e.Message);
            }

//.........这里部分代码省略.........
开发者ID:BauerUK,项目名称:WorldCupBot,代码行数:101,代码来源:Program.cs

示例11: TestConnectionStability

        /// <summary>
        /// just testing the IRC chat connection stability...
        /// </summary>
        private static void TestConnectionStability()
        {
            while (true)
            {
                try
                {
                    irc_test = new IrcClient();
                    irc_test.AutoRetry = true;
                    irc_test.AutoReconnect = true;
                    irc_test.OnChannelMessage += new IrcEventHandler(irc_test_OnChannelMessage);
                    irc_test.OnRawMessage += new IrcEventHandler(irc_test_OnRawMessage);
                    // here we try to connect to the server and exceptions get handled
                    irc_test.Connect(serverlist, port);
                }
                catch (ConnectionException e)
                {
                    // something went wrong, the reason will be shown
                    logger.Trace("couldn't connect! Reason: " + e.Message);
                    //Exit();
                }

                try
                {
                    // here we logon and register our nickname and so on
                    irc_test.Login(nick, real);

                    // join the channel
                    irc_test.RfcJoin(channel);

                    // here we tell the IRC API to go into a receive mode, all events
                    // will be triggered by _this_ thread (main thread in this case)
                    // Listen() blocks by default, you can also use ListenOnce() if you
                    // need that does one IRC operation and then returns, so you need then
                    // an own loop
                    irc_test.Listen();

                    // when Listen() returns our IRC session is over, to be sure we call
                    // disconnect manually
                    irc_test.Disconnect();
                }
                catch (ConnectionException e)
                {
                    // this exception is handled becaused Disconnect() can throw a not
                    // connected exception
                    logger.Trace("Connection exception: " + e.Message);
                    //Exit();
                }
                catch (Exception e)
                {
                    // this should not happen by just in case we handle it nicely
                    logger.Trace("Error occurred! Message: " + e.Message);
                    logger.Trace("Exception: " + e.StackTrace);
                    //Exit();
                }

                logger.Trace("Going to sleep");
                System.Threading.Thread.Sleep(5*60000);
                logger.Trace("===========================================");
            }
        }
开发者ID:novalis78,项目名称:prelude-irc,代码行数:63,代码来源:Program.cs

示例12: Main

        public static void Main(string[] args)
        {
            //this method is just for some tests
            //TestConnectionStability();
            //return;

            int cycle_cnt = 0;
            while (true)
            {
                cycle_cnt++;
                //Console.Clear();
                Console.WriteLine("Cycle: " + cycle_cnt);
                Thread.CurrentThread.Name = "Main";

                #region Settings
                string startupPath = Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
                if (File.Exists(startupPath + "\\settings.ini"))
                    profile = new Ini(startupPath + "\\settings.ini");
                else
                {
                    logger.Trace("Did not find" + startupPath);

                }
                channel = (string)profile.GetValue("Main", "Channel");
                nick = (string)profile.GetValue("Main", "Nick");
                real = (string)profile.GetValue("Main", "Real");
                #endregion

                #region IRC Setup
                irc = new IrcClient();
                irc.SendDelay = 500;
                irc.ActiveChannelSyncing = true;
                irc.OnChannelMessage += new IrcEventHandler(OnChannelMessage);
                irc.OnQueryMessage += new IrcEventHandler(OnQueryMessage);
                irc.OnBan += new BanEventHandler(OnBanMessage);

                irc.OnError += new Meebey.SmartIrc4net.ErrorEventHandler(OnError);
                irc.OnPart += new PartEventHandler(irc_OnPart);
                irc.OnRawMessage += new IrcEventHandler(OnRawMessage);
                if (proactiveMode)
                {
                    timer = new System.Timers.Timer();
                    timer.Elapsed += new System.Timers.ElapsedEventHandler(autoAnswering);
                }
                #endregion

                sl = new SortedList();

                Console.WriteLine("**********************************************************");
                Console.WriteLine("These are my settings: ");
                Console.WriteLine("Trying to connect to " + serverlist[0] + " on port " + port + " - joining channel: " + channel);
                Console.WriteLine("My nickname is: " + nick + " and my real name is: " + real);
                Console.WriteLine("**********************************************************");
                try
                {
                    irc.AutoRetry = true;
                    irc.AutoReconnect = true;
                    irc.Connect(serverlist, port);
                }
                catch (ConnectionException e)
                {
                    logger.Trace("couldn't connect! Reason: " + e.Message);
                }

                try
                {
                    // here we logon and register our nickname and so on
                    irc.OnRawMessage += new IrcEventHandler(irc_OnRawMessage);
                    irc.Login(nick, real);

                    //load all channels
                    irc.RfcList("");

                    Dictionary<string, int> chann = new Dictionary<string, int>();

                    // join the channel
                    irc.RfcJoin(channel);
                    irc.OnChannelAction += new ActionEventHandler(irc_OnChannelAction);

                    #region Prelude Setup
                    //initialize interface
                    logger.Trace("Loading Prelude...");
                    pi = new PreLudeInterface();
                    //define path to mind file
                    pi.loadedMind = "mind.mdu";
                    pi.avoidLearnByRepeating = true;
                    pi.initializedAssociater = Mind.MatchingAlgorithm.Dice;
                    //start your engine ...
                    pi.initializeEngine();
                    logger.Trace("Prelude loaded and initialized...");
                    #endregion

                    // spawn a new thread to read the stdin of the console, this we use
                    // for reading IRC commands from the keyboard while the IRC connection
                    // stays in its own thread
                    new Thread(new ThreadStart(ReadCommands)).Start();
                    irc.Listen();
                    // when Listen() returns our IRC session is over, to be sure we call
                    // disconnect manually
                    irc.Disconnect();
//.........这里部分代码省略.........
开发者ID:novalis78,项目名称:prelude-irc,代码行数:101,代码来源:Program.cs

示例13: Connect

        /// <summary>
        /// Creates and sets up an IrcClient instance and connects to a server according to "server"
        /// </summary>
        public void Connect(ServerDescriptor server)
        {
            if (server == null)
                throw new ArgumentNullException("server");

            IrcClient irc = new IrcClient();

            // Settings
            irc.AutoReconnect = true;
            irc.Encoding = System.Text.Encoding.UTF8;
            irc.SendDelay = config.GetInt("send-delay", 200);
            irc.ActiveChannelSyncing = config.GetBoolean("use-active-channel-syncing", false);
            irc.UseSsl = server.UseSsl;

            // Bind event handlers
            irc.OnChannelMessage += OnChannelMessage;
            irc.OnQueryMessage += OnQueryMessage;
            irc.OnQueryNotice += OnQueryNotice;
            irc.OnDisconnected += OnDisconnected;

            // Create scrollback buffer
            scrollback[server.Host] = new C5.CircularQueue<string>(1000);

            try
            {
                log.Info("Connecting to server " + server.Host);
                irc.Connect(server.Host, server.Port);
            }
            catch (ConnectionException e)
            {
                log.Error("Could not connect to server " + irc.Address, e);
                Exit();
            }

            try
            {
                irc.Login(server.Nick,
                    config.GetString("realname", "slave"),
                    0,
                    config.GetString("username", "slave")
                );

                foreach (string channel in server.Channels)
                    irc.RfcJoin(channel);

                ircs[irc.Address] = irc;
            }
            catch (ConnectionException e)
            {
                log.Error("Connection error", e);
                Exit();
            }
            catch (Exception e)
            {
                Exit();
            }
        }
开发者ID:Crobol,项目名称:Bot,代码行数:60,代码来源:IrcComponent.cs

示例14: Connect

        public void Connect()
        {
            while (true)
            {
                _irc = new IrcClient();

                Logger.InfoFormat("Connecting to: {0}:{1}", _settings.Server, _settings.Port);
                try
                {
                    _irc.Encoding = System.Text.Encoding.UTF8;
                    _irc.SendDelay = 500;
                    _irc.ActiveChannelSyncing = true;
                    _irc.AutoReconnect = false;
                    _irc.AutoRejoinOnKick = true;
                    _irc.AutoRetry = true;
                    _irc.AutoRetryDelay = 10000;

                    _irc.OnQueryMessage += OnQueryMessage;
                    _irc.OnQueryNotice += OnQueryMessage;
                    _irc.OnError += OnError;
                    _irc.OnChannelMessage += OnChannelMessage;
                    //_irc.OnRawMessage += (x, e) => Logger.Info(e.Data.RawMessage);

                    _irc.Connect(_settings.Server, _settings.Port);
                }
                catch (Exception e)
                {
                    // Log this shit
                    Logger.Error(e.ToString());
                }

                Logger.Info("Connected! Joining channels");

                try
                {
                    _irc.Login(_settings.Nickname, "Name");

                    if (!String.IsNullOrWhiteSpace(_settings.Password))
                    {
                        _irc.RfcPrivmsg("NickServ", "identify " + _settings.Password);
                    }

                    foreach (var channel in _settings.GetAllChannels())
                    {
                        _irc.RfcJoin(channel);
                    }

                    _checkTimer.Change(TimeSpan.Zero, _settings.Period);
                }
                catch (Exception e)
                {
                    Logger.Error(e.ToString());
                }

                try
                {
                    _irc.Listen();
                    Logger.Error("Lost connection to IRC (Automatically reconnecting in 10 seconds)");
                    Thread.Sleep(10000);

                    if (_irc.IsConnected)
                    {
                        _irc.Disconnect();
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(e.ToString());
                }
            }
        }
开发者ID:devast8a,项目名称:StreamBot,代码行数:71,代码来源:Bot.cs

示例15: DoHive

		private void DoHive(bool enabled)
		{
			try
			{
				// Is everything ok?
				if((txtIRCserver.Text == "" || txtIRCchannel.Text == "") && enabled)
				{
					disableHive.Checked = true;
				}
				else if(enabled)
				{
					try { IPHostEntry ipHost = Dns.GetHostEntry(txtIRCserver.Text); }
					catch { disableHive.Checked = true; }
				}
				if(disableHive.Checked && enabled)
				{
					new frmWtf().Show();
					MessageBox.Show("Did you filled IRC options correctly?", "What the shit.");
					return;
				}

				// We are starting connection. Disable input in IRC boxes.
				txtIRCserver.Enabled = !enabled;
				txtIRCport.Enabled = !enabled;
				txtIRCchannel.Enabled = !enabled;

				// Lets try this!
				ircenabled = enabled;
				if(enabled)
				{
					label25.Text = "Connecting..";
					irc = new IrcClient();
					irc.OnConnected += IrcConnected;
					irc.OnReadLine += OnReadLine;
					irc.OnChannelMessage += OnMessage;
					irc.OnOp += OnOp;
					irc.OnDeop += OnDeOp;
					irc.OnPart += OnPart;
					irc.OnNickChange += OnNickChange;
					irc.OnTopic += OnTopic;
					irc.OnTopicChange += OnTopicChange;
					irc.OnQuit += OnQuit;
					irc.OnKick += OnKick;
					irc.OnDisconnected += IrcDisconnected;
					irc.OnNames += OnNames;
					irc.AutoRejoinOnKick = true;
					irc.AutoRejoin = true;
					try
					{
						int port;
						if(!int.TryParse(txtIRCport.Text, out port)) port = 6667;
						irc.Connect(txtIRCserver.Text, port);
						channel = txtIRCchannel.Text.ToLower();

						irc.Login("LOIC_" + Functions.RandomString(), "Newfag's remote LOIC", 0, "IRCLOIC");

						// Spawn a thread to handle the listen.
						irclisten = new Thread(new ThreadStart(IrcListenThread));
						irclisten.Start();
					}
					catch
					{ }
				}
				else
				{
					try
					{
						if(irc != null) irc.Disconnect();
					}
					catch
					{ }
					label25.Text = "Disconnected.";
				}
			}
			catch
			{ }
		}
开发者ID:alienity,项目名称:LOIC,代码行数:77,代码来源:frmMain.cs


注:本文中的Meebey.SmartIrc4net.IrcClient.Connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。