diff --git a/.gitignore b/.gitignore index f1ffa51..2c814cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /target -/textures/*/* +/assets/*/*/* diff --git a/src/main.rs b/src/main.rs index 96ac443..cb01f0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,12 +40,12 @@ async fn main() { .route("/punkcraft/session/join", post(minecraft_session::join)) .route("/punkcraft/session/hasJoined", get(minecraft_session::has_joined)) .route("/punkcraft/session/profile", get(minecraft_session::profile)) - .route("/textures/skin/{filename}", get(|path| minecraft_session::serve_texture("textures/skin", path))) - .route("/textures/cape/{filename}", get(|path| minecraft_session::serve_texture("textures/cape", 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("assets/session_textures/cape", path))) // web .route("/punkcraft/session/register", post(web::register::register)) .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(); } diff --git a/src/minecraft_session/has_joined.rs b/src/minecraft_session/has_joined.rs index e5fac27..1528fd0 100644 --- a/src/minecraft_session/has_joined.rs +++ b/src/minecraft_session/has_joined.rs @@ -34,7 +34,15 @@ pub async fn has_joined( }))).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, &[¶ms.username, ¶ms.server_id]).await { Ok(row) => row, Err(_) => return (StatusCode::NOT_FOUND, Json(serde_json::json!({ @@ -44,6 +52,8 @@ pub async fn has_joined( }; 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) } diff --git a/src/minecraft_session/mod.rs b/src/minecraft_session/mod.rs index 372d208..0a1c381 100644 --- a/src/minecraft_session/mod.rs +++ b/src/minecraft_session/mod.rs @@ -24,20 +24,20 @@ pub struct HasJoinedProperty { 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!({ "timestamp": chrono::Utc::now().timestamp(), "profileId": uuid, "profileName": username, "textures": { "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": { "model": "slim" } }, "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), } } }); diff --git a/src/minecraft_session/profile.rs b/src/minecraft_session/profile.rs index b472547..1565c55 100644 --- a/src/minecraft_session/profile.rs +++ b/src/minecraft_session/profile.rs @@ -32,7 +32,14 @@ pub async fn profile( }))).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, &[¶ms.uuid]).await { Ok(row) => row, Err(_) => return (StatusCode::NOT_FOUND, Json(serde_json::json!({ @@ -42,6 +49,8 @@ pub async fn profile( }; 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) }