require login only when session is invalid

This commit is contained in:
Carson McManus 2021-07-27 19:50:39 -04:00
parent d8ffc179e0
commit d2bf5478ba
2 changed files with 20 additions and 6 deletions

View file

@ -130,7 +130,7 @@ impl SteamGuardAccount {
return params;
}
pub fn get_trade_confirmations(&self) {
pub fn get_trade_confirmations(&self) -> Result<Vec<String>, reqwest::Error> {
// uri: "https://steamcommunity.com/mobileconf/conf"
// confirmation details:
let url = "https://steamcommunity.com".parse::<Url>().unwrap();
@ -175,16 +175,18 @@ impl SteamGuardAccount {
let conf_key = &caps[2];
let conf_type = &caps[3];
let conf_creator = &caps[4];
debug!("{} {} {} {}", conf_id, conf_key, conf_type, conf_creator);
debug!("conf_id={} conf_key={} conf_type={} conf_creator={}", conf_id, conf_key, conf_type, conf_creator);
return Ok(vec![format!("conf_id={} conf_key={} conf_type={} conf_creator={}", conf_id, conf_key, conf_type, conf_creator)]);
}
_ => {
info!("No confirmations");
return Ok(vec![]);
}
}
};
}
Err(e) => {
error!("error: {:?}", e);
return;
return Err(e);
}
}
}

View file

@ -128,10 +128,22 @@ fn main() {
info!("trade");
for a in selected_accounts.iter_mut() {
let mut account = a; // why is this necessary?
do_login(&mut account);
info!("Checking for trade confirmations");
account.get_trade_confirmations();
loop {
match account.get_trade_confirmations() {
Ok(confs) => {
for conf in confs {
println!("{}", conf);
}
break;
}
Err(_) => {
info!("failed to get trade confirmations, asking user to log in");
do_login(&mut account);
}
}
}
}
} else {
let server_time = steamapi::get_server_time();