Added support for connecting to a password-protected server.

This commit is contained in:
Aaron Weiss 2014-12-09 16:17:05 -05:00
parent 1fa18b7f6e
commit 31281d2820
2 changed files with 14 additions and 11 deletions

View file

@ -19,12 +19,12 @@ pub struct Config {
pub username: Option<String>,
/// The bot's real name.
pub realname: Option<String>,
/// The bot's password.
pub password: Option<String>,
/// The server to connect to.
pub server: Option<String>,
/// The port to connect on.
pub port: Option<u16>,
/// The password to connect to the server.
pub password: Option<String>,
/// Whether or not to use SSL.
/// Bots will automatically panic if this is enabled without SSL support.
pub use_ssl: Option<bool>,
@ -91,13 +91,6 @@ impl Config {
self.realname.as_ref().map(|s| s[]).unwrap_or(self.nickname())
}
/// Gets the password specified in the configuration.
/// This defaults to a blank string when not specified.
#[experimental]
pub fn password(&self) -> &str {
self.password.as_ref().map(|s| s[]).unwrap_or("")
}
/// Gets the address of the server specified in the configuration.
/// This panics when not specified.
#[experimental]
@ -116,6 +109,13 @@ impl Config {
})
}
/// Gets the server password specified in the configuration.
/// This defaults to a blank string when not specified.
#[experimental]
pub fn password(&self) -> &str {
self.password.as_ref().map(|s| s[]).unwrap_or("")
}
/// Gets whether or not to use SSL with this connection.
/// This defaults to false when not specified.
#[experimental]

View file

@ -3,8 +3,8 @@
use std::io::IoResult;
use data::{Command, Config, User};
use data::Command::{CAP, INVITE, JOIN, KILL, MODE, NICK, NOTICE, KICK};
use data::Command::{OPER, PONG, PRIVMSG, SAMODE, SANICK, TOPIC, USER};
use data::Command::{CAP, INVITE, JOIN, KICK, KILL, MODE, NICK, NOTICE};
use data::Command::{OPER, PASS, PONG, PRIVMSG, SAMODE, SANICK, TOPIC, USER};
use data::command::CapSubCommand::{END, REQ};
use data::kinds::{IrcReader, IrcWriter};
use server::{Server, ServerIterator};
@ -47,6 +47,9 @@ impl<'a, T: IrcReader, U: IrcWriter> Wrapper<'a, T, U> {
// We'll issue a CAP REQ for multi-prefix support to improve access level tracking.
try!(self.server.send(CAP(REQ, Some("multi-prefix"))));
try!(self.server.send(CAP(END, None))); // Then, send a CAP END to end the negotiation.
if self.server.config().password() != "" {
try!(self.server.send(PASS(self.server.config().password())));
}
try!(self.server.send(NICK(self.server.config().nickname())));
self.server.send(USER(self.server.config().username(), "0",
self.server.config().real_name()))