fix: be more polite to ServerListPings
				
					
				
			This commit is contained in:
		
							parent
							
								
									21e1d8431f
								
							
						
					
					
						commit
						e930eb2f82
					
				
					 2 changed files with 19 additions and 1 deletions
				
			
		
							
								
								
									
										14
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/main.rs
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -16,7 +16,7 @@ use tokio::{
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
use crate::{
 | 
			
		||||
    netty::WriteExtNetty,
 | 
			
		||||
    netty::{WriteExtNetty, ReadExtNetty},
 | 
			
		||||
    proto::{ClientboundControlMessage, ServerboundControlMessage},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -279,6 +279,18 @@ async fn politely_disconnect(
 | 
			
		|||
                .await?;
 | 
			
		||||
            connection.write_varint(buf.len() as i32).await?;
 | 
			
		||||
            connection.write_all(&buf).await?;
 | 
			
		||||
            let packet = netty::read_packet(&mut connection).await?;
 | 
			
		||||
            let mut packet = packet.as_slice();
 | 
			
		||||
            let id = packet.read_varint()?;
 | 
			
		||||
            if id != 1 {
 | 
			
		||||
                return Err(anyhow!("Packet isn't a Ping Request(0x01), but {:#04x}", id));
 | 
			
		||||
            }
 | 
			
		||||
            let payload = packet.read_long()?;
 | 
			
		||||
            let mut buf = Vec::with_capacity(1 + 8);
 | 
			
		||||
            buf.write_varint(1).await?;
 | 
			
		||||
            buf.write_u64(payload).await?;
 | 
			
		||||
            connection.write_varint(buf.len() as i32).await?;
 | 
			
		||||
            connection.write_all(&buf).await?;
 | 
			
		||||
        }
 | 
			
		||||
        netty::HandshakeType::Login => {
 | 
			
		||||
            let _ = netty::read_packet(&mut connection).await?;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,6 +39,12 @@ pub trait ReadExtNetty: Read {
 | 
			
		|||
        Ok(u16::from_be_bytes(buf))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn read_long(&mut self) -> Result<u64, NettyReadError> {
 | 
			
		||||
        let mut buf = [0u8; 8];
 | 
			
		||||
        self.read_exact(&mut buf)?;
 | 
			
		||||
        Ok(u64::from_be_bytes(buf))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn read_string(&mut self) -> Result<String, NettyReadError> {
 | 
			
		||||
        let len = self.read_varint()?;
 | 
			
		||||
        let mut buf = vec![0u8; len as usize];
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue