示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IrcProvider"/> class.
        /// </summary>
        /// <param name="jobManager">The <see cref="IJobManager"/> for the provider.</param>
        /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/> to get the <see cref="IAssemblyInformationProvider.VersionString"/> from.</param>
        /// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/>.</param>
        /// <param name="logger">The <see cref="ILogger"/> for the <see cref="Provider"/>.</param>
        /// <param name="chatBot">The <see cref="Models.ChatBot"/> for the <see cref="Provider"/>.</param>
        public IrcProvider(
            IJobManager jobManager,
            IAssemblyInformationProvider assemblyInformationProvider,
            IAsyncDelayer asyncDelayer,
            ILogger <IrcProvider> logger,
            Models.ChatBot chatBot)
            : base(jobManager, logger, chatBot)
        {
            if (assemblyInformationProvider == null)
            {
                throw new ArgumentNullException(nameof(assemblyInformationProvider));
            }

            this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));

            var builder = chatBot.CreateConnectionStringBuilder();

            if (builder == null || !builder.Valid || !(builder is IrcConnectionStringBuilder ircBuilder))
            {
                throw new InvalidOperationException("Invalid ChatConnectionStringBuilder!");
            }

            address  = ircBuilder.Address;
            port     = ircBuilder.Port.Value;
            nickname = ircBuilder.Nickname;

            password     = ircBuilder.Password;
            passwordType = ircBuilder.PasswordType;

            client = new IrcFeatures
            {
                SupportNonRfc        = true,
                CtcpUserInfo         = "You are going to play. And I am going to watch. And everything will be just fine...",
                AutoRejoin           = true,
                AutoRejoinOnKick     = true,
                AutoRelogin          = true,
                AutoRetry            = true,
                AutoRetryLimit       = TimeoutSeconds,
                AutoRetryDelay       = TimeoutSeconds,
                ActiveChannelSyncing = true,
                AutoNickHandling     = true,
                CtcpVersion          = assemblyInformationProvider.VersionString,
                UseSsl = ircBuilder.UseSsl.Value,
            };
            if (ircBuilder.UseSsl.Value)
            {
                client.ValidateServerCertificate = true;                 // dunno if it defaults to that or what
            }
            client.OnChannelMessage += Client_OnChannelMessage;
            client.OnQueryMessage   += Client_OnQueryMessage;

            channelIdMap      = new Dictionary <ulong, string>();
            queryChannelIdMap = new Dictionary <ulong, string>();
            channelIdCounter  = 1;
        }
示例#2
0
        /// <summary>
        /// Construct an <see cref="IrcProvider"/>
        /// </summary>
        /// <param name="application">The <see cref="IApplication"/> to get the <see cref="IApplication.VersionString"/> from</param>
        /// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/></param>
        /// <param name="logger">The value of logger</param>
        /// <param name="address">The value of <see cref="address"/></param>
        /// <param name="port">The value of <see cref="port"/></param>
        /// <param name="nickname">The value of <see cref="nickname"/></param>
        /// <param name="password">The value of <see cref="password"/></param>
        /// <param name="passwordType">The value of <see cref="passwordType"/></param>
        /// <param name="useSsl">If <see cref="IrcConnection.UseSsl"/> should be used</param>
        public IrcProvider(IApplication application, IAsyncDelayer asyncDelayer, ILogger <IrcProvider> logger, string address, ushort port, string nickname, string password, IrcPasswordType?passwordType, bool useSsl)
        {
            if (application == null)
            {
                throw new ArgumentNullException(nameof(application));
            }
            this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
            this.logger       = logger ?? throw new ArgumentNullException(nameof(logger));

            this.address  = address ?? throw new ArgumentNullException(nameof(address));
            this.port     = port;
            this.nickname = nickname ?? throw new ArgumentNullException(nameof(nickname));

            if (passwordType.HasValue && password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            if (password != null && !passwordType.HasValue)
            {
                throw new ArgumentNullException(nameof(passwordType));
            }

            this.password     = password;
            this.passwordType = passwordType;

            client = new IrcFeatures
            {
                SupportNonRfc        = true,
                CtcpUserInfo         = "You are going to play. And I am going to watch. And everything will be just fine...",
                AutoRejoin           = true,
                AutoRejoinOnKick     = true,
                AutoRelogin          = true,
                AutoRetry            = true,
                AutoRetryLimit       = TimeoutSeconds,
                AutoRetryDelay       = TimeoutSeconds,
                ActiveChannelSyncing = true,
                AutoNickHandling     = true,
                CtcpVersion          = application.VersionString,
                UseSsl = useSsl
            };
            if (useSsl)
            {
                client.ValidateServerCertificate = true;                    //dunno if it defaults to that or what
            }
            client.OnChannelMessage += Client_OnChannelMessage;
            client.OnQueryMessage   += Client_OnQueryMessage;

            channelIdMap      = new Dictionary <ulong, string>();
            queryChannelIdMap = new Dictionary <ulong, string>();
            channelIdCounter  = 1;
            disconnecting     = false;
        }
示例#3
0
文件: IrcEngine.cs 项目: anwarul/yok
        /// <summary>
        ///     Start the irc connection
        /// </summary>
        /// <returns>True if is ok</returns>
        public bool Start()
        {
            var ret = false;

            Logger.Info("Starting...");

            try
            {
                _irc                      = new IrcFeatures();
                _irc.OnConnected         += OnConnected;
                _irc.OnDisconnected      += OnDisconnected;
                _irc.OnReadLine          += OnReadLine;
                _irc.OnChannelMessage    += OnMessage;
                _irc.AutoRetry            = true;
                _irc.AutoRetryLimit       = 0;
                _irc.AutoRetryDelay       = 120;
                _irc.AutoReconnect        = true;
                _irc.AutoRelogin          = true;
                _irc.AutoRejoin           = true;
                _irc.AutoNickHandling     = false;
                _irc.ActiveChannelSyncing = true;
                _irc.SendDelay            = 250;

                _ircServer  = Config.GetStringValue(Globals.YokXmlIrcserver);
                _ircPort    = Config.GetIntValue(Globals.YokXmlIrcport);
                _ircChannel = Config.GetStringValue(Globals.YokXmlIrcchannel);
                _ircNick    = Config.GetStringValue(Globals.YokXmlIrcnick);

                _irc.Connect(_ircServer, _ircPort);

                _irc.Login("yok_" + _ircNick, "remote yok", 0, "IRCYOK");

                _irclisten = new Thread(IrcListenThread);
                _irclisten.Start();

                Directory.CreateDirectory(Utils.GetBasePath() + "\\scripts");

                Logger.Info("Started Succesfully");

                ret = true;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            return(ret);
        }
示例#4
0
        /// <summary>
        /// Baut eine Verbindung mit den angegebenen Daten auf
        /// </summary>
        public void Connect()
        {
            _connection = new IrcFeatures();

            _connection.ActiveChannelSyncing = true;

            _connection.CtcpSource       = "Frag Suchiman in freenode";
            _connection.CtcpUrl          = _connection.CtcpSource;
            _connection.CtcpUserInfo     = "Ich bin ein automatisch denkendes Wesen auch bekannt als Bot";
            _connection.CtcpVersion      = "FritzBot:v3:" + Environment.OSVersion.Platform.ToString();
            _connection.Encoding         = Encoding.GetEncoding("iso-8859-1");
            _connection.EnableUTF8Recode = true;

            _connection.OnChannelAction  += _connection_OnMessage;
            _connection.OnChannelMessage += _connection_OnMessage;
            _connection.OnChannelNotice  += _connection_OnMessage;

            _connection.OnQueryAction  += _connection_OnMessage;
            _connection.OnQueryMessage += _connection_OnMessage;
            _connection.OnQueryNotice  += _connection_OnMessage;

            _connection.OnNickChange += _connection_OnNickChange;
            _connection.OnJoin       += _connection_OnJoin;
            _connection.OnKick       += _connection_OnKick;
            _connection.OnPart       += _connection_OnPart;
            _connection.OnQuit       += _connection_OnQuit;

            _connection.OnConnectionError += _connection_OnConnectionError;

            _connection.Connect(Settings.Address, Settings.Port);
            _connection.Login(Settings.Nickname, Settings.Nickname, 0, Settings.Nickname);

            if (Settings.NickServPassword != null)
            {
                _connection.SendMessage(SendType.Message, "nickserv", "identify " + Settings.NickServPassword);
            }

            foreach (ServerChannel channel in Settings.Channels)
            {
                _connection.RfcJoin(channel.Name, Priority.Critical);
            }

            _listener = Toolbox.SafeThreadStart("ListenThread " + Settings.Address, true, _connection.Listen);

            Connected = true;
        }
示例#5
0
        /// <summary>
        /// Implements the <see cref="IDisposable"/> pattern. Calls <see cref="Disconnect"/> and sets <see cref="irc"/> to <see langword="null"/>
        /// </summary>
        /// <param name="disposing"><see langword="true"/> if <see cref="Dispose()"/> was called manually, <see langword="false"/> if it was from the finalizer</param>
        void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                    Disconnect();
                    irc = null;
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
示例#6
0
 /// <summary>
 /// Trennt die Verbindung zum Server
 /// </summary>
 public void Disconnect()
 {
     Connected = false;
     if (_connection != null)
     {
         if (_connection.IsConnected)
         {
             try
             {
                 _connection.RfcQuit(Settings.QuitMessage);
                 _connection.Disconnect();
             }
             catch (NotConnectedException) { }
             Log.Information("Verbindung zu Server {ServerAddress} getrennt", Settings.Address);
         }
         _connection = null;
     }
 }
示例#7
0
 /// <summary>
 /// Construct a <see cref="IRCChatProvider"/>
 /// </summary>
 /// <param name="info">The <see cref="ChatSetupInfo"/></param>
 public IRCChatProvider(ChatSetupInfo info)
 {
     IRCConfig = new IRCSetupInfo(info);
     irc       = new IrcFeatures()
     {
         SupportNonRfc        = true,
         CtcpUserInfo         = Server.VersionString,
         AutoRejoin           = true,
         AutoRejoinOnKick     = true,
         AutoRelogin          = true,
         AutoRetry            = true,
         AutoRetryLimit       = 5,
         AutoRetryDelay       = 5,
         ActiveChannelSyncing = true,
     };
     irc.OnChannelMessage += Irc_OnChannelMessage;
     irc.OnQueryMessage   += Irc_OnQueryMessage;
 }