lib: Move out bootstrap_find_servers
This commit is contained in:
parent
bd1f8096ac
commit
23bba30baa
|
@ -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?;
|
||||
|
|
|
@ -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?;
|
||||
|
|
|
@ -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<u32, CMServerEntry<'a>>,
|
||||
success: u32,
|
||||
message: &'a str,
|
||||
}
|
||||
|
||||
pub async fn bootstrap_find_servers() -> Result<Vec<String>, 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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
pub mod connection;
|
||||
pub mod error;
|
||||
pub mod message;
|
||||
pub mod selection;
|
||||
|
||||
pub use error::ClientError;
|
||||
|
|
56
lib/src/selection.rs
Normal file
56
lib/src/selection.rs
Normal file
|
@ -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<u32, CMServerEntry<'a>>,
|
||||
pub success: u32,
|
||||
pub message: &'a str,
|
||||
}
|
||||
|
||||
pub async fn bootstrap_find_servers() -> Result<Vec<String>, 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())
|
||||
}
|
Loading…
Reference in a new issue