use std::net::{TcpListener, TcpStream};
use std::io::prelude::*;
mod client;

fn main() {
    let listener = TcpListener::bind("127.0.0.1:25567").unwrap();
    let mut buf: [u8; 256] = [1; 256];
    for stream in listener.incoming() {
        //stream.unwrap().write(buf);
        match stream {
            Ok(mut stream) => {
                /*println!("Go!");
                stream.write("test succes/n".as_bytes());
                stream.read(&mut buf);
                stream.flush();*/
                println!("Go!");
                let leng = stream.read(&mut buf).unwrap();
                println!("{}", leng);
                if buf[0] < 200 {
                    buf[(buf[0]-1) as usize] += 2;
                    let mut sstream = TcpStream::connect("127.0.0.1:25565").unwrap();
                    sstream.write(&buf[.. leng]);
                    let c1 = client::Client::new(stream,sstream, &buf);
                    c1.to_string();
                    c1.start_proxy();
                }
                //c1.start_proxy().0.join();
                //c1.start_proxy().1.join();
                },

            Err(_e) => println!("{}",_e),
        }
    }
}

