329 } |
329 } |
330 server.react(client_id, actions); |
330 server.react(client_id, actions); |
331 } |
331 } |
332 AddVote{vote, is_forced} => { |
332 AddVote{vote, is_forced} => { |
333 let mut actions = Vec::new(); |
333 let mut actions = Vec::new(); |
334 if let (c, Some(r)) = server.client_and_room(client_id) { |
334 if let Some(r) = server.room(client_id) { |
335 let mut result = None; |
335 let mut result = None; |
336 if let Some(ref mut voting) = r.voting { |
336 if let Some(ref mut voting) = r.voting { |
337 if is_forced || voting.votes.iter().find(|(id, _)| client_id == *id).is_none() { |
337 if is_forced || voting.votes.iter().find(|(id, _)| client_id == *id).is_none() { |
338 actions.push(server_chat("Your vote has been counted.").send_self().action()); |
338 actions.push(server_chat("Your vote has been counted.".to_string()) |
|
339 .send_self().action()); |
339 voting.votes.push((client_id, vote)); |
340 voting.votes.push((client_id, vote)); |
340 let i = voting.votes.iter(); |
341 let i = voting.votes.iter(); |
341 let pro = i.clone().filter(|(_, v)| *v).count(); |
342 let pro = i.clone().filter(|(_, v)| *v).count(); |
342 let contra = i.filter(|(_, v)| !*v).count(); |
343 let contra = i.filter(|(_, v)| !*v).count(); |
343 let success_quota = voting.voters.len() / 2 + 1; |
344 let success_quota = voting.voters.len() / 2 + 1; |
345 result = Some(true); |
346 result = Some(true); |
346 } else if is_forced && !vote || contra > voting.voters.len() - success_quota { |
347 } else if is_forced && !vote || contra > voting.voters.len() - success_quota { |
347 result = Some(false); |
348 result = Some(false); |
348 } |
349 } |
349 } else { |
350 } else { |
350 actions.push(server_chat("You already have voted.").send_self().action()); |
351 actions.push(server_chat("You already have voted.".to_string()) |
|
352 .send_self().action()); |
351 } |
353 } |
352 } else { |
354 } else { |
353 actions.push(server_chat("There's no voting going on.").send_self().action()); |
355 actions.push(server_chat("There's no voting going on.".to_string()) |
|
356 .send_self().action()); |
354 } |
357 } |
355 |
358 |
356 if let Some(res) = result { |
359 if let Some(res) = result { |
357 actions.push(server_chat("Voting closed.") |
360 actions.push(server_chat("Voting closed.".to_string()) |
358 .send_all().in_room(r.id).action()); |
361 .send_all().in_room(r.id).action()); |
359 let voting = replace(&mut r.voting, None).unwrap(); |
362 let voting = replace(&mut r.voting, None).unwrap(); |
360 if res { |
363 if res { |
361 actions.push(ApplyVoting(voting.kind, r.id)); |
364 actions.push(ApplyVoting(voting.kind, r.id)); |
362 } |
365 } |
376 actions.push(Kicked.send_self().action()); |
379 actions.push(Kicked.send_self().action()); |
377 actions.push(MoveToLobby("kicked".to_string())); |
380 actions.push(MoveToLobby("kicked".to_string())); |
378 } |
381 } |
379 } |
382 } |
380 }, |
383 }, |
381 VoteType::Map(_) => { |
384 VoteType::Map(None) => (), |
382 unimplemented!(); |
385 VoteType::Map(Some(name)) => { |
|
386 if let Some(location) = server.rooms[room_id].load_config(&name) { |
|
387 actions.push(server_chat(location.to_string()) |
|
388 .send_all().in_room(room_id).action()); |
|
389 actions.push(SendRoomUpdate(None)); |
|
390 for (_, c) in server.clients.iter() { |
|
391 if c.room_id == Some(room_id) { |
|
392 actions.push(SendRoomData{ |
|
393 to: c.id, teams: false, |
|
394 config: true, flags: false}) |
|
395 } |
|
396 } |
|
397 } |
383 }, |
398 }, |
384 VoteType::Pause => { |
399 VoteType::Pause => { |
385 if let Some(ref mut info) = server.rooms[room_id].game_info { |
400 if let Some(ref mut info) = server.rooms[room_id].game_info { |
386 info.is_paused = !info.is_paused; |
401 info.is_paused = !info.is_paused; |
387 actions.push(server_chat("Pause toggled.") |
402 actions.push(server_chat("Pause toggled.".to_string()) |
388 .send_all().in_room(room_id).action()); |
403 .send_all().in_room(room_id).action()); |
389 actions.push(ForwardEngineMessage(vec![to_engine_msg(once(b'I'))]) |
404 actions.push(ForwardEngineMessage(vec![to_engine_msg(once(b'I'))]) |
390 .send_all().in_room(room_id).action()); |
405 .send_all().in_room(room_id).action()); |
391 } |
406 } |
392 }, |
407 }, |
529 }; |
544 }; |
530 server.react(client_id, actions); |
545 server.react(client_id, actions); |
531 } |
546 } |
532 SendTeamRemovalMessage(team_name) => { |
547 SendTeamRemovalMessage(team_name) => { |
533 let mut actions = Vec::new(); |
548 let mut actions = Vec::new(); |
534 if let (c, Some(r)) = server.client_and_room(client_id) { |
549 if let Some(r) = server.room(client_id) { |
535 if let Some(ref mut info) = r.game_info { |
550 if let Some(ref mut info) = r.game_info { |
536 let msg = once(b'F').chain(team_name.bytes()); |
551 let msg = once(b'F').chain(team_name.bytes()); |
537 actions.push(ForwardEngineMessage(vec![to_engine_msg(msg)]). |
552 actions.push(ForwardEngineMessage(vec![to_engine_msg(msg)]). |
538 send_all().in_room(r.id).but_self().action()); |
553 send_all().in_room(r.id).but_self().action()); |
539 info.teams_in_game -= 1; |
554 info.teams_in_game -= 1; |