HashMap<ClientId, ClientState> -> Clients
This commit is contained in:
parent
728ac715c0
commit
a8b7e4fa4e
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||||||
use libpso::packet::ship::*;
|
use libpso::packet::ship::*;
|
||||||
use crate::common::serverstate::ClientId;
|
use crate::common::serverstate::ClientId;
|
||||||
use crate::common::leveltable::CharacterLevelTable;
|
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::character::{CharacterBytesBuilder, FullCharacterBytesBuilder};
|
||||||
use crate::ship::location::{ClientLocation, LobbyId, AreaClient};
|
use crate::ship::location::{ClientLocation, LobbyId, AreaClient};
|
||||||
use crate::entity::character::CharacterEntity;
|
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,
|
pub fn join_lobby(id: ClientId,
|
||||||
lobby: LobbyId,
|
lobby: LobbyId,
|
||||||
client_location: &ClientLocation,
|
client_location: &ClientLocation,
|
||||||
clients: &HashMap<ClientId, ClientState>,
|
clients: &Clients,
|
||||||
level_table: &CharacterLevelTable)
|
level_table: &CharacterLevelTable)
|
||||||
-> Result<JoinLobby, ShipError> {
|
-> Result<JoinLobby, ShipError> {
|
||||||
let lobby_clients = client_location.get_clients_in_lobby(lobby).map_err(|err| ShipError::ClientError(format!("{:?}", err)))?;
|
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,
|
pub fn add_to_lobby(id: ClientId,
|
||||||
lobby: LobbyId,
|
lobby: LobbyId,
|
||||||
client_location: &ClientLocation,
|
client_location: &ClientLocation,
|
||||||
clients: &HashMap<ClientId, ClientState>,
|
clients: &Clients,
|
||||||
level_table: &CharacterLevelTable)
|
level_table: &CharacterLevelTable)
|
||||||
-> Result<AddToLobby, ShipError> {
|
-> Result<AddToLobby, ShipError> {
|
||||||
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
|
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::login::{Login, LoginResponse, AccountStatus, Session};
|
||||||
use libpso::packet::ship::*;
|
use libpso::packet::ship::*;
|
||||||
use crate::common::serverstate::ClientId;
|
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::login::login::get_login_status;
|
||||||
use crate::entity::gateway::EntityGateway;
|
use crate::entity::gateway::EntityGateway;
|
||||||
use crate::ship::items::ActiveItemDatabase;
|
use crate::ship::items::ActiveItemDatabase;
|
||||||
@ -10,7 +10,7 @@ use crate::ship::items::ActiveItemDatabase;
|
|||||||
pub fn validate_login<EG: EntityGateway>(id: ClientId,
|
pub fn validate_login<EG: EntityGateway>(id: ClientId,
|
||||||
pkt: &Login,
|
pkt: &Login,
|
||||||
entity_gateway: &mut EG,
|
entity_gateway: &mut EG,
|
||||||
clients: &mut HashMap<ClientId, ClientState>,
|
clients: &mut Clients,
|
||||||
item_database: &mut ActiveItemDatabase,
|
item_database: &mut ActiveItemDatabase,
|
||||||
ship_name: &String)
|
ship_name: &String)
|
||||||
-> Result<Vec<SendShipPacket>, ShipError> {
|
-> Result<Vec<SendShipPacket>, ShipError> {
|
||||||
|
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||||||
use libpso::packet::ship::*;
|
use libpso::packet::ship::*;
|
||||||
use crate::common::serverstate::ClientId;
|
use crate::common::serverstate::ClientId;
|
||||||
use crate::common::leveltable::CharacterLevelTable;
|
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::character::{CharacterBytesBuilder, FullCharacterBytesBuilder};
|
||||||
use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS};
|
use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS};
|
||||||
use libpso::character::character;
|
use libpso::character::character;
|
||||||
@ -11,7 +11,7 @@ use crate::entity::gateway::EntityGateway;
|
|||||||
pub fn player_chat(id: ClientId,
|
pub fn player_chat(id: ClientId,
|
||||||
msg: &PlayerChat,
|
msg: &PlayerChat,
|
||||||
client_location: &ClientLocation,
|
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 client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
|
||||||
let cmsg = PlayerChat::new(client.user.id.0, msg.message.clone());
|
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,
|
pub fn request_infoboard(id: ClientId,
|
||||||
request_infoboard: &ViewInfoboardRequest,
|
request_infoboard: &ViewInfoboardRequest,
|
||||||
client_location: &ClientLocation,
|
client_location: &ClientLocation,
|
||||||
clients: &HashMap<ClientId, ClientState>)
|
clients: &Clients)
|
||||||
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
||||||
let area_clients = client_location.get_client_neighbors(id).unwrap();
|
let area_clients = client_location.get_client_neighbors(id).unwrap();
|
||||||
let r = area_clients.iter()
|
let r = area_clients.iter()
|
||||||
@ -42,7 +42,7 @@ pub fn request_infoboard(id: ClientId,
|
|||||||
|
|
||||||
pub fn write_infoboard<EG: EntityGateway>(id: ClientId,
|
pub fn write_infoboard<EG: EntityGateway>(id: ClientId,
|
||||||
new_infoboard: &WriteInfoboard,
|
new_infoboard: &WriteInfoboard,
|
||||||
clients: &mut HashMap<ClientId, ClientState>,
|
clients: &mut Clients,
|
||||||
entity_gateway: &mut EG)
|
entity_gateway: &mut EG)
|
||||||
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
||||||
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
|
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 libpso::packet::messages::*;
|
||||||
use crate::common::serverstate::ClientId;
|
use crate::common::serverstate::ClientId;
|
||||||
use crate::common::leveltable::CharacterLevelTable;
|
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::character::{CharacterBytesBuilder, FullCharacterBytesBuilder};
|
||||||
use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS};
|
use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS};
|
||||||
use libpso::character::character;
|
use libpso::character::character;
|
||||||
@ -26,7 +26,7 @@ pub fn guildcard_send(id: ClientId,
|
|||||||
guildcard_send: &GuildcardSend,
|
guildcard_send: &GuildcardSend,
|
||||||
target: u32,
|
target: u32,
|
||||||
client_location: &ClientLocation,
|
client_location: &ClientLocation,
|
||||||
clients: &HashMap<ClientId, ClientState>)
|
clients: &Clients)
|
||||||
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
||||||
let client = clients.get(&id).unwrap();
|
let client = clients.get(&id).unwrap();
|
||||||
let msg = DirectMessage{
|
let msg = DirectMessage{
|
||||||
|
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||||||
use libpso::packet::ship::*;
|
use libpso::packet::ship::*;
|
||||||
use crate::common::serverstate::ClientId;
|
use crate::common::serverstate::ClientId;
|
||||||
use crate::common::leveltable::CharacterLevelTable;
|
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::character::{CharacterBytesBuilder, FullCharacterBytesBuilder};
|
||||||
use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS};
|
use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS};
|
||||||
use crate::ship::packet;
|
use crate::ship::packet;
|
||||||
@ -11,7 +11,7 @@ use libpso::character::character;
|
|||||||
// this function needs a better home
|
// this function needs a better home
|
||||||
pub fn block_selected(id: ClientId,
|
pub fn block_selected(id: ClientId,
|
||||||
pkt: &MenuSelect,
|
pkt: &MenuSelect,
|
||||||
clients: &mut HashMap<ClientId, ClientState>,
|
clients: &mut Clients,
|
||||||
level_table: &CharacterLevelTable)
|
level_table: &CharacterLevelTable)
|
||||||
-> Result<Vec<SendShipPacket>, ShipError> {
|
-> Result<Vec<SendShipPacket>, ShipError> {
|
||||||
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
|
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,
|
pub fn send_player_to_lobby(id: ClientId,
|
||||||
_pkt: &CharData,
|
_pkt: &CharData,
|
||||||
client_location: &mut ClientLocation,
|
client_location: &mut ClientLocation,
|
||||||
clients: &HashMap<ClientId, ClientState>,
|
clients: &Clients,
|
||||||
level_table: &CharacterLevelTable)
|
level_table: &CharacterLevelTable)
|
||||||
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError> {
|
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError> {
|
||||||
let lobby = client_location.add_client_to_next_available_lobby(id, LobbyId(0)).map_err(|_| ShipError::TooManyClients)?;
|
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 libpso::packet::ship::*;
|
||||||
use crate::common::serverstate::ClientId;
|
use crate::common::serverstate::ClientId;
|
||||||
use crate::common::leveltable::CharacterLevelTable;
|
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::character::{CharacterBytesBuilder, FullCharacterBytesBuilder};
|
||||||
use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS};
|
use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS};
|
||||||
use libpso::character::character;
|
use libpso::character::character;
|
||||||
@ -11,7 +11,7 @@ use crate::ship::room;
|
|||||||
pub fn create_room(id: ClientId,
|
pub fn create_room(id: ClientId,
|
||||||
create_room: &CreateRoom,
|
create_room: &CreateRoom,
|
||||||
client_location: &mut ClientLocation,
|
client_location: &mut ClientLocation,
|
||||||
clients: &mut HashMap<ClientId, ClientState>,
|
clients: &mut Clients,
|
||||||
rooms: &mut Rooms)
|
rooms: &mut Rooms)
|
||||||
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
||||||
let area = client_location.get_area(id).unwrap();
|
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,
|
pub fn join_room(id: ClientId,
|
||||||
pkt: &MenuSelect,
|
pkt: &MenuSelect,
|
||||||
client_location: &mut ClientLocation,
|
client_location: &mut ClientLocation,
|
||||||
clients: &mut HashMap<ClientId, ClientState>,
|
clients: &mut Clients,
|
||||||
level_table: &CharacterLevelTable,
|
level_table: &CharacterLevelTable,
|
||||||
rooms: &mut Rooms)
|
rooms: &mut Rooms)
|
||||||
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError> {
|
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError> {
|
||||||
|
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||||||
use libpso::packet::ship::*;
|
use libpso::packet::ship::*;
|
||||||
use crate::common::serverstate::ClientId;
|
use crate::common::serverstate::ClientId;
|
||||||
use crate::common::leveltable::CharacterLevelTable;
|
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::character::{CharacterBytesBuilder, FullCharacterBytesBuilder};
|
||||||
use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS};
|
use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS};
|
||||||
use libpso::character::character;
|
use libpso::character::character;
|
||||||
@ -10,7 +10,7 @@ use crate::entity::gateway::EntityGateway;
|
|||||||
|
|
||||||
pub fn update_config<EG: EntityGateway>(id: ClientId,
|
pub fn update_config<EG: EntityGateway>(id: ClientId,
|
||||||
update_config: &UpdateConfig,
|
update_config: &UpdateConfig,
|
||||||
clients: &mut HashMap<ClientId, ClientState>,
|
clients: &mut Clients,
|
||||||
entity_gateway: &mut EG)
|
entity_gateway: &mut EG)
|
||||||
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
||||||
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
|
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 const SHIP_PORT: u16 = 23423;
|
||||||
pub type Rooms = [Option<room::RoomState>; MAX_ROOMS];
|
pub type Rooms = [Option<room::RoomState>; MAX_ROOMS];
|
||||||
|
pub type Clients = HashMap<ClientId, ClientState>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ShipError {
|
pub enum ShipError {
|
||||||
@ -162,7 +163,7 @@ impl ClientState {
|
|||||||
|
|
||||||
pub struct ShipServerState<EG: EntityGateway> {
|
pub struct ShipServerState<EG: EntityGateway> {
|
||||||
entity_gateway: EG,
|
entity_gateway: EG,
|
||||||
clients: HashMap<ClientId, ClientState>,
|
clients: Clients,
|
||||||
client_location: ClientLocation,
|
client_location: ClientLocation,
|
||||||
level_table: CharacterLevelTable,
|
level_table: CharacterLevelTable,
|
||||||
name: String,
|
name: String,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user