Browse Source

HashMap<ClientId, ClientState> -> Clients

pbs
jake 5 years ago
parent
commit
a8b7e4fa4e
  1. 6
      src/ship/packet/builder/lobby.rs
  2. 4
      src/ship/packet/handler/auth.rs
  3. 8
      src/ship/packet/handler/communication.rs
  4. 4
      src/ship/packet/handler/direct_message.rs
  5. 6
      src/ship/packet/handler/lobby.rs
  6. 6
      src/ship/packet/handler/room.rs
  7. 4
      src/ship/packet/handler/settings.rs
  8. 3
      src/ship/ship.rs

6
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<ClientId, ClientState>,
clients: &Clients,
level_table: &CharacterLevelTable)
-> Result<JoinLobby, ShipError> {
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<ClientId, ClientState>,
clients: &Clients,
level_table: &CharacterLevelTable)
-> Result<AddToLobby, ShipError> {
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();

4
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<EG: EntityGateway>(id: ClientId,
pkt: &Login,
entity_gateway: &mut EG,
clients: &mut HashMap<ClientId, ClientState>,
clients: &mut Clients,
item_database: &mut ActiveItemDatabase,
ship_name: &String)
-> Result<Vec<SendShipPacket>, ShipError> {

8
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<ClientId, ClientState>) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
clients: &Clients) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + 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<ClientId, ClientState>)
clients: &Clients)
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + 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<EG: EntityGateway>(id: ClientId,
new_infoboard: &WriteInfoboard,
clients: &mut HashMap<ClientId, ClientState>,
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();

4
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<ClientId, ClientState>)
clients: &Clients)
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
let client = clients.get(&id).unwrap();
let msg = DirectMessage{

6
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<ClientId, ClientState>,
clients: &mut Clients,
level_table: &CharacterLevelTable)
-> Result<Vec<SendShipPacket>, 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<ClientId, ClientState>,
clients: &Clients,
level_table: &CharacterLevelTable)
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError> {
let lobby = client_location.add_client_to_next_available_lobby(id, LobbyId(0)).map_err(|_| ShipError::TooManyClients)?;

6
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<ClientId, ClientState>,
clients: &mut Clients,
rooms: &mut Rooms)
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + 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<ClientId, ClientState>,
clients: &mut Clients,
level_table: &CharacterLevelTable,
rooms: &mut Rooms)
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError> {

4
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<EG: EntityGateway>(id: ClientId,
update_config: &UpdateConfig,
clients: &mut HashMap<ClientId, ClientState>,
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();

3
src/ship/ship.rs

@ -28,6 +28,7 @@ use crate::ship::packet::handler;
pub const SHIP_PORT: u16 = 23423;
pub type Rooms = [Option<room::RoomState>; MAX_ROOMS];
pub type Clients = HashMap<ClientId, ClientState>;
#[derive(Debug)]
pub enum ShipError {
@ -162,7 +163,7 @@ impl ClientState {
pub struct ShipServerState<EG: EntityGateway> {
entity_gateway: EG,
clients: HashMap<ClientId, ClientState>,
clients: Clients,
client_location: ClientLocation,
level_table: CharacterLevelTable,
name: String,

Loading…
Cancel
Save