make greeting argument optional
authoralfadur
Mon, 03 Jun 2019 23:50:26 +0300
changeset 15132 1e45db229f9f
parent 15131 6a8c294f49c9
child 15133 6a1ba3540fa0
make greeting argument optional
rust/hedgewars-server/src/handlers/common.rs
rust/hedgewars-server/src/handlers/inroom.rs
rust/hedgewars-server/src/protocol/messages.rs
rust/hedgewars-server/src/protocol/parser.rs
rust/hedgewars-server/src/protocol/test.rs
--- a/rust/hedgewars-server/src/handlers/common.rs	Mon Jun 03 23:15:05 2019 +0300
+++ b/rust/hedgewars-server/src/handlers/common.rs	Mon Jun 03 23:50:26 2019 +0300
@@ -612,8 +612,8 @@
 #[cfg(test)]
 mod tests {
     use super::*;
+    use crate::handlers::actions::PendingMessage;
     use crate::protocol::messages::HwServerMessage::ChatMsg;
-    use crate::server::actions::PendingMessage;
 
     fn reply2string(r: HwServerMessage) -> String {
         match r {
--- a/rust/hedgewars-server/src/handlers/inroom.rs	Mon Jun 03 23:15:05 2019 +0300
+++ b/rust/hedgewars-server/src/handlers/inroom.rs	Mon Jun 03 23:50:26 2019 +0300
@@ -159,7 +159,7 @@
         }
         Greeting(text) => {
             if client.is_admin() || client.is_master() && !room.is_fixed() {
-                room.greeting = text;
+                room.greeting = text.unwrap_or(String::new());
             }
         }
         MaxTeams(count) => {
--- a/rust/hedgewars-server/src/protocol/messages.rs	Mon Jun 03 23:15:05 2019 +0300
+++ b/rust/hedgewars-server/src/protocol/messages.rs	Mon Jun 03 23:50:26 2019 +0300
@@ -54,7 +54,7 @@
     MaxTeams(u8),
     Fix,
     Unfix,
-    Greeting(String),
+    Greeting(Option<String>),
     CallVote(Option<VoteType>),
     Vote(bool),
     ForceVote(bool),
@@ -335,7 +335,8 @@
             MaxTeams(count) => msg!["CMD", format!("MAXTEAMS {}", count)],
             Fix => msg!["CMD", "FIX"],
             Unfix => msg!["CMD", "UNFIX"],
-            Greeting(msg) => msg!["CMD", format!("GREETING {}", msg)],
+            Greeting(None) => msg!["CMD", "GREETING"],
+            Greeting(Some(msg)) => msg!["CMD", format!("GREETING {}", msg)],
             //CallVote(Option<(String, Option<String>)>) =>, ??
             Vote(msg) => msg!["CMD", format!("VOTE {}", if *msg { "YES" } else { "NO" })],
             ForceVote(msg) => msg!["CMD", format!("FORCE {}", if *msg { "YES" } else { "NO" })],
--- a/rust/hedgewars-server/src/protocol/parser.rs	Mon Jun 03 23:15:05 2019 +0300
+++ b/rust/hedgewars-server/src/protocol/parser.rs	Mon Jun 03 23:50:26 2019 +0300
@@ -273,7 +273,6 @@
             |i| cmdc_single_arg(i, "LOADROOM", a_line, LoadRoom),
             |i| cmdc_single_arg(i, "GLOBAL", a_line, Global),
             |i| cmdc_single_arg(i, "WATCH", u32_line, Watch),
-            |i| cmdc_single_arg(i, "GREETING", a_line, Greeting),
             |i| cmdc_single_arg(i, "VOTE", yes_no_line, Vote),
             |i| cmdc_single_arg(i, "FORCE", yes_no_line, ForceVote),
             |i| cmdc_single_arg(i, "INFO", a_line, Info),
@@ -288,6 +287,10 @@
         alt((
             cmd_no_arg_message,
             cmd_single_arg_message,
+            |i| {
+                precededc(i, hw_tag_no_case("GREETING"), opt_space_arg)
+                    .map(|(i, s)| (i, Greeting(s)))
+            },
             |i| precededc(i, hw_tag_no_case("PART"), opt_space_arg).map(|(i, s)| (i, Part(s))),
             |i| precededc(i, hw_tag_no_case("QUIT"), opt_space_arg).map(|(i, s)| (i, Quit(s))),
             |i| {
--- a/rust/hedgewars-server/src/protocol/test.rs	Mon Jun 03 23:15:05 2019 +0300
+++ b/rust/hedgewars-server/src/protocol/test.rs	Mon Jun 03 23:50:26 2019 +0300
@@ -216,7 +216,7 @@
             45 => MaxTeams(u8),
             46 => Fix(),
             47 => Unfix(),
-            48 => Greeting(Ascii),
+            48 => Greeting(Option<Ascii>),
             //49 => CallVote(Option<(String, Option<String>)>),
             50 => Vote(bool),
             51 => ForceVote(bool),