add server configuration
This commit is contained in:
26
src/main.rs
26
src/main.rs
@@ -1,10 +1,14 @@
|
||||
use std::net::{TcpListener, TcpStream};
|
||||
use std::io::prelude::*;
|
||||
mod client;
|
||||
mod conf;
|
||||
mod protocol;
|
||||
|
||||
fn main() {
|
||||
let listener = TcpListener::bind("127.0.0.1:25567").unwrap();
|
||||
let mut buf: [u8; 256] = [1; 256];
|
||||
let servers = conf::Servers::new();
|
||||
|
||||
for stream in listener.incoming() {
|
||||
//stream.unwrap().write(buf);
|
||||
match stream {
|
||||
@@ -15,20 +19,28 @@ fn main() {
|
||||
stream.flush();*/
|
||||
println!("Go!");
|
||||
let leng = stream.read(&mut buf).unwrap();
|
||||
println!("{}", buf[6]);
|
||||
if buf[0] < 200 {
|
||||
let mut hs = protocol::HandShake::new(&mut buf[.. leng]);
|
||||
if hs.get_raw()[0] < 200 {
|
||||
let mut sstream;
|
||||
|
||||
if buf[6]==49 {
|
||||
buf[(buf[0]-1) as usize] -= 2;
|
||||
if hs.get_raw()[6]==49 {
|
||||
//buf[(buf[0]-1) as usize] -= 2;
|
||||
println!("p0:{}",hs.get_port());
|
||||
hs.replace_port(servers.get_server(&hs.getHostName()).unwrap().1);
|
||||
println!("p1:{}",hs.get_port());
|
||||
sstream = TcpStream::connect("127.0.0.1:25565").unwrap();
|
||||
} else {
|
||||
buf[(buf[0]-1) as usize] -= 1;
|
||||
println!("p0:{}",hs.get_port());
|
||||
match servers.get_server(&hs.getHostName()) {
|
||||
Some(s) => hs.replace_port(s.1),
|
||||
None => hs.replace_port(25565),
|
||||
}
|
||||
println!("p1:{}",hs.get_port());
|
||||
sstream = TcpStream::connect("127.0.0.1:25566").unwrap();
|
||||
}
|
||||
//let mut sstream = TcpStream::connect("127.0.0.1:25565").unwrap();
|
||||
sstream.write(&buf[.. leng]);
|
||||
let c1 = client::Client::new(stream,sstream, &buf);
|
||||
sstream.write(hs.get_raw());
|
||||
let c1 = client::Client::new(stream,sstream, hs);
|
||||
c1.to_string();
|
||||
c1.start_proxy();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user