Browse Source

Minor fix to LoginResponse parsing, other tiny cleanups.

wip
Titouan Rigoudy 9 years ago
parent
commit
5e1c019de8
2 changed files with 8 additions and 5 deletions
  1. +3
    -4
      src/proto/packet.rs
  2. +5
    -1
      src/proto/server.rs

+ 3
- 4
src/proto/packet.rs View File

@ -95,7 +95,7 @@ impl Packet {
pub fn finalize(mut self) -> Vec<u8> {
let bytes_len = (self.bytes.len() - U32_SIZE) as u32;
{
let mut first_word = &mut self.bytes[..4];
let mut first_word = &mut self.bytes[..U32_SIZE];
first_word.write_u32::<LittleEndian>(bytes_len).unwrap();
}
self.bytes
@ -116,9 +116,8 @@ impl io::Read for Packet {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut slice = &self.bytes[self.cursor..];
let result = slice.read(buf);
match result {
Ok(num_bytes_read) => self.cursor += num_bytes_read,
Err(_) => ()
if let Ok(num_bytes_read) = result {
self.cursor += num_bytes_read
}
result
}


+ 5
- 1
src/proto/server.rs View File

@ -143,6 +143,10 @@ impl LoginResponse {
let resp = if ok {
let motd = try!(packet.read_str());
let ip = net::Ipv4Addr::from(try!(packet.read_uint()));
match packet.read_bool() {
Ok(value) => debug!("LoginResponse last field: {}", value),
Err(e) => debug!("Error reading LoginResponse field: {:?}", e),
}
LoginResponse::LoginOk {
motd: motd,
ip: ip,
@ -150,7 +154,7 @@ impl LoginResponse {
}
} else {
LoginResponse::LoginFail {
reason: try!(packet.read_str()).to_string()
reason: try!(packet.read_str())
}
};
Ok(resp)


Loading…
Cancel
Save