5 }; |
5 }; |
6 use super::{ |
6 use super::{ |
7 server::HWServer, |
7 server::HWServer, |
8 room::{GameInfo}, |
8 room::{GameInfo}, |
9 client::HWClient, |
9 client::HWClient, |
10 coretypes::{ClientId, RoomId, VoteType}, |
10 coretypes::{ClientId, RoomId, GameCfg, VoteType}, |
11 room::HWRoom, |
11 room::HWRoom, |
12 handlers |
12 handlers |
13 }; |
13 }; |
14 use protocol::messages::{ |
14 use protocol::messages::{ |
15 HWProtocolMessage, |
15 HWProtocolMessage, |
16 HWServerMessage, |
16 HWServerMessage, |
17 HWServerMessage::*, |
17 HWServerMessage::*, |
18 server_chat |
18 server_chat |
19 }; |
19 }; |
20 use utils::to_engine_msg; |
20 use utils::to_engine_msg; |
|
21 use rand::{thread_rng, Rng, distributions::Uniform}; |
21 |
22 |
22 pub enum Destination { |
23 pub enum Destination { |
23 ToId(ClientId), |
24 ToId(ClientId), |
24 ToSelf, |
25 ToSelf, |
25 ToAll { |
26 ToAll { |
379 }, |
380 }, |
380 VoteType::Map(_) => { |
381 VoteType::Map(_) => { |
381 unimplemented!(); |
382 unimplemented!(); |
382 }, |
383 }, |
383 VoteType::Pause => { |
384 VoteType::Pause => { |
384 if let Some(ref mut info) = server.room(client_id).unwrap().game_info { |
385 if let Some(ref mut info) = server.rooms[room_id].game_info { |
385 info.is_paused = !info.is_paused; |
386 info.is_paused = !info.is_paused; |
386 actions.push(server_chat("Pause toggled.") |
387 actions.push(server_chat("Pause toggled.") |
387 .send_all().in_room(room_id).action()); |
388 .send_all().in_room(room_id).action()); |
388 actions.push(ForwardEngineMessage(vec![to_engine_msg(once(b'I'))]) |
389 actions.push(ForwardEngineMessage(vec![to_engine_msg(once(b'I'))]) |
389 .send_all().in_room(room_id).action()); |
390 .send_all().in_room(room_id).action()); |
390 } |
391 } |
391 }, |
392 }, |
392 VoteType::NewSeed => { |
393 VoteType::NewSeed => { |
393 unimplemented!(); |
394 let seed = thread_rng().gen_range(0, 1_000_000_000).to_string(); |
|
395 let cfg = GameCfg::Seed(seed); |
|
396 actions.push(cfg.to_server_msg().send_all().in_room(room_id).action()); |
|
397 server.rooms[room_id].set_config(cfg); |
394 }, |
398 }, |
395 VoteType::HedgehogsPerTeam(number) => { |
399 VoteType::HedgehogsPerTeam(number) => { |
396 let r = &mut server.rooms[room_id]; |
400 let r = &mut server.rooms[room_id]; |
397 let nicks = r.set_hedgehogs_number(number); |
401 let nicks = r.set_hedgehogs_number(number); |
398 actions.extend(nicks.into_iter().map(|n| |
402 actions.extend(nicks.into_iter().map(|n| |