275 }; |
275 }; |
276 server.react(client_id, actions); |
276 server.react(client_id, actions); |
277 } |
277 } |
278 CallVote(None) => { |
278 CallVote(None) => { |
279 server.react(client_id, vec![ |
279 server.react(client_id, vec![ |
280 server_chat("Available callvote commands: kick <nickname>, map <name>, pause, newseed, hedgehogs <number>") |
280 server_chat("Available callvote commands: kick <nickname>, map <name>, pause, newseed, hedgehogs <number>".to_string()) |
281 .send_self().action()]) |
281 .send_self().action()]) |
282 } |
282 } |
283 CallVote(Some(kind)) => { |
283 CallVote(Some(kind)) => { |
284 let is_in_game = server.rooms[room_id].game_info.is_some(); |
284 let is_in_game = server.rooms[room_id].game_info.is_some(); |
285 let error = match &kind { |
285 let error = match &kind { |
286 VoteType::Kick(nick) => { |
286 VoteType::Kick(nick) => { |
287 if server.find_client(&nick).filter(|c| c.room_id == Some(room_id)).is_some() { |
287 if server.find_client(&nick).filter(|c| c.room_id == Some(room_id)).is_some() { |
288 None |
288 None |
289 } else { |
289 } else { |
290 Some("/callvote kick: No such user!") |
290 Some("/callvote kick: No such user!".to_string()) |
291 } |
291 } |
292 }, |
292 }, |
293 VoteType::Map(None) => { |
293 VoteType::Map(None) => { |
294 Some("/callvote map: Not implemented") |
294 let names: Vec<_> = server.rooms[room_id].saves.keys().cloned().collect(); |
|
295 if names.is_empty() { |
|
296 Some("/callvote map: No maps saved in this room!".to_string()) |
|
297 } else { |
|
298 Some(format!("Available maps: {}", names.join(", "))) |
|
299 } |
295 }, |
300 }, |
296 VoteType::Map(Some(name)) => { |
301 VoteType::Map(Some(name)) => { |
297 Some("/callvote map: Not implemented") |
302 if server.rooms[room_id].saves.get(&name[..]).is_some() { |
|
303 Some("/callvote map: No such map!".to_string()) |
|
304 } else { |
|
305 None |
|
306 } |
298 }, |
307 }, |
299 VoteType::Pause => { |
308 VoteType::Pause => { |
300 if is_in_game { |
309 if is_in_game { |
301 None |
310 None |
302 } else { |
311 } else { |
303 Some("/callvote pause: No game in progress!") |
312 Some("/callvote pause: No game in progress!".to_string()) |
304 } |
313 } |
305 }, |
314 }, |
306 VoteType::NewSeed => { |
315 VoteType::NewSeed => { |
307 None |
316 None |
308 }, |
317 }, |
309 VoteType::HedgehogsPerTeam(number) => { |
318 VoteType::HedgehogsPerTeam(number) => { |
310 match number { |
319 match number { |
311 1...8 => None, |
320 1...8 => None, |
312 _ => Some("/callvote hedgehogs: Specify number from 1 to 8.") |
321 _ => Some("/callvote hedgehogs: Specify number from 1 to 8.".to_string()) |
313 } |
322 } |
314 }, |
323 }, |
315 }; |
324 }; |
316 match error { |
325 match error { |
317 None => { |
326 None => { |
318 let msg = voting_description(&kind); |
327 let msg = voting_description(&kind); |
319 let voting = Voting::new(kind, server.room_clients(client_id)); |
328 let voting = Voting::new(kind, server.room_clients(client_id)); |
320 server.rooms[room_id].voting = Some(voting); |
329 server.rooms[room_id].voting = Some(voting); |
321 server.react(client_id, vec![ |
330 server.react(client_id, vec![ |
322 server_chat(&msg).send_all().in_room(room_id).action(), |
331 server_chat(msg).send_all().in_room(room_id).action(), |
323 AddVote{ vote: true, is_forced: false}]); |
332 AddVote{ vote: true, is_forced: false}]); |
324 } |
333 } |
325 Some(msg) => { |
334 Some(msg) => { |
326 server.react(client_id, vec![ |
335 server.react(client_id, vec![ |
327 server_chat(msg).send_self().action()]) |
336 server_chat(msg).send_self().action()]) |