2020-04-21 23:45:40 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use libpso::packet::ship::*;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use crate::common::serverstate::ClientId;
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-02 22:08:37 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								use crate::ship::ship::{SendShipPacket, ShipError, Clients};
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-21 23:45:40 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								use crate::entity::gateway::EntityGateway;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-06-02 18:51:18 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								pub async fn update_config<EG: EntityGateway>(id: ClientId,
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-21 23:45:40 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                        update_config: &UpdateConfig,
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-22 23:49:49 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								                                        clients: &mut Clients,
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-21 23:45:40 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                        entity_gateway: &mut EG)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                        -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    client.character.config.update(update_config);
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-26 00:02:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    entity_gateway.save_character(&client.character).await.unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-04-21 23:45:40 -06:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    Box::new(None.into_iter())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-02 21:24:32 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								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> {
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-30 19:02:56 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    // TODO: don't unwrap?
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-02 21:24:32 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    client.character.option_flags = save_options.options;
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-26 00:02:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    entity_gateway.save_character(&client.character).await.unwrap();
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-02 21:24:32 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    Box::new(None.into_iter())
							 | 
						
					
						
							
								
									
										
										
										
											2020-10-26 00:02:48 -06:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							
								
									
										
										
										
											2021-05-30 19:02:56 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2022-01-05 22:57:15 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								pub async fn keyboard_config<EG: EntityGateway>(id: ClientId,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                                keyboard_config: &KeyboardConfig,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                                clients: &mut Clients,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                                entity_gateway: &mut EG)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                                -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    client.character.keyboard_config.update(keyboard_config);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    entity_gateway.save_character(&client.character).await.unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    Box::new(None.into_iter())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								pub async fn gamepad_config<EG: EntityGateway>(id: ClientId,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                                gamepad_config: &GamepadConfig,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                                clients: &mut Clients,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                                entity_gateway: &mut EG)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                                                -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    client.character.gamepad_config.update(gamepad_config);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    entity_gateway.save_character(&client.character).await.unwrap();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    Box::new(None.into_iter())
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |