Compare commits

...

2 commits

Author SHA1 Message Date
fa99261efc
fix(flake): automatically restart on death 2024-02-06 15:28:24 +09:00
e930eb2f82
fix: be more polite to ServerListPings 2024-02-06 15:26:38 +09:00
3 changed files with 20 additions and 1 deletions

View file

@ -125,6 +125,7 @@
Group = cfg.group;
ExecStart =
"${cfg.package}/bin/quiclime";
Restart = "on-failure";
};
environment = {

View file

@ -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?;

View file

@ -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];