chore: added logging to MS fallback

This commit is contained in:
dev@ftbsc 2023-01-22 20:25:29 +01:00
parent be1ac67d16
commit 80675338af

View file

@ -3,7 +3,7 @@ use std::collections::HashMap;
use axum::{extract::{State, Query, Path}, http::StatusCode, Json}; use axum::{extract::{State, Query, Path}, http::StatusCode, Json};
use chrono::{Duration, Utc}; use chrono::{Duration, Utc};
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter}; use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
use tracing::{info, warn}; use tracing::{info, warn, error};
use uuid::Uuid; use uuid::Uuid;
use crate::{AppState, proto, JoinAttempt, entities}; use crate::{AppState, proto, JoinAttempt, entities};
@ -47,14 +47,14 @@ pub async fn has_joined_wrapper(State(state): State<AppState>, Query(query): Que
} }
pub async fn has_joined_microsoft(_state: &AppState, username: &String, server_id: &String, _user_ip: Option<&String>) -> Result<Json<proto::JoinResponse>, StatusCode> { pub async fn has_joined_microsoft(_state: &AppState, username: &String, server_id: &String, _user_ip: Option<&String>) -> Result<Json<proto::JoinResponse>, StatusCode> {
Ok( info!(target: "SESSION", "[HAS_JOINED] falling back to MS");
Json( // TODO don't do it with a format!!! let res = // TODO don't do it with a format!!!
reqwest::get(format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={}&serverId={}", username, server_id)) reqwest::get(format!("https://sessionserver.mojang.com/session/minecraft/hasJoined?username={}&serverId={}", username, server_id))
.await.map_err(|_| StatusCode::SERVICE_UNAVAILABLE)? .await.map_err(|e| { error!(target:"MS", "error before: {:?}", e); StatusCode::SERVICE_UNAVAILABLE })?
.json::<proto::JoinResponse>() .json::<proto::JoinResponse>()
.await.map_err(|_| StatusCode::UNAUTHORIZED)? .await.map_err(|e| { error!(target:"MS", "error after: {:?}", e); StatusCode::UNAUTHORIZED })?;
) info!(target:"MS", "answering with {:?}", res);
) Ok(Json(res))
} }
pub async fn has_joined_local(state: &AppState, username: &String, server_id: &String, user_ip: Option<&String>) -> Result<Json<proto::JoinResponse>, StatusCode> { pub async fn has_joined_local(state: &AppState, username: &String, server_id: &String, user_ip: Option<&String>) -> Result<Json<proto::JoinResponse>, StatusCode> {