mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-05-06 07:17:27 +00:00
fix(minecraft java): EncoderException error when timestamp not included (#255)
This commit is contained in:
commit
a5f15a040a
1 changed files with 10 additions and 4 deletions
|
|
@ -11,6 +11,7 @@ use crate::{
|
|||
use byteorder::LittleEndian;
|
||||
use serde_json::Value;
|
||||
use std::net::SocketAddr;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
pub struct Java {
|
||||
socket: TcpSocket,
|
||||
|
|
@ -83,10 +84,15 @@ impl Java {
|
|||
}
|
||||
|
||||
fn send_ping_request(&mut self) -> GDResult<()> {
|
||||
self.send(
|
||||
[0x01] // Packet ID (1)
|
||||
.to_vec(),
|
||||
)?;
|
||||
let timestamp = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_millis() as i64;
|
||||
|
||||
let mut payload = [0x01].to_vec(); // Packet ID (1)
|
||||
payload.extend_from_slice(×tamp.to_be_bytes()); // Timestamp (long, 8 bytes)
|
||||
|
||||
self.send(payload)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue