Skip to content

Commit

Permalink
API for getting server and game status
Browse files Browse the repository at this point in the history
  • Loading branch information
dadodasyra committed Mar 2, 2024
1 parent 0a365b0 commit b36a9ca
Show file tree
Hide file tree
Showing 4 changed files with 449 additions and 5 deletions.
7 changes: 7 additions & 0 deletions frontend/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
62 changes: 62 additions & 0 deletions frontend/src-tauri/src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use std::time::Instant;

// Assuming these are your global variables in the `api` module
#[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)]
pub enum GameStatus {
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.
*/
#[tauri::command]
pub async fn get_game_status(&self) -> GameStatus {
self.game_status.clone()
}

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

#[tauri::command]

pub async fn get_server_port(&self) -> u16 {
self.server_port
}

#[tauri::command]

pub async fn get_last_updated_server_ip(&self) -> Instant {
self.last_updated_server_ip
}
}

Loading

0 comments on commit b36a9ca

Please sign in to comment.