Added info_messages.rs and moved string literals to it

This commit is contained in:
Kyler 2024-06-03 00:52:43 -06:00
parent 2e067be5af
commit ec81b13385
5 changed files with 47 additions and 21 deletions

View File

@ -12,6 +12,7 @@ use purple_cello_mc_protocol::{
use crate::status_handle; use crate::status_handle;
use crate::login_handle; use crate::login_handle;
use crate::listener; use crate::listener;
use crate::info_messages;
pub async fn handle_client( pub async fn handle_client(
client_socket: TcpStream, client_socket: TcpStream,
@ -80,9 +81,7 @@ pub async fn handle_client(
} }
None => { None => {
login::clientbound::Disconnect { login::clientbound::Disconnect {
reason: "\"Server Error (Server is down or \ reason: info_messages::BACKEND_DOWN_DISCONNECT
restarting)\nPlease contact the admins if the issue persists:\n\
purplecelloserver@gmail.com\""
.to_string() .to_string()
} }
.write(&mut client_conn) .write(&mut client_conn)

29
src/info_messages.rs Normal file
View File

@ -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";

View File

@ -9,6 +9,7 @@ mod login_handle;
mod client; mod client;
mod listener; mod listener;
mod whitelist; mod whitelist;
mod info_messages;
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> { async fn main() -> Result<(), Box<dyn Error>> {

View File

@ -18,6 +18,7 @@ use purple_cello_mc_protocol::{
}; };
use crate::listener; use crate::listener;
use crate::info_messages;
const EXPIRATION_DURATION: Duration = Duration::from_secs(3600); const EXPIRATION_DURATION: Duration = Duration::from_secs(3600);
@ -187,8 +188,8 @@ pub async fn respond_status(
protocol: 0, protocol: 0,
}, },
description: mc_types::Chat { description: mc_types::Chat {
text: "Server Error (Server may be starting)" text: info_messages::BACKEND_DOWN_PING
.to_string() + "\nPurple Cello Server", .to_string(),
}, },
players: status::clientbound::StatusPlayers { players: status::clientbound::StatusPlayers {
max: 0, max: 0,

View File

@ -2,11 +2,11 @@
use std::fs; use std::fs;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use serde_json::Value; use serde_json::Value;
const EXPIRATION_DURATION: Duration = Duration::from_secs(10); use crate::info_messages;
// const EXPIRATION_DURATION: Duration = Duration::from_secs(60);
const EXPIRATION_DURATION: Duration = Duration::from_secs(60);
#[derive(PartialEq)] #[derive(PartialEq)]
pub struct Player { pub struct Player {
@ -146,7 +146,7 @@ impl WhitelistFile {
if player.player_uuid.is_none() { if player.player_uuid.is_none() {
return PlayerAllowed::False( return PlayerAllowed::False(
"Invalid UUID (UUID Missing)".to_string()); info_messages::UUID_MISSING_DISCONNECT.to_string());
} }
let whitelist = self.get_whitelist(); let whitelist = self.get_whitelist();
@ -173,21 +173,17 @@ impl WhitelistFile {
} }
if is_inactive { if is_inactive {
PlayerAllowed::False("Whitelist Status Inactive!\n\ PlayerAllowed::False(
Please contact the admins to reactivate:\n\ info_messages::WHITELIST_STATUS_INACTIVE_DISCONNECT.to_string())
purplecelloserver@gmail.com".to_string()
)
} else if invalid_username { } else if invalid_username {
PlayerAllowed::False("Invalid Username!\n\ PlayerAllowed::False(
Please contact the admins to update your username:\n\ info_messages::USERNAME_INVALID_DISCONNECT.to_string())
purplecelloserver@gmail.com".to_string()
)
} else if invalid_uuid { } else if invalid_uuid {
PlayerAllowed::False("Invalid UUID".to_string()) PlayerAllowed::False(
info_messages::UUID_INVALID_DISCONNECT.to_string())
} else { } else {
PlayerAllowed::False("Not whitelisted on this server.\n\ PlayerAllowed::False(
Please direct whitelist requests to the admins:\n\ info_messages::NOT_WHITELISTED_DISCONNECT.to_string())
purplecelloserver@gmail.com".to_string())
} }
} }