Browse Source

options saved to character!

pbs
andy 4 years ago
parent
commit
db23a9794e
  1. 3
      src/entity/character.rs
  2. 1
      src/entity/gateway/inmemory.rs
  3. 11
      src/ship/character.rs
  4. 1
      src/ship/packet/handler/lobby.rs
  5. 12
      src/ship/packet/handler/settings.rs
  6. 5
      src/ship/ship.rs

3
src/entity/character.rs

@ -260,6 +260,7 @@ pub struct NewCharacterEntity {
pub tech_menu: CharacterTechMenu, pub tech_menu: CharacterTechMenu,
pub meseta: u32, pub meseta: u32,
pub bank_meseta: u32, pub bank_meseta: u32,
pub option_flags: u32,
} }
impl NewCharacterEntity { impl NewCharacterEntity {
@ -280,6 +281,7 @@ impl NewCharacterEntity {
tech_menu: CharacterTechMenu::new(), tech_menu: CharacterTechMenu::new(),
meseta: 0, meseta: 0,
bank_meseta: 0, bank_meseta: 0,
option_flags: 0,
} }
} }
} }
@ -307,4 +309,5 @@ pub struct CharacterEntity {
pub meseta: u32, pub meseta: u32,
// TODO: this should not be tied to the character // TODO: this should not be tied to the character
pub bank_meseta: u32, pub bank_meseta: u32,
pub option_flags: u32,
} }

1
src/entity/gateway/inmemory.rs

@ -127,6 +127,7 @@ impl EntityGateway for InMemoryGateway {
tech_menu: character.tech_menu, tech_menu: character.tech_menu,
meseta: character.meseta, meseta: character.meseta,
bank_meseta: character.bank_meseta, bank_meseta: character.bank_meseta,
option_flags: character.option_flags,
}; };
characters.insert(new_character.id, new_character.clone()); characters.insert(new_character.id, new_character.clone());
Some(new_character) Some(new_character)

11
src/ship/character.rs

@ -86,6 +86,7 @@ pub struct FullCharacterBytesBuilder<'a> {
joystick_config: Option<&'a [u8; 0x38]>, joystick_config: Option<&'a [u8; 0x38]>,
symbol_chat: Option<&'a [u8; 1248]>, symbol_chat: Option<&'a [u8; 1248]>,
tech_menu: Option<&'a [u8; 40]>, tech_menu: Option<&'a [u8; 40]>,
option_flags: Option<u32>,
} }
@ -101,6 +102,7 @@ impl<'a> FullCharacterBytesBuilder<'a> {
joystick_config: None, joystick_config: None,
symbol_chat: None, symbol_chat: None,
tech_menu: None, tech_menu: None,
option_flags: None,
} }
} }
@ -167,6 +169,13 @@ impl<'a> FullCharacterBytesBuilder<'a> {
} }
} }
pub fn option_flags(self, option_flags: u32) -> FullCharacterBytesBuilder<'a> {
FullCharacterBytesBuilder {
option_flags: Some(option_flags),
..self
}
}
pub fn build(self) -> character::FullCharacter { pub fn build(self) -> character::FullCharacter {
let character = self.character.unwrap(); let character = self.character.unwrap();
let stats = self.stats.unwrap(); let stats = self.stats.unwrap();
@ -177,6 +186,7 @@ impl<'a> FullCharacterBytesBuilder<'a> {
let joystick_config = self.joystick_config.unwrap(); let joystick_config = self.joystick_config.unwrap();
let symbol_chat = self.symbol_chat.unwrap(); let symbol_chat = self.symbol_chat.unwrap();
let tech_menu = self.tech_menu.unwrap(); let tech_menu = self.tech_menu.unwrap();
let option_flags = self.option_flags.unwrap();
let mut inventory_items = inventory.as_client_inventory_items(); let mut inventory_items = inventory.as_client_inventory_items();
inventory_items[7].material_count = character.materials.power as u8; inventory_items[7].material_count = character.materials.power as u8;
@ -207,6 +217,7 @@ impl<'a> FullCharacterBytesBuilder<'a> {
symbol_chats: *symbol_chat, symbol_chats: *symbol_chat,
tech_menu: *tech_menu, tech_menu: *tech_menu,
bank: bank.as_client_bank_items(), bank: bank.as_client_bank_items(),
option_flags: option_flags,
..character::FullCharacter::default() ..character::FullCharacter::default()
} }
} }

1
src/ship/packet/handler/lobby.rs

@ -34,6 +34,7 @@ pub fn block_selected(id: ClientId,
.joystick_config(&client.settings.settings.joystick_config) .joystick_config(&client.settings.settings.joystick_config)
.symbol_chat(&client.settings.settings.symbol_chats) .symbol_chat(&client.settings.settings.symbol_chats)
.tech_menu(&client.character.tech_menu.as_bytes()) .tech_menu(&client.character.tech_menu.as_bytes())
.option_flags(client.character.option_flags)
.build(); .build();
Ok(vec![ Ok(vec![

12
src/ship/packet/handler/settings.rs

@ -13,3 +13,15 @@ pub async fn update_config<EG: EntityGateway>(id: ClientId,
entity_gateway.save_character(&client.character).await; entity_gateway.save_character(&client.character).await;
Box::new(None.into_iter()) Box::new(None.into_iter())
} }
pub async fn save_options<EG: EntityGateway>(id: ClientId,
save_options: &SaveOptions,
clients: &mut Clients,
entity_gateway: &mut EG)
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
// // 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;
Box::new(None.into_iter())
}

5
src/ship/ship.rs

@ -92,6 +92,7 @@ pub enum RecvShipPacket {
QuestChunkAck(QuestChunkAck), QuestChunkAck(QuestChunkAck),
DoneLoadingQuest(DoneLoadingQuest), DoneLoadingQuest(DoneLoadingQuest),
FullCharacterData(Box<FullCharacterData>), FullCharacterData(Box<FullCharacterData>),
SaveOptions(SaveOptions),
} }
impl RecvServerPacket for RecvShipPacket { impl RecvServerPacket for RecvShipPacket {
@ -128,6 +129,7 @@ impl RecvServerPacket for RecvShipPacket {
0xA2 => Ok(RecvShipPacket::RequestQuestList(RequestQuestList::from_bytes(data)?)), 0xA2 => Ok(RecvShipPacket::RequestQuestList(RequestQuestList::from_bytes(data)?)),
0xAC => Ok(RecvShipPacket::DoneLoadingQuest(DoneLoadingQuest::from_bytes(data)?)), 0xAC => Ok(RecvShipPacket::DoneLoadingQuest(DoneLoadingQuest::from_bytes(data)?)),
0xE7 => Ok(RecvShipPacket::FullCharacterData(Box::new(FullCharacterData::from_bytes(data)?))), 0xE7 => Ok(RecvShipPacket::FullCharacterData(Box::new(FullCharacterData::from_bytes(data)?))),
0x1ED => Ok(RecvShipPacket::SaveOptions(SaveOptions::from_bytes(data)?)),
_ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec())) _ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
} }
} }
@ -561,6 +563,9 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
RecvShipPacket::FullCharacterData(full_character_data) => { RecvShipPacket::FullCharacterData(full_character_data) => {
Box::new(None.into_iter()) Box::new(None.into_iter())
}, },
RecvShipPacket::SaveOptions(save_options) => {
handler::settings::save_options(id, save_options, &mut self.clients, &mut self.entity_gateway).await
},
}) })
} }

Loading…
Cancel
Save