diff --git a/src/entity/character.rs b/src/entity/character.rs index f035a4a..a1cf2b3 100644 --- a/src/entity/character.rs +++ b/src/entity/character.rs @@ -2,6 +2,7 @@ use std::convert::{From, Into, TryFrom, TryInto}; use std::collections::HashMap; use libpso::character::character; +use libpso::packet::ship::{UpdateConfig}; #[derive(Copy, Clone, Hash, PartialEq, Eq)] pub enum CharacterClass { @@ -213,6 +214,14 @@ impl CharacterConfig { raw_data: [0; 0xE8], } } + + pub fn update(&mut self, new_config: &UpdateConfig) { + self.raw_data = new_config.config; + } + + pub fn as_bytes(&self) -> [u8; 0xE8] { + self.raw_data + } } diff --git a/src/ship/character.rs b/src/ship/character.rs index ceb0894..b85bc71 100644 --- a/src/ship/character.rs +++ b/src/ship/character.rs @@ -67,6 +67,7 @@ impl<'a> CharacterBytesBuilder<'a> { hair_b: character.appearance.hair_b, prop_x: character.appearance.prop_x, prop_y: character.appearance.prop_y, + config: character.config.as_bytes(), techniques: character.techs.as_bytes(), ..character::Character::default() } diff --git a/src/ship/ship.rs b/src/ship/ship.rs index fa98bdb..b0c6668 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -43,6 +43,7 @@ pub enum RecvShipPacket { PlayerChat(PlayerChat), CreateRoom(CreateRoom), RoomNameRequest(RoomNameRequest), + UpdateConfig(UpdateConfig), } impl RecvServerPacket for RecvShipPacket { @@ -56,6 +57,7 @@ impl RecvServerPacket for RecvShipPacket { 0x06 => Ok(RecvShipPacket::PlayerChat(PlayerChat::from_bytes(data)?)), 0xC1 => Ok(RecvShipPacket::CreateRoom(CreateRoom::from_bytes(data)?)), 0x8A => Ok(RecvShipPacket::RoomNameRequest(RoomNameRequest::from_bytes(data)?)), + 0x7ED => Ok(RecvShipPacket::UpdateConfig(UpdateConfig::from_bytes(data)?)), _ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec())) } } @@ -398,6 +400,13 @@ impl ShipServerState { let room_state = self.rooms[area.id()].as_ref().unwrap(); Box::new(vec![(id, SendShipPacket::RoomNameResponse(RoomNameResponse {name: room_state.name.clone()}))].into_iter()) } + + fn update_config(&mut self, id: ClientId, update_config: &UpdateConfig) -> Box + Send> { + let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap(); + client.character.config.update(update_config); + self.entity_gateway.set_character(&client.character); + Box::new(None.into_iter()) + } } @@ -450,7 +459,10 @@ impl ServerState for ShipServerState { }, RecvShipPacket::RoomNameRequest(_req) => { self.room_name_request(id) - } + }, + RecvShipPacket::UpdateConfig(pkt) => { + self.update_config(id, pkt) + }, }) }