Implement to_raw_protocol for Rnd and enable tests. Add cargo/rls build artifacts to .gitignore
authorMarcin Mielniczuk <marmistrz.dev@zoho.eu>
Mon, 02 Jul 2018 16:46:13 +0300
changeset 13433 fb104e150878
parent 13432 ee3fa3b8809d
child 13434 745e9174038e
child 13435 2e5a5eee8d80
Implement to_raw_protocol for Rnd and enable tests. Add cargo/rls build artifacts to .gitignore
.gitignore
gameServer2/src/protocol/messages.rs
gameServer2/src/protocol/test.rs
--- 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
--- 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],
--- 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<T>: Sized { fn into2(self) -> T; }
 impl <T> Into2<T> for T { fn into2(self) -> T { self } }
+impl Into2<Vec<String>> for Vec<Ascii> {
+    fn into2(self) -> Vec<String> {
+        self.into_iter().map(|x| x.0).collect()
+    }
+}
 impl Into2<String> for Ascii { fn into2(self) -> String { self.0 } }
 impl Into2<Option<String>> for Option<Ascii>{
     fn into2(self) -> Option<String> { self.map(|x| {x.0}) }
@@ -90,7 +95,7 @@
         15 => CreateRoom(Ascii, Option<Ascii>),
         16 => JoinRoom(Ascii, Option<Ascii>),
         17 => Follow(Ascii),
-        //18 => Rnd(Vec<String>),
+        18 => Rnd(Vec<Ascii>),
         19 => Kick(Ascii),
         20 => Ban(Ascii, Ascii, u32),
         21 => BanIP(Ascii, Ascii, u32),