From 8735824495da5cf6744c4b0f69b6c40cd16e6275 Mon Sep 17 00:00:00 2001 From: Luuk van Oijen Date: Wed, 15 Nov 2023 13:38:07 +0100 Subject: [PATCH] start of http stuff --- src/server/http.rs | 14 ++++++++++++++ src/server/mod.rs | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/server/http.rs diff --git a/src/server/http.rs b/src/server/http.rs new file mode 100644 index 0000000..9c34521 --- /dev/null +++ b/src/server/http.rs @@ -0,0 +1,14 @@ +use tokio::io::{AsyncReadExt, AsyncWriteExt}; +use tokio::net::{ + tcp::{OwnedReadHalf, OwnedWriteHalf}, + TcpStream, +}; + +pub async fn handle_http_get(socket: TcpStream) { + let (read_half, write_half) = socket.into_split(); + todo!() +} + +async fn read_get_request(socket: &mut OwnedReadHalf) { + todo!() +} diff --git a/src/server/mod.rs b/src/server/mod.rs index 6fa7f92..95f2e20 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -16,12 +16,14 @@ mod car; mod client; mod packet; mod plugins; +mod http; pub use backend::*; pub use car::*; pub use client::*; pub use packet::*; pub use plugins::*; +pub use http::*; pub use crate::config::Config; @@ -171,6 +173,22 @@ impl Server { } } }, + 'D' => { + // Download connection (for old protocol) + // New protocol should use HTTP for downloads, so + // I will leave this unimplemented for now. + }, + 'G' => { + // This is probably an HTTP GET request! + let mut tmp = [0u8; 3]; + socket.read_exact(&mut tmp).await.expect("Failed to read from socket!"); + if tmp[0] as char == 'E' && tmp[1] as char == 'T' && tmp[2] as char == ' ' { + trace!("HTTP GET request found!"); + handle_http_get(socket).await; + } else { + trace!("Unknown G packet received, not sure what to do!"); + } + }, _ => {}, }; });