HashMap<ClientId, ClientState> -> Clients
This commit is contained in:
parent
728ac715c0
commit
a8b7e4fa4e
src/ship
@ -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();
|
||||
|
@ -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> {
|
||||
|
@ -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,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{
|
||||
|
@ -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)?;
|
||||
|
@ -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> {
|
||||
|
@ -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();
|
||||
|
@ -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…
x
Reference in New Issue
Block a user