From f61c3b437e5d6f3f32ec558576aa656aaa7dae5e Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 11 Jul 2024 15:27:49 +0200 Subject: send protocol version --- server/protocol/src/lib.rs | 6 ++++++ server/src/main.rs | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'server') diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs index 2287633d..94bebf05 100644 --- a/server/protocol/src/lib.rs +++ b/server/protocol/src/lib.rs @@ -24,6 +24,8 @@ use std::{ pub use glam; +pub const VERSION: (u32, u32) = (1, 0); + #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] #[serde(transparent)] pub struct PlayerID(pub i64); @@ -106,6 +108,10 @@ pub enum Message { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "snake_case", tag = "type")] pub enum PacketC { + Version { + minor: u32, + major: u32, + }, Init { id: PlayerID, }, diff --git a/server/src/main.rs b/server/src/main.rs index f81ee38c..90d090d8 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -18,7 +18,7 @@ use anyhow::{anyhow, Result}; use clap::Parser; use futures_util::{SinkExt, StreamExt}; -use hurrycurry_protocol::{PacketC, PacketS, PlayerID}; +use hurrycurry_protocol::{PacketC, PacketS, PlayerID, VERSION}; use hurrycurry_server::{data::DATA_DIR, state::State}; use log::{debug, info, trace, warn, LevelFilter}; use std::{path::PathBuf, process::exit, str::FromStr, sync::Arc, time::Duration}; @@ -108,13 +108,22 @@ async fn run() -> anyhow::Result<()> { warn!("invalid ws handshake"); continue; }; + info!("{addr} connected via websocket"); + let (mut write, mut read) = sock.split(); let state = state.clone(); let mut rx = rx.resubscribe(); let (error_tx, mut error_rx) = channel::(8); - info!("{addr} connected via websocket"); + let mut init = state.write().await.game.prime_client(); - init.insert(0, PacketC::Init { id }); + init.insert( + 0, + PacketC::Version { + major: VERSION.0, + minor: VERSION.1, + }, + ); + init.insert(1, PacketC::Init { id }); spawn(async move { for p in init { if let Err(e) = write -- cgit v1.2.3-70-g09d2