Eliminated feature use for beta.
This commit is contained in:
parent
b68f7fc726
commit
c26d297e62
8 changed files with 57 additions and 33 deletions
|
@ -13,7 +13,8 @@ fn main() {
|
||||||
.. Default::default()
|
.. Default::default()
|
||||||
};
|
};
|
||||||
let server = Arc::new(IrcServer::from_config(config).unwrap());
|
let server = Arc::new(IrcServer::from_config(config).unwrap());
|
||||||
server.conn().set_keepalive(Some(5)).unwrap();
|
// FIXME: if set_keepalive is stabilized, this can be readded.
|
||||||
|
// server.conn().set_keepalive(Some(5)).unwrap();
|
||||||
let server = server.clone();
|
let server = server.clone();
|
||||||
let _ = spawn(move || {
|
let _ = spawn(move || {
|
||||||
server.identify().unwrap();
|
server.identify().unwrap();
|
||||||
|
|
|
@ -86,6 +86,9 @@ impl Connection<BufReader<NetStream>, BufWriter<NetStream>> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
FIXME: removed until set_keepalive is stabilized.
|
||||||
/// Sets the keepalive for the network stream.
|
/// Sets the keepalive for the network stream.
|
||||||
#[unstable = "Rust IO has not stabilized."]
|
#[unstable = "Rust IO has not stabilized."]
|
||||||
pub fn set_keepalive(&self, delay_in_seconds: Option<u32>) -> Result<()> {
|
pub fn set_keepalive(&self, delay_in_seconds: Option<u32>) -> Result<()> {
|
||||||
|
@ -100,6 +103,7 @@ impl Connection<BufReader<NetStream>, BufWriter<NetStream>> {
|
||||||
&mut NetStream::SslTcpStream(ref mut ssl) => f(ssl.get_mut()),
|
&mut NetStream::SslTcpStream(ref mut ssl) => f(ssl.get_mut()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable]
|
#[stable]
|
||||||
|
@ -337,15 +341,14 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "encode")]
|
#[cfg(feature = "encode")]
|
||||||
fn recv_iso885915() {
|
fn recv_iso885915() {
|
||||||
let conn = Connection::new(
|
let data = [0xA4, 0xA6, 0xA8, 0xB4, 0xB8, 0xBC, 0xBD, 0xBE];
|
||||||
Cursor::new({
|
let conn = Connection::new(Cursor::new({
|
||||||
let mut vec = Vec::new();
|
let mut vec = Vec::new();
|
||||||
vec.push_all(b"PRIVMSG test :");
|
vec.extend("PRIVMSG test :".as_bytes());
|
||||||
vec.push_all(&[0xA4, 0xA6, 0xA8, 0xB4, 0xB8, 0xBC, 0xBD, 0xBE]);
|
vec.extend(data.iter());
|
||||||
vec.push_all(b"\r\n");
|
vec.extend("\r\n".as_bytes());
|
||||||
vec
|
vec.into_iter().map(|b| *b).collect::<Vec<_>>()
|
||||||
}), sink()
|
}), sink());
|
||||||
);
|
|
||||||
assert_eq!(&conn.recv("l9").unwrap()[..], "PRIVMSG test :€ŠšŽžŒœŸ\r\n");
|
assert_eq!(&conn.recv("l9").unwrap()[..], "PRIVMSG test :€ŠšŽžŒœŸ\r\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1089,7 +1089,7 @@ impl Command {
|
||||||
|
|
||||||
/// A list of all of the subcommands for the capabilities extension.
|
/// A list of all of the subcommands for the capabilities extension.
|
||||||
#[stable]
|
#[stable]
|
||||||
#[derive(Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub enum CapSubCommand {
|
pub enum CapSubCommand {
|
||||||
/// Requests a list of the server's capabilities.
|
/// Requests a list of the server's capabilities.
|
||||||
#[stable]
|
#[stable]
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl Config {
|
||||||
/// Determines whether or not the nickname provided is the owner of the bot.
|
/// Determines whether or not the nickname provided is the owner of the bot.
|
||||||
#[stable]
|
#[stable]
|
||||||
pub fn is_owner(&self, nickname: &str) -> bool {
|
pub fn is_owner(&self, nickname: &str) -> bool {
|
||||||
self.owners.as_ref().map(|o| o.contains(&String::from_str(nickname))).unwrap()
|
self.owners.as_ref().map(|o| o.contains(&nickname.to_string())).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the nickname specified in the configuration.
|
/// Gets the nickname specified in the configuration.
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
//! Enumeration of all the possible server responses.
|
//! Enumeration of all the possible server responses.
|
||||||
#![stable]
|
#![stable]
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
use std::num::FromPrimitive;
|
use std::mem::transmute;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use client::data::message::Message;
|
use client::data::message::Message;
|
||||||
|
|
||||||
/// List of all server responses as defined in [RFC 2812](http://tools.ietf.org/html/rfc2812).
|
/// List of all server responses as defined in [RFC 2812](http://tools.ietf.org/html/rfc2812).
|
||||||
/// All commands are documented with their expected form from the RFC.
|
/// All commands are documented with their expected form from the RFC.
|
||||||
#[derive(Copy, Debug, PartialEq, FromPrimitive)]
|
#[derive(Clone, Copy, Debug, PartialEq, FromPrimitive)]
|
||||||
#[repr(u16)]
|
#[repr(u16)]
|
||||||
#[stable]
|
#[stable]
|
||||||
pub enum Response {
|
pub enum Response {
|
||||||
|
@ -448,8 +448,23 @@ impl Response {
|
||||||
impl FromStr for Response {
|
impl FromStr for Response {
|
||||||
type Err = &'static str;
|
type Err = &'static str;
|
||||||
fn from_str(s: &str) -> Result<Response, &'static str> {
|
fn from_str(s: &str) -> Result<Response, &'static str> {
|
||||||
if let Ok(respcode) = s.parse() {
|
if let Ok(rc) = s.parse::<u16>() {
|
||||||
FromPrimitive::from_u16(respcode).ok_or("Failed to convert response code to u16.")
|
// This wall of text was brought to you by the slated removal of FromPrimitive.
|
||||||
|
if (rc > 0 && rc < 5) || (rc > 200 && rc < 213) || rc == 219 || rc == 221 || rc == 234
|
||||||
|
|| rc == 235 || rc == 242 || rc == 243 || (rc > 250 && rc < 260) ||
|
||||||
|
(rc > 260 && rc < 264) || (rc > 300 && rc < 307) ||
|
||||||
|
(rc > 310 && rc < 326 && rc != 320) || rc == 331 || rc == 332 || rc == 341 ||
|
||||||
|
rc == 342 || (rc > 345 && rc < 354 && rc != 350) ||
|
||||||
|
(rc > 363 && rc < 377 && rc != 370) || (rc > 380 && rc < 384) ||
|
||||||
|
(rc > 390 && rc < 396) || (rc > 400 && rc < 415 && rc != 410) ||
|
||||||
|
(rc > 420 && rc < 425) || (rc > 430 && rc < 434) || rc == 436 || rc == 437 ||
|
||||||
|
(rc > 440 && rc < 447) || rc == 451 || (rc > 460 && rc < 468) ||
|
||||||
|
(rc > 470 && rc < 479) || (rc > 480 && rc < 486) || rc == 491 || rc == 501 ||
|
||||||
|
rc == 502 {
|
||||||
|
Ok(unsafe { transmute(rc) })
|
||||||
|
} else {
|
||||||
|
Err("Failed to parse due to unknown response code.")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Err("Failed to parse response code.")
|
Err("Failed to parse response code.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ impl User {
|
||||||
|
|
||||||
/// Removes an access level from the list, and updates the highest level if necessary.
|
/// Removes an access level from the list, and updates the highest level if necessary.
|
||||||
fn sub_access_level(&mut self, level: AccessLevel) {
|
fn sub_access_level(&mut self, level: AccessLevel) {
|
||||||
if let Some(n) = self.access_levels[..].position_elem(&level) {
|
if let Some(n) = self.access_levels.iter().position(|x| *x == level) {
|
||||||
self.access_levels.swap_remove(n);
|
self.access_levels.swap_remove(n);
|
||||||
}
|
}
|
||||||
if level == self.highest_access_level() {
|
if level == self.highest_access_level() {
|
||||||
|
@ -176,15 +176,14 @@ impl PartialOrd for AccessLevel {
|
||||||
impl FromStr for AccessLevel {
|
impl FromStr for AccessLevel {
|
||||||
type Err = &'static str;
|
type Err = &'static str;
|
||||||
fn from_str(s: &str) -> Result<AccessLevel, &'static str> {
|
fn from_str(s: &str) -> Result<AccessLevel, &'static str> {
|
||||||
if s.len() == 0 { Err("No access level in an empty string.") } else {
|
match s.chars().next() {
|
||||||
Ok(match s.char_at(0) {
|
Some('~') => Ok(AccessLevel::Owner),
|
||||||
'~' => AccessLevel::Owner,
|
Some('&') => Ok(AccessLevel::Admin),
|
||||||
'&' => AccessLevel::Admin,
|
Some('@') => Ok(AccessLevel::Oper),
|
||||||
'@' => AccessLevel::Oper,
|
Some('%') => Ok(AccessLevel::HalfOp),
|
||||||
'%' => AccessLevel::HalfOp,
|
Some('+') => Ok(AccessLevel::Voice),
|
||||||
'+' => AccessLevel::Voice,
|
None => Err("No access level in an empty string."),
|
||||||
_ => return Err("Failed to parse access level."),
|
_ =>Err("Failed to parse access level."),
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,7 +139,9 @@ impl<T: IrcRead, U: IrcWrite> IrcServer<T, U> {
|
||||||
if resp == Response::RPL_NAMREPLY {
|
if resp == Response::RPL_NAMREPLY {
|
||||||
if cfg!(not(feature = "nochanlists")) {
|
if cfg!(not(feature = "nochanlists")) {
|
||||||
if let Some(users) = msg.suffix.clone() {
|
if let Some(users) = msg.suffix.clone() {
|
||||||
if let [_, _, ref chan] = &msg.args[..] {
|
if msg.args.len() == 3 {
|
||||||
|
// TODO: replace with slice pattern matching when/if stable
|
||||||
|
let ref chan = msg.args[2];
|
||||||
for user in users.split(" ") {
|
for user in users.split(" ") {
|
||||||
if match self.chanlists.lock().unwrap().get_mut(chan) {
|
if match self.chanlists.lock().unwrap().get_mut(chan) {
|
||||||
Some(vec) => { vec.push(User::new(user)); false },
|
Some(vec) => { vec.push(User::new(user)); false },
|
||||||
|
@ -186,23 +188,26 @@ impl<T: IrcRead, U: IrcWrite> IrcServer<T, U> {
|
||||||
Some(ref suffix) => &suffix[..],
|
Some(ref suffix) => &suffix[..],
|
||||||
None => &msg.args[0][..],
|
None => &msg.args[0][..],
|
||||||
};
|
};
|
||||||
if let Some(vec) = self.chanlists.lock().unwrap().get_mut(&String::from_str(chan)) {
|
if let Some(vec) = self.chanlists.lock().unwrap().get_mut(&chan.to_string()) {
|
||||||
if let Some(ref src) = msg.prefix {
|
if let Some(ref src) = msg.prefix {
|
||||||
if let Some(i) = src.find('!') {
|
if let Some(i) = src.find('!') {
|
||||||
if &msg.command[..] == "JOIN" {
|
if &msg.command[..] == "JOIN" {
|
||||||
vec.push(User::new(&src[..i]));
|
vec.push(User::new(&src[..i]));
|
||||||
} else {
|
} else {
|
||||||
if let Some(n) = vec.position_elem(&User::new(&src[..i])) {
|
if let Some(n) = vec.iter().position(|x| x.get_name() == &src[..i]) {
|
||||||
vec.swap_remove(n);
|
vec.swap_remove(n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let ("MODE", [ref chan, ref mode, ref user]) = (&msg.command[..], &msg.args[..]) {
|
} else if let ("MODE", 3) = (&msg.command[..], msg.args.len()) {
|
||||||
|
let ref chan = msg.args[0]; // TODO: replace with slice pattern matching when/if stable
|
||||||
|
let ref mode = msg.args[1];
|
||||||
|
let ref user = msg.args[2];
|
||||||
if cfg!(not(feature = "nochanlists")) {
|
if cfg!(not(feature = "nochanlists")) {
|
||||||
if let Some(vec) = self.chanlists.lock().unwrap().get_mut(chan) {
|
if let Some(vec) = self.chanlists.lock().unwrap().get_mut(chan) {
|
||||||
if let Some(n) = vec.position_elem(&User::new(&user)) {
|
if let Some(n) = vec.iter().position(|x| &x.get_name() == user) {
|
||||||
vec[n].update_access_level(&mode);
|
vec[n].update_access_level(&mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,7 +224,9 @@ impl<T: IrcRead, U: IrcWrite> IrcServer<T, U> {
|
||||||
Some(ref source) => source.find('!').map_or(&source[..], |i| &source[..i]),
|
Some(ref source) => source.find('!').map_or(&source[..], |i| &source[..i]),
|
||||||
None => "",
|
None => "",
|
||||||
};
|
};
|
||||||
if let ("PRIVMSG", [ref target]) = (&msg.command[..], &msg.args[..]) {
|
if let ("PRIVMSG", 1) = (&msg.command[..], msg.args.len()) {
|
||||||
|
// TODO: replace with slice pattern matching when/if stable
|
||||||
|
let ref target = msg.args[0];
|
||||||
let resp = if target.starts_with("#") { &target[..] } else { source };
|
let resp = if target.starts_with("#") { &target[..] } else { source };
|
||||||
match msg.suffix {
|
match msg.suffix {
|
||||||
Some(ref msg) if msg.starts_with("\u{001}") => {
|
Some(ref msg) if msg.starts_with("\u{001}") => {
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#![unstable]
|
#![unstable]
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
#![feature(collections, core, slice_patterns, str_char, tcp)]
|
|
||||||
#[cfg(feature = "ctcp")] extern crate time;
|
#[cfg(feature = "ctcp")] extern crate time;
|
||||||
#[cfg(feature = "encode")] extern crate encoding;
|
#[cfg(feature = "encode")] extern crate encoding;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
|
|
Loading…
Reference in a new issue