Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server & game status detection #21

Merged
merged 10 commits into from
Mar 4, 2024
9 changes: 8 additions & 1 deletion frontend/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "better_fleet"
version = "0.1.0"
description = "To kill FleetCreator"
description = "A better fleet creator"
authors = ["Zelytra", "dadodasyra"]
license = ""
repository = ""
Expand All @@ -18,6 +18,13 @@ tauri-build = { version = "1.5.1", features = [] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.6.0", features = [] }
anyhow = "1.0.80"
socket2 = "0.5.6"
tokio = { version = "1.36.0", features = ["full"] }
winapi = { version = "0.3.9", features = ["winsock2"] }
etherparse = "0.14.2"
hostname = "0.3"
sysinfo = "0.30.6"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
Expand Down
59 changes: 59 additions & 0 deletions frontend/src-tauri/src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use std::time::Instant;
use serde::Serialize;

// Assuming these are your global variables in the `api` module
dadodasyra marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Clone)]
pub struct Api {
pub game_status: GameStatus,
pub server_ip: String,
pub server_port: u16,
pub last_updated_server_ip: Instant
}

#[derive(PartialEq, Debug, Clone, Serialize)]
pub enum GameStatus {
dadodasyra marked this conversation as resolved.
Show resolved Hide resolved
Closed,
Started,
MainMenu,
InGameNotLoaded,
InGame,
Unknown
}

impl Api {
pub fn new() -> Self {
Self {
game_status: GameStatus::Unknown,
server_ip: String::new(),
server_port: 0,
last_updated_server_ip: Instant::now()
}
}

/**
* This is the most accurate info you can get about what's going on.
* It's updated AT LEAST every 5 seconds. (1-5 secs)
* This information is prioritized over the others.
*/
pub async fn get_game_status(&self) -> GameStatus {
self.game_status.clone()
}

/**
* Server IP, may be updated
*/
pub async fn get_server_ip(&self) -> String {
self.server_ip.clone()
}


pub async fn get_server_port(&self) -> u16 {
dadodasyra marked this conversation as resolved.
Show resolved Hide resolved
self.server_port
}


pub async fn get_last_updated_server_ip(&self) -> Instant {
dadodasyra marked this conversation as resolved.
Show resolved Hide resolved
self.last_updated_server_ip
}
}

Loading
Loading