Exemplo n.º 1
0
        /// <summary>
        /// Sets the credentials from the command line.
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public Credentials ParseCredentials(Parameters parameters)
        {
            var credentials = new Credentials
            {
                Server = parameters.AsString("s"),
                Port = parameters.AsInteger("p"),
                Password = parameters.AsString("pwd"),
                Nick = parameters.AsString("n"),
                Name = parameters.AsString("r")
            };

            return credentials;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the default credentials.
        /// </summary>
        /// <returns></returns>
        public Credentials GetCredentials()
        {
            // Get Configuration
            var config = ConfigService.GetConfig();

            var credentials = new Credentials
            {
                Server = config.GetValue("Credentials", "Server", string.Empty),
                Port = config.GetValue("Credentials", "Port", string.Empty).AsInt32(),
                Password = config.GetValue("Credentials", "Password", string.Empty),
                Nick = config.GetValue("Credentials", "Nick", "bot"),
                Name = config.GetValue("Credentials", "Name", "bot")
            };

            return credentials;
        }
Exemplo n.º 3
0
        public void TestStoreCredentials()
        {
            var config = new Config();

            var credentials = new Credentials
            {
                Server = "irc.example.com",
                Port = 123,
                Password = "******"
            };

            Mock<IConfigService>()
                .Setup(call => call.GetConfig())
                .Returns(config);

            service.SetCredentials(credentials);

            Assert.AreEqual("123", config.GetValue("Credentials", "Port", string.Empty));
            Assert.AreEqual("irc.example.com", config.GetValue("Credentials", "Server", string.Empty));
            Assert.AreEqual("Password", config.GetValue("Credentials", "Password", string.Empty));
        }
Exemplo n.º 4
0
        public void TestValidateCredentialsNoServer()
        {
            var credentials = new Credentials
            {
                Server = "",
                Port = 6667,
                Password = "******",
                Nick = "nick",
                Name = "name"
            };

            var result = service.Validate(credentials);

            Assert.IsFalse(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Logs in with the specified credentials.
        /// </summary>
        /// <param name="credentials">The credentials.</param>
        public void Login(Credentials credentials)
        {
            loginCredentials = credentials;

            if (connection.Connect(credentials.Server, credentials.Port))
            {
                connection.Send("PASS {0}", credentials.Password);
                connection.Send("USER {0} {0} {0} :{1}", credentials.Nick, credentials.Name);
                connection.Send("NICK {0}", credentials.Nick);

                LoggedIn = true;

                lastPong = DateTime.Now;

                // Assign Context information
                Context.Nick = credentials.Nick;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Sets the credentials.
        /// </summary>
        /// <param name="credentials">The credentials.</param>
        public void SetCredentials(Credentials credentials)
        {
            // Get Configuration
            var config = ConfigService.GetConfig();

            // Set values
            config.SetValue("Credentials", "Server", credentials.Server);
            config.SetValue("Credentials", "Port", credentials.Port.ToString());
            config.SetValue("Credentials", "Password", credentials.Password);
            config.SetValue("Credentials", "Nick", credentials.Nick);
            config.SetValue("Credentials", "Name", credentials.Name);

            // Save to disk
            ConfigService.SetConfig(config);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Validates the specified credentials.
        /// </summary>
        /// <param name="credentials">The credentials.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public bool Validate(Credentials credentials)
        {
            if (string.IsNullOrEmpty(credentials.Server))
            {
                return false;
            }

            if (credentials.Port == 0)
            {
                return false;
            }

            if (string.IsNullOrEmpty(credentials.Nick))
            {
                return false;
            }

            return true;
        }