Change gen_session_id to mcstatus' implementation
See 1aef08b293/mcstatus/querier.py (L21)
This commit is contained in:
parent
c39742a44f
commit
25ae6adda9
@ -8,6 +8,9 @@ edition = "2018"
|
|||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rand = "^0.8"
|
||||||
|
|
||||||
[dependencies.tokio]
|
[dependencies.tokio]
|
||||||
version = "^1.0"
|
version = "^1.0"
|
||||||
features = ["net", "time"]
|
features = ["net", "time"]
|
||||||
|
@ -44,15 +44,9 @@ use tokio::{
|
|||||||
pub const SESSION_ID_MASK: u32 = 0x0F0F0F0F;
|
pub const SESSION_ID_MASK: u32 = 0x0F0F0F0F;
|
||||||
const REQUEST_HEADER: [u8; 2] = [0xFE, 0xFD];
|
const REQUEST_HEADER: [u8; 2] = [0xFE, 0xFD];
|
||||||
|
|
||||||
static mut SESSION_ID_COUNTER: u16 = 0;
|
|
||||||
|
|
||||||
fn gen_session_id() -> u32 {
|
fn gen_session_id() -> u32 {
|
||||||
unsafe {
|
|
||||||
SESSION_ID_COUNTER = SESSION_ID_COUNTER.wrapping_add(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut session_id_bytes = [0; 4];
|
let mut session_id_bytes = [0; 4];
|
||||||
for (i, b) in unsafe { SESSION_ID_COUNTER }.to_be_bytes().iter().enumerate() {
|
for (i, b) in rand::random::<u16>().to_be_bytes().iter().enumerate() {
|
||||||
session_id_bytes[i * 2] = b >> 4;
|
session_id_bytes[i * 2] = b >> 4;
|
||||||
session_id_bytes[i * 2 + 1] = b & 0x0F;
|
session_id_bytes[i * 2 + 1] = b & 0x0F;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user