From 845cae43895ee1369581659f63ecb5003fed833a Mon Sep 17 00:00:00 2001 From: extrawurst Date: Mon, 8 Dec 2025 20:51:46 -0500 Subject: [PATCH] make player and client bound together this cleansup and allows rejoining a running server --- crates/server/src/player.rs | 5 +++-- crates/shared/src/protocol/mod.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/server/src/player.rs b/crates/server/src/player.rs index 32c527f..23497d7 100644 --- a/crates/server/src/player.rs +++ b/crates/server/src/player.rs @@ -14,7 +14,7 @@ use shared::{ hitpoints::{Hitpoints, Kill}, npc::SpawnCharacter, player::{Player, PlayerBodyMesh}, - protocol::{PlaySound, PlayerId, events::ClientHeadChanged}, + protocol::{OwnedByClient, PlaySound, PlayerId, events::ClientHeadChanged}, tb_entities::SpawnPoint, }; @@ -24,7 +24,7 @@ pub fn plugin(app: &mut App) { pub fn spawn( mut commands: Commands, - _owner: Entity, + owner: Entity, query: Query<&Transform, With>, heads_db: Res, ) -> Option { @@ -58,6 +58,7 @@ pub fn spawn( UiActiveHeads::default(), Inputs::default(), Replicated, + OwnedByClient(owner), )) .with_children(|c| { c.spawn(( diff --git a/crates/shared/src/protocol/mod.rs b/crates/shared/src/protocol/mod.rs index 0152e1b..754f691 100644 --- a/crates/shared/src/protocol/mod.rs +++ b/crates/shared/src/protocol/mod.rs @@ -189,3 +189,11 @@ impl TbMapIdCounter { #[derive(Resource, Reflect, Default, Deref, DerefMut)] #[reflect(Resource)] pub struct TbMapEntityMapping(pub HashMap); + +#[derive(Component)] +#[relationship(relationship_target = ClientOwns)] +pub struct OwnedByClient(pub Entity); + +#[derive(Component)] +#[relationship_target(relationship = OwnedByClient, linked_spawn)] +pub struct ClientOwns(Entity);