fix: don't interrupt login if error getting character info
This commit is contained in:
parent
12741c0c33
commit
e0683e1036
|
@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use chrono::{Duration, Utc};
|
use chrono::{Duration, Utc};
|
||||||
use lodestone_scraper::LodestoneScraper;
|
use lodestone_scraper::LodestoneScraper;
|
||||||
use log::trace;
|
use log::{trace, warn};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use crate::{AuthenticateRequest, AuthenticateResponse, ClientState, State, User, util, World, WsStream};
|
use crate::{AuthenticateRequest, AuthenticateResponse, ClientState, State, User, util, World, WsStream};
|
||||||
|
@ -34,23 +34,30 @@ pub async fn authenticate(state: Arc<RwLock<State>>, client_state: Arc<RwLock<Cl
|
||||||
if Utc::now().naive_utc().signed_duration_since(user.last_updated) >= Duration::hours(2) {
|
if Utc::now().naive_utc().signed_duration_since(user.last_updated) >= Duration::hours(2) {
|
||||||
let info = LodestoneScraper::default()
|
let info = LodestoneScraper::default()
|
||||||
.character(user.lodestone_id as u64)
|
.character(user.lodestone_id as u64)
|
||||||
.await
|
.await;
|
||||||
.context("could not get character info")?;
|
|
||||||
let world_name = info.world.as_str();
|
|
||||||
|
|
||||||
user.name = info.name.clone();
|
match info {
|
||||||
user.world = world_name.to_string();
|
Ok(info) => {
|
||||||
|
let world_name = info.world.as_str();
|
||||||
|
|
||||||
sqlx::query!(
|
user.name = info.name.clone();
|
||||||
// language=sqlite
|
user.world = world_name.to_string();
|
||||||
"update users set name = ?, world = ?, last_updated = current_timestamp where lodestone_id = ?",
|
|
||||||
info.name,
|
sqlx::query!(
|
||||||
world_name,
|
// language=sqlite
|
||||||
user.lodestone_id,
|
"update users set name = ?, world = ?, last_updated = current_timestamp where lodestone_id = ?",
|
||||||
)
|
info.name,
|
||||||
.execute(&state.read().await.db)
|
world_name,
|
||||||
.await
|
user.lodestone_id,
|
||||||
.context("could not update user")?;
|
)
|
||||||
|
.execute(&state.read().await.db)
|
||||||
|
.await
|
||||||
|
.context("could not update user")?;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
warn!("could not get character info during login: {:#?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let world = World::from_str(&user.world).map_err(|_| anyhow::anyhow!("invalid world in db"))?;
|
let world = World::from_str(&user.world).map_err(|_| anyhow::anyhow!("invalid world in db"))?;
|
||||||
|
|
Loading…
Reference in New Issue