79 lines
2.6 KiB
Rust
79 lines
2.6 KiB
Rust
/*
|
|
* Yggdrasil: Minecraft authentication server
|
|
* Copyright (C) 2023 0xf8.dev@proton.me
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_json::Value;
|
|
use tide::prelude::json;
|
|
|
|
use structs::profile::Profile;
|
|
|
|
use crate::*;
|
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
pub struct GameProfile {}
|
|
|
|
impl GameProfile {
|
|
pub async fn from_profile(db: &Database, profile: &Profile) -> Value {
|
|
// Textures object
|
|
let mut object = json!({
|
|
"timestamp": get_unix_timestamp() as u64,
|
|
"profile_id": profile.uuid.to_owned(),
|
|
"profile_name": profile.name.to_owned(),
|
|
"textures": {}
|
|
});
|
|
|
|
if profile.skin_variant != "NONE" {
|
|
let skin_url = profile.get_skin(db).await;
|
|
|
|
if skin_url.is_some() {
|
|
object["textures"]["SKIN"] = json!({ "url": skin_url });
|
|
}
|
|
}
|
|
|
|
if profile.active_cape.is_some() {
|
|
let cape_url = profile.get_cape(db).await;
|
|
|
|
if cape_url.is_some() {
|
|
object["textures"]["CAPE"] = json!({ "url": cape_url });
|
|
}
|
|
}
|
|
|
|
// This is the actual game profile
|
|
json!({
|
|
"id": profile.uuid.replace("-", ""),
|
|
"name": profile.name.to_owned(),
|
|
"properties": [
|
|
// TODO: signing textures
|
|
// unsigned ? encode : sign
|
|
Self::encode_textures(&object)
|
|
// Self::sign_textures(object)
|
|
]
|
|
})
|
|
}
|
|
|
|
pub fn encode_textures(textures: &Value) -> Value {
|
|
use base64::{Engine, engine::general_purpose::URL_SAFE as base64};
|
|
|
|
let serialized = textures.to_string();
|
|
let mut encoded = String::new();
|
|
base64.encode_string(serialized, &mut encoded);
|
|
|
|
json!({
|
|
"name": "textures",
|
|
"value": encoded
|
|
})
|
|
}
|
|
|
|
pub fn sign_textures(textures: &Value) -> Value {
|
|
// TODO: signing textures
|
|
unimplemented!()
|
|
}
|
|
} |