aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2022-10-15 22:43:13 +0200
committermetamuffin <metamuffin@disroot.org>2022-10-15 22:43:13 +0200
commit5cb11b387459462dbf283b7572207c10b6d3661f (patch)
treea0f936b2ce0c93d4f7551efc9724d159d3003d7a
parent4dc45825e4b86fcda4ff5dcc0231a5fd6e745164 (diff)
downloadtrash-proxy-5cb11b387459462dbf283b7572207c10b6d3661f.tar
trash-proxy-5cb11b387459462dbf283b7572207c10b6d3661f.tar.bz2
trash-proxy-5cb11b387459462dbf283b7572207c10b6d3661f.tar.zst
a
-rw-r--r--Cargo.lock19
-rw-r--r--Cargo.toml6
-rw-r--r--proxy.yaml3
-rw-r--r--src/main.rs88
4 files changed, 91 insertions, 25 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7105a74..6d1d96f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -101,7 +101,6 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "azalea"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"anyhow",
"async-trait",
@@ -115,7 +114,6 @@ dependencies = [
[[package]]
name = "azalea-auth"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"azalea-buf",
"uuid",
@@ -124,7 +122,6 @@ dependencies = [
[[package]]
name = "azalea-block"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"azalea-block-macros",
"azalea-buf",
@@ -133,7 +130,6 @@ dependencies = [
[[package]]
name = "azalea-block-macros"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"proc-macro2",
"quote",
@@ -143,12 +139,10 @@ dependencies = [
[[package]]
name = "azalea-brigadier"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
[[package]]
name = "azalea-buf"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"azalea-buf-macros",
"byteorder",
@@ -161,7 +155,6 @@ dependencies = [
[[package]]
name = "azalea-buf-macros"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"proc-macro2",
"quote",
@@ -171,7 +164,6 @@ dependencies = [
[[package]]
name = "azalea-chat"
version = "0.1.1"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"azalea-buf",
"azalea-language",
@@ -183,7 +175,6 @@ dependencies = [
[[package]]
name = "azalea-client"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"anyhow",
"azalea-auth",
@@ -204,7 +195,6 @@ dependencies = [
[[package]]
name = "azalea-core"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"azalea-buf",
"azalea-chat",
@@ -215,7 +205,6 @@ dependencies = [
[[package]]
name = "azalea-crypto"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"aes",
"azalea-buf",
@@ -230,7 +219,6 @@ dependencies = [
[[package]]
name = "azalea-language"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"lazy_static",
"serde",
@@ -240,7 +228,6 @@ dependencies = [
[[package]]
name = "azalea-nbt"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"ahash",
"azalea-buf",
@@ -253,7 +240,6 @@ dependencies = [
[[package]]
name = "azalea-physics"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"azalea-block",
"azalea-core",
@@ -264,7 +250,6 @@ dependencies = [
[[package]]
name = "azalea-protocol"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"async-compression",
"async-recursion",
@@ -297,7 +282,6 @@ dependencies = [
[[package]]
name = "azalea-protocol-macros"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"proc-macro2",
"quote",
@@ -307,7 +291,6 @@ dependencies = [
[[package]]
name = "azalea-registry"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"azalea-buf",
"azalea-registry-macros",
@@ -316,7 +299,6 @@ dependencies = [
[[package]]
name = "azalea-registry-macros"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"proc-macro2",
"quote",
@@ -326,7 +308,6 @@ dependencies = [
[[package]]
name = "azalea-world"
version = "0.1.0"
-source = "git+https://github.com/mat-1/azalea#a348f67b9646cf51bedf413bf79271391bdb23b2"
dependencies = [
"azalea-block",
"azalea-buf",
diff --git a/Cargo.toml b/Cargo.toml
index cff762c..854e287 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,9 +6,9 @@ edition = "2021"
[dependencies]
anyhow = "1.0.65"
-azalea = { git = "https://github.com/mat-1/azalea" }
-azalea-protocol = { git = "https://github.com/mat-1/azalea" }
-azalea-chat = { git = "https://github.com/mat-1/azalea" }
+azalea = { path = "../external/azalea/azalea" }
+azalea-protocol = { path = "../external/azalea/azalea-protocol" }
+azalea-chat = { path = "../external/azalea/azalea-chat" }
env_logger = "0.9.1"
uuid = "1.1.2"
parking_lot = "^0.12.1"
diff --git a/proxy.yaml b/proxy.yaml
index 1d466f0..910424d 100644
--- a/proxy.yaml
+++ b/proxy.yaml
@@ -2,5 +2,6 @@ backend: 127.0.0.1:25567
bind: 0.0.0.0:25565
whitelist:
- username: metamuffin
- token: mEAWs8bQqkYrZKqT!!
+ token: mEAWs8bQqkYrZKqT
+
diff --git a/src/main.rs b/src/main.rs
index d79e98f..9a16629 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,8 +1,15 @@
pub mod config;
use anyhow::bail;
+use azalea_chat::text_component::legacy_color_code_to_text_component;
+use azalea_protocol::packets::handshake::client_intention_packet::ClientIntentionPacket;
use azalea_protocol::packets::handshake::ServerboundHandshakePacket;
use azalea_protocol::packets::login::ServerboundLoginPacket;
+use azalea_protocol::packets::status::clientbound_pong_response_packet::ClientboundPongResponsePacket;
+use azalea_protocol::packets::status::clientbound_status_response_packet::{
+ ClientboundStatusResponsePacket, Players, Version,
+};
+use azalea_protocol::packets::status::{ClientboundStatusPacket, ServerboundStatusPacket};
use azalea_protocol::packets::ConnectionProtocol;
use azalea_protocol::read::read_packet;
use azalea_protocol::write::write_packet;
@@ -23,7 +30,7 @@ async fn main() {
let config =
Arc::new(serde_yaml::from_str::<Config>(&read_to_string("proxy.yaml").unwrap()).unwrap());
- let listener = TcpListener::bind("127.0.0.1:25565").await.unwrap();
+ let listener = TcpListener::bind(config.bind).await.unwrap();
info!("listening");
loop {
match listener.accept().await {
@@ -65,6 +72,7 @@ async fn handle_client(
);
match p.intention {
ConnectionProtocol::Status => {
+ handle_status_intent(config, downstream_writer, downstream_reader).await?;
bail!("we dont support ping yet")
}
ConnectionProtocol::Login => {}
@@ -102,7 +110,7 @@ async fn handle_client(
ServerboundLoginPacket::CustomQuery(_) => bail!("custom query not supported"),
};
- let upstream = TcpStream::connect("127.0.0.1:25567").await?;
+ let upstream = TcpStream::connect(config.backend).await?;
let (upstream_reader, mut upstream_writer) = upstream.into_split();
write_packet(
@@ -178,3 +186,79 @@ async fn connect(mut writer: OwnedWriteHalf, mut reader: OwnedReadHalf) -> anyho
writer.write_all(&buf[..size]).await?;
}
}
+
+async fn handle_status_intent(
+ config: Arc<Config>,
+ mut writer: OwnedWriteHalf,
+ mut reader: OwnedReadHalf,
+) -> anyhow::Result<()> {
+ let mut buf = BytesMut::new();
+ let upstream = TcpStream::connect(config.backend).await?;
+ let (upstream_reader, mut upstream_writer) = upstream.into_split();
+
+ write_packet(
+ &ServerboundHandshakePacket::ClientIntention(ClientIntentionPacket {
+ protocol_version: 760,
+ hostname: "127.0.0.1".to_string(),
+ port: 25567,
+ intention: ConnectionProtocol::Status,
+ }),
+ &mut upstream_writer,
+ None,
+ &mut None,
+ )
+ .await?;
+
+ tokio::spawn(async move {
+ connect(writer, upstream_reader).await.unwrap();
+ });
+
+ connect(upstream_writer, reader).await?;
+
+ return Ok(());
+
+ loop {
+ let req = read_packet::<ServerboundStatusPacket, _>(&mut reader, &mut buf, None, &mut None)
+ .await?;
+ info!("{req:?}");
+ match req {
+ ServerboundStatusPacket::StatusRequest(..) => {
+ write_packet(
+ &ClientboundStatusPacket::StatusResponse(ClientboundStatusResponsePacket {
+ description: azalea_chat::component::Component::Text(
+ legacy_color_code_to_text_component("blub"),
+ ),
+ favicon: None,
+ players: Players {
+ max: 10,
+ online: 0,
+ sample: vec![],
+ },
+ version: Version {
+ name: azalea_chat::component::Component::Text(
+ legacy_color_code_to_text_component("blub"),
+ ),
+ protocol: 760,
+ },
+ }),
+ &mut writer,
+ None,
+ &mut None,
+ )
+ .await?;
+ }
+ ServerboundStatusPacket::PingRequest(p) => {
+ write_packet(
+ &ClientboundStatusPacket::PongResponse(ClientboundPongResponsePacket {
+ time: p.time,
+ }),
+ &mut writer,
+ None,
+ &mut None,
+ )
+ .await?;
+ }
+ }
+ }
+ Ok(())
+}