mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-31 08:22:33 +00:00
parse protocol version
one thing less to care about when porting
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"version": 770,
|
||||
"serverbound": {
|
||||
"handshake": [
|
||||
"intention"
|
||||
|
||||
@@ -6,6 +6,7 @@ use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Packets {
|
||||
version: u32,
|
||||
serverbound: HashMap<String, Vec<String>>,
|
||||
clientbound: HashMap<String, Vec<String>>,
|
||||
}
|
||||
@@ -15,10 +16,14 @@ pub(crate) fn build() -> TokenStream {
|
||||
|
||||
let packets: Packets = serde_json::from_str(include_str!("../../assets/packets.json"))
|
||||
.expect("Failed to parse packets.json");
|
||||
let version = packets.version;
|
||||
let serverbound_consts = parse_packets(packets.serverbound);
|
||||
let clientbound_consts = parse_packets(packets.clientbound);
|
||||
|
||||
quote!(
|
||||
/// The current Minecraft protocol version. This changes only when the protocol itself is modified.
|
||||
pub const CURRENT_MC_PROTOCOL: u32 = #version;
|
||||
|
||||
pub mod serverbound {
|
||||
#serverbound_consts
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use std::{
|
||||
io::{Read, Write},
|
||||
marker::PhantomData,
|
||||
num::NonZeroU16,
|
||||
};
|
||||
|
||||
use aes::cipher::{BlockDecryptMut, BlockEncryptMut, BlockSizeUser, generic_array::GenericArray};
|
||||
@@ -27,10 +26,6 @@ pub mod ser;
|
||||
#[cfg(feature = "serverbound")]
|
||||
pub mod server;
|
||||
|
||||
/// The current Minecraft protocol number.
|
||||
/// Don't forget to change this when porting.
|
||||
pub const CURRENT_MC_PROTOCOL: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(770) };
|
||||
|
||||
pub const MAX_PACKET_SIZE: u64 = 2097152;
|
||||
pub const MAX_PACKET_DATA_SIZE: usize = 8388608;
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
use async_trait::async_trait;
|
||||
use pumpkin_protocol::CURRENT_MC_PROTOCOL;
|
||||
use pumpkin_data::packet::CURRENT_MC_PROTOCOL;
|
||||
use pumpkin_util::text::click::ClickEvent;
|
||||
use pumpkin_util::text::hover::HoverEvent;
|
||||
use pumpkin_util::text::{TextComponent, color::NamedColor};
|
||||
use std::borrow::Cow;
|
||||
|
||||
use crate::server::CURRENT_MC_VERSION;
|
||||
use crate::{
|
||||
GIT_VERSION,
|
||||
command::{
|
||||
CommandError, CommandExecutor, CommandSender, args::ConsumedArgs, tree::CommandTree,
|
||||
},
|
||||
server::CURRENT_MC_VERSION,
|
||||
};
|
||||
|
||||
const NAMES: [&str; 2] = ["pumpkin", "version"];
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
compile_error!("Compiling for WASI targets is not supported!");
|
||||
|
||||
use plugin::PluginManager;
|
||||
use pumpkin_data::packet::CURRENT_MC_PROTOCOL;
|
||||
use std::{
|
||||
io::{self},
|
||||
sync::LazyLock,
|
||||
@@ -49,7 +50,6 @@ use tokio::sync::Mutex;
|
||||
|
||||
use crate::server::CURRENT_MC_VERSION;
|
||||
use pumpkin::{PumpkinServer, SHOULD_STOP, STOP_INTERRUPT, init_log, stop_server};
|
||||
use pumpkin_protocol::CURRENT_MC_PROTOCOL;
|
||||
use pumpkin_util::text::{TextComponent, color::NamedColor};
|
||||
use std::time::Instant;
|
||||
// Setup some tokens to allow us to identify which event is for which socket.
|
||||
@@ -92,7 +92,6 @@ async fn main() {
|
||||
.thread_name(|_| "rayon-worker".to_string())
|
||||
.build_global()
|
||||
.expect("Rayon thread pool can only be initialized once");
|
||||
|
||||
log::info!(
|
||||
"Starting Pumpkin {CARGO_PKG_VERSION} ({GIT_VERSION}) for Minecraft {CURRENT_MC_VERSION} (Protocol {CURRENT_MC_PROTOCOL})",
|
||||
);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::num::NonZeroI32;
|
||||
|
||||
use pumpkin_protocol::{CURRENT_MC_PROTOCOL, ConnectionState, server::handshake::SHandShake};
|
||||
use pumpkin_data::packet::CURRENT_MC_PROTOCOL;
|
||||
use pumpkin_protocol::{ConnectionState, server::handshake::SHandShake};
|
||||
use pumpkin_util::text::TextComponent;
|
||||
|
||||
use crate::{net::Client, server::CURRENT_MC_VERSION};
|
||||
@@ -16,7 +15,7 @@ impl Client {
|
||||
self.connection_state.store(handshake.next_state);
|
||||
if self.connection_state.load() != ConnectionState::Status {
|
||||
let protocol = version;
|
||||
match protocol.cmp(&NonZeroI32::from(CURRENT_MC_PROTOCOL).get()) {
|
||||
match protocol.cmp(&(CURRENT_MC_PROTOCOL as i32)) {
|
||||
std::cmp::Ordering::Less => {
|
||||
self.kick(TextComponent::translate(
|
||||
"multiplayer.disconnect.outdated_client",
|
||||
|
||||
@@ -2,14 +2,14 @@ use core::error;
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{Cursor, Read},
|
||||
num::NonZeroU32,
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use base64::{Engine as _, engine::general_purpose};
|
||||
use pumpkin_config::{BASIC_CONFIG, BasicConfiguration};
|
||||
use pumpkin_data::packet::CURRENT_MC_PROTOCOL;
|
||||
use pumpkin_protocol::{
|
||||
CURRENT_MC_PROTOCOL, Players, StatusResponse, Version,
|
||||
Players, StatusResponse, Version,
|
||||
client::{config::CPluginMessage, status::CStatusResponse},
|
||||
codec::{Codec, var_int::VarInt},
|
||||
};
|
||||
@@ -144,7 +144,7 @@ impl CachedStatus {
|
||||
StatusResponse {
|
||||
version: Some(Version {
|
||||
name: CURRENT_MC_VERSION.into(),
|
||||
protocol: NonZeroU32::from(CURRENT_MC_PROTOCOL).get(),
|
||||
protocol: CURRENT_MC_PROTOCOL,
|
||||
}),
|
||||
players: Some(Players {
|
||||
max: config.max_players,
|
||||
|
||||
@@ -12,7 +12,7 @@ pub fn is_april() -> bool {
|
||||
|
||||
#[must_use]
|
||||
pub fn modify_chat_message(message: &str) -> Option<String> {
|
||||
if !advanced_config().fun.april_fools && is_april() {
|
||||
if !advanced_config().fun.april_fools || !is_april() {
|
||||
return None;
|
||||
}
|
||||
let mut words: Vec<&str> = message.split_whitespace().collect();
|
||||
|
||||
Reference in New Issue
Block a user