Merge pull request 'save_options' (#225) from save_options into master
Reviewed-by: jake <jake@sharnoth.com>
This commit is contained in:
		
						commit
						aa08e67f6b
					
				| @ -260,6 +260,7 @@ pub struct NewCharacterEntity { | ||||
|     pub tech_menu: CharacterTechMenu, | ||||
|     pub meseta: u32, | ||||
|     pub bank_meseta: u32, | ||||
|     pub option_flags: u32, | ||||
| } | ||||
| 
 | ||||
| impl NewCharacterEntity { | ||||
| @ -280,6 +281,7 @@ impl NewCharacterEntity { | ||||
|             tech_menu: CharacterTechMenu::new(), | ||||
|             meseta: 0, | ||||
|             bank_meseta: 0, | ||||
|             option_flags: 0, | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -307,4 +309,5 @@ pub struct CharacterEntity { | ||||
|     pub meseta: u32, | ||||
|     // TODO: this should not be tied to the character
 | ||||
|     pub bank_meseta: u32, | ||||
|     pub option_flags: u32, | ||||
| } | ||||
|  | ||||
| @ -127,6 +127,7 @@ impl EntityGateway for InMemoryGateway { | ||||
|             tech_menu: character.tech_menu, | ||||
|             meseta: character.meseta, | ||||
|             bank_meseta: character.bank_meseta, | ||||
|             option_flags: character.option_flags, | ||||
|         }; | ||||
|         characters.insert(new_character.id, new_character.clone()); | ||||
|         Some(new_character) | ||||
|  | ||||
| @ -86,6 +86,7 @@ pub struct FullCharacterBytesBuilder<'a> { | ||||
|     joystick_config: Option<&'a [u8; 0x38]>, | ||||
|     symbol_chat: Option<&'a [u8; 1248]>, | ||||
|     tech_menu: Option<&'a [u8; 40]>, | ||||
|     option_flags: Option<u32>, | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| @ -101,6 +102,7 @@ impl<'a> FullCharacterBytesBuilder<'a> { | ||||
|             joystick_config: None, | ||||
|             symbol_chat: 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 { | ||||
|         let character = self.character.unwrap(); | ||||
|         let stats = self.stats.unwrap(); | ||||
| @ -177,6 +186,7 @@ impl<'a> FullCharacterBytesBuilder<'a> { | ||||
|         let joystick_config = self.joystick_config.unwrap(); | ||||
|         let symbol_chat = self.symbol_chat.unwrap(); | ||||
|         let tech_menu = self.tech_menu.unwrap(); | ||||
|         let option_flags = self.option_flags.unwrap(); | ||||
| 
 | ||||
|         let mut inventory_items = inventory.as_client_inventory_items(); | ||||
|         inventory_items[7].material_count = character.materials.power as u8; | ||||
| @ -207,6 +217,7 @@ impl<'a> FullCharacterBytesBuilder<'a> { | ||||
|             symbol_chats: *symbol_chat, | ||||
|             tech_menu: *tech_menu, | ||||
|             bank: bank.as_client_bank_items(), | ||||
|             option_flags: option_flags, | ||||
|             ..character::FullCharacter::default() | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -34,6 +34,7 @@ pub fn block_selected(id: ClientId, | ||||
|         .joystick_config(&client.settings.settings.joystick_config) | ||||
|         .symbol_chat(&client.settings.settings.symbol_chats) | ||||
|         .tech_menu(&client.character.tech_menu.as_bytes()) | ||||
|         .option_flags(client.character.option_flags) | ||||
|         .build(); | ||||
| 
 | ||||
|     Ok(vec![ | ||||
|  | ||||
| @ -13,3 +13,15 @@ pub async fn update_config<EG: EntityGateway>(id: ClientId, | ||||
|     entity_gateway.save_character(&client.character).await; | ||||
|     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()) | ||||
| } | ||||
| @ -92,6 +92,7 @@ pub enum RecvShipPacket { | ||||
|     QuestChunkAck(QuestChunkAck), | ||||
|     DoneLoadingQuest(DoneLoadingQuest), | ||||
|     FullCharacterData(Box<FullCharacterData>), | ||||
|     SaveOptions(SaveOptions), | ||||
| } | ||||
| 
 | ||||
| impl RecvServerPacket for RecvShipPacket { | ||||
| @ -128,6 +129,7 @@ impl RecvServerPacket for RecvShipPacket { | ||||
|             0xA2 => Ok(RecvShipPacket::RequestQuestList(RequestQuestList::from_bytes(data)?)), | ||||
|             0xAC => Ok(RecvShipPacket::DoneLoadingQuest(DoneLoadingQuest::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())) | ||||
|         } | ||||
|     } | ||||
| @ -561,6 +563,9 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> { | ||||
|             RecvShipPacket::FullCharacterData(full_character_data) => { | ||||
|                 Box::new(None.into_iter()) | ||||
|             }, | ||||
|             RecvShipPacket::SaveOptions(save_options) => { | ||||
|                 handler::settings::save_options(id, save_options, &mut self.clients, &mut self.entity_gateway).await | ||||
|             }, | ||||
|         }) | ||||
|     } | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										31
									
								
								tests/test_character.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								tests/test_character.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,31 @@ | ||||
| use elseware::common::serverstate::{ClientId, ServerState}; | ||||
| use elseware::entity::gateway::{EntityGateway, InMemoryGateway}; | ||||
| use elseware::ship::ship::{ShipServerState, RecvShipPacket}; | ||||
| 
 | ||||
| use libpso::packet::ship::*; | ||||
| 
 | ||||
| #[path = "common.rs"] | ||||
| mod common; | ||||
| use common::*; | ||||
| 
 | ||||
| #[async_std::test] | ||||
| async fn test_save_options<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, options: u32) { | ||||
|     let mut entity_gateway = InMemoryGateway::new(); | ||||
| 
 | ||||
|     let (user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; | ||||
| 
 | ||||
|     let mut ship = ShipServerState::builder() | ||||
|         .gateway(entity_gateway.clone()) | ||||
|         .build(); | ||||
|     log_in_char(&mut ship, ClientId(1), "a1", "a").await; | ||||
|     join_lobby(&mut ship, ClientId(1)).await; | ||||
| 
 | ||||
|     ship.handle(ClientId(1), &RecvShipPacket::SaveOptions(SaveOptions{ | ||||
|         options: 12345, | ||||
|     })).await.unwrap().for_each(drop); | ||||
| 
 | ||||
|     let characters = entity_gateway.get_characters_by_user(&user1).await; | ||||
|     let char = characters[0].as_ref().unwrap(); | ||||
| 
 | ||||
|     assert!(char.option_flags == 12345); | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user