# HG changeset patch # User Marcin Mielniczuk # Date 1530539173 -10800 # Node ID fb104e150878ba4f69d040e5533ec83dcb593898 # Parent ee3fa3b8809d3023cdc347a13271bee2bf9e69df Implement to_raw_protocol for Rnd and enable tests. Add cargo/rls build artifacts to .gitignore diff -r ee3fa3b8809d -r fb104e150878 .gitignore --- a/.gitignore Mon Jul 02 16:25:49 2018 +0300 +++ b/.gitignore Mon Jul 02 16:46:13 2018 +0300 @@ -81,3 +81,5 @@ *.mode1v3 *.mode2v3 Testing/* +gameServer2/rls +gameServer2/target diff -r ee3fa3b8809d -r fb104e150878 gameServer2/src/protocol/messages.rs --- a/gameServer2/src/protocol/messages.rs Mon Jul 02 16:25:49 2018 +0300 +++ b/gameServer2/src/protocol/messages.rs Mon Jul 02 16:46:13 2018 +0300 @@ -140,8 +140,12 @@ }; } -impl<'a> HWProtocolMessage { - pub fn to_raw_protocol(&self) -> String { +impl HWProtocolMessage { + /** Converts the message to a raw `String`, which can be sent over the network. + * + * This is the inverse of the `message` parser. + */ + pub(crate) fn to_raw_protocol(&self) -> String { use self::HWProtocolMessage::*; match self { Ping => msg!["PING"], @@ -166,7 +170,11 @@ JoinRoom(name, Some(password)) => msg!["JOIN_ROOM", name, password], Follow(name) => msg!["FOLLOW", name], - Rnd(args) => msg!["RND", args.join(" ")], + Rnd(args) => if args.is_empty() { + msg!["CMD", "RND"] + } else { + msg!["CMD", format!("RND {}", args.join(" "))] + }, Kick(name) => msg!["KICK", name], Ban(name, reason, time) => msg!["BAN", name, reason, time], BanIP(ip, reason, time) => msg!["BAN_IP", ip, reason, time], diff -r ee3fa3b8809d -r fb104e150878 gameServer2/src/protocol/test.rs --- a/gameServer2/src/protocol/test.rs Mon Jul 02 16:25:49 2018 +0300 +++ b/gameServer2/src/protocol/test.rs Mon Jul 02 16:46:13 2018 +0300 @@ -12,6 +12,11 @@ // Due to inability to define From between Options trait Into2: Sized { fn into2(self) -> T; } impl Into2 for T { fn into2(self) -> T { self } } +impl Into2> for Vec { + fn into2(self) -> Vec { + self.into_iter().map(|x| x.0).collect() + } +} impl Into2 for Ascii { fn into2(self) -> String { self.0 } } impl Into2> for Option{ fn into2(self) -> Option { self.map(|x| {x.0}) } @@ -90,7 +95,7 @@ 15 => CreateRoom(Ascii, Option), 16 => JoinRoom(Ascii, Option), 17 => Follow(Ascii), - //18 => Rnd(Vec), + 18 => Rnd(Vec), 19 => Kick(Ascii), 20 => Ban(Ascii, Ascii, u32), 21 => BanIP(Ascii, Ascii, u32),