equal
deleted
inserted
replaced
1 use mio; |
1 use mio; |
2 |
2 |
3 use crate::{ |
3 use crate::{ |
4 server::{ |
4 server::{ |
5 coretypes::{ClientId, RoomId, Voting, VoteType}, |
5 coretypes::{ |
|
6 ClientId, RoomId, Voting, VoteType, |
|
7 MAX_HEDGEHOGS_PER_TEAM |
|
8 }, |
6 server::HWServer, |
9 server::HWServer, |
7 room::{HWRoom, RoomFlags}, |
10 room::{HWRoom, RoomFlags}, |
8 actions::{Action, Action::*} |
11 actions::{Action, Action::*} |
9 }, |
12 }, |
10 protocol::messages::{ |
13 protocol::messages::{ |
51 #[cfg(canhazslicepatterns)] |
54 #[cfg(canhazslicepatterns)] |
52 fn is_msg_valid(msg: &[u8], team_indices: &[u8]) -> bool { |
55 fn is_msg_valid(msg: &[u8], team_indices: &[u8]) -> bool { |
53 match msg { |
56 match msg { |
54 [size, typ, body..] => VALID_MESSAGES.contains(typ) |
57 [size, typ, body..] => VALID_MESSAGES.contains(typ) |
55 && match body { |
58 && match body { |
56 [1...8, team, ..] if *typ == b'h' => team_indices.contains(team), |
59 [1...MAX_HEDGEHOGS_PER_TEAM, team, ..] if *typ == b'h' => |
|
60 team_indices.contains(team), |
57 _ => *typ != b'h' |
61 _ => *typ != b'h' |
58 }, |
62 }, |
59 _ => false |
63 _ => false |
60 } |
64 } |
61 } |
65 } |
225 if let (c, Some(r)) = server.client_and_room(client_id) { |
229 if let (c, Some(r)) = server.client_and_room(client_id) { |
226 let addable_hedgehogs = r.addable_hedgehogs(); |
230 let addable_hedgehogs = r.addable_hedgehogs(); |
227 let actions = if let Some((_, team)) = r.find_team_and_owner_mut(|t| t.name == team_name) { |
231 let actions = if let Some((_, team)) = r.find_team_and_owner_mut(|t| t.name == team_name) { |
228 if !c.is_master() { |
232 if !c.is_master() { |
229 vec![ProtocolError("You're not the room master!".to_string())] |
233 vec![ProtocolError("You're not the room master!".to_string())] |
230 } else if number < 1 || number > 8 |
234 } else if number < 1 || number > MAX_HEDGEHOGS_PER_TEAM |
231 || number > addable_hedgehogs + team.hedgehogs_number { |
235 || number > addable_hedgehogs + team.hedgehogs_number { |
232 vec![HedgehogsNumber(team.name.clone(), team.hedgehogs_number) |
236 vec![HedgehogsNumber(team.name.clone(), team.hedgehogs_number) |
233 .send_self().action()] |
237 .send_self().action()] |
234 } else { |
238 } else { |
235 team.hedgehogs_number = number; |
239 team.hedgehogs_number = number; |
375 VoteType::NewSeed => { |
379 VoteType::NewSeed => { |
376 None |
380 None |
377 }, |
381 }, |
378 VoteType::HedgehogsPerTeam(number) => { |
382 VoteType::HedgehogsPerTeam(number) => { |
379 match number { |
383 match number { |
380 1...8 => None, |
384 1...MAX_HEDGEHOGS_PER_TEAM => None, |
381 _ => Some("/callvote hedgehogs: Specify number from 1 to 8.".to_string()) |
385 _ => Some("/callvote hedgehogs: Specify number from 1 to 8.".to_string()) |
382 } |
386 } |
383 }, |
387 }, |
384 }; |
388 }; |
385 match error { |
389 match error { |