gameServer2/src/server/core.rs
changeset 14392 e335b3120f59
parent 14375 cc99f7c673c7
equal deleted inserted replaced
14391:42776184fc39 14392:e335b3120f59
     1 use slab;
     1 use slab;
     2 use crate::utils;
     2 use crate::utils;
     3 use super::{
     3 use super::{
       
     4     io::HWServerIO,
     4     client::HWClient, room::HWRoom, actions, handlers,
     5     client::HWClient, room::HWRoom, actions, handlers,
     5     coretypes::{ClientId, RoomId},
     6     coretypes::{ClientId, RoomId},
     6     actions::{Destination, PendingMessage}
     7     actions::{Destination, PendingMessage}
     7 };
     8 };
     8 use crate::protocol::messages::*;
     9 use crate::protocol::messages::*;
    10 use base64::{encode};
    11 use base64::{encode};
    11 use log::*;
    12 use log::*;
    12 
    13 
    13 type Slab<T> = slab::Slab<T>;
    14 type Slab<T> = slab::Slab<T>;
    14 
    15 
    15 
       
    16 pub struct HWServer {
    16 pub struct HWServer {
    17     pub clients: Slab<HWClient>,
    17     pub clients: Slab<HWClient>,
    18     pub rooms: Slab<HWRoom>,
    18     pub rooms: Slab<HWRoom>,
    19     pub lobby_id: RoomId,
    19     pub lobby_id: RoomId,
    20     pub output: Vec<(Vec<ClientId>, HWServerMessage)>,
    20     pub output: Vec<(Vec<ClientId>, HWServerMessage)>,
    21     pub removed_clients: Vec<ClientId>,
    21     pub removed_clients: Vec<ClientId>,
       
    22     pub io: Box<dyn HWServerIO>
    22 }
    23 }
    23 
    24 
    24 impl HWServer {
    25 impl HWServer {
    25     pub fn new(clients_limit: usize, rooms_limit: usize) -> HWServer {
    26     pub fn new(clients_limit: usize, rooms_limit: usize, io: Box<dyn HWServerIO>) -> HWServer {
    26         let rooms = Slab::with_capacity(rooms_limit);
    27         let rooms = Slab::with_capacity(rooms_limit);
    27         let clients = Slab::with_capacity(clients_limit);
    28         let clients = Slab::with_capacity(clients_limit);
    28         let mut server = HWServer {
    29         let mut server = HWServer {
    29             clients, rooms,
    30             clients, rooms,
    30             lobby_id: 0,
    31             lobby_id: 0,
    31             output: vec![],
    32             output: vec![],
    32             removed_clients: vec![]
    33             removed_clients: vec![],
       
    34             io
    33         };
    35         };
    34         server.lobby_id = server.add_room();
    36         server.lobby_id = server.add_room();
    35         server
    37         server
    36     }
    38     }
    37 
    39