From ec81b13385071c6dbfe97eba3680ab3abb1eb81d Mon Sep 17 00:00:00 2001 From: Kyler <59854022+KylerOlsen@users.noreply.github.com> Date: Mon, 3 Jun 2024 00:52:43 -0600 Subject: [PATCH] Added info_messages.rs and moved string literals to it --- src/client.rs | 5 ++--- src/info_messages.rs | 29 +++++++++++++++++++++++++++++ src/main.rs | 1 + src/status_handle.rs | 5 +++-- src/whitelist.rs | 28 ++++++++++++---------------- 5 files changed, 47 insertions(+), 21 deletions(-) create mode 100644 src/info_messages.rs diff --git a/src/client.rs b/src/client.rs index 27ad9ff..0efd35f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -12,6 +12,7 @@ use purple_cello_mc_protocol::{ use crate::status_handle; use crate::login_handle; use crate::listener; +use crate::info_messages; pub async fn handle_client( client_socket: TcpStream, @@ -80,9 +81,7 @@ pub async fn handle_client( } None => { login::clientbound::Disconnect { - reason: "\"Server Error (Server is down or \ -restarting)\nPlease contact the admins if the issue persists:\n\ -purplecelloserver@gmail.com\"" + reason: info_messages::BACKEND_DOWN_DISCONNECT .to_string() } .write(&mut client_conn) diff --git a/src/info_messages.rs b/src/info_messages.rs new file mode 100644 index 0000000..dc6872c --- /dev/null +++ b/src/info_messages.rs @@ -0,0 +1,29 @@ +// Yeahbut June 2024 + +pub const BACKEND_DOWN_PING: &str = "\ +Server Error (Server may be starting)\n\ +Purple Cello Server"; + +pub const BACKEND_DOWN_DISCONNECT: &str = "\ +\"Server Error (Server is down or restarting)\n\ +Please contact the admins if the issue persists:\n\ +purplecelloserver@gmail.com\""; + +pub const UUID_MISSING_DISCONNECT: &str = "Invalid UUID! (UUID Missing)"; + +pub const WHITELIST_STATUS_INACTIVE_DISCONNECT: &str = "\ +Whitelist Status Inactive!\n\ +Please contact the admins to reactivate:\n\ +purplecelloserver@gmail.com"; + +pub const USERNAME_INVALID_DISCONNECT: &str = "\ +Invalid Username!\n\ +Please contact the admins to update your username:\n\ +purplecelloserver@gmail.com"; + +pub const UUID_INVALID_DISCONNECT: &str = "Invalid UUID!"; + +pub const NOT_WHITELISTED_DISCONNECT: &str = "\ +Not whitelisted on this server.\n\ +Please direct whitelist requests to the admins:\n\ +purplecelloserver@gmail.com"; diff --git a/src/main.rs b/src/main.rs index 709bb14..b89cf14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ mod login_handle; mod client; mod listener; mod whitelist; +mod info_messages; #[tokio::main] async fn main() -> Result<(), Box> { diff --git a/src/status_handle.rs b/src/status_handle.rs index 62438ac..dfb2570 100644 --- a/src/status_handle.rs +++ b/src/status_handle.rs @@ -18,6 +18,7 @@ use purple_cello_mc_protocol::{ }; use crate::listener; +use crate::info_messages; const EXPIRATION_DURATION: Duration = Duration::from_secs(3600); @@ -187,8 +188,8 @@ pub async fn respond_status( protocol: 0, }, description: mc_types::Chat { - text: "Server Error (Server may be starting)" - .to_string() + "\nPurple Cello Server", + text: info_messages::BACKEND_DOWN_PING + .to_string(), }, players: status::clientbound::StatusPlayers { max: 0, diff --git a/src/whitelist.rs b/src/whitelist.rs index 4c518de..0c5afc7 100644 --- a/src/whitelist.rs +++ b/src/whitelist.rs @@ -2,11 +2,11 @@ use std::fs; use std::time::{Duration, Instant}; - use serde_json::Value; -const EXPIRATION_DURATION: Duration = Duration::from_secs(10); -// const EXPIRATION_DURATION: Duration = Duration::from_secs(60); +use crate::info_messages; + +const EXPIRATION_DURATION: Duration = Duration::from_secs(60); #[derive(PartialEq)] pub struct Player { @@ -146,7 +146,7 @@ impl WhitelistFile { if player.player_uuid.is_none() { return PlayerAllowed::False( - "Invalid UUID (UUID Missing)".to_string()); + info_messages::UUID_MISSING_DISCONNECT.to_string()); } let whitelist = self.get_whitelist(); @@ -173,21 +173,17 @@ impl WhitelistFile { } if is_inactive { - PlayerAllowed::False("Whitelist Status Inactive!\n\ -Please contact the admins to reactivate:\n\ -purplecelloserver@gmail.com".to_string() - ) + PlayerAllowed::False( + info_messages::WHITELIST_STATUS_INACTIVE_DISCONNECT.to_string()) } else if invalid_username { - PlayerAllowed::False("Invalid Username!\n\ -Please contact the admins to update your username:\n\ -purplecelloserver@gmail.com".to_string() - ) + PlayerAllowed::False( + info_messages::USERNAME_INVALID_DISCONNECT.to_string()) } else if invalid_uuid { - PlayerAllowed::False("Invalid UUID".to_string()) + PlayerAllowed::False( + info_messages::UUID_INVALID_DISCONNECT.to_string()) } else { - PlayerAllowed::False("Not whitelisted on this server.\n\ -Please direct whitelist requests to the admins:\n\ -purplecelloserver@gmail.com".to_string()) + PlayerAllowed::False( + info_messages::NOT_WHITELISTED_DISCONNECT.to_string()) } }