diff --git a/src/main.rs b/src/main.rs index 5e955f5..287999d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,8 +84,10 @@ impl JoinAttempt { pub struct AppState { store: Arc>>, db: DatabaseConnection, - cfg: CliArgs, secret: String, + token_duration: u32, + time_window: u32, + fallback: bool, } #[tokio::main] @@ -126,7 +128,7 @@ async fn main() -> Result<(), Box> { // CUSTOM .route("/register/unmigrated", post(register_unmigrated)) .fallback(fallback_route) - .with_state(AppState { store, db, cfg, secret }); + .with_state(AppState { store, db, token_duration, time_window, fallback, secret }); info!(target: "MAIN", "serving Yggdrasil on {}", &addr); diff --git a/src/routes/auth.rs b/src/routes/auth.rs index 6242143..acbba17 100644 --- a/src/routes/auth.rs +++ b/src/routes/auth.rs @@ -14,7 +14,7 @@ pub async fn validate(State(state): State, Json(payload): Json Duration::seconds(state.cfg.token_duration as i64) { + if Utc::now() - t.created_at > Duration::seconds(state.token_duration as i64) { warn!(target: "AUTH", "[VALIDATE] expired token!"); return Err(StatusCode::UNAUTHORIZED); } diff --git a/src/routes/session.rs b/src/routes/session.rs index 355af00..a86aeac 100644 --- a/src/routes/session.rs +++ b/src/routes/session.rs @@ -24,7 +24,7 @@ pub async fn join(State(state): State, Json(payload): Json, Query(query): Que match has_joined_local(&state, username, server_id, user_ip).await { Ok(r) => Ok(r), Err(e) => { - if state.cfg.fallback { + if state.fallback { Ok(has_joined_microsoft(&state, username, server_id, user_ip).await?) } else { Err(e) @@ -82,7 +82,7 @@ pub async fn has_joined_local(state: &AppState, username: &String, server_id: &S match state.store.lock().await.get(&user.uuid) { Some(join) => { - if Utc::now() - join.time < Duration::seconds(state.cfg.time_window as i64) + if Utc::now() - join.time < Duration::seconds(state.time_window as i64) && join.server.to_lowercase() == server_id.to_lowercase() { let response = proto::JoinResponse { id: user.uuid.simple().to_string(),