mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 23:44:38 +00:00
Merge branch 'improve-entities' of https://github.com/mat-1/azalea into improve-entities
This commit is contained in:
commit
109418de21
3 changed files with 13 additions and 40 deletions
|
@ -18,6 +18,8 @@ pub enum SessionServerError {
|
||||||
InvalidSession,
|
InvalidSession,
|
||||||
#[error("Unknown sessionserver error: {0}")]
|
#[error("Unknown sessionserver error: {0}")]
|
||||||
Unknown(String),
|
Unknown(String),
|
||||||
|
#[error("Forbidden operation (expired session?)")]
|
||||||
|
ForbiddenOperation,
|
||||||
#[error("Unexpected response from sessionserver (status code {status_code}): {body}")]
|
#[error("Unexpected response from sessionserver (status code {status_code}): {body}")]
|
||||||
UnexpectedResponse { status_code: u16, body: String },
|
UnexpectedResponse { status_code: u16, body: String },
|
||||||
}
|
}
|
||||||
|
@ -71,10 +73,13 @@ pub async fn join(
|
||||||
Err(SessionServerError::AuthServersUnreachable)
|
Err(SessionServerError::AuthServersUnreachable)
|
||||||
}
|
}
|
||||||
"InvalidCredentialsException" => Err(SessionServerError::InvalidSession),
|
"InvalidCredentialsException" => Err(SessionServerError::InvalidSession),
|
||||||
|
"ForbiddenOperationException" => Err(SessionServerError::ForbiddenOperation),
|
||||||
_ => Err(SessionServerError::Unknown(forbidden.error)),
|
_ => Err(SessionServerError::Unknown(forbidden.error)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
status_code => {
|
status_code => {
|
||||||
|
// log the headers
|
||||||
|
log::debug!("Error headers: {:#?}", res.headers());
|
||||||
let body = res.text().await?;
|
let body = res.text().await?;
|
||||||
Err(SessionServerError::UnexpectedResponse {
|
Err(SessionServerError::UnexpectedResponse {
|
||||||
status_code: status_code.as_u16(),
|
status_code: status_code.as_u16(),
|
||||||
|
|
|
@ -315,7 +315,11 @@ impl Client {
|
||||||
// both times, give up
|
// both times, give up
|
||||||
return Err(e.into());
|
return Err(e.into());
|
||||||
}
|
}
|
||||||
if let SessionServerError::InvalidSession = e {
|
if matches!(
|
||||||
|
e,
|
||||||
|
SessionServerError::InvalidSession
|
||||||
|
| SessionServerError::ForbiddenOperation
|
||||||
|
) {
|
||||||
// uh oh, we got an invalid session and have
|
// uh oh, we got an invalid session and have
|
||||||
// to reauthenticate now
|
// to reauthenticate now
|
||||||
account.refresh().await?;
|
account.refresh().await?;
|
||||||
|
|
|
@ -1,46 +1,10 @@
|
||||||
//! Translate Minecraft strings from their id.
|
//! Translate Minecraft strings from their id.
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::io::Read;
|
use std::collections::HashMap;
|
||||||
use std::path::Path;
|
|
||||||
use std::{collections::HashMap, fs::File};
|
|
||||||
// use tokio::fs::File;
|
|
||||||
|
|
||||||
// pub struct Language {
|
pub static STORAGE: Lazy<HashMap<String, String>> =
|
||||||
// pub storage: HashMap<String, String>,
|
Lazy::new(|| serde_json::from_str(include_str!("en_us.json")).unwrap());
|
||||||
// }
|
|
||||||
|
|
||||||
// impl Language {
|
|
||||||
// pub async fn load() -> Self {
|
|
||||||
// // TODO: download from mojang's servers and cache somewhere
|
|
||||||
|
|
||||||
// let mut storage = HashMap::new();
|
|
||||||
// let mut file = File::open("en_us.json").unwrap();
|
|
||||||
// let mut contents = String::new();
|
|
||||||
// file.read_to_string(&mut contents).unwrap();
|
|
||||||
// let en_us: HashMap<String, String> =
|
|
||||||
// serde_json::from_str(&contents).unwrap(); Language { storage: en_us }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// pub fn get(&self, key: &str) -> Option<&str> {
|
|
||||||
// self.storage.get(key)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// yeah i just decided to do this because otherwise we would have to have a
|
|
||||||
// Language object that we passed around everywhere which is not convenient
|
|
||||||
// The code above is kept in case I come up with a better solution
|
|
||||||
|
|
||||||
pub static STORAGE: Lazy<HashMap<String, String>> = Lazy::new(|| {
|
|
||||||
serde_json::from_str(&{
|
|
||||||
let src_dir = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/src/en_us.json"));
|
|
||||||
let mut file = File::open(src_dir).unwrap();
|
|
||||||
let mut contents = String::new();
|
|
||||||
file.read_to_string(&mut contents).unwrap();
|
|
||||||
contents
|
|
||||||
})
|
|
||||||
.unwrap()
|
|
||||||
});
|
|
||||||
|
|
||||||
pub fn get(key: &str) -> Option<&str> {
|
pub fn get(key: &str) -> Option<&str> {
|
||||||
STORAGE.get(key).map(|s| s.as_str())
|
STORAGE.get(key).map(|s| s.as_str())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue