Rethink message types a bit
authorunC0Rr
Thu, 25 Jul 2019 14:23:25 +0200
changeset 15285 7515ae6010bb
parent 15284 24828281c9c5
child 15286 07e909ba4203
Rethink message types a bit
rust/hedgewars-engine-messages/src/messages.rs
rust/hedgewars-engine-messages/src/parser.rs
--- a/rust/hedgewars-engine-messages/src/messages.rs	Thu Jul 25 00:05:30 2019 +0300
+++ b/rust/hedgewars-engine-messages/src/messages.rs	Thu Jul 25 14:23:25 2019 +0200
@@ -28,7 +28,6 @@
     TeamControlLost(String),
     TimeWrap,
     Taunt(u8),
-    HogSay(String),
     Heartbeat,
 }
 
@@ -36,14 +35,15 @@
 pub enum UnsyncedEngineMessage {
     TeamControlGained(String),
     TeamControlLost(String),
+    HogSay(String),
+    ChatMessage(String),
+    TeamMessage(String),
 }
 
 #[derive(Debug, PartialEq, Clone)]
 pub enum UnorderedEngineMessage {
     Ping,
     Pong,
-    ChatMessage(String),
-    TeamMessage(String),
     Error(String),
     Warning(String),
     StopSyncing,
@@ -194,7 +194,6 @@
             TeamControlGained(str) => ems![b'g', str],
             TeamControlLost(str) => ems![b'f', str],
             Taunt(s) => vec![b't', *s],
-            HogSay(str) => ems![b'h', str],
             Heartbeat => em![b'+'],
             TimeWrap => unreachable!(),
         }
@@ -207,6 +206,9 @@
         match self {
             TeamControlGained(str) => ems![b'G', str],
             TeamControlLost(str) => ems![b'F', str],
+            HogSay(str) => ems![b'h', str],
+            ChatMessage(str) => ems![b's', str],
+            TeamMessage(str) => ems![b'b', str],
         }
     }
 }
@@ -217,8 +219,6 @@
         match self {
             Ping => em![b'?'],
             Pong => em![b'!'],
-            ChatMessage(str) => ems![b's', str],
-            TeamMessage(str) => ems![b'b', str],
             Error(str) => ems![b'E', str],
             Warning(_) => unreachable!(),
             StopSyncing => unreachable!(),
--- a/rust/hedgewars-engine-messages/src/parser.rs	Thu Jul 25 00:05:30 2019 +0300
+++ b/rust/hedgewars-engine-messages/src/parser.rs	Thu Jul 25 14:23:25 2019 +0200
@@ -55,7 +55,6 @@
       | do_parse!(tag!("P") >> x: be_i24 >> y: be_i24 >> ( CursorMove(x, y) ))
       | do_parse!(tag!("f") >> s: string_tail >> ( SyncedEngineMessage::TeamControlLost(s) ))
       | do_parse!(tag!("g") >> s: string_tail >> ( SyncedEngineMessage::TeamControlGained(s) ))
-      | do_parse!(tag!("h") >> s: string_tail >> ( HogSay(s) ))
       | do_parse!(tag!("t") >> t: be_u8 >> ( Taunt(t) ))
       | do_parse!(tag!("w") >> w: be_u8 >> ( SetWeapon(w) ))
       | do_parse!(tag!("~") >> s: be_u8 >> ( Slot(s) ))
@@ -65,6 +64,9 @@
 named!(unsynced_message<&[u8], UnsyncedEngineMessage>, alt!(
         do_parse!(tag!("F") >> s: string_tail >> ( UnsyncedEngineMessage::TeamControlLost(s) ))
       | do_parse!(tag!("G") >> s: string_tail >> ( UnsyncedEngineMessage::TeamControlGained(s) ))
+      | do_parse!(tag!("h") >> s: string_tail >> ( UnsyncedEngineMessage::HogSay(s) ))
+      | do_parse!(tag!("s") >> s: string_tail >> ( UnsyncedEngineMessage::ChatMessage(s)) )
+      | do_parse!(tag!("b") >> s: string_tail >> ( UnsyncedEngineMessage::TeamMessage(s)) ) // TODO: wtf is the format
 ));
 
 named!(unordered_message<&[u8], UnorderedEngineMessage>, alt!(
@@ -72,8 +74,6 @@
     | do_parse!(tag!("!") >> ( Pong ))
     | do_parse!(tag!("E") >> s: string_tail >> ( UnorderedEngineMessage::Error(s)) )
     | do_parse!(tag!("W") >> s: string_tail >> ( Warning(s)) )
-    | do_parse!(tag!("s") >> s: string_tail >> ( ChatMessage(s)) )
-    | do_parse!(tag!("b") >> s: string_tail >> ( TeamMessage(s)) ) // TODO: wtf is the format
     | do_parse!(tag!("M") >> s: string_tail >> ( GameSetupChecksum(s)) )
     | do_parse!(tag!("o") >> ( StopSyncing ))
     | do_parse!(tag!("I") >> ( PauseToggled ))