add server configuration
This commit is contained in:
parent
15aa4ec967
commit
d10eba033f
19
Cargo.lock
generated
19
Cargo.lock
generated
@ -2,6 +2,25 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
|
||||
|
||||
[[package]]
|
||||
name = "minecraft_proxy"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"linked-hash-map",
|
||||
"yaml-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yaml-rust"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
|
||||
dependencies = [
|
||||
"linked-hash-map",
|
||||
]
|
||||
|
@ -2,3 +2,7 @@
|
||||
name = "minecraft_proxy"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
yaml-rust = "*"
|
||||
linked-hash-map = "*"
|
@ -1,30 +0,0 @@
|
||||
use std::string;
|
||||
|
||||
|
||||
pub struct HandShake<'a> {
|
||||
len_pack: u8,
|
||||
len_dom: u8,
|
||||
datagram: &'a[u8],
|
||||
host: &'a[u8],
|
||||
port: &'a[u8],
|
||||
}
|
||||
|
||||
impl<'a> HandShake<'a>{
|
||||
pub fn new(data: &[u8]) -> HandShake {
|
||||
let len_pack = data[0];
|
||||
println!("{}", len_pack);
|
||||
let len_dom = data[4];
|
||||
println!("{}", len_dom);
|
||||
HandShake {
|
||||
len_pack: len_pack,
|
||||
len_dom: len_dom,
|
||||
datagram: data.clone(),
|
||||
host: (&data[5 .. ((len_dom + 5) as usize)]).clone(),
|
||||
port: (&data[((len_pack - 2) as usize) .. ((len_pack - 1) as usize)]).clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getHostName(&self) -> String {
|
||||
String::from_utf8(self.datagram[5 .. ((self.len_dom+5) as usize)].to_vec()).unwrap()
|
||||
}
|
||||
}
|
@ -3,26 +3,26 @@ use std::io::prelude::*;
|
||||
use std::thread;
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
|
||||
mod HandShake;
|
||||
use crate::protocol;
|
||||
|
||||
pub struct Client<'a>{
|
||||
client: Arc<Mutex<TcpStream>>,
|
||||
server:Arc<Mutex<TcpStream>>,
|
||||
//client: &'static TcpStream,
|
||||
//server: &'static TcpStream,
|
||||
hs: HandShake::HandShake<'a>,
|
||||
hs: protocol::HandShake<'a>,
|
||||
run : Arc<RwLock<bool>>,
|
||||
//run: &'static bool
|
||||
}
|
||||
|
||||
impl<'a> Client<'a> {
|
||||
pub fn new(client: TcpStream, server: TcpStream, handshake: &[u8]) -> Client{
|
||||
pub fn new(client: TcpStream, server: TcpStream, handshake: protocol::HandShake) -> Client{
|
||||
Client {
|
||||
client: Arc::new(Mutex::new(client)),
|
||||
server: Arc::new(Mutex::new(server)),
|
||||
//client: client,
|
||||
//server: server,
|
||||
hs: HandShake::HandShake::new(handshake),
|
||||
hs: handshake,
|
||||
run: Arc::new(RwLock::new(true)),
|
||||
//run: &true,
|
||||
}
|
||||
|
62
src/conf/mod.rs
Normal file
62
src/conf/mod.rs
Normal file
@ -0,0 +1,62 @@
|
||||
use yaml_rust::yaml;
|
||||
use std::fs::File;
|
||||
use std::str::FromStr;
|
||||
use std::io::prelude::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
static file: &str = "mrprox.conf";
|
||||
|
||||
pub struct Servers{
|
||||
l_servers : HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl Servers {
|
||||
pub fn new() -> Servers {
|
||||
Servers{
|
||||
l_servers: Self::get_servers(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_servers() -> HashMap<String, String> {
|
||||
let mut f = File::open(&file).unwrap();
|
||||
let mut s = String::new();
|
||||
let mut ret = HashMap::new();
|
||||
f.read_to_string(&mut s).unwrap();
|
||||
let docs = yaml::YamlLoader::load_from_str(&s).unwrap();
|
||||
let docs2;
|
||||
match &docs[0]["servers"] {
|
||||
yaml::Yaml::Hash(ref h) => docs2 = h,
|
||||
_ => return ret,
|
||||
}
|
||||
|
||||
|
||||
for (k, v) in docs2{
|
||||
//println!("{}",String::from(doc.as_str().unwrap()));
|
||||
ret.insert(String::from(k.as_str().unwrap()),
|
||||
String::from(v.as_str().unwrap()));
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
fn get_host(&self, host: &String) -> Option<(&String, &String)>{
|
||||
self.l_servers.get_key_value(host)
|
||||
}
|
||||
|
||||
pub fn get_server(&self, host: &String) -> Option<(String, u16)>{
|
||||
let raw: Vec<&str>;
|
||||
match self.get_host(host){
|
||||
Some(h) => raw=h.1.split(":").collect(),
|
||||
None => return None,
|
||||
}
|
||||
|
||||
if raw.len() == 2 {
|
||||
|
||||
match FromStr::from_str(raw[1]) {
|
||||
Ok(p) => return Some((String::from(raw[0]),p)),
|
||||
Err(_e) => return None,
|
||||
}
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
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();
|
||||
}
|
||||
|
@ -2,7 +2,8 @@ minecraft_proxy_sources = [
|
||||
cargo_sources,
|
||||
'main.rs',
|
||||
'client/mod.rs',
|
||||
'client/HandShake.rs',
|
||||
'protocol/mod.rs',
|
||||
'conf/mod.rs',
|
||||
]
|
||||
|
||||
minecraft_proxy_deps = [
|
||||
|
48
src/protocol/mod.rs
Normal file
48
src/protocol/mod.rs
Normal file
@ -0,0 +1,48 @@
|
||||
use std::string;
|
||||
|
||||
pub struct HandShake<'a> {
|
||||
len_pack: u8,
|
||||
len_dom: u8,
|
||||
port_pos: usize,
|
||||
datagram: &'a mut [u8],
|
||||
//host: &'a [u8],
|
||||
//port: &'a mut [u8],
|
||||
}
|
||||
|
||||
impl<'a> HandShake<'a>{
|
||||
pub fn new(data: &'a mut[u8]) -> HandShake {
|
||||
let len_pack = data[0];
|
||||
println!("{}", len_pack);
|
||||
let len_dom = data[4];
|
||||
println!("{}", len_dom);
|
||||
HandShake {
|
||||
len_pack: len_pack,
|
||||
len_dom: len_dom,
|
||||
datagram: data,
|
||||
port_pos: (len_pack - 2) as usize,
|
||||
//host: (&mut data[5 .. ((len_dom + 5) as usize)]),
|
||||
//port: (&mut data[((len_pack - 2) as usize) .. ((len_pack - 1) as usize)]),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn getHostName(&self) -> String {
|
||||
String::from_utf8(self.datagram[5 .. ((self.len_dom+5) as usize)].to_vec()).unwrap()
|
||||
}
|
||||
|
||||
pub fn get_port(&self) -> u16 {
|
||||
u16::from_be_bytes([(self.datagram[(self.len_pack - 2) as usize]),
|
||||
(self.datagram[(self.len_pack - 1) as usize])])
|
||||
}
|
||||
|
||||
pub fn replace_port(&mut self, n_port: u16){
|
||||
let s_port = n_port.to_ne_bytes();
|
||||
self.datagram[self.port_pos]=s_port[0];
|
||||
self.datagram[self.port_pos+1]=s_port[1];
|
||||
}
|
||||
|
||||
|
||||
pub fn get_raw(&self) -> &[u8]{
|
||||
self.datagram
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
@ -0,0 +1 @@
|
||||
dd99c6c05f983f28
|
@ -0,0 +1 @@
|
||||
{"rustc":7760963814944444074,"features":"[]","target":2880346732057363471,"profile":3735503092003429423,"path":14627486416815506953,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/linked-hash-map-b53301f2a9f6de72/dep-lib-linked-hash-map"}}],"rustflags":[],"metadata":11673622644101893762,"config":2202906307356721367,"compile_kind":0}
|
@ -0,0 +1 @@
|
||||
1f70adb73f12469c
|
@ -0,0 +1 @@
|
||||
{"rustc":7760963814944444074,"features":"[]","target":9069231020325575711,"profile":7309141686862299243,"path":1684066648322511884,"deps":[[3982932547530265283,"linked_hash_map",false,2900204222073444829],[14371587128542172710,"yaml_rust",false,4607209719658667149]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/minecraft_proxy-34995ff564ebc3ef/dep-bin-minecraft_proxy"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
@ -0,0 +1 @@
|
||||
1482aa83b88656ad
|
@ -0,0 +1 @@
|
||||
{"rustc":7760963814944444074,"features":"[]","target":9069231020325575711,"profile":1021633075455700787,"path":1684066648322511884,"deps":[[14371587128542172710,"yaml_rust",false,4607209719658667149]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/minecraft_proxy-7f9e2b57e1c33290/dep-test-bin-minecraft_proxy"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
@ -0,0 +1 @@
|
||||
ee91158f507e016c
|
@ -0,0 +1 @@
|
||||
{"rustc":7760963814944444074,"features":"[]","target":9069231020325575711,"profile":7309141686862299243,"path":1684066648322511884,"deps":[[14371587128542172710,"yaml_rust",false,4607209719658667149]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/minecraft_proxy-ce2f01d15d35a6f6/dep-bin-minecraft_proxy"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
@ -0,0 +1 @@
|
||||
3118d2a16f2fb405
|
@ -0,0 +1 @@
|
||||
{"rustc":7760963814944444074,"features":"[]","target":9069231020325575711,"profile":1021633075455700787,"path":1684066648322511884,"deps":[[3982932547530265283,"linked_hash_map",false,2900204222073444829],[14371587128542172710,"yaml_rust",false,4607209719658667149]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/minecraft_proxy-fa6473a382e03cbf/dep-test-bin-minecraft_proxy"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
This file has an mtime of when this was started.
|
@ -0,0 +1 @@
|
||||
8d5cfb79d418f03f
|
@ -0,0 +1 @@
|
||||
{"rustc":7760963814944444074,"features":"[]","target":9877899882793075686,"profile":3735503092003429423,"path":2385833681204664976,"deps":[[3982932547530265283,"linked_hash_map",false,2900204222073444829]],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/yaml-rust-425adb7692278778/dep-lib-yaml-rust"}}],"rustflags":[],"metadata":3685397162052115131,"config":2202906307356721367,"compile_kind":0}
|
BIN
target/rls/debug/deps/liblinked_hash_map-b53301f2a9f6de72.rmeta
Normal file
BIN
target/rls/debug/deps/liblinked_hash_map-b53301f2a9f6de72.rmeta
Normal file
Binary file not shown.
BIN
target/rls/debug/deps/libyaml_rust-425adb7692278778.rmeta
Normal file
BIN
target/rls/debug/deps/libyaml_rust-425adb7692278778.rmeta
Normal file
Binary file not shown.
5
target/rls/debug/deps/linked_hash_map-b53301f2a9f6de72.d
Normal file
5
target/rls/debug/deps/linked_hash_map-b53301f2a9f6de72.d
Normal file
@ -0,0 +1,5 @@
|
||||
/home/roche/Proyectos/minecraft_proxy/target/rls/debug/deps/linked_hash_map-b53301f2a9f6de72.rmeta: /home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/linked-hash-map-0.5.6/src/lib.rs
|
||||
|
||||
/home/roche/Proyectos/minecraft_proxy/target/rls/debug/deps/linked_hash_map-b53301f2a9f6de72.d: /home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/linked-hash-map-0.5.6/src/lib.rs
|
||||
|
||||
/home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/linked-hash-map-0.5.6/src/lib.rs:
|
8
target/rls/debug/deps/minecraft_proxy-34995ff564ebc3ef.d
Normal file
8
target/rls/debug/deps/minecraft_proxy-34995ff564ebc3ef.d
Normal file
@ -0,0 +1,8 @@
|
||||
/home/roche/Proyectos/minecraft_proxy/target/rls/debug/deps/minecraft_proxy-34995ff564ebc3ef.rmeta: src/main.rs src/client/mod.rs src/conf/mod.rs src/protocol/mod.rs
|
||||
|
||||
/home/roche/Proyectos/minecraft_proxy/target/rls/debug/deps/minecraft_proxy-34995ff564ebc3ef.d: src/main.rs src/client/mod.rs src/conf/mod.rs src/protocol/mod.rs
|
||||
|
||||
src/main.rs:
|
||||
src/client/mod.rs:
|
||||
src/conf/mod.rs:
|
||||
src/protocol/mod.rs:
|
8
target/rls/debug/deps/minecraft_proxy-7f9e2b57e1c33290.d
Normal file
8
target/rls/debug/deps/minecraft_proxy-7f9e2b57e1c33290.d
Normal file
@ -0,0 +1,8 @@
|
||||
/home/roche/Proyectos/minecraft_proxy/target/rls/debug/deps/minecraft_proxy-7f9e2b57e1c33290.rmeta: src/main.rs src/client/mod.rs src/client/HandShake.rs src/conf/mod.rs
|
||||
|
||||
/home/roche/Proyectos/minecraft_proxy/target/rls/debug/deps/minecraft_proxy-7f9e2b57e1c33290.d: src/main.rs src/client/mod.rs src/client/HandShake.rs src/conf/mod.rs
|
||||
|
||||
src/main.rs:
|
||||
src/client/mod.rs:
|
||||
src/client/HandShake.rs:
|
||||
src/conf/mod.rs:
|
8
target/rls/debug/deps/minecraft_proxy-ce2f01d15d35a6f6.d
Normal file
8
target/rls/debug/deps/minecraft_proxy-ce2f01d15d35a6f6.d
Normal file
@ -0,0 +1,8 @@
|
||||
/home/roche/Proyectos/minecraft_proxy/target/rls/debug/deps/minecraft_proxy-ce2f01d15d35a6f6.rmeta: src/main.rs src/client/mod.rs src/client/HandShake.rs src/conf/mod.rs
|
||||
|
||||
/home/roche/Proyectos/minecraft_proxy/target/rls/debug/deps/minecraft_proxy-ce2f01d15d35a6f6.d: src/main.rs src/client/mod.rs src/client/HandShake.rs src/conf/mod.rs
|
||||
|
||||
src/main.rs:
|
||||
src/client/mod.rs:
|
||||
src/client/HandShake.rs:
|
||||
src/conf/mod.rs:
|
8
target/rls/debug/deps/minecraft_proxy-fa6473a382e03cbf.d
Normal file
8
target/rls/debug/deps/minecraft_proxy-fa6473a382e03cbf.d
Normal file
@ -0,0 +1,8 @@
|
||||
/home/roche/Proyectos/minecraft_proxy/target/rls/debug/deps/minecraft_proxy-fa6473a382e03cbf.rmeta: src/main.rs src/client/mod.rs src/conf/mod.rs src/protocol/mod.rs
|
||||
|
||||
/home/roche/Proyectos/minecraft_proxy/target/rls/debug/deps/minecraft_proxy-fa6473a382e03cbf.d: src/main.rs src/client/mod.rs src/conf/mod.rs src/protocol/mod.rs
|
||||
|
||||
src/main.rs:
|
||||
src/client/mod.rs:
|
||||
src/conf/mod.rs:
|
||||
src/protocol/mod.rs:
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
9
target/rls/debug/deps/yaml_rust-425adb7692278778.d
Normal file
9
target/rls/debug/deps/yaml_rust-425adb7692278778.d
Normal file
@ -0,0 +1,9 @@
|
||||
/home/roche/Proyectos/minecraft_proxy/target/rls/debug/deps/yaml_rust-425adb7692278778.rmeta: /home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/lib.rs /home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/emitter.rs /home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/parser.rs /home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/scanner.rs /home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/yaml.rs
|
||||
|
||||
/home/roche/Proyectos/minecraft_proxy/target/rls/debug/deps/yaml_rust-425adb7692278778.d: /home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/lib.rs /home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/emitter.rs /home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/parser.rs /home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/scanner.rs /home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/yaml.rs
|
||||
|
||||
/home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/lib.rs:
|
||||
/home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/emitter.rs:
|
||||
/home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/parser.rs:
|
||||
/home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/scanner.rs:
|
||||
/home/roche/.cargo/registry/src/github.com-1ecc6299db9ec823/yaml-rust-0.4.5/src/yaml.rs:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user