237 if let (c, Some(r)) = server.client_and_room(client_id) { |
237 if let (c, Some(r)) = server.client_and_room(client_id) { |
238 if c.teams_in_game > 0 { |
238 if c.teams_in_game > 0 { |
239 let decoding = decode(&em[..]).unwrap(); |
239 let decoding = decode(&em[..]).unwrap(); |
240 let messages = by_msg(&decoding); |
240 let messages = by_msg(&decoding); |
241 let valid = messages.clone().filter(|m| is_msg_valid(m, &c.team_indices)); |
241 let valid = messages.clone().filter(|m| is_msg_valid(m, &c.team_indices)); |
242 let _non_empty = messages.filter(|m| !is_msg_empty(m)); |
242 let non_empty = messages.filter(|m| !is_msg_empty(m)); |
243 let _last_valid_timed_msg = valid.clone().scan(None, |res, msg| match msg { |
243 let last_msg = valid.clone().scan(None, |res, msg| match msg { |
244 [_, b'+', ..] => Some(msg), |
244 [_, b'+', ..] => Some(msg), |
245 [_, typ, ..] if NON_TIMED_MESSAGES.contains(typ) => *res, |
245 [_, typ, ..] if NON_TIMED_MESSAGES.contains(typ) => *res, |
246 _ => None |
246 _ => None |
247 }).next(); |
247 }).next().map(|s| encode(s)); |
248 |
248 |
249 let em_response = encode(&valid.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
249 let em_response = encode(&valid.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
250 if !em_response.is_empty() { |
250 if !em_response.is_empty() { |
251 actions.push(ForwardEngineMessage(em_response) |
251 actions.push(ForwardEngineMessage(em_response) |
252 .send_all().in_room(r.id).but_self().action()); |
252 .send_all().in_room(r.id).but_self().action()); |
|
253 } |
|
254 let em_log = encode(&non_empty.flat_map(|msg| msg).cloned().collect::<Vec<_>>()); |
|
255 if let Some(ref mut info) = r.game_info { |
|
256 info.msg_log.push_str(&em_log); |
|
257 if last_msg.is_some() { |
|
258 info.last_msg = last_msg; |
|
259 } |
253 } |
260 } |
254 } |
261 } |
255 } |
262 } |
256 server.react(client_id, actions) |
263 server.react(client_id, actions) |
257 } |
264 } |