diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c41cc9e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..c74d07f --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "sRAC" +version = "0.1.0" diff --git a/PROTOCOL.md b/PROTOCOL.md index bb93075..029f1ea 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -55,9 +55,7 @@ Client sends: Server sends: -- `0x00` if successful or `0x01` if the username is already taken - -*legacy servers send nothing on successful registration* +- `0x01` if the username is already taken ## Sending authorized messages diff --git a/README.md b/README.md index 37b4359..25376c5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # sRAC -server for RAC +simple server for RAC + +## Usage + +```bash +git clone https://github.com/MeexReay/sRAC +cd sRAC +cargo run 127.0.0.1:42666 +``` \ No newline at end of file diff --git a/config.yml b/config.yml deleted file mode 100644 index b2b221d..0000000 --- a/config.yml +++ /dev/null @@ -1,4 +0,0 @@ -host: 127.0.0.1:42666 - -threadpool: 10 -timeout: 5 # in seconds diff --git a/src/main.rs b/src/main.rs index e7a11a9..ef67405 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,27 @@ -fn main() { - println!("Hello, world!"); +use std::{env::args, error::Error, io::Read, net::{TcpListener, TcpStream}, thread}; + +fn accept_stream(mut stream: TcpStream) -> Result<(), Box> { + let mut buf = vec![0; 4096]; + + stream.read(&mut buf)?; + + if buf[0] + + Ok(()) +} + +fn main() { + let addr = args().skip(1).next().expect("needs at least 1 argument (host:port)"); + + let listener = TcpListener::bind(&addr).expect("error trying bind to the provided addr"); + + println!("Server started on {}", &addr); + + for stream in listener.incoming() { + let Ok(stream) = stream else { continue }; + + thread::spawn(move || { + let _ = accept_stream(stream); + }); + } }