Compare commits
2 Commits
c8a048c7dd
...
d7fd387745
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d7fd387745 | ||
![]() |
f94ff928c2 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,3 @@
|
||||
/target
|
||||
/textures/*/*
|
||||
/assets/*/*/*
|
||||
|
||||
|
24
README.md
24
README.md
@ -1,24 +1,2 @@
|
||||
# Документация
|
||||
# backend
|
||||
|
||||
## PostgreSQL
|
||||
``` sql
|
||||
create table accounts (
|
||||
-- Параметры авторизации
|
||||
id serial primary key,
|
||||
username varchar(16) not null unique,
|
||||
uuid char(32) default replace(gen_random_uuid()::text, '-', '') not null unique,
|
||||
password TEXT not null,
|
||||
access_token char(32) default '',
|
||||
server_id varchar(42) default '',
|
||||
-- Дополнительные параметры
|
||||
email varchar(32) not null unique,
|
||||
email_verify BOOLEAN not null default false,
|
||||
location int not null default 0,
|
||||
skin_type boolean not null default true,
|
||||
firstname varchar(16),
|
||||
middlename varchar(16),
|
||||
lastname varchar(16),
|
||||
registration_date timestamp default current_timestamp,
|
||||
balance decimal(10,2) not null default 0.00
|
||||
)
|
||||
```
|
@ -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();
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user