Added support for connecting to a password-protected server.
This commit is contained in:
parent
1fa18b7f6e
commit
31281d2820
2 changed files with 14 additions and 11 deletions
|
@ -19,12 +19,12 @@ pub struct Config {
|
||||||
pub username: Option<String>,
|
pub username: Option<String>,
|
||||||
/// The bot's real name.
|
/// The bot's real name.
|
||||||
pub realname: Option<String>,
|
pub realname: Option<String>,
|
||||||
/// The bot's password.
|
|
||||||
pub password: Option<String>,
|
|
||||||
/// The server to connect to.
|
/// The server to connect to.
|
||||||
pub server: Option<String>,
|
pub server: Option<String>,
|
||||||
/// The port to connect on.
|
/// The port to connect on.
|
||||||
pub port: Option<u16>,
|
pub port: Option<u16>,
|
||||||
|
/// The password to connect to the server.
|
||||||
|
pub password: Option<String>,
|
||||||
/// Whether or not to use SSL.
|
/// Whether or not to use SSL.
|
||||||
/// Bots will automatically panic if this is enabled without SSL support.
|
/// Bots will automatically panic if this is enabled without SSL support.
|
||||||
pub use_ssl: Option<bool>,
|
pub use_ssl: Option<bool>,
|
||||||
|
@ -91,13 +91,6 @@ impl Config {
|
||||||
self.realname.as_ref().map(|s| s[]).unwrap_or(self.nickname())
|
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.
|
/// Gets the address of the server specified in the configuration.
|
||||||
/// This panics when not specified.
|
/// This panics when not specified.
|
||||||
#[experimental]
|
#[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.
|
/// Gets whether or not to use SSL with this connection.
|
||||||
/// This defaults to false when not specified.
|
/// This defaults to false when not specified.
|
||||||
#[experimental]
|
#[experimental]
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
use std::io::IoResult;
|
use std::io::IoResult;
|
||||||
use data::{Command, Config, User};
|
use data::{Command, Config, User};
|
||||||
use data::Command::{CAP, INVITE, JOIN, KILL, MODE, NICK, NOTICE, KICK};
|
use data::Command::{CAP, INVITE, JOIN, KICK, KILL, MODE, NICK, NOTICE};
|
||||||
use data::Command::{OPER, PONG, PRIVMSG, SAMODE, SANICK, TOPIC, USER};
|
use data::Command::{OPER, PASS, PONG, PRIVMSG, SAMODE, SANICK, TOPIC, USER};
|
||||||
use data::command::CapSubCommand::{END, REQ};
|
use data::command::CapSubCommand::{END, REQ};
|
||||||
use data::kinds::{IrcReader, IrcWriter};
|
use data::kinds::{IrcReader, IrcWriter};
|
||||||
use server::{Server, ServerIterator};
|
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.
|
// 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(REQ, Some("multi-prefix"))));
|
||||||
try!(self.server.send(CAP(END, None))); // Then, send a CAP END to end the negotiation.
|
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())));
|
try!(self.server.send(NICK(self.server.config().nickname())));
|
||||||
self.server.send(USER(self.server.config().username(), "0",
|
self.server.send(USER(self.server.config().username(), "0",
|
||||||
self.server.config().real_name()))
|
self.server.config().real_name()))
|
||||||
|
|
Loading…
Add table
Reference in a new issue