aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-07-11 15:27:49 +0200
committermetamuffin <metamuffin@disroot.org>2024-07-11 15:27:49 +0200
commitf61c3b437e5d6f3f32ec558576aa656aaa7dae5e (patch)
tree2f63feb303404e74ed72cc225c0ebcaf41722043
parent17e7cb63bf70b35a58cf52ebea4bb543c450320f (diff)
downloadhurrycurry-f61c3b437e5d6f3f32ec558576aa656aaa7dae5e.tar
hurrycurry-f61c3b437e5d6f3f32ec558576aa656aaa7dae5e.tar.bz2
hurrycurry-f61c3b437e5d6f3f32ec558576aa656aaa7dae5e.tar.zst
send protocol version
-rw-r--r--server/protocol/src/lib.rs6
-rw-r--r--server/src/main.rs15
-rw-r--r--test-client/main.ts5
-rw-r--r--test-client/protocol.ts3
4 files changed, 24 insertions, 5 deletions
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::<PacketC>(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
diff --git a/test-client/main.ts b/test-client/main.ts
index f295e0ca..0d2ba8fb 100644
--- a/test-client/main.ts
+++ b/test-client/main.ts
@@ -98,7 +98,7 @@ export const players = new Map<PlayerID, PlayerData>()
export const tiles = new Map<string, TileData>()
export const items_removed = new Set<ItemData>()
-export let data: Gamedata = { item_names: [], tile_names: [], spawn: [0, 0], tile_collide: [], tile_interact: [], map_names: [] }
+export let data: Gamedata = { item_names: [], tile_names: [], spawn: [0, 0], tile_collide: [], tile_interact: [], maps: {} }
export let time_remaining: number | null = null
export let global_message: MessageData | undefined = undefined
@@ -126,6 +126,9 @@ function packet(p: PacketC) {
if (!["position", "set_progress", "update_map"].includes(p.type))
console.log(p);
switch (p.type) {
+ case "version":
+ console.log(`Protocol version: ${p.major}.${p.minor}`);
+ break;
case "init":
my_id = p.id
break;
diff --git a/test-client/protocol.ts b/test-client/protocol.ts
index 10b5b2dc..2cd58f75 100644
--- a/test-client/protocol.ts
+++ b/test-client/protocol.ts
@@ -44,7 +44,8 @@ export type PacketS =
| { type: "collide", player: PlayerID, force: Vec2 } // Apply force to another player as a result of a collision
export type PacketC =
- { type: "init", id: PlayerID } // You just connected. This is your id for this session.
+ { type: "version", minor: number, major: number } // Sent once after connecting to ensure you client is compatible
+ | { type: "init", id: PlayerID } // You just connected. This is your id for this session.
| { type: "data", data: Gamedata } // Game data was changed
| { type: "add_player", id: PlayerID, name: string, position: Vec2, character: number } // Somebody else joined (or was already in the game)
| { type: "remove_player", id: PlayerID } // Somebody left