use hyper::{Body, Request, Response, Server, service::{make_service_fn, service_fn}}; use serde_json::Value; use std::convert::Infallible; use serde::Deserialize; #[derive(Debug, Deserialize)] struct MatchData { map: Option, round: Option, player_id: Option, player_state: Option, player_weapons: Option, player_match_stats: Option, allplayers_id: Option, } #[derive(Debug, Deserialize)] struct MapData { name: Option, // Add other map-specific fields as necessary } #[derive(Debug, Deserialize)] struct RoundData { phase: Option, // Add other round-specific fields as necessary } #[derive(Debug, Deserialize)] struct PlayerIdData { id: Option, // Add other player_id-specific fields as necessary } #[derive(Debug, Deserialize)] struct PlayerStateData { health: Option, armor: Option, flashed: Option, // Add other player_state-specific fields as necessary } #[derive(Debug, Deserialize)] struct PlayerWeaponsData { primary: Option, secondary: Option, // Add other player_weapons-specific fields as necessary } #[derive(Debug, Deserialize)] struct PlayerMatchStatsData { kills: Option, deaths: Option, // Add other player_match_stats-specific fields as necessary } #[derive(Debug, Deserialize)] struct AllPlayersIdData { players: Vec, // Add other allplayers_id-specific fields as necessary } async fn handle_request(req: Request) -> Result, Infallible> { if req.method() == hyper::Method::POST { let whole_body = hyper::body::to_bytes(req.into_body()).await.unwrap(); let json: Value = serde_json::from_slice(&whole_body).unwrap(); // Print the raw JSON for debugging println!("Received JSON: {}", json); // Print out the parsed data for debugging if let Some(map) = json.as_object() { for (key, value) in map { println!("{}: {}", key, value); } } else { println!("Received data is not a JSON object"); } // Respond to the GSI service Ok(Response::new(Body::from("Received"))) } else { Ok(Response::new(Body::from("Unsupported HTTP method"))) } } #[tokio::main] async fn main() { let make_svc = make_service_fn(|_conn| async { Ok::<_, Infallible>(service_fn(handle_request)) }); let addr = ([0, 0, 0, 0], 5000).into(); // Listen on all interfaces on port 3000 let server = Server::bind(&addr).serve(make_svc); println!("Listening on http://{}", addr); if let Err(e) = server.await { eprintln!("server error: {}", e); } }