Esempio n. 1
0
 private void TryConnectIrc(ServerCfg server)
 {
     if (!ircClientManager.ConnectIrc(server))
     {
         Logger.Log(this, "FATAL: IRC Connection failed. Application will now exit.", LogLevel.Error);
         Shutdown();
     }
     ircClientManager[server.ServerName].JoinChannels(server.AutoJoinChannels);
 }
Esempio n. 2
0
        /// <summary>
        /// Connects the bot to the IRC server
        /// </summary>
        public bool ConnectIrc(ServerCfg server)
        {
            var client = new IrcClient();
            var statsDatabaseManager = new StatsDatabaseManager(ConnectDatabase(server.Backend), server.UseNickserv);
            var wrapper = new IrcClientWrapper(client, statsDatabaseManager, server.ServerName);
            HookupIrcEvents(client, wrapper, server.ServerName);

            var host = server.Host;
            var port = server.Port;
            var nick = server.Identity.Nick;
            var ident = server.Identity.Ident;
            var realname = server.Identity.RealName;
            var password = server.Password;
            var tls = server.UseTls;
            var verify = server.VerifyCertificate;
            var slackCompatMode = server.CompatModes.Contains("slack");

            // Slack IRC messes up domain names by prepending http://<domain> to everything that looks like a domain name or incorrectly formatted URL,
            // despite the fact that such formatting should really be done by IRC clients, not servers.
            // BaggyBot doesn't like this; it messes up several of his commands, such as -resolve and -ping.
            // Therefore, when Slack Compatibility Mode is enabled, we add a SlackIrcProcessor which strips these misformatted domain names from the message.
            if (slackCompatMode)
            {
                client.DataProcessors.Add(new SlackIrcProcessor());
            }

            Logger.Log(this, "Connecting to the IRC server..");
            Logger.Log(this, "\tNick\t" + nick);
            Logger.Log(this, "\tIdent\t" + ident);
            Logger.Log(this, "\tName\t" + realname);
            Logger.Log(this, "\tHost\t" + host);
            Logger.Log(this, "\tPort\t" + port);
            try
            {
                client.Connect(new ConnectionInfo
                {
                    Host = host,
                    Port = port,
                    Nick = nick,
                    Ident = ident,
                    Password = password,
                    RealName = realname,
                    useTLS = tls,
                    verifyServerCertificate = verify
                });

                try
                {
                    clients.Add(server.ServerName, wrapper);
                }
                catch (ArgumentException)
                {
                    Logger.Log(this, "Failed to add the IRC server: a server with the same name already exists.", LogLevel.Error);
                    client.Disconnect();
                    return false;
                }
                return true;
            }
            catch (SocketException e)
            {
                Logger.Log(this, "Failed to connect to the IRC server: " + e.Message, LogLevel.Error);
                return false;
            }
            catch (ArgumentException e)
            {
                Logger.Log(this, $"Failed to connect to the IRC server: The settings file does not contain a value for \"{e.ParamName}\"", LogLevel.Error);
                return false;
            }
            catch (Exception e)
            {
                Logger.Log(this, "Failed to connect to the IRC server: " + e.Message, LogLevel.Error);
                return false;
            }
        }
Esempio n. 3
0
        /*private void JoinInitialChannels(string[] channels)
        {
            foreach (var channel in channels)
            {
                // NOTE: Join might fail if the server does not accept JOIN commands before it has sent the entire MOTD to the client
                if (string.IsNullOrWhiteSpace(channel))
                {
                    Logger.Log(this, $"Unable to join {channel}: invalid channel name.", LogLevel.Error);
                }
                else
                {
                    if (ircInterface.JoinChannel(channel))
                    {
                        Logger.Log(this, $"Ready to collect statistics in {channel}.", LogLevel.Info);
                    }
                    else
                    {
                        Logger.Log(this, $"Auto-joining {channel} failed.");
                    }
                }
            }
        }*/
        public void Connect(ServerCfg[] servers)
        {
            foreach (var server in servers)
            {
                TryConnectIrc(server);
            }

            OnPostConnect();

            if (previousVersion != null && previousVersion != Version)
            {
                NotifyOperator($"Succesfully updated from version {previousVersion} to version {Version}");
            }
            EnterMainLoop();
        }