public IrcConnection(ConnectionSettings settings, Action<Event> enqueueMethod) { BotEnqueue = enqueueMethod; _settings = settings; _entities = new EntityManager(_settings.InitialNick); _parser = new IrcParser(this); }
public ConnectionService(IRCQueueBot q) : base(q) { _csettings = LoadConnectionSettings(Q.Config); if (_csettings == null) { Log(LogLevel.Error, "Failed to load IRC connection settings."); throw new Exception(); } _irc = new IrcConnection(_csettings, Q.Enqueue); }
private ConnectionSettings LoadConnectionSettings(IniConfiguration conf) { ConnectionSettings s = new ConnectionSettings(); // Server string server = conf["connection.server"]; if (String.IsNullOrWhiteSpace(server)) { Log(LogLevel.Error, "Connector: Server value is missing"); return null; } Log(LogLevel.Info, "Config: Server = " + server); s.ServerAddress = server; // Port string portin = conf["connection.port"]; if (String.IsNullOrWhiteSpace(portin)) { Log(LogLevel.Error, "Config: Port value is missing"); return null; } if (portin[0] == '+') { Log(LogLevel.Info, "Config: SSL is set"); s.UseSSL = true; portin = portin.Substring(1); } if (portin[0] == '+') { Log(LogLevel.Info, "Config: Will attempt to verify SSL"); s.UseSSLVerify = true; portin = portin.Substring(1); } int port; if (int.TryParse(portin, out port)) { if (port < 1 || port > 65535) { Log(LogLevel.Error, "Config: Port value is out of range"); return null; } Log(LogLevel.Info, "Config: Port = " + port); s.ServerPort = port; } else { Log(LogLevel.Error, "Config: Port value is invalid"); return null; } // Password string password = conf["connection.password"]; if (String.IsNullOrWhiteSpace(password)) { Log(LogLevel.Info, "Config: Server password not set"); } else { Log(LogLevel.Info, "Config: Server password set"); s.ServerPassword = password; } // Nick string nick = conf["connection.nick"]; if (string.IsNullOrWhiteSpace(nick)) { Log(LogLevel.Error, "Config: Nick value is missing"); return null; } Log(LogLevel.Info, "Config: Nick = " + nick); s.InitialNick = nick; // Ident string ident = conf["connection.ident"]; if (string.IsNullOrWhiteSpace(ident)) { Log(LogLevel.Error, "Config: Ident value is missing"); return null; } Log(LogLevel.Info, "Config: Ident = " + ident); s.Ident = ident; // Real name string realname = conf["connection.realname"]; if (string.IsNullOrWhiteSpace(realname)) { Log(LogLevel.Error, "Config: Real Name value is missing"); return null; } Log(LogLevel.Info, "Config: Real Name = " + realname); s.Realname = realname; return s; }