Skip to content

Commit

Permalink
Translate authentication errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Jan 23, 2025
1 parent 7ec4cc7 commit c4364d5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions pumpkin-config/src/networking/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub struct AuthenticationConfig {
/// Whether to use Mojang authentication.
pub enabled: bool,
pub auth_url: Option<String>,
pub connect_timeout: u32,
pub read_timeout: u32,
pub prevent_proxy_connections: bool,
pub prevent_proxy_connection_auth_url: Option<String>,
/// Player profile handling.
Expand All @@ -24,6 +26,8 @@ impl Default for AuthenticationConfig {
textures: Default::default(),
auth_url: None,
prevent_proxy_connection_auth_url: None,
connect_timeout: 5000,
read_timeout: 5000,
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions pumpkin/src/net/packet/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,18 @@ impl Client {
.await
{
Ok(new_profile) => *profile = new_profile,
Err(e) => {
self.kick(&TextComponent::text(e.to_string())).await;
return;
Err(error) => {
self.kick(&match error {
AuthError::FailedResponse => {
TextComponent::translate("multiplayer.disconnect.authservers_down", [])
}
AuthError::UnverifiedUsername => TextComponent::translate(
"multiplayer.disconnect.unverified_username",
[],
),
e => TextComponent::text(e.to_string()),
})
.await;
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions pumpkin/src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use connection_cache::{CachedBranding, CachedStatus};
use crossbeam::atomic::AtomicCell;
use hmac::digest::consts::U6;
use key_store::KeyStore;
use pumpkin_config::BASIC_CONFIG;
use pumpkin_config::{ADVANCED_CONFIG, BASIC_CONFIG};
use pumpkin_data::entity::EntityType;
use pumpkin_inventory::drag_handler::DragHandler;
use pumpkin_inventory::{Container, OpenContainer};
Expand Down Expand Up @@ -88,7 +89,12 @@ impl Server {
pub fn new() -> Self {
let auth_client = BASIC_CONFIG.online_mode.then(|| {
reqwest::Client::builder()
.timeout(Duration::from_millis(5000))
.connect_timeout(Duration::from_millis(
ADVANCED_CONFIG.networking.authentication.connect_timeout as u64,
))
.read_timeout(Duration::from_millis(
ADVANCED_CONFIG.networking.authentication.read_timeout as u64,
))
.build()
.expect("Failed to to make reqwest client")
});
Expand Down

0 comments on commit c4364d5

Please sign in to comment.