mirror of
https://gitea.tendokyu.moe/ppc/amnet.git
synced 2026-10-11 17:08:10 +03:00
add test server
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user