aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--proxy.yaml8
-rw-r--r--readme.md27
-rw-r--r--src/main.rs26
3 files changed, 34 insertions, 27 deletions
diff --git a/proxy.yaml b/proxy.yaml
deleted file mode 100644
index ff3b194..0000000
--- a/proxy.yaml
+++ /dev/null
@@ -1,8 +0,0 @@
-protocol: 760
-backend: 127.0.0.1:25567
-bind: 0.0.0.0:25565
-whitelist:
- - username: metamuffin
- token: mEAWs8bQqkYrZKqT
-
-
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..4d7abfd
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,27 @@
+# trash-proxy
+
+A really bad minecraft reverse proxy for authentification of offline clients.
+
+Supported version: 1.19.2
+
+Whenever a client connects, the username is checked against all tokens in the
+whitelist, the first match will determine the username you log in as.
+
+## Usage
+
+- Install with `cargo install --path .`
+- Write configuration to `./proxy.yaml`
+- Run `trash-proxy`
+
+## Example configuration
+
+```
+protocol: 760
+backend: 127.0.0.1:25567
+bind: 0.0.0.0:25565
+whitelist:
+ - username: Steve
+ token: veryverysecret
+ - username: Alex
+ token: hunter2
+```
diff --git a/src/main.rs b/src/main.rs
index d1459e1..220c4c9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,6 +20,7 @@ use tokio::{
tcp::{OwnedReadHalf, OwnedWriteHalf},
TcpListener, TcpStream,
},
+ sync::RwLock,
};
#[tokio::main]
@@ -29,34 +30,21 @@ async fn main() {
.parse_env("LOG")
.init();
- let config =
- Arc::new(serde_yaml::from_str::<Config>(&read_to_string("proxy.yaml").unwrap()).unwrap());
+ let config = RwLock::new(Arc::new(
+ serde_yaml::from_str::<Config>(&read_to_string("proxy.yaml").unwrap()).unwrap(),
+ ));
- let listener = TcpListener::bind(config.bind).await.unwrap();
+ let listener = TcpListener::bind(config.read().await.bind).await.unwrap();
info!("listening");
loop {
match listener.accept().await {
Ok((sock, addr)) => {
info!("connected: {addr}");
- let config = config.clone();
+ let config = config.read().await.clone();
tokio::spawn(async move {
match handle_client(config, sock).await {
Ok(()) => info!("disconnected: {addr}"),
- Err(err) => {
- // write_packet::<ClientboundLoginPacket, _>(
- // &ClientboundLoginPacket::LoginDisconnect(
- // ClientboundLoginDisconnectPacket {
- // reason: azalea_chat::component::Component::Text(
- // legacy_color_code_to_text_component(&format!("{err}")),
- // ),
- // },
- // ),
- // &mut sock,
- // None,
- // &mut None,
- // );
- warn!("error: ({addr}) {err}")
- }
+ Err(err) => warn!("error: ({addr}) {err}"),
}
});
}