skin client update fix

This commit is contained in:
PIVODEVAT 2025-01-19 22:08:10 +03:00
parent 330142f0bf
commit f94ff928c2
5 changed files with 30 additions and 11 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
/target /target
/textures/*/* /assets/*/*/*

View File

@ -40,12 +40,12 @@ async fn main() {
.route("/punkcraft/session/join", post(minecraft_session::join)) .route("/punkcraft/session/join", post(minecraft_session::join))
.route("/punkcraft/session/hasJoined", get(minecraft_session::has_joined)) .route("/punkcraft/session/hasJoined", get(minecraft_session::has_joined))
.route("/punkcraft/session/profile", get(minecraft_session::profile)) .route("/punkcraft/session/profile", get(minecraft_session::profile))
.route("/textures/skin/{filename}", get(|path| minecraft_session::serve_texture("textures/skin", path))) .route("/textures/skin/{filename}", get(|path| minecraft_session::serve_texture("assets/session_textures/skin", path)))
.route("/textures/cape/{filename}", get(|path| minecraft_session::serve_texture("textures/cape", path))) .route("/textures/cape/{filename}", get(|path| minecraft_session::serve_texture("assets/session_textures/cape", path)))
// web // web
.route("/punkcraft/session/register", post(web::register::register)) .route("/punkcraft/session/register", post(web::register::register))
.with_state(shared_pool); .with_state(shared_pool);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3001").await.unwrap(); let listener = tokio::net::TcpListener::bind("127.0.0.1:3001").await.unwrap();
serve(listener, app).await.unwrap(); serve(listener, app).await.unwrap();
} }

View File

@ -34,7 +34,15 @@ pub async fn has_joined(
}))).into_response() }))).into_response()
}; };
let query = "SELECT uuid FROM accounts WHERE username = $1 AND server_id = $2";
let query = "
SELECT
uuid,
TO_CHAR(skin_date, 'YYYY-MM-DD_HH24-MI-SS') AS skin_date
TO_CHAR(cape_date, 'YYYY-MM-DD_HH24-MI-SS') AS cape_date
FROM accounts
WHERE username = $1 AND server_id = $2";
let row = match conn.query_one(query, &[&params.username, &params.server_id]).await { let row = match conn.query_one(query, &[&params.username, &params.server_id]).await {
Ok(row) => row, Ok(row) => row,
Err(_) => return (StatusCode::NOT_FOUND, Json(serde_json::json!({ Err(_) => return (StatusCode::NOT_FOUND, Json(serde_json::json!({
@ -44,6 +52,8 @@ pub async fn has_joined(
}; };
let uuid = row.get("uuid"); let uuid = row.get("uuid");
let skin_date = row.get("skin_date");
let cape_date = row.get("cape_date");
create_profile_response(uuid, params.username) create_profile_response(uuid, params.username, skin_date, cape_date)
} }

View File

@ -24,20 +24,20 @@ pub struct HasJoinedProperty {
value: String, value: String,
} }
fn create_profile_response(uuid: String, username: String) -> Response { fn create_profile_response(uuid: String, username: String, skin_date: String, cape_date: String) -> Response {
let textures = serde_json::json!({ let textures = serde_json::json!({
"timestamp": chrono::Utc::now().timestamp(), "timestamp": chrono::Utc::now().timestamp(),
"profileId": uuid, "profileId": uuid,
"profileName": username, "profileName": username,
"textures": { "textures": {
"SKIN": { "SKIN": {
"url": format!("http://root-kit.ru:3001/textures/skin/{}.png", uuid), "url": format!("https://root-kit.ru:3002/textures/skin/skin_{}_{}.png", uuid, skin_date),
"metadata": { "metadata": {
"model": "slim" "model": "slim"
} }
}, },
"CAPE": { "CAPE": {
"url": format!("http://root-kit.ru:3001/textures/cape/{}.png", uuid), "url": format!("https://root-kit.ru:3002/textures/cape/cape_{}_{}.png", uuid, cape_date),
} }
} }
}); });

View File

@ -32,7 +32,14 @@ pub async fn profile(
}))).into_response() }))).into_response()
}; };
let query = "SELECT username FROM accounts WHERE uuid = $1"; let query = "
SELECT
username,
TO_CHAR(skin_date, 'YYYY-MM-DD_HH24-MI-SS') AS skin_date
TO_CHAR(cape_date, 'YYYY-MM-DD_HH24-MI-SS') AS cape_date
FROM accounts
WHERE uuid = $1";
let row = match conn.query_one(query, &[&params.uuid]).await { let row = match conn.query_one(query, &[&params.uuid]).await {
Ok(row) => row, Ok(row) => row,
Err(_) => return (StatusCode::NOT_FOUND, Json(serde_json::json!({ Err(_) => return (StatusCode::NOT_FOUND, Json(serde_json::json!({
@ -42,6 +49,8 @@ pub async fn profile(
}; };
let username: String = row.get("username"); let username: String = row.get("username");
let skin_date: String = row.get("skin_date");
let cape_date: String = row.get("cape_date");
create_profile_response(params.uuid, username) create_profile_response(params.uuid, username, skin_date, cape_date)
} }