From 0b8aef3b8cbca0ca10f0391e3fb96d7897d1a75c Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 30 May 2021 19:02:56 +0000 Subject: [PATCH] start setting up keyboard config stuff --- src/entity/character.rs | 26 ++++++++++++++++++++++++-- src/ship/packet/handler/settings.rs | 13 ++++++++++++- src/ship/ship.rs | 2 ++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/entity/character.rs b/src/entity/character.rs index 432017d..8a0aa0d 100644 --- a/src/entity/character.rs +++ b/src/entity/character.rs @@ -2,8 +2,8 @@ use std::convert::{From, Into}; use std::collections::HashMap; use serde::{Serialize, Deserialize}; -use libpso::packet::ship::{UpdateConfig, WriteInfoboard}; -use libpso::character::character::{DEFAULT_PALETTE_CONFIG, DEFAULT_TECH_MENU}; +use libpso::packet::ship::{UpdateConfig, WriteInfoboard, KeyboardConfig}; +use libpso::character::character::{DEFAULT_PALETTE_CONFIG, DEFAULT_TECH_MENU, DEFAULT_KEYBOARD_CONFIG1}; use crate::entity::item::tech::Technique; use crate::entity::account::UserAccountId; @@ -264,6 +264,28 @@ pub struct CharacterMaterials { pub tp: u32, } +#[derive(Clone)] +pub struct CharacterKeyboardConfig { + pub keyboard: [u8; 0x16C], +} + +impl CharacterKeyboardConfig { + fn new() -> CharacterKeyboardConfig { + CharacterKeyboardConfig { + keyboard: DEFAULT_KEYBOARD_CONFIG1, + } + } + + pub fn update(&mut self, new_config: &KeyboardConfig) { + self.keyboard = new_config.keyboard_config; + } + + pub fn as_bytes(&self) -> [u8; 0x16C] { + self.keyboard + } +} + + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, Default, derive_more::Display)] pub struct CharacterEntityId(pub u32); diff --git a/src/ship/packet/handler/settings.rs b/src/ship/packet/handler/settings.rs index b2df392..6063f74 100644 --- a/src/ship/packet/handler/settings.rs +++ b/src/ship/packet/handler/settings.rs @@ -19,9 +19,20 @@ pub async fn save_options(id: ClientId, clients: &mut Clients, entity_gateway: &mut EG) -> Box + Send> { - // // TODO: don't unwrap? + // TODO: don't unwrap? let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap(); client.character.option_flags = save_options.options; entity_gateway.save_character(&client.character).await.unwrap(); Box::new(None.into_iter()) } + +// pub async fn keyboard_config(id: ClientId, +// keyboard_config: &KeyboardConfig, +// clients: &mut Clients, +// entity_gateway: &mut EG) +// -> Box + Send> { +// let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap(); +// client.character.option_flags = save_options.options; +// entity_gateway.save_character(&client.character).await.unwrap(); +// Box::new(None.into_iter()) +// } \ No newline at end of file diff --git a/src/ship/ship.rs b/src/ship/ship.rs index d784677..f76a441 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -115,6 +115,7 @@ pub enum RecvShipPacket { RequestShipBlockList(RequestShipBlockList), ItemsToTrade(ItemsToTrade), TradeConfirmed(TradeConfirmed), + KeyboardConfig(KeyboardConfig), } impl RecvServerPacket for RecvShipPacket { @@ -156,6 +157,7 @@ impl RecvServerPacket for RecvShipPacket { 0xD2 => Ok(RecvShipPacket::TradeConfirmed(TradeConfirmed::from_bytes(data)?)), 0xE7 => Ok(RecvShipPacket::FullCharacterData(Box::new(FullCharacterData::from_bytes(data)?))), 0x1ED => Ok(RecvShipPacket::SaveOptions(SaveOptions::from_bytes(data)?)), + 0x4ED => Ok(RecvShipPacket::KeyboardConfig(KeyboardConfig::from_bytes(data)?)), _ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec())) } }