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
Merged
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [macos-latest, ubuntu-20.04, windows-latest]
platform: [windows-latest]
defaults:
run:
working-directory: 'frontend'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [macos-latest, ubuntu-20.04, windows-latest]
platform: [windows-latest]
defaults:
run:
working-directory: 'frontend'
Expand Down
10 changes: 9 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,14 @@ 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"
netstat2 = "0.9.1"

[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
64 changes: 64 additions & 0 deletions frontend/src-tauri/src/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use std::time::Instant;
use serde::Serialize;

// This whole file is used to cache data from thread and expose it to the frontend.
#[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, // Game is closed
Started, // Game is in first menu after launch / launching / stopping
MainMenu, // In menu to select game mode
InGame, // Status when the remote IP and port was found and player is in game
Unknown // Default / errored status, this should not be used
}

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, should only be used when GameStatus is InGame.
*/
pub async fn get_server_ip(&self) -> String {
self.server_ip.clone()
}


/**
* Server port, should only be used when GameStatus is InGame.
*/
pub async fn get_server_port(&self) -> u16 {
dadodasyra marked this conversation as resolved.
Show resolved Hide resolved
self.server_port
}

/**
* This corresponds to a timestamp of the last time the server IP was updated.
* This may be used to check if the thread crashed / if something gones wrong.
*/
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