Use StatusCode in auth server response check

This commit is contained in:
Ryan 2022-10-04 23:35:34 -07:00
parent b330f97642
commit e985bae469

View file

@ -13,7 +13,7 @@ use flume::{Receiver, Sender};
use num::BigInt; use num::BigInt;
use rand::rngs::OsRng; use rand::rngs::OsRng;
use rayon::iter::ParallelIterator; use rayon::iter::ParallelIterator;
use reqwest::Client as HttpClient; use reqwest::{Client as HttpClient, StatusCode};
use rsa::{PaddingScheme, PublicKeyParts, RsaPrivateKey}; use rsa::{PaddingScheme, PublicKeyParts, RsaPrivateKey};
use serde::Deserialize; use serde::Deserialize;
use serde_json::{json, Value}; use serde_json::{json, Value};
@ -715,17 +715,18 @@ async fn handle_login<C: Config>(
&hex_hash, &hex_hash,
&remote_addr.ip(), &remote_addr.ip(),
); );
let resp = server.0.http_client.get(url).send().await?; let resp = server.0.http_client.get(url).send().await?;
match resp.status().as_u16() { match resp.status() {
200 => (), StatusCode::OK => {}
204 => { StatusCode::NO_CONTENT => {
let reason = Text::translate("multiplayer.disconnect.unverified_username"); let reason = Text::translate("multiplayer.disconnect.unverified_username");
c.enc.write_packet(&DisconnectLogin { reason }).await?; c.enc.write_packet(&DisconnectLogin { reason }).await?;
bail!("Could not verify username"); bail!("Could not verify username");
} }
status => { status => {
bail!("session server GET request failed: {status}"); bail!("session server GET request failed (status code {status})");
} }
} }