fix: handle characters on pages other than first

This commit is contained in:
Anna 2024-01-24 07:05:56 -05:00
parent dc0e23c3da
commit 38851af678
Signed by: anna
GPG Key ID: D0943384CD9F87D1
4 changed files with 598 additions and 666 deletions

1219
server/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -20,14 +20,14 @@ rand = "0.8"
regex = "1"
reqwest = { version = "0.11", default-features = false }
rmp-serde = "1"
rustyline = { version = "12", default-features = false }
rustyline = { version = "13", default-features = false }
serde = { version = "1", features = ["derive"] }
serde_bytes = "0.11"
serde_repr = "0.1"
sha3 = "0.10"
sqlx = { version = "0.7", features = ["runtime-tokio-rustls", "sqlite", "chrono"] }
tokio-tungstenite = "0.19"
toml = "0.7"
tokio-tungstenite = "0.21"
toml = "0.8"
url = { version = "2", features = ["serde"] }
uuid = { version = "1", features = ["serde", "v4"] }

View File

@ -1,7 +1,7 @@
use std::sync::Arc;
use anyhow::{Context, Result};
use chrono::{DateTime, Duration, Utc};
use chrono::{Duration, TimeZone, Utc};
use lodestone_scraper::LodestoneScraper;
use rand::RngCore;
use tokio::sync::RwLock;
@ -15,15 +15,28 @@ pub async fn register(state: Arc<RwLock<State>>, _client_state: Arc<RwLock<Clien
.context("invalid world id")?;
// look up character
let character = scraper.character_search()
.name(&req.name)
.world(world)
.send()
.await?
.results
.into_iter()
.find(|c| c.name == req.name && Some(c.world) == world_from_id(req.world))
.context("could not find character")?;
let mut page = 1;
let character = loop {
let search = scraper.character_search()
.name(&req.name)
.world(world)
.page(page)
.send()
.await?;
let chara = search
.results
.into_iter()
.find(|c| c.name == req.name && Some(c.world) == world_from_id(req.world));
if chara.is_some() {
break chara;
}
page += 1;
if page > search.pagination.total_pages {
break None;
}
};
let character = character.context("could not find character")?;
let lodestone_id = character.id as i64;
// get challenge
@ -38,7 +51,7 @@ pub async fn register(state: Arc<RwLock<State>>, _client_state: Arc<RwLock<Clien
if !req.challenge_completed || challenge.is_none() {
let generate = match &challenge {
Some(r) if Utc::now().signed_duration_since(DateTime::<Utc>::from_utc(r.created_at, Utc)) > Duration::minutes(5) => {
Some(r) if Utc::now().signed_duration_since(Utc.from_utc_datetime(&r.created_at)) > Duration::minutes(5) => {
// set up a challenge if one hasn't been set up in the last five minutes
true
}

View File

@ -73,7 +73,9 @@ pub fn spawn(config: &Config, state: Arc<RwLock<State>>) {
.await
.ok();
let timestamp = Utc::now().timestamp_nanos();
let timestamp = Utc::now()
.timestamp_nanos_opt()
.unwrap_or_default();
let mut line_format = format!(
"logged_in value={logged_in}u {timestamp}\nmessages_this_instance value={messages_this_instance}u {timestamp}\nmessages_new value={messages_new}u {timestamp}\n",