From a7dc49996f66fd2a164e4dc04c1846c0a18f6d17 Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Mon, 8 Jun 2020 19:50:56 -0400 Subject: [PATCH] Give the message structs friendlier field names on the Rust side, because Serde lets us do that --- src/net/mod.rs | 37 ++++++++++++++++++++++++++++++------- src/net/server.rs | 6 +++--- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/net/mod.rs b/src/net/mod.rs index 5722896..db7e4f6 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -15,11 +15,22 @@ pub type GameState = Value; #[serde(tag = "t")] pub enum ClientMessage { #[serde(rename = "s")] - SetState { s: GameState }, + SetState { + #[serde(rename = "s")] + new_state: GameState + }, #[serde(rename = "i")] - Input { i: PlayerInput }, + Input { + #[serde(rename = "i")] + local_input: PlayerInput + }, #[serde(rename = "g")] - GetState { c: usize, s: GameState }, + GetState { + #[serde(rename = "c")] + cookie: usize, + #[serde(rename = "s")] + state: GameState + }, } #[derive(Serialize, Debug, Clone)] @@ -34,12 +45,24 @@ pub enum ServerMessage { #[serde(rename = "m")] Meta { #[serde(flatten)] - m: Meta, + #[serde(rename = "m")] + meta: Meta, }, #[serde(rename = "s")] - SetState { u: Option, s: GameState }, + SetState { + #[serde(rename = "u")] + player_id: Option, + #[serde(rename = "s")] + state: GameState + }, #[serde(rename = "i")] - Input { i: Vec }, + Input { + #[serde(rename = "i")] + total_input: Vec + }, #[serde(rename = "g")] - GetState { c: usize }, + GetState { + #[serde(rename = "c")] + cookie: usize + }, } diff --git a/src/net/server.rs b/src/net/server.rs index 3a0e6d3..e5e8569 100644 --- a/src/net/server.rs +++ b/src/net/server.rs @@ -16,14 +16,14 @@ const CHANNEL_BUFFER: usize = 200; pub async fn greet(sink: &mut Sender) -> Result<()> { let mut greeting = iter(vec![ ServerMessage::Meta { - m: Meta { + meta: Meta { version: "Unstable", helo: Some("Dedicated base2020 server".into()), }, }, ServerMessage::SetState { - u: Some(0), - s: json!({}), + player_id: Some(0), + state: json!({}), }, ]) .map(Ok);