adopt proposed alternative name for cached data
This commit is contained in:
parent
8bf8ba14da
commit
d68a25b169
@ -10,33 +10,49 @@ use pumpkin_protocol::{
|
||||
|
||||
use super::CURRENT_MC_VERSION;
|
||||
|
||||
pub struct BikeShedServerListing {
|
||||
pub struct CachedStatus {
|
||||
_status_response: StatusResponse,
|
||||
// We cache the json response here so we don't parse it every time someone makes a Status request.
|
||||
// Keep in mind that we must parse this again, when the StatusResponse changes which usually happen when a player joins or leaves
|
||||
status_response_json: String,
|
||||
}
|
||||
|
||||
pub struct CachedBranding {
|
||||
/// Cached Server brand buffer so we don't have to rebuild them every time a player joins
|
||||
cached_server_brand: Vec<u8>,
|
||||
}
|
||||
|
||||
impl BikeShedServerListing {
|
||||
impl CachedBranding {
|
||||
pub fn new() -> CachedBranding {
|
||||
let cached_server_brand = Self::build_brand();
|
||||
CachedBranding {
|
||||
cached_server_brand,
|
||||
}
|
||||
}
|
||||
pub fn get_branding(&self) -> CPluginMessage {
|
||||
CPluginMessage::new("minecraft:brand", &self.cached_server_brand)
|
||||
}
|
||||
fn build_brand() -> Vec<u8> {
|
||||
let brand = "Pumpkin";
|
||||
let mut buf = vec![];
|
||||
let _ = VarInt(brand.len() as i32).encode(&mut buf);
|
||||
buf.extend_from_slice(brand.as_bytes());
|
||||
buf
|
||||
}
|
||||
}
|
||||
|
||||
impl CachedStatus {
|
||||
pub fn new() -> Self {
|
||||
let status_response = Self::build_response(&BASIC_CONFIG);
|
||||
let status_response_json = serde_json::to_string(&status_response)
|
||||
.expect("Failed to parse Status response into JSON");
|
||||
let cached_server_brand = Self::build_brand();
|
||||
|
||||
BikeShedServerListing {
|
||||
CachedStatus {
|
||||
_status_response: status_response,
|
||||
status_response_json,
|
||||
cached_server_brand,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_branding(&self) -> CPluginMessage {
|
||||
CPluginMessage::new("minecraft:brand", &self.cached_server_brand)
|
||||
}
|
||||
|
||||
pub fn get_status(&self) -> CStatusResponse<'_> {
|
||||
CStatusResponse::new(&self.status_response_json)
|
||||
}
|
||||
@ -83,12 +99,4 @@ impl BikeShedServerListing {
|
||||
general_purpose::STANDARD.encode_string(image, &mut result);
|
||||
result
|
||||
}
|
||||
|
||||
fn build_brand() -> Vec<u8> {
|
||||
let brand = "Pumpkin";
|
||||
let mut buf = vec![];
|
||||
let _ = VarInt(brand.len() as i32).encode(&mut buf);
|
||||
buf.extend_from_slice(brand.as_bytes());
|
||||
buf
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
use connection_cache::{CachedBranding, CachedStatus};
|
||||
use key_store::KeyStore;
|
||||
use bikeshed_server_listing::BikeShedServerListing;
|
||||
use mio::Token;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use pumpkin_config::BASIC_CONFIG;
|
||||
@ -31,11 +31,14 @@ use crate::{
|
||||
world::World,
|
||||
};
|
||||
|
||||
mod connection_cache;
|
||||
mod key_store;
|
||||
pub const CURRENT_MC_VERSION: &str = "1.21.1";
|
||||
|
||||
pub struct Server {
|
||||
key_store: KeyStore,
|
||||
server_listing: CachedStatus,
|
||||
server_branding: CachedBranding,
|
||||
pub plugin_loader: PluginLoader,
|
||||
|
||||
pub command_dispatcher: Arc<CommandDispatcher<'static>>,
|
||||
@ -57,7 +60,6 @@ impl Server {
|
||||
pub fn new() -> Self {
|
||||
// TODO: only create when needed
|
||||
|
||||
let server_listing = BikeShedServerListing::new();
|
||||
let auth_client = if BASIC_CONFIG.online_mode {
|
||||
Some(
|
||||
reqwest::Client::builder()
|
||||
@ -89,7 +91,8 @@ impl Server {
|
||||
command_dispatcher: Arc::new(command_dispatcher),
|
||||
auth_client,
|
||||
key_store: KeyStore::new(),
|
||||
server_listing,
|
||||
server_listing: CachedStatus::new(),
|
||||
server_branding: CachedBranding::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,7 +150,7 @@ impl Server {
|
||||
}
|
||||
|
||||
pub fn get_branding(&self) -> CPluginMessage<'_> {
|
||||
self.server_listing.get_branding()
|
||||
self.server_branding.get_branding()
|
||||
}
|
||||
|
||||
pub fn get_status(&self) -> CStatusResponse<'_> {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user