Skip to content

Commit adb3daf

Browse files
committed
fix(setup): can now check if phone number available during transfer process
1 parent 5d78d5d commit adb3daf

2 files changed

Lines changed: 47 additions & 30 deletions

File tree

src/commands/setup.rs

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use steamguard::{
66
phonelinker::PhoneLinker,
77
steamapi::PhoneClient,
88
token::Tokens,
9+
transport::TransportError,
910
AccountLinkError, AccountLinker, FinalizeLinkError,
1011
};
1112

@@ -59,7 +60,7 @@ where
5960
}
6061
Err(AccountLinkError::AuthenticatorPresent) => {
6162
eprintln!("It looks like there's already an authenticator on this account. If you want to link it to steamguard-cli, you'll need to remove it first. If you remove it using your revocation code (R#####), you'll get a 15 day trade ban.");
62-
eprintln!("However, you can \"transfer\" the authenticator to steamguard-cli if you have access to the phone number associated with your account. This will cause you to get only a 2 day trade ban.");
63+
eprintln!("However, you can \"transfer\" the authenticator to steamguard-cli if you have access to the phone number associated with your account. You can also add a phone number to the account to transfer the authenticator. This will cause you to get only a 2 day trade ban.");
6364
eprintln!("If you were using SDA or WinAuth, you can import it into steamguard-cli with the `import` command, and have no trade ban.");
6465
eprintln!("You can't have the same authenticator on steamguard-cli and the steam mobile app at the same time.");
6566

@@ -70,42 +71,36 @@ where
7071
let answer = tui::prompt_char("What would you like to do?", "Tra");
7172
match answer {
7273
't' => {
73-
let mut already_added_phone_number = false;
74+
let has_phone_number: bool = if let Ok(has_phone_number) =
75+
fetch_has_phone_number(transport.clone(), linker.tokens())
76+
{
77+
has_phone_number
78+
} else {
79+
warn!("Failed to check if account has phone number. Assuming that it does and continuing...");
80+
true
81+
};
82+
83+
if !has_phone_number {
84+
warn!("Account does not have a phone number.");
85+
eprintln!("You can't transfer an authenticator without a phone number on the account. Let's add one.");
86+
87+
do_add_phone_number(transport.clone(), linker.tokens())?;
88+
info!("Pausing for 20 seconds to let Steam catch up...");
89+
// I haven't actually rigorously tested how long it takes for Steam to propagate this change. This is a guess.
90+
// 3 seconds is definitely too short (tested).
91+
std::thread::sleep(std::time::Duration::from_secs(20));
92+
}
93+
7494
loop {
7595
if let Err(err) = Self::transfer_new_account(&mut linker, manager) {
76-
if !already_added_phone_number {
77-
error!("Failed to transfer authenticator. {}", err);
78-
info!("There's nothing else to be done right now. Wait a few minutes and try again.");
79-
match tui::prompt_char("Would you like to try again?", "yN")
80-
{
81-
'y' => {
82-
continue;
83-
}
84-
_ => debug!("Declined, aborting."),
85-
}
86-
return Err(err);
87-
}
88-
info!("I can't check if you already have a phone number, but I can try to add one for you.");
89-
90-
match tui::prompt_char(
91-
"Would you like to add a phone number to this account?",
92-
"yN",
93-
) {
96+
error!("Failed to transfer authenticator. {}", err);
97+
info!("There's nothing else to be done right now. Wait a few minutes and try again.");
98+
match tui::prompt_char("Would you like to try again?", "yN") {
9499
'y' => {
95-
do_add_phone_number(
96-
transport.clone(),
97-
linker.tokens(),
98-
)?;
99-
info!("Lets try the transfer again. Pausing for 20 seconds to let Steam catch up...");
100-
already_added_phone_number = true;
101-
// I haven't actually rigorously tested how long it takes for Steam to propagate this change. This is a guess.
102-
// 3 seconds is definitely too short (tested).
103-
std::thread::sleep(std::time::Duration::from_secs(20));
104100
continue;
105101
}
106102
_ => debug!("Declined, aborting."),
107103
}
108-
109104
return Err(err);
110105
}
111106

@@ -307,6 +302,17 @@ impl SetupCommand {
307302
}
308303
}
309304

305+
pub fn fetch_has_phone_number<T: Transport>(
306+
transport: T,
307+
tokens: &Tokens,
308+
) -> Result<bool, TransportError> {
309+
let client: PhoneClient<T> = PhoneClient::new(transport);
310+
311+
let linker = PhoneLinker::new(client, tokens.clone());
312+
313+
linker.has_phone_number()
314+
}
315+
310316
pub fn do_add_phone_number<T: Transport>(transport: T, tokens: &Tokens) -> anyhow::Result<()> {
311317
let client = PhoneClient::new(transport);
312318

steamguard/src/phonelinker.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ where
115115

116116
Ok(resp.seconds_to_wait)
117117
}
118+
119+
/// Whether or not the account has a phone number associated with it.
120+
pub fn has_phone_number(&self) -> Result<bool, TransportError> {
121+
let req = CPhone_AccountPhoneStatus_Request::new();
122+
let status = self
123+
.client
124+
.account_phone_status(req, self.tokens.access_token())?;
125+
126+
let data = status.into_response_data();
127+
Ok(data.has_phone())
128+
}
118129
}
119130

120131
#[derive(Debug, thiserror::Error)]

0 commit comments

Comments
 (0)