Fix hash_joined.rs

This commit is contained in:
0xf8 2023-06-21 17:34:32 -04:00
parent 49f462370a
commit 4e3bfad908
Signed by: 0xf8
GPG Key ID: 446580D758689584

View File

@ -10,16 +10,17 @@
*/
use anyhow::anyhow;
use log::info;
use tide::{prelude::*, Request, Result};
use yggdrasil::Database;
use yggdrasil::errors::YggdrasilError;
use yggdrasil::structs::game_profile::GameProfile;
use yggdrasil::structs::profile::Profile;
use yggdrasil::structs::session::Session;
use yggdrasil::structs::game_profile::GameProfile;
#[derive(Deserialize, Debug)]
struct HasJoinedBody {
struct HasJoinedQuery {
pub username: String,
#[serde(rename = "serverId")]
@ -29,13 +30,13 @@ struct HasJoinedBody {
}
pub async fn has_joined(mut req: Request<Database>) -> Result {
let Ok(body) = req.body_json::<HasJoinedBody>().await else {
let Ok(query) = req.query::<HasJoinedQuery>() else {
// No args
return Err(YggdrasilError::new_bad_request("One or more required fields was missing.").into())
};
// Get profile
let Some(profile) = Profile::from_name(req.state(), body.username).await else {
let Some(profile) = Profile::from_name(req.state(), query.username.to_string()).await else {
return Err(YggdrasilError::new_bad_request("Profile does not exist.").into())
};
@ -45,12 +46,18 @@ pub async fn has_joined(mut req: Request<Database>) -> Result {
};
// Check IP if requested
if let Some(ip) = body.ip {
if let Some(ip) = query.ip {
if ip != session.ip_addr {
return Err(YggdrasilError::new_forbidden("IP address does not match.").into())
}
}
// TODO: what is server id and why doesn't it match?
// Check server id
// if query.server_id != session.server_id {
// return Err(YggdrasilError::new_forbidden("Server ID does not match.").into())
// }
// Remove session
session.delete(req.state()).await?;