rust/hedgewars-server/src/core/types.rs
changeset 15804 747278149393
parent 15547 863059f61793
child 15882 f185e7367dd3
equal deleted inserted replaced
15803:b06b33cf0a89 15804:747278149393
       
     1 use hedgewars_network_protocol::types::{RoomConfig, TeamInfo, VoteType};
     1 use serde_derive::{Deserialize, Serialize};
     2 use serde_derive::{Deserialize, Serialize};
     2 
     3 
     3 pub type ClientId = usize;
     4 pub type ClientId = usize;
     4 pub type RoomId = usize;
     5 pub type RoomId = usize;
     5 
       
     6 pub const MAX_HEDGEHOGS_PER_TEAM: u8 = 8;
       
     7 
       
     8 #[derive(PartialEq, Eq, Clone, Debug)]
       
     9 pub enum ServerVar {
       
    10     MOTDNew(String),
       
    11     MOTDOld(String),
       
    12     LatestProto(u16),
       
    13 }
       
    14 
       
    15 #[derive(PartialEq, Eq, Clone, Debug)]
       
    16 pub enum GameCfg {
       
    17     FeatureSize(u32),
       
    18     MapType(String),
       
    19     MapGenerator(u32),
       
    20     MazeSize(u32),
       
    21     Seed(String),
       
    22     Template(u32),
       
    23 
       
    24     Ammo(String, Option<String>),
       
    25     Scheme(String, Vec<String>),
       
    26     Script(String),
       
    27     Theme(String),
       
    28     DrawnMap(String),
       
    29 }
       
    30 
       
    31 #[derive(PartialEq, Eq, Clone, Debug, Default)]
       
    32 pub struct TeamInfo {
       
    33     pub owner: String,
       
    34     pub name: String,
       
    35     pub color: u8,
       
    36     pub grave: String,
       
    37     pub fort: String,
       
    38     pub voice_pack: String,
       
    39     pub flag: String,
       
    40     pub difficulty: u8,
       
    41     pub hedgehogs_number: u8,
       
    42     pub hedgehogs: [HedgehogInfo; MAX_HEDGEHOGS_PER_TEAM as usize],
       
    43 }
       
    44 
       
    45 #[derive(PartialEq, Eq, Clone, Debug, Default)]
       
    46 pub struct HedgehogInfo {
       
    47     pub name: String,
       
    48     pub hat: String,
       
    49 }
       
    50 
       
    51 #[derive(Clone, Serialize, Deserialize, Debug)]
       
    52 pub struct Ammo {
       
    53     pub name: String,
       
    54     pub settings: Option<String>,
       
    55 }
       
    56 
       
    57 #[derive(Clone, Serialize, Deserialize, Debug)]
       
    58 pub struct Scheme {
       
    59     pub name: String,
       
    60     pub settings: Vec<String>,
       
    61 }
       
    62 
       
    63 #[derive(Clone, Serialize, Deserialize, Debug)]
       
    64 pub struct RoomConfig {
       
    65     pub feature_size: u32,
       
    66     pub map_type: String,
       
    67     pub map_generator: u32,
       
    68     pub maze_size: u32,
       
    69     pub seed: String,
       
    70     pub template: u32,
       
    71 
       
    72     pub ammo: Ammo,
       
    73     pub scheme: Scheme,
       
    74     pub script: String,
       
    75     pub theme: String,
       
    76     pub drawn_map: Option<String>,
       
    77 }
       
    78 
       
    79 impl RoomConfig {
       
    80     pub fn new() -> RoomConfig {
       
    81         RoomConfig {
       
    82             feature_size: 12,
       
    83             map_type: "+rnd+".to_string(),
       
    84             map_generator: 0,
       
    85             maze_size: 0,
       
    86             seed: "seed".to_string(),
       
    87             template: 0,
       
    88 
       
    89             ammo: Ammo {
       
    90                 name: "Default".to_string(),
       
    91                 settings: None,
       
    92             },
       
    93             scheme: Scheme {
       
    94                 name: "Default".to_string(),
       
    95                 settings: Vec::new(),
       
    96             },
       
    97             script: "Normal".to_string(),
       
    98             theme: "\u{1f994}".to_string(),
       
    99             drawn_map: None,
       
   100         }
       
   101     }
       
   102 
       
   103     pub fn set_config(&mut self, cfg: GameCfg) {
       
   104         match cfg {
       
   105             GameCfg::FeatureSize(s) => self.feature_size = s,
       
   106             GameCfg::MapType(t) => self.map_type = t,
       
   107             GameCfg::MapGenerator(g) => self.map_generator = g,
       
   108             GameCfg::MazeSize(s) => self.maze_size = s,
       
   109             GameCfg::Seed(s) => self.seed = s,
       
   110             GameCfg::Template(t) => self.template = t,
       
   111 
       
   112             GameCfg::Ammo(n, s) => {
       
   113                 self.ammo = Ammo {
       
   114                     name: n,
       
   115                     settings: s,
       
   116                 }
       
   117             }
       
   118             GameCfg::Scheme(n, s) => {
       
   119                 self.scheme = Scheme {
       
   120                     name: n,
       
   121                     settings: s,
       
   122                 }
       
   123             }
       
   124             GameCfg::Script(s) => self.script = s,
       
   125             GameCfg::Theme(t) => self.theme = t,
       
   126             GameCfg::DrawnMap(m) => self.drawn_map = Some(m),
       
   127         };
       
   128     }
       
   129 
       
   130     pub fn to_map_config(&self) -> Vec<String> {
       
   131         vec![
       
   132             self.feature_size.to_string(),
       
   133             self.map_type.to_string(),
       
   134             self.map_generator.to_string(),
       
   135             self.maze_size.to_string(),
       
   136             self.seed.to_string(),
       
   137             self.template.to_string(),
       
   138         ]
       
   139     }
       
   140 
       
   141     pub fn to_game_config(&self) -> Vec<GameCfg> {
       
   142         use GameCfg::*;
       
   143         let mut v = vec![
       
   144             Ammo(self.ammo.name.to_string(), self.ammo.settings.clone()),
       
   145             Scheme(self.scheme.name.to_string(), self.scheme.settings.clone()),
       
   146             Script(self.script.to_string()),
       
   147             Theme(self.theme.to_string()),
       
   148         ];
       
   149         if let Some(ref m) = self.drawn_map {
       
   150             v.push(DrawnMap(m.to_string()))
       
   151         }
       
   152         v
       
   153     }
       
   154 }
       
   155 
     6 
   156 #[derive(Debug)]
     7 #[derive(Debug)]
   157 pub struct Replay {
     8 pub struct Replay {
   158     pub config: RoomConfig,
     9     pub config: RoomConfig,
   159     pub teams: Vec<TeamInfo>,
    10     pub teams: Vec<TeamInfo>,
   160     pub message_log: Vec<String>,
    11     pub message_log: Vec<String>,
   161 }
       
   162 
       
   163 #[derive(PartialEq, Eq, Clone, Debug)]
       
   164 pub enum VoteType {
       
   165     Kick(String),
       
   166     Map(Option<String>),
       
   167     Pause,
       
   168     NewSeed,
       
   169     HedgehogsPerTeam(u8),
       
   170 }
       
   171 
       
   172 pub struct Vote {
       
   173     pub is_pro: bool,
       
   174     pub is_forced: bool,
       
   175 }
    12 }
   176 
    13 
   177 #[derive(Clone, Debug)]
    14 #[derive(Clone, Debug)]
   178 pub struct Voting {
    15 pub struct Voting {
   179     pub ttl: u32,
    16     pub ttl: u32,