mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-02-16 10:41:01 +00:00
wip heartbeat stuff
This commit is contained in:
@@ -21,8 +21,8 @@ futures = "0.3.29"
|
||||
|
||||
reqwest = { version = "0.11", features = ["json"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "*"
|
||||
serde-aux = "4.2.0"
|
||||
serde_json = "*"
|
||||
|
||||
toml = "0.5"
|
||||
flate2 = "1.0"
|
||||
|
||||
@@ -14,28 +14,32 @@ pub struct GeneralSettings {
|
||||
#[serde(rename = "Port")]
|
||||
pub port: Option<u16>,
|
||||
|
||||
#[serde(rename = "Name")]
|
||||
pub name: String,
|
||||
|
||||
#[serde(rename = "Description")]
|
||||
pub description: String,
|
||||
|
||||
#[serde(rename = "AuthKey")]
|
||||
pub auth_key: Option<String>,
|
||||
|
||||
#[serde(rename = "MaxCars")]
|
||||
pub max_cars: Option<u8>,
|
||||
|
||||
#[serde(rename = "MaxPlayers")]
|
||||
pub max_players: usize,
|
||||
|
||||
#[serde(rename = "Private")]
|
||||
pub private: bool,
|
||||
|
||||
#[serde(rename = "Map")]
|
||||
pub map: String,
|
||||
|
||||
// Options below are not yet supported
|
||||
#[serde(rename = "Name")]
|
||||
pub name: String,
|
||||
#[serde(rename = "LogChat")]
|
||||
pub log_chat: bool,
|
||||
#[serde(rename = "Debug")]
|
||||
pub debug: bool,
|
||||
#[serde(rename = "AuthKey")]
|
||||
pub auth_key: Option<String>,
|
||||
#[serde(rename = "Private")]
|
||||
pub private: bool,
|
||||
#[serde(rename = "Description")]
|
||||
pub description: String,
|
||||
#[serde(rename = "ResourceFolder")]
|
||||
pub resource_folder: String,
|
||||
}
|
||||
|
||||
59
src/main.rs
59
src/main.rs
@@ -2,6 +2,8 @@
|
||||
#[macro_use] extern crate async_trait;
|
||||
#[macro_use] extern crate lazy_static;
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
mod server;
|
||||
mod config;
|
||||
|
||||
@@ -39,6 +41,8 @@ async fn main() {
|
||||
|
||||
let user_config = std::sync::Arc::new(user_config);
|
||||
|
||||
tokio::spawn(backend_heartbeat(user_config.clone()));
|
||||
|
||||
let mut server = server::Server::new(user_config)
|
||||
.await
|
||||
.map_err(|e| error!("{:?}", e))
|
||||
@@ -50,3 +54,58 @@ async fn main() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct HeartbeatInfo {
|
||||
uuid: String,
|
||||
players: usize,
|
||||
maxplayers: usize,
|
||||
port: u16,
|
||||
map: String,
|
||||
private: String, // Needs to be either "true" or "false"
|
||||
version: String,
|
||||
clientversion: String,
|
||||
name: String,
|
||||
modlist: String,
|
||||
modstotalsize: usize,
|
||||
modstotal: usize,
|
||||
playerslist: String,
|
||||
desc: String,
|
||||
}
|
||||
|
||||
async fn backend_heartbeat(config: std::sync::Arc<config::Config>) {
|
||||
let info = HeartbeatInfo {
|
||||
uuid: config.general.auth_key.clone().unwrap_or(String::from("Unknown name!")),
|
||||
players: 0, // TODO: Implement this. Easiest would probably be to have the server send updates every so often
|
||||
maxplayers: config.general.max_players,
|
||||
port: config.general.port.unwrap_or(30814),
|
||||
map: config.general.map.clone(),
|
||||
private: if config.general.private { String::from("true") } else { String::from("false") },
|
||||
version: String::from("1.0"),
|
||||
clientversion: String::from("2.0"), // TODO: What? I think for now I can fill in 2.0
|
||||
name: config.general.name.clone(),
|
||||
modlist: String::from("-"), // TODO: Implement this.
|
||||
modstotalsize: 0, // TODO: Implement this.
|
||||
modstotal: 0, // TODO: Implement this.
|
||||
playerslist: String::from("luuk-bepis;"), // TODO: Implement this
|
||||
desc: config.general.description.clone(),
|
||||
};
|
||||
|
||||
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(30));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
|
||||
heartbeat_post(&info).await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn heartbeat_post(heartbeat_info: &HeartbeatInfo) {
|
||||
if let Err(e) = reqwest::Client::new()
|
||||
.post("https://backend.beammp.com/heartbeat")
|
||||
.form(heartbeat_info)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
error!("Heartbeat error occured: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user