Browse Source

move settings

pbs
jake 5 years ago
parent
commit
832a53821d
  1. 1
      src/ship/packet/handler/mod.rs
  2. 20
      src/ship/packet/handler/settings.rs
  3. 9
      src/ship/ship.rs

1
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;

20
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<EG: EntityGateway>(id: ClientId,
update_config: &UpdateConfig,
clients: &mut HashMap<ClientId, ClientState>,
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);
entity_gateway.save_character(&client.character);
Box::new(None.into_iter())
}

9
src/ship/ship.rs

@ -283,13 +283,6 @@ impl<EG: EntityGateway> ShipServerState<EG> {
},
}
}
fn update_config(&mut self, id: ClientId, update_config: &UpdateConfig) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + 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<EG: EntityGateway> ServerState for ShipServerState<EG> {
@ -343,7 +336,7 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
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)

Loading…
Cancel
Save