From a8b7e4fa4ec5923686042ee8ecd85ac00acf3d0d Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 22 Apr 2020 23:49:49 -0600 Subject: [PATCH] HashMap -> Clients --- src/ship/packet/builder/lobby.rs | 6 +++--- src/ship/packet/handler/auth.rs | 4 ++-- src/ship/packet/handler/communication.rs | 8 ++++---- src/ship/packet/handler/direct_message.rs | 4 ++-- src/ship/packet/handler/lobby.rs | 6 +++--- src/ship/packet/handler/room.rs | 6 +++--- src/ship/packet/handler/settings.rs | 4 ++-- src/ship/ship.rs | 3 ++- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/ship/packet/builder/lobby.rs b/src/ship/packet/builder/lobby.rs index 56aaf66..6c89536 100644 --- a/src/ship/packet/builder/lobby.rs +++ b/src/ship/packet/builder/lobby.rs @@ -2,7 +2,7 @@ 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::ship::{SendShipPacket, ShipError, ClientState, Clients}; use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder}; use crate::ship::location::{ClientLocation, LobbyId, AreaClient}; use crate::entity::character::CharacterEntity; @@ -44,7 +44,7 @@ fn player_info(tag: u32, client: &ClientState, area_client: &AreaClient, level_t pub fn join_lobby(id: ClientId, lobby: LobbyId, client_location: &ClientLocation, - clients: &HashMap, + clients: &Clients, level_table: &CharacterLevelTable) -> Result { let lobby_clients = client_location.get_clients_in_lobby(lobby).map_err(|err| ShipError::ClientError(format!("{:?}", err)))?; @@ -72,7 +72,7 @@ pub fn join_lobby(id: ClientId, pub fn add_to_lobby(id: ClientId, lobby: LobbyId, client_location: &ClientLocation, - clients: &HashMap, + clients: &Clients, level_table: &CharacterLevelTable) -> Result { let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id)).unwrap(); diff --git a/src/ship/packet/handler/auth.rs b/src/ship/packet/handler/auth.rs index 0268ba4..4b61d6b 100644 --- a/src/ship/packet/handler/auth.rs +++ b/src/ship/packet/handler/auth.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use libpso::packet::login::{Login, LoginResponse, AccountStatus, Session}; use libpso::packet::ship::*; use crate::common::serverstate::ClientId; -use crate::ship::ship::{SendShipPacket, ShipError, ClientState}; +use crate::ship::ship::{SendShipPacket, ShipError, ClientState, Clients}; use crate::login::login::get_login_status; use crate::entity::gateway::EntityGateway; use crate::ship::items::ActiveItemDatabase; @@ -10,7 +10,7 @@ use crate::ship::items::ActiveItemDatabase; pub fn validate_login(id: ClientId, pkt: &Login, entity_gateway: &mut EG, - clients: &mut HashMap, + clients: &mut Clients, item_database: &mut ActiveItemDatabase, ship_name: &String) -> Result, ShipError> { diff --git a/src/ship/packet/handler/communication.rs b/src/ship/packet/handler/communication.rs index 17916e4..e2c84aa 100644 --- a/src/ship/packet/handler/communication.rs +++ b/src/ship/packet/handler/communication.rs @@ -2,7 +2,7 @@ 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::ship::{SendShipPacket, ShipError, ClientState, Clients}; use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder}; use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS}; use libpso::character::character; @@ -11,7 +11,7 @@ use crate::entity::gateway::EntityGateway; pub fn player_chat(id: ClientId, msg: &PlayerChat, client_location: &ClientLocation, - clients: &HashMap) -> Result + Send>, ShipError> { + clients: &Clients) -> Result + Send>, ShipError> { let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?; let cmsg = PlayerChat::new(client.user.id.0, msg.message.clone()); @@ -24,7 +24,7 @@ pub fn player_chat(id: ClientId, pub fn request_infoboard(id: ClientId, request_infoboard: &ViewInfoboardRequest, client_location: &ClientLocation, - clients: &HashMap) + clients: &Clients) -> Box + Send> { let area_clients = client_location.get_client_neighbors(id).unwrap(); let r = area_clients.iter() @@ -42,7 +42,7 @@ pub fn request_infoboard(id: ClientId, pub fn write_infoboard(id: ClientId, new_infoboard: &WriteInfoboard, - clients: &mut HashMap, + clients: &mut Clients, entity_gateway: &mut EG) -> Box + Send> { let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap(); diff --git a/src/ship/packet/handler/direct_message.rs b/src/ship/packet/handler/direct_message.rs index ceb4e05..a824684 100644 --- a/src/ship/packet/handler/direct_message.rs +++ b/src/ship/packet/handler/direct_message.rs @@ -4,7 +4,7 @@ use libpso::packet::ship::*; use libpso::packet::messages::*; use crate::common::serverstate::ClientId; use crate::common::leveltable::CharacterLevelTable; -use crate::ship::ship::{SendShipPacket, ShipError, ClientState, Rooms}; +use crate::ship::ship::{SendShipPacket, ShipError, ClientState, Clients, Rooms}; use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder}; use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS}; use libpso::character::character; @@ -26,7 +26,7 @@ pub fn guildcard_send(id: ClientId, guildcard_send: &GuildcardSend, target: u32, client_location: &ClientLocation, - clients: &HashMap) + clients: &Clients) -> Box + Send> { let client = clients.get(&id).unwrap(); let msg = DirectMessage{ diff --git a/src/ship/packet/handler/lobby.rs b/src/ship/packet/handler/lobby.rs index dcc627d..9be8556 100644 --- a/src/ship/packet/handler/lobby.rs +++ b/src/ship/packet/handler/lobby.rs @@ -2,7 +2,7 @@ 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::ship::{SendShipPacket, ShipError, ClientState, Clients}; use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder}; use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS}; use crate::ship::packet; @@ -11,7 +11,7 @@ use libpso::character::character; // this function needs a better home pub fn block_selected(id: ClientId, pkt: &MenuSelect, - clients: &mut HashMap, + clients: &mut Clients, level_table: &CharacterLevelTable) -> Result, ShipError> { let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?; @@ -41,7 +41,7 @@ pub fn block_selected(id: ClientId, pub fn send_player_to_lobby(id: ClientId, _pkt: &CharData, client_location: &mut ClientLocation, - clients: &HashMap, + clients: &Clients, level_table: &CharacterLevelTable) -> Result, ShipError> { let lobby = client_location.add_client_to_next_available_lobby(id, LobbyId(0)).map_err(|_| ShipError::TooManyClients)?; diff --git a/src/ship/packet/handler/room.rs b/src/ship/packet/handler/room.rs index 3553dda..fa046d8 100644 --- a/src/ship/packet/handler/room.rs +++ b/src/ship/packet/handler/room.rs @@ -2,7 +2,7 @@ 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, Rooms}; +use crate::ship::ship::{SendShipPacket, ShipError, ClientState, Rooms, Clients}; use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder}; use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS}; use libpso::character::character; @@ -11,7 +11,7 @@ use crate::ship::room; pub fn create_room(id: ClientId, create_room: &CreateRoom, client_location: &mut ClientLocation, - clients: &mut HashMap, + clients: &mut Clients, rooms: &mut Rooms) -> Box + Send> { let area = client_location.get_area(id).unwrap(); @@ -78,7 +78,7 @@ pub fn room_name_request(id: ClientId, pub fn join_room(id: ClientId, pkt: &MenuSelect, client_location: &mut ClientLocation, - clients: &mut HashMap, + clients: &mut Clients, level_table: &CharacterLevelTable, rooms: &mut Rooms) -> Result, ShipError> { diff --git a/src/ship/packet/handler/settings.rs b/src/ship/packet/handler/settings.rs index 096f512..93ed14a 100644 --- a/src/ship/packet/handler/settings.rs +++ b/src/ship/packet/handler/settings.rs @@ -2,7 +2,7 @@ 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::ship::{SendShipPacket, ShipError, ClientState, Clients}; use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder}; use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS}; use libpso::character::character; @@ -10,7 +10,7 @@ use crate::entity::gateway::EntityGateway; pub fn update_config(id: ClientId, update_config: &UpdateConfig, - clients: &mut HashMap, + clients: &mut Clients, entity_gateway: &mut EG) -> Box + Send> { let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap(); diff --git a/src/ship/ship.rs b/src/ship/ship.rs index f95eafc..5ef4728 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -28,6 +28,7 @@ use crate::ship::packet::handler; pub const SHIP_PORT: u16 = 23423; pub type Rooms = [Option; MAX_ROOMS]; +pub type Clients = HashMap; #[derive(Debug)] pub enum ShipError { @@ -162,7 +163,7 @@ impl ClientState { pub struct ShipServerState { entity_gateway: EG, - clients: HashMap, + clients: Clients, client_location: ClientLocation, level_table: CharacterLevelTable, name: String,