From 268c1571807578e3d471888d57f2ef5936f61b30 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 1 Apr 2025 19:22:13 -0400 Subject: [PATCH] Send actual player data to other clients Instead of a placeholder actor, you can now see the other player's correct appearance. --- src/bin/kawari-world.rs | 10 ++++----- src/world/connection.rs | 45 ++++++++++------------------------------- 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/src/bin/kawari-world.rs b/src/bin/kawari-world.rs index 6dad038..3a47492 100644 --- a/src/bin/kawari-world.rs +++ b/src/bin/kawari-world.rs @@ -71,7 +71,7 @@ async fn main_loop(mut recv: Receiver) -> Result<(), std::io::Error> { } } } - ToServer::ActorSpawned(from_id, actor) => { + ToServer::ActorSpawned(from_id, actor, common) => { for (id, handle) in &mut data.clients { let id = *id; @@ -79,7 +79,7 @@ async fn main_loop(mut recv: Receiver) -> Result<(), std::io::Error> { continue; } - let msg = FromServer::ActorSpawn(actor); + let msg = FromServer::ActorSpawn(actor, common.clone()); if handle.send(msg).is_err() { to_remove.push(id); @@ -426,7 +426,7 @@ async fn client_loop( exit_rotation = None; // tell the other players we're here - connection.handle.send(ToServer::ActorSpawned(connection.id, Actor { id: ObjectId(connection.player_data.actor_id), hp: 100 })).await; + connection.handle.send(ToServer::ActorSpawned(connection.id, Actor { id: ObjectId(connection.player_data.actor_id), hp: 100 }, connection.get_player_common_spawn(None, None))).await; } ClientZoneIpcData::Unk1 { category, param1, .. @@ -981,8 +981,8 @@ async fn client_loop( msg = internal_recv.recv() => match msg { Some(msg) => match msg { FromServer::Message(msg)=>connection.send_message(&msg).await, - FromServer::ActorSpawn(actor) => { - connection.spawn_actor(actor).await + FromServer::ActorSpawn(actor, common) => { + connection.spawn_actor(actor, common).await }, FromServer::ActorMove(actor_id, position) => connection.set_actor_position(actor_id, position).await, }, diff --git a/src/world/connection.rs b/src/world/connection.rs index 62dc2f9..4ae471a 100644 --- a/src/world/connection.rs +++ b/src/world/connection.rs @@ -19,12 +19,11 @@ use crate::{ use super::{ Actor, Event, Inventory, Item, LuaPlayer, StatusEffects, WorldDatabase, Zone, - chat_handler::CUSTOMIZE_DATA, ipc::{ - ActorControlSelf, ActorMove, ActorSetPos, BattleNpcSubKind, ClientZoneIpcSegment, - CommonSpawn, ContainerInfo, ContainerType, DisplayFlag, Equip, InitZone, ItemInfo, - NpcSpawn, ObjectKind, PlayerSubKind, ServerZoneIpcData, ServerZoneIpcSegment, StatusEffect, - StatusEffectList, UpdateClassInfo, WeatherChange, + ActorControlSelf, ActorMove, ActorSetPos, ClientZoneIpcSegment, CommonSpawn, ContainerInfo, + ContainerType, DisplayFlag, Equip, InitZone, ItemInfo, NpcSpawn, ObjectKind, PlayerSubKind, + ServerZoneIpcData, ServerZoneIpcSegment, StatusEffect, StatusEffectList, UpdateClassInfo, + WeatherChange, }, }; @@ -57,7 +56,7 @@ pub enum FromServer { /// A chat message. Message(String), /// An actor has been spawned. - ActorSpawn(Actor), + ActorSpawn(Actor, CommonSpawn), /// An actor moved to a new position. ActorMove(u32, Position), } @@ -96,7 +95,7 @@ impl ClientHandle { pub enum ToServer { NewClient(ClientHandle), Message(ClientId, String), - ActorSpawned(ClientId, Actor), + ActorSpawned(ClientId, Actor, CommonSpawn), ActorMoved(ClientId, u32, Position), FatalError(std::io::Error), } @@ -303,10 +302,12 @@ impl ZoneConnection { .await; } - pub async fn spawn_actor(&mut self, actor: Actor) { + pub async fn spawn_actor(&mut self, actor: Actor, mut common: CommonSpawn) { // There is no reason for us to spawn our own player again. It's probably a bug!' assert!(actor.id.0 != self.player_data.actor_id); + common.spawn_index = self.get_free_spawn_index(); + let ipc = ServerZoneIpcSegment { unk1: 20, unk2: 0, @@ -314,31 +315,7 @@ impl ZoneConnection { server_id: 0, timestamp: timestamp_secs(), data: ServerZoneIpcData::NpcSpawn(NpcSpawn { - common: CommonSpawn { - hp_curr: 100, - hp_max: 100, - mp_curr: 100, - mp_max: 100, - look: CUSTOMIZE_DATA, - spawn_index: self.get_free_spawn_index(), - bnpc_base: 13498, - bnpc_name: 10261, - object_kind: ObjectKind::BattleNpc(BattleNpcSubKind::Enemy), - level: 1, - models: [ - 0, // head - 89, // body - 89, // hands - 89, // legs - 89, // feet - 0, // ears - 0, // neck - 0, // wrists - 0, // left finger - 0, // right finger - ], - ..Default::default() - }, + common, ..Default::default() }), }; @@ -716,7 +693,7 @@ impl ZoneConnection { } pub fn get_player_common_spawn( - &mut self, + &self, exit_position: Option, exit_rotation: Option, ) -> CommonSpawn {