vapored: Use GetCMListForConnect

This commit is contained in:
Artemis Tosini 2024-09-04 20:56:18 +00:00
parent ba92101e06
commit 4207832545
Signed by: artemist
GPG key ID: ADFFE553DCBB831E

View file

@ -28,30 +28,46 @@ use crate::message::{CMProtoBufMessage, CMRawProtoBufMessage};
const CHANNEL_CAPACITY: usize = 16;
#[derive(Debug, Deserialize)]
struct GetCMListResult<'a> {
// No need to check servers, we're only implementing websockets
serverlist_websockets: BTreeMap<u32, &'a str>,
result: u32,
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)]
struct GetCMListForConnectResponse<'a> {
serverlist: BTreeMap<u32, CMServerEntry<'a>>,
success: u32,
message: &'a str,
}
pub async fn bootstrap_find_servers() -> eyre::Result<Vec<String>> {
// TODO: Use GetCMListForConnect, seems to be new API
let result_text = reqwest::get("https://api.steampowered.com/ISteamDirectory/GetCMList/v1/?cellid=0&maxcount=10&format=vdf").await?.text().await?;
let result: GetCMListResult = keyvalues_serde::from_str(&result_text)?;
let response = reqwest::get(
"https://api.steampowered.com/ISteamDirectory/GetCMListForConnect/v1/?cellid=0&format=vdf",
)
.await?
.text()
.await?;
let result: GetCMListForConnectResponse = keyvalues_serde::from_str(&response)?;
if result.result != 1 {
if result.success != 1 {
eyre::bail!(
"GetCMList returned bad result {} wtih message {}",
result.result,
result.success,
result.message
)
}
Ok(result
.serverlist_websockets
.serverlist
.values()
.map(|host| format!("wss://{}/cmsocket/", host))
.filter(|entry| entry.server_type == "websockets")
.map(|entry| format!("wss://{}/cmsocket/", entry.endpoint))
.collect())
}