pub fn recv_packet_from_server(&mut self) -> Option<buffer::Buffer> {
        match self.get_packet_header() {
            Some(mut p) => {
                //check kill byte or blank packet
                if p.data[0] == 255 || p.data[3] == 0 && p.data[4] == 0 {
                    return None;
                }
                let mut bytes_read = 5; //we already have the header, read the data
                let goal_bytes = p.data.len();
                'z: loop {
                    if self.stream_killed == true {
                        return None;
                    }
                    match self.stream().read(&mut p.data[bytes_read..goal_bytes]) {
                        Ok(read) => {
                            bytes_read += read;
                            if bytes_read == goal_bytes {
                                break 'z; //we have the full packet
                            }
                        }
                        Err(e) => {
                            match e.kind() {
                                ErrorKind::ConnectionReset => (),
                                _ => {
                                    eprintln!(
                                        "NetFactory::recv_packet: Error reading packet: {}",
                                        e
                                    );
                                }
                            };
                            break 'z;
                        }
                    };
                }
                return Some(p)
            }
            None => return None,
        }
    }
/// Reads a packet from the server
Reads a packet from the server
Reads a packet from the server
pub fn recv_packet_from_server(&mut self) -> Option<buffer::Buffer> {
        match self.get_packet_header() {
            Some(mut p) => {
                //check kill byte or blank packet
                if p.data[0] == 255 || p.data[3] == 0 && p.data[4] == 0 {
                    return None;
                }
                let mut bytes_read = 5; //we already have the header, read the data
                let goal_bytes = p.data.len();
                'z: loop {
                    if self.stream_killed == true {
                        return None;
                    }
                    match self.stream().read(&mut p.data[bytes_read..goal_bytes]) {
                        Ok(read) => {
                            bytes_read += read;
                            if bytes_read == goal_bytes {
                                break 'z; //we have the full packet
                            }
                        }
                        Err(e) => {
                            match e.kind() {
                                ErrorKind::ConnectionReset => (),
                                _ => {
                                    eprintln!(
                                        "NetFactory::recv_packet: Error reading packet: {}",
                                        e
                                    );
                                }
                            };
                            break 'z;
                        }
                    };
                }
                return Some(p)
            }
            None => return None,
        }
    }
pub fn recv_packet_from_server ( & mut self ) -> Option < buffer :: Buffer > { match self . get_packet_header ( ) { Some ( mut p ) => { //check kill byte or blank packet if p . data [ 0 ] == 255 || p . data [ 3 ] == 0 && p . data [ 4 ] == 0 { return None ; } let mut bytes_read = 5 ; //we already have the header, read the data let goal_bytes = p . data . len ( ) ; ' z : loop { if self . stream_killed == true { return None ; } match self . stream ( ) . read ( & mut p . data [ bytes_read .. goal_bytes ] ) { Ok ( read ) => { bytes_read += read ; if bytes_read == goal_bytes { break ' z ; //we have the full packet } } Err ( e ) => { match e . kind ( ) { ErrorKind :: ConnectionReset => ( ) , _ => { eprintln ! ( " " e ) ; } } ; break ' z ; } } ; } return Some ( p ) } None => return None , } }
Reads a packet from the server
Reads a packet from the server
&mut self
&mut self