Added basic message handling, and fixed a bug in message parsing.
This commit is contained in:
parent
4479c59e79
commit
16f29f179a
3 changed files with 16 additions and 4 deletions
|
@ -21,6 +21,6 @@ fn main() {
|
||||||
let server = IrcServer::from_config(config).unwrap();
|
let server = IrcServer::from_config(config).unwrap();
|
||||||
identify(&server).unwrap();
|
identify(&server).unwrap();
|
||||||
for message in server.iter() {
|
for message in server.iter() {
|
||||||
println!("{}", message.into_string())
|
println!("{}", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl FromStr for Message {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let suffix = if state.contains(":") {
|
let suffix = if state.contains(":") {
|
||||||
let suffix = state.find(':').map(|i| state[i+1..state.len()-1]);
|
let suffix = state.find(':').map(|i| state[i+1..state.len()-2]);
|
||||||
state = state.find(':').map_or("", |i| state[..i]);
|
state = state.find(':').map_or("", |i| state[..i]);
|
||||||
suffix
|
suffix
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#![experimental]
|
#![experimental]
|
||||||
use std::io::{BufferedReader, BufferedWriter, IoResult, TcpStream};
|
use std::io::{BufferedReader, BufferedWriter, IoResult, TcpStream};
|
||||||
use conn::Connection;
|
use conn::Connection;
|
||||||
use data::command::Command;
|
use data::command::{Command, PONG};
|
||||||
use data::config::Config;
|
use data::config::Config;
|
||||||
use data::kinds::{IrcReader, IrcWriter};
|
use data::kinds::{IrcReader, IrcWriter};
|
||||||
use data::message::Message;
|
use data::message::Message;
|
||||||
|
@ -69,6 +69,14 @@ impl<'a, T, U> IrcServer<'a, T, U> where T: IrcWriter, U: IrcReader {
|
||||||
config: config
|
config: config
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_message(&self, message: &Message) {
|
||||||
|
if message.command[] == "PING" {
|
||||||
|
self.send(PONG(message.args[0][], None)).unwrap();
|
||||||
|
println!("PING! PONG!");
|
||||||
|
}
|
||||||
|
/* TODO: implement more message handling */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An Iterator over an IrcServer's incoming Messages
|
/// An Iterator over an IrcServer's incoming Messages
|
||||||
|
@ -92,7 +100,11 @@ impl<'a, T, U> Iterator<Message> for ServerIterator<'a, T, U> where T: IrcWriter
|
||||||
let line = self.server.conn.recv();
|
let line = self.server.conn.recv();
|
||||||
match line {
|
match line {
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
Ok(msg) => from_str(msg[])
|
Ok(msg) => {
|
||||||
|
let message = from_str(msg[]);
|
||||||
|
self.server.handle_message(message.as_ref().unwrap());
|
||||||
|
message
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue