aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs1
-rw-r--r--src/main.rs182
2 files changed, 94 insertions, 89 deletions
diff --git a/src/config.rs b/src/config.rs
index 45ed6f2..b3d4e31 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
+ pub protocol: u32,
pub backend: SocketAddr,
pub bind: SocketAddr,
pub whitelist: Vec<PlayerConfig>,
diff --git a/src/main.rs b/src/main.rs
index 8111ebd..d1459e1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -84,6 +84,9 @@ async fn handle_client(config: Arc<Config>, sock: TcpStream) -> Result<(), anyho
"new client (version={}, intent={:?})",
p.protocol_version, p.intention
);
+ if p.protocol_version == config.protocol {
+ bail!("protocol version unsupported")
+ }
match p.intention {
ConnectionProtocol::Status => {
handle_status_intent(config, downstream_writer, downstream_reader).await?;
@@ -147,47 +150,6 @@ async fn handle_client(config: Arc<Config>, sock: TcpStream) -> Result<(), anyho
connect(upstream_writer, downstream_reader).await?;
Ok(())
- // for _ in 0..3 {
- // let a = read_packet::<ClientboundLoginPacket, _>(
- // &mut upstream_reader,
- // &mut buf,
- // None,
- // &mut None,
- // )
- // .await?;
- // debug!("login {a:?}");
- // write_packet(&a, &mut downstream_writer, None, &mut None).await?;
- // }
-
- // tokio::spawn(async move {
- // let mut buf = BytesMut::new();
- // loop {
- // let a = read_packet::<ClientboundGamePacket, _>(
- // &mut upstream_reader,
- // &mut buf,
- // None,
- // &mut None,
- // )
- // .await
- // .unwrap();
- // debug!("downstream {a:?}");
- // write_packet(&a, &mut downstream_writer, None, &mut None)
- // .await
- // .unwrap();
- // }
- // });
-
- // loop {
- // let a = read_packet::<ClientboundGamePacket, _>(
- // &mut downstream_reader,
- // &mut buf,
- // None,
- // &mut None,
- // )
- // .await?;
- // debug!("upstream {a:?}");
- // write_packet(&a, &mut upstream_writer, None, &mut None).await?;
- // }
}
async fn connect(mut writer: OwnedWriteHalf, mut reader: OwnedReadHalf) -> anyhow::Result<()> {
@@ -213,9 +175,9 @@ async fn handle_status_intent(
write_packet(
&ServerboundHandshakePacket::ClientIntention(ClientIntentionPacket {
- protocol_version: 760,
- hostname: "127.0.0.1".to_string(),
- port: 25567,
+ protocol_version: config.protocol,
+ hostname: config.backend.ip().to_string(),
+ port: config.backend.port(),
intention: ConnectionProtocol::Status,
}),
&mut upstream_writer,
@@ -231,49 +193,91 @@ async fn handle_status_intent(
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(())
}
+
+// 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(())
+
+// for _ in 0..3 {
+// let a = read_packet::<ClientboundLoginPacket, _>(
+// &mut upstream_reader,
+// &mut buf,
+// None,
+// &mut None,
+// )
+// .await?;
+// debug!("login {a:?}");
+// write_packet(&a, &mut downstream_writer, None, &mut None).await?;
+// }
+
+// tokio::spawn(async move {
+// let mut buf = BytesMut::new();
+// loop {
+// let a = read_packet::<ClientboundGamePacket, _>(
+// &mut upstream_reader,
+// &mut buf,
+// None,
+// &mut None,
+// )
+// .await
+// .unwrap();
+// debug!("downstream {a:?}");
+// write_packet(&a, &mut downstream_writer, None, &mut None)
+// .await
+// .unwrap();
+// }
+// });
+
+// loop {
+// let a = read_packet::<ClientboundGamePacket, _>(
+// &mut downstream_reader,
+// &mut buf,
+// None,
+// &mut None,
+// )
+// .await?;
+// debug!("upstream {a:?}");
+// write_packet(&a, &mut upstream_writer, None, &mut None).await?;
+// }