--- a/rust/hedgewars-server/src/protocol.rs Fri Apr 12 22:36:54 2019 +0300
+++ b/rust/hedgewars-server/src/protocol.rs Fri Apr 12 23:16:44 2019 +0300
@@ -11,7 +11,6 @@
pub struct ProtocolDecoder {
buf: netbuf::Buf,
- consumed: usize,
is_recovering: bool,
}
@@ -19,7 +18,6 @@
pub fn new() -> ProtocolDecoder {
ProtocolDecoder {
buf: netbuf::Buf::new(),
- consumed: 0,
is_recovering: false,
}
}
@@ -48,19 +46,16 @@
pub fn extract_messages(&mut self) -> Vec<messages::HWProtocolMessage> {
let mut messages = vec![];
- let mut consumed = 0;
if !self.is_recovering {
loop {
- match parser::message(&self.buf[consumed..]) {
+ match parser::message(&self.buf[..]) {
Ok((tail, message)) => {
messages.push(message);
- consumed += self.buf.len() - tail.len();
+ self.buf.consume(self.buf.len() - tail.len());
}
Err(nom::Err::Incomplete(_)) => break,
Err(nom::Err::Failure(e)) | Err(nom::Err::Error(e)) => {
debug!("Invalid message: {:?}", e);
- self.buf.consume(consumed);
- consumed = 0;
if !self.recover() || self.buf.is_empty() {
break;
}
@@ -68,7 +63,6 @@
}
}
}
- self.buf.consume(consumed);
messages
}
}
--- a/rust/hedgewars-server/src/server/handlers.rs Fri Apr 12 22:36:54 2019 +0300
+++ b/rust/hedgewars-server/src/server/handlers.rs Fri Apr 12 23:16:44 2019 +0300
@@ -207,7 +207,7 @@
response.remove_client(client_id);
}
}
- } else {
+ } else if server.clients.contains(client_id) {
match message {
HWProtocolMessage::Quit(Some(msg)) => {
common::remove_client(server, response, "User quit: ".to_string() + &msg);
--- a/rust/hedgewars-server/src/server/network.rs Fri Apr 12 22:36:54 2019 +0300
+++ b/rust/hedgewars-server/src/server/network.rs Fri Apr 12 23:16:44 2019 +0300
@@ -498,9 +498,7 @@
Ok((messages, state)) => {
for message in messages {
debug!("Handling message {:?} for client {}", message, client_id);
- if self.server.clients.contains(client_id) {
- handlers::handle(&mut self.server, client_id, &mut response, message);
- }
+ handlers::handle(&mut self.server, client_id, &mut response, message);
}
match state {
NetworkClientState::NeedsRead => {