diff --git a/lib/examples/login_qr.rs b/lib/examples/login_qr.rs index 96d91ff..1832eff 100644 --- a/lib/examples/login_qr.rs +++ b/lib/examples/login_qr.rs @@ -19,7 +19,7 @@ pub async fn main() -> eyre::Result<()> { env_logger::init(); color_eyre::install()?; - let servers = vapore::connection::bootstrap_find_servers().await?; + let servers = vapore::selection::bootstrap_find_servers().await?; log::debug!("Found servers: {:?}", servers); let session = vapore::connection::CMSession::connect(&servers[0]).await?; diff --git a/lib/examples/login_steamguard.rs b/lib/examples/login_steamguard.rs index cc4e4e5..722bd6a 100644 --- a/lib/examples/login_steamguard.rs +++ b/lib/examples/login_steamguard.rs @@ -27,7 +27,7 @@ pub async fn main() -> eyre::Result<()> { env_logger::init(); color_eyre::install()?; - let servers = vapore::connection::bootstrap_find_servers().await?; + let servers = vapore::selection::bootstrap_find_servers().await?; log::debug!("Found servers: {:?}", servers); let session = CMSession::connect(&servers[0]).await?; diff --git a/lib/src/connection.rs b/lib/src/connection.rs index 5654de3..a17c951 100644 --- a/lib/src/connection.rs +++ b/lib/src/connection.rs @@ -1,6 +1,6 @@ use core::time; use std::{ - collections::{BTreeMap, HashMap, VecDeque}, + collections::{HashMap, VecDeque}, future::Future, marker::PhantomData, pin::Pin, @@ -22,10 +22,7 @@ use vapore_proto::{ }; use crate::{ - error::{ - BadResponseActionSnafu, EResultSnafu, ReqwestSnafu, VdfSnafu, WebSocketConnectSnafu, - WebSocketSnafu, - }, + error::{BadResponseActionSnafu, WebSocketConnectSnafu, WebSocketSnafu}, message::{CMProtoBufMessage, CMRawProtoBufMessage}, ClientError, }; @@ -33,53 +30,6 @@ use crate::{ /// Maximum number of messages in the buffer for by-message-type subscriptions const CHANNEL_CAPACITY: usize = 16; -#[derive(Debug, Deserialize)] -pub struct CMServerEntry<'a> { - endpoint: &'a str, - legacy_endpoint: &'a str, - #[serde(rename = "type")] - server_type: &'a str, - dc: &'a str, - realm: &'a str, - load: u32, - wtd_load: f64, -} - -#[derive(Debug, Deserialize)] -pub struct GetCMListForConnectResponse<'a> { - serverlist: BTreeMap>, - success: u32, - message: &'a str, -} - -pub async fn bootstrap_find_servers() -> Result, ClientError> { - let response = reqwest::get( - "https://api.steampowered.com/ISteamDirectory/GetCMListForConnect/v1/?cellid=0&format=vdf", - ) - .await - .context(ReqwestSnafu {})? - .text() - .await - .context(ReqwestSnafu {})?; - let result: GetCMListForConnectResponse = - keyvalues_serde::from_str(&response).context(VdfSnafu {})?; - - ensure!( - result.success == 1, - EResultSnafu { - eresult: result.success, - message: result.message - } - ); - - Ok(result - .serverlist - .values() - .filter(|entry| entry.server_type == "websockets") - .map(|entry| format!("wss://{}/cmsocket/", entry.endpoint)) - .collect()) -} - #[derive(Clone)] struct SessionInner { /// Steam ID of current user. When set to None we are not logged in diff --git a/lib/src/lib.rs b/lib/src/lib.rs index d666841..1501238 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -1,5 +1,6 @@ pub mod connection; pub mod error; pub mod message; +pub mod selection; pub use error::ClientError; diff --git a/lib/src/selection.rs b/lib/src/selection.rs new file mode 100644 index 0000000..7a900c7 --- /dev/null +++ b/lib/src/selection.rs @@ -0,0 +1,56 @@ +use std::collections::BTreeMap; + +use serde::Deserialize; +use snafu::prelude::*; + +use crate::{ + error::{EResultSnafu, ReqwestSnafu, VdfSnafu}, + ClientError, +}; + +#[derive(Debug, Deserialize)] +pub struct CMServerEntry<'a> { + pub endpoint: &'a str, + pub legacy_endpoint: &'a str, + #[serde(rename = "type")] + pub server_type: &'a str, + pub dc: &'a str, + pub realm: &'a str, + pub load: u32, + pub wtd_load: f64, +} + +#[derive(Debug, Deserialize)] +pub struct GetCMListForConnectResponse<'a> { + pub serverlist: BTreeMap>, + pub success: u32, + pub message: &'a str, +} + +pub async fn bootstrap_find_servers() -> Result, ClientError> { + let response = reqwest::get( + "https://api.steampowered.com/ISteamDirectory/GetCMListForConnect/v1/?cellid=0&format=vdf", + ) + .await + .context(ReqwestSnafu {})? + .text() + .await + .context(ReqwestSnafu {})?; + let result: GetCMListForConnectResponse = + keyvalues_serde::from_str(&response).context(VdfSnafu {})?; + + ensure!( + result.success == 1, + EResultSnafu { + eresult: result.success, + message: result.message + } + ); + + Ok(result + .serverlist + .values() + .filter(|entry| entry.server_type == "websockets") + .map(|entry| format!("wss://{}/cmsocket/", entry.endpoint)) + .collect()) +}