backend/src/minecraft_session/mod.rs

58 lines
1.5 KiB
Rust
Raw Normal View History

2024-12-28 21:35:45 +03:00
use base64::Engine;
use axum::{response::{Response, IntoResponse}, Json, http::StatusCode};
use serde::Serialize;
pub mod join;
pub mod has_joined;
pub mod profile;
pub mod textures;
pub use join::join;
pub use has_joined::has_joined;
pub use profile::profile;
pub use textures::serve_texture;
#[derive(Serialize)]
pub struct HasJoinedResponse {
id: String,
name: String,
properties: Vec<HasJoinedProperty>,
}
#[derive(Serialize)]
pub struct HasJoinedProperty {
name: String,
value: String,
}
fn create_profile_response(uuid: String, username: String) -> Response {
let textures = serde_json::json!({
"timestamp": chrono::Utc::now().timestamp(),
"profileId": uuid,
"profileName": username,
"textures": {
"SKIN": {
"url": format!("http://root-kit.ru:3001/textures/skin/{}.png", uuid),
"metadata": {
"model": "slim"
}
},
"CAPE": {
"url": format!("http://root-kit.ru:3001/textures/cape/{}.png", uuid),
}
}
});
let textures_base64 = base64::engine::general_purpose::STANDARD.encode(textures.to_string());
let response = HasJoinedResponse {
id: uuid,
name: username.clone(),
properties: vec![HasJoinedProperty {
name: "textures".to_string(),
value: textures_base64,
}],
};
(StatusCode::OK, Json(response)).into_response()
}