diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-09-04 12:10:37 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-09-04 12:10:37 -0400 |
commit | ed1802dfb4f4a9b313d73837fce245c92d073210 (patch) | |
tree | fafcad02a7837eae9c86a3a7459a8e69811b9cc3 | |
parent | 1934d05dcc6dca723eca6a53ecd251923fda7fcd (diff) | |
download | rust-irc-ed1802dfb4f4a9b313d73837fce245c92d073210.tar.gz rust-irc-ed1802dfb4f4a9b313d73837fce245c92d073210.zip |
allow setting the user's hostname too
eventually we should default this to something more sensible than
"localhost"
-rw-r--r-- | src/client.rs | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/src/client.rs b/src/client.rs index 3635312..f9b289c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -9,7 +9,9 @@ pub struct ClientBuilder { realname: String, username: String, - host: String, + hostname: Option<String>, + + servername: String, port: u16, } @@ -18,14 +20,16 @@ pub struct Client { } impl ClientBuilder { - pub fn new (nick: &str, host: &str) -> ClientBuilder { + pub fn new (nick: &str, servername: &str) -> ClientBuilder { ClientBuilder { nick: nick.to_string(), pass: None, realname: nick.to_string(), username: nick.to_string(), - host: host.to_string(), + hostname: None, + + servername: servername.to_string(), port: 6667, } } @@ -45,6 +49,11 @@ impl ClientBuilder { self } + pub fn set_hostname (&mut self, hostname: &str) -> &mut ClientBuilder { + self.hostname = Some(hostname.to_string()); + self + } + pub fn set_port (&mut self, port: u16) -> &mut ClientBuilder { self.port = port; self @@ -59,14 +68,22 @@ impl ClientBuilder { vec![self.nick.clone()], ) ); + + let hostname = match &self.hostname { + &Some(ref host) => host.clone(), + &None => { + // XXX get the name of the local end of the connection + "localhost".to_string() + }, + }; client.write( Message::new( None, CommandMessage(User), vec![ self.username.clone(), - "localhost".to_string(), // XXX - self.host.clone(), + hostname, + self.servername.clone(), self.realname.clone(), ], ) @@ -75,7 +92,7 @@ impl ClientBuilder { } pub fn connect_raw (&mut self) -> Client { - let mut stream = io::TcpStream::connect(self.host.as_slice(), self.port); + let mut stream = io::TcpStream::connect(self.servername.as_slice(), self.port); Client { conn: io::BufferedStream::new(stream.unwrap()) } } } |