aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src-tauri/src/main.rs')
-rw-r--r--src-tauri/src/main.rs35
1 files changed, 34 insertions, 1 deletions
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 96be489f..b47a796e 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -9,7 +9,7 @@ use std::{
time::Duration,
};
-use app::*;
+use app::{*, constants::{APP_USER_AGENT, MASTER_SERVER_URL, SERVER_BROWSER_ENDPOINT}};
mod github;
use github::release_notes::{
@@ -30,6 +30,7 @@ use mod_management::{
mod northstar;
use northstar::get_northstar_version_number;
+use serde::{Deserialize, Serialize};
use tauri::Manager;
use tauri_plugin_store::PluginBuilder;
use tokio::time::sleep;
@@ -105,6 +106,7 @@ fn main() {
clean_up_download_folder_caller,
get_newest_flightcore_version,
delete_northstar_mod,
+ get_server_player_count,
delete_thunderstore_mod,
])
.run(tauri::generate_context!())
@@ -307,3 +309,34 @@ async fn clean_up_download_folder_caller(
Err(err) => Err(err.to_string()),
}
}
+
+
+/// Gets server and playercount from master server API
+#[tauri::command]
+async fn get_server_player_count() -> Result<(i32, usize), String> {
+
+ let url = format!("{MASTER_SERVER_URL}{SERVER_BROWSER_ENDPOINT}");
+ let client = reqwest::Client::new();
+ let res = client
+ .get(url)
+ .header(reqwest::header::USER_AGENT, APP_USER_AGENT)
+ .send()
+ .await
+ .unwrap()
+ .text()
+ .await
+ .unwrap();
+
+ let ns_servers: Vec<NorthstarServer> =
+ serde_json::from_str(&res).expect("JSON was not well-formatted");
+
+ // Get server count
+ let server_count = ns_servers.len();
+
+ // Sum up player count
+ let total_player_count: i32 = ns_servers.iter().map(|server| server.player_count).sum();
+
+ dbg!((total_player_count, server_count));
+
+ Ok((total_player_count, server_count))
+}