-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API for getting server and game status
- Loading branch information
1 parent
0a365b0
commit b36a9ca
Showing
4 changed files
with
449 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
Oops, something went wrong.