equal
deleted
inserted
replaced
3 }; |
3 }; |
4 use server::{ |
4 use server::{ |
5 coretypes::{ClientId, RoomId, TeamInfo, GameCfg, GameCfg::*, Voting}, |
5 coretypes::{ClientId, RoomId, TeamInfo, GameCfg, GameCfg::*, Voting}, |
6 client::{HWClient} |
6 client::{HWClient} |
7 }; |
7 }; |
|
8 use serde::{Serialize, Deserialize}; |
|
9 use serde_yaml; |
8 |
10 |
9 const MAX_HEDGEHOGS_IN_ROOM: u8 = 64; |
11 const MAX_HEDGEHOGS_IN_ROOM: u8 = 64; |
10 const MAX_TEAMS_IN_ROOM: u8 = 8; |
12 const MAX_TEAMS_IN_ROOM: u8 = 8; |
11 |
13 |
12 #[derive(Clone)] |
14 #[derive(Clone, Serialize, Deserialize)] |
13 struct Ammo { |
15 struct Ammo { |
14 name: String, |
16 name: String, |
15 settings: Option<String> |
17 settings: Option<String> |
16 } |
18 } |
17 |
19 |
18 #[derive(Clone)] |
20 #[derive(Clone, Serialize, Deserialize)] |
19 struct Scheme { |
21 struct Scheme { |
20 name: String, |
22 name: String, |
21 settings: Option<Vec<String>> |
23 settings: Option<Vec<String>> |
22 } |
24 } |
23 |
25 |
24 #[derive(Clone)] |
26 #[derive(Clone, Serialize, Deserialize)] |
25 struct RoomConfig { |
27 struct RoomConfig { |
26 feature_size: u32, |
28 feature_size: u32, |
27 map_type: String, |
29 map_type: String, |
28 map_generator: u32, |
30 map_generator: u32, |
29 maze_size: u32, |
31 maze_size: u32, |
107 pub fn client_teams(&self, client_id: ClientId) -> impl Iterator<Item = &TeamInfo> + Clone { |
109 pub fn client_teams(&self, client_id: ClientId) -> impl Iterator<Item = &TeamInfo> + Clone { |
108 client_teams_impl(&self.teams_at_start, client_id) |
110 client_teams_impl(&self.teams_at_start, client_id) |
109 } |
111 } |
110 } |
112 } |
111 |
113 |
|
114 #[derive(Serialize, Deserialize)] |
112 pub struct RoomSave { |
115 pub struct RoomSave { |
113 pub location: String, |
116 pub location: String, |
114 config: RoomConfig |
117 config: RoomConfig |
115 } |
118 } |
116 |
119 |
350 |
353 |
351 pub fn delete_config(&mut self, name: &str) -> bool { |
354 pub fn delete_config(&mut self, name: &str) -> bool { |
352 self.saves.remove(name).is_some() |
355 self.saves.remove(name).is_some() |
353 } |
356 } |
354 |
357 |
|
358 pub fn get_saves(&self) -> Result<String, serde_yaml::Error> { |
|
359 serde_yaml::to_string(&(&self.greeting, &self.saves)) |
|
360 } |
|
361 |
|
362 pub fn set_saves(&mut self, text: &str) -> Result<(), serde_yaml::Error> { |
|
363 serde_yaml::from_str::<(String, HashMap<String, RoomSave>)>(text).map(|(greeting, saves)| { |
|
364 self.greeting = greeting; |
|
365 self.saves = saves; |
|
366 }) |
|
367 } |
|
368 |
355 pub fn team_info(owner: &HWClient, team: &TeamInfo) -> Vec<String> { |
369 pub fn team_info(owner: &HWClient, team: &TeamInfo) -> Vec<String> { |
356 let mut info = vec![ |
370 let mut info = vec![ |
357 team.name.clone(), |
371 team.name.clone(), |
358 team.grave.clone(), |
372 team.grave.clone(), |
359 team.fort.clone(), |
373 team.fort.clone(), |