From 832a53821da18ebbe0476c31240ce4be199c4634 Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 21 Apr 2020 23:45:40 -0600 Subject: [PATCH] move settings --- src/ship/packet/handler/mod.rs | 1 + src/ship/packet/handler/settings.rs | 20 ++++++++++++++++++++ src/ship/ship.rs | 9 +-------- 3 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 src/ship/packet/handler/settings.rs diff --git a/src/ship/packet/handler/mod.rs b/src/ship/packet/handler/mod.rs index 0928362..b9ba696 100644 --- a/src/ship/packet/handler/mod.rs +++ b/src/ship/packet/handler/mod.rs @@ -2,3 +2,4 @@ pub mod auth; pub mod communication; pub mod lobby; pub mod room; +pub mod settings; diff --git a/src/ship/packet/handler/settings.rs b/src/ship/packet/handler/settings.rs new file mode 100644 index 0000000..096f512 --- /dev/null +++ b/src/ship/packet/handler/settings.rs @@ -0,0 +1,20 @@ +use std::collections::HashMap; +use libpso::packet::ship::*; +use crate::common::serverstate::ClientId; +use crate::common::leveltable::CharacterLevelTable; +use crate::ship::ship::{SendShipPacket, ShipError, ClientState}; +use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder}; +use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS}; +use libpso::character::character; +use crate::entity::gateway::EntityGateway; + +pub fn update_config(id: ClientId, + update_config: &UpdateConfig, + clients: &mut HashMap, + entity_gateway: &mut EG) + -> Box + Send> { + let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap(); + client.character.config.update(update_config); + entity_gateway.save_character(&client.character); + Box::new(None.into_iter()) +} diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 02f6926..548ef33 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -283,13 +283,6 @@ impl ShipServerState { }, } } - - 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.save_character(&client.character); - Box::new(None.into_iter()) - } } impl ServerState for ShipServerState { @@ -343,7 +336,7 @@ impl ServerState for ShipServerState { handler::room::room_name_request(id, &self.client_location, &self.rooms) }, RecvShipPacket::UpdateConfig(pkt) => { - self.update_config(id, pkt) + handler::settings::update_config(id, pkt, &mut self.clients, &mut self.entity_gateway) }, RecvShipPacket::ViewInfoboardRequest(pkt) => { handler::communication::request_infoboard(id, pkt, &self.client_location, &self.clients)