/// <summary> /// Prepare a connection to an IRC server but do not open it. This sets the text Encoding to Default. /// </summary> /// <param name = "args">The set of information need to connect to an IRC server</param> /// <param name = "enableCtcp">True if this Connection should support CTCP.</param> /// <param name = "enableDcc">True if this Connection should support DCC.</param> public Connection(ConnectionArgs args, bool enableCtcp, bool enableDcc) { _propertiesRegex = new Regex("([A-Z]+)=([^\\s]+)", RegexOptions.Compiled | RegexOptions.Singleline); _registered = false; _connected = false; _handleNickFailure = true; ConnectionArgs = args; _parsers = new ArrayList(); _sender = new Sender(this); _listener = new Listener(); RegisterDelegates(); _timeLastSent = DateTime.Now; EnableCtcp = enableCtcp; EnableDcc = enableDcc; TextEncoding = Encoding.Default; }
/// <summary> /// Initializes a new instance of the <see cref="AlarisBase"/> class. /// </summary> /// <param name="configuration">The configuration object.</param> /// <param name="serverId"></param> /// <param name="parallelized">if set to <c>true</c> [parallelized].</param> /// <param name="additionalCommandAssemblies">The additional command assemblies.</param> protected AlarisBase(AlarisConfig configuration, byte serverId = 0, bool parallelized = true, params Assembly[] additionalCommandAssemblies) { if (_isInstantiated) return; _isInstantiated = true; IsParallelized = parallelized; Config = configuration.Config; _server = Config.Servers[serverId]; _serverId = serverId; ProcessConfiguration(); Instance = this; Log.Info("Initializing"); var sw = new Stopwatch(); sw.Start(); _crashHandler = new CrashHandler(); var addonInitializationTask = new Task(() => { if (AddonsEnabled) { Log.Info("Initializing AddonManager"); AddonManager = new AddonManager(); AddonManager.Initialize(); AddonManager.LoadPluginsFromDirectory(AddonDirectory); } }); var commandManagerInitializationTask = addonInitializationTask.ContinueWith(prev => { Log.Info("Setting up commands"); CommandManager = new CommandManager {CommandPrefix = "@"}; CommandManager.CreateMappings(); }); addonInitializationTask.Start(); Task.Factory.StartNew(() => { _scriptManager = new ScriptManager(_scriptsDir); _scriptManager.Run(); }); Log.Info("Starting Identd"); Identd.Start(_server.Nickname); var connectionArgs = new ConnectionArgs(_server.Nickname, _server.Address); _connection = new Connection(connectionArgs, true, false) { TextEncoding = Encoding.GetEncoding("Latin1") }; _connection.CtcpResponder = new CtcpResponder(_connection) { VersionResponse = "Alaris " + Utility.BotVersion, SourceResponse = "https://www.github.com/twl/alaris", UserInfoResponse = "Alaris multi-functional bot." }; Log.Info("Text encoding is {0}", _connection.TextEncoding.WebName); Log.Info("CTCP is enabled"); SetupHandlers(); Connect(); sw.Stop(); Log.Info("Startup time: {0} ms", sw.ElapsedMilliseconds); }
/// <summary> /// The USER command is only used at the beginning of Connection to specify /// the username, hostname and realname of a new user. /// </summary> /// <param name = "args">The user Connection data</param> internal void User(ConnectionArgs args) { lock (this) { Buffer.Append("USER"); Buffer.Append(Space); Buffer.Append(args.UserName); Buffer.Append(Space); Buffer.Append(args.ModeMask); Buffer.Append(Space); Buffer.Append('*'); Buffer.Append(Space); Buffer.Append(args.RealName); Connection.SendCommand(Buffer); } }
/// <summary> /// User registration consists of 3 commands: /// 1. PASS /// 2. NICK /// 3. USER /// Pass will rarely fail but the proposed Nick might already be taken in /// which case the client will have to register by manually calling Nick /// and User. /// </summary> internal void RegisterConnection(ConnectionArgs args) { Pass(args.ServerPassword); Nick(args.Nick); User(args); }
/// <summary> /// Used for internal test purposes only. /// </summary> internal Connection(ConnectionArgs args) { ConnectionArgs = args; _sender = new Sender(this); _listener = new Listener(); _timeLastSent = DateTime.Now; EnableCtcp = true; EnableDcc = true; TextEncoding = Encoding.Default; }
/// <summary> /// Prepare a connection to an IRC server but do not open it. /// </summary> /// <param name = "args">The set of information need to connect to an IRC server</param> /// <param name = "enableCtcp">True if this Connection should support CTCP.</param> /// <param name = "enableDcc">True if this Connection should support DCC.</param> /// <param name = "textEncoding">The text encoding for the incoming stream.</param> public Connection(Encoding textEncoding, ConnectionArgs args, bool enableCtcp, bool enableDcc) : this(args, enableCtcp, enableDcc) { TextEncoding = textEncoding; }