mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-09-22 22:28:22 +03:00
add test server
This commit is contained in:
Generated
+11
@@ -18,6 +18,17 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "amnet-server-test"
|
||||
version = "2.0.0"
|
||||
dependencies = [
|
||||
"amnet",
|
||||
"axum",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atomic-waker"
|
||||
version = "1.1.2"
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
[workspace]
|
||||
members = ["amnet-server"]
|
||||
members = ["amnet-server", "amnet-server-test"]
|
||||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "2.0.0"
|
||||
authors = ["ppc"]
|
||||
description = "AMNet IC Card Switcher"
|
||||
description = "AMNet IC Card Switcher"
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
[package]
|
||||
name = "amnet-server-test"
|
||||
edition = "2024"
|
||||
|
||||
version.workspace = true
|
||||
authors.workspace = true
|
||||
description = "AMNet Server Test Application"
|
||||
|
||||
[[bin]]
|
||||
name = "amnet-server-test"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
amnet = { path = "../amnet-server" }
|
||||
axum = "0.8.8"
|
||||
tokio = { version = "1", features = ["rt-multi-thread", "macros", "net", "time"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = "0.3"
|
||||
@@ -0,0 +1,65 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use amnet::{build_server, CardSlot, ServerConfig, Metrics, format_hex_bytes};
|
||||
use tokio::net::TcpListener;
|
||||
use tracing::{info, warn};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(tracing::Level::DEBUG)
|
||||
.init();
|
||||
|
||||
let config = ServerConfig::instance();
|
||||
|
||||
info!("AMNet Server (Test Application)");
|
||||
|
||||
info!("Configuration:");
|
||||
info!(" Game ID: {}", config.game_id.as_deref().unwrap_or("(not set)"));
|
||||
info!(" Server Name: {}", config.server_name);
|
||||
info!(" Listen Address: {}", config.server_listen_address);
|
||||
info!(" Physical Card Use IDm: {}", config.physical_card_use_idm);
|
||||
info!("");
|
||||
|
||||
// Start the webserver in the background
|
||||
let app = build_server();
|
||||
let listen_addr = config.server_listen_address.as_str();
|
||||
|
||||
let listener = match TcpListener::bind(listen_addr).await {
|
||||
Ok(l) => l,
|
||||
Err(e) => {
|
||||
warn!("Failed to bind to {}: {}", listen_addr, e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
Metrics::instance().set_start_time();
|
||||
|
||||
info!("Server started on {}", listen_addr);
|
||||
info!("Submit a card via the web API and it will be detected here.");
|
||||
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = axum::serve(listener, app).await {
|
||||
warn!("Server error: {}", e);
|
||||
}
|
||||
});
|
||||
|
||||
loop {
|
||||
if let Err(_) = Metrics::instance().set_last_poll() {
|
||||
warn!("Failed to update poll metrics");
|
||||
}
|
||||
|
||||
if let Some(card) = CardSlot::instance().request_card(None) {
|
||||
info!("=== CARD DETECTED ===");
|
||||
info!(" Access Code: {}", format_hex_bytes(&card.access_code));
|
||||
|
||||
if let Some(idm) = card.card_idm {
|
||||
info!(" Card IDm: {}", format_hex_bytes(&idm));
|
||||
} else {
|
||||
info!(" Card IDm: (not provided)");
|
||||
}
|
||||
}
|
||||
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
}
|
||||
@@ -169,6 +169,7 @@ pub extern "system" fn DllMain(_hinst_dll: *mut std::ffi::c_void, fdw_reason: u3
|
||||
}
|
||||
|
||||
tracing_subscriber::fmt()
|
||||
.with_max_level(tracing::Level::DEBUG)
|
||||
.with_ansi(false) // some targets that are injected into don't play nicely with ansi codes
|
||||
.init();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user