From a863e973688af0cdb07141a3a6112d7f5f0fac34 Mon Sep 17 00:00:00 2001 From: Alvsch Date: Thu, 17 Oct 2024 00:23:05 +0200 Subject: [PATCH] forwarded port defaults to player socket address port --- pumpkin/src/client/client_packet.rs | 5 ++- pumpkin/src/client/mod.rs | 9 ++++-- pumpkin/src/main.rs | 2 +- pumpkin/src/proxy/velocity.rs | 49 ++++++++++++++++++----------- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/pumpkin/src/client/client_packet.rs b/pumpkin/src/client/client_packet.rs index 8440a9803..dbfcc89d5 100644 --- a/pumpkin/src/client/client_packet.rs +++ b/pumpkin/src/client/client_packet.rs @@ -20,7 +20,10 @@ use uuid::Uuid; use crate::{ client::authentication::{self, validate_textures, GameProfile}, entity::player::{ChatMode, Hand}, - proxy::{bungeecord::bungeecord_login, velocity::{receive_plugin_response, velocity_login}}, + proxy::{ + bungeecord::bungeecord_login, + velocity::{receive_plugin_response, velocity_login}, + }, server::{Server, CURRENT_MC_VERSION}, }; diff --git a/pumpkin/src/client/mod.rs b/pumpkin/src/client/mod.rs index a362ac19c..12b3b8f7d 100644 --- a/pumpkin/src/client/mod.rs +++ b/pumpkin/src/client/mod.rs @@ -1,8 +1,11 @@ use std::{ - collections::VecDeque, io::{self, Write}, net::SocketAddr, sync::{ + collections::VecDeque, + io::{self, Write}, + net::SocketAddr, + sync::{ atomic::{AtomicBool, AtomicI32}, Arc, - } + }, }; use crate::{ @@ -394,7 +397,7 @@ impl Client { dbg!("a"); self.kick(&err.to_string()); break; - }, + } } } dec.clear(); diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 59944e348..7b7be6fae 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -221,7 +221,7 @@ fn main() -> io::Result<()> { )?; let keep_alive = tokio::sync::mpsc::channel(1024); let client = - Arc::new(Client::new(id, connection, addr, keep_alive.0.into())); + Arc::new(Client::new(id, connection, address, keep_alive.0.into())); { let client = client.clone(); diff --git a/pumpkin/src/proxy/velocity.rs b/pumpkin/src/proxy/velocity.rs index 8a422ff3c..634a72d31 100644 --- a/pumpkin/src/proxy/velocity.rs +++ b/pumpkin/src/proxy/velocity.rs @@ -4,11 +4,14 @@ use bytes::{BufMut, BytesMut}; use hmac::{Hmac, Mac}; use pumpkin_config::proxy::VelocityConfig; use pumpkin_protocol::{ - bytebuf::ByteBuffer, client::login::{CLoginPluginRequest, CLoginSuccess}, server::login::SLoginPluginResponse, Property + bytebuf::ByteBuffer, + client::login::{CLoginPluginRequest, CLoginSuccess}, + server::login::SLoginPluginResponse, + Property, }; use sha2::Sha256; -use crate::client::Client; +use crate::client::{authentication::GameProfile, Client}; type HmacSha256 = Hmac; @@ -61,28 +64,31 @@ pub fn receive_plugin_response( return; } // TODO: no unwrap - let addr: SocketAddr = SocketAddr::new(buf.get_string().unwrap().parse::().unwrap(), 0); + let addr: SocketAddr = SocketAddr::new( + buf.get_string().unwrap().parse::().unwrap(), + client.address.lock().port(), + ); *client.address.lock() = addr; let uuid = buf.get_uuid().unwrap(); - - let username = buf.get_string().unwrap(); - - // Read game profile properties - let properties = buf.get_list(|data| { - let name = data.get_string()?; - let value = data.get_string()?; - let signature = data.get_option(|data| { - data.get_string() - })?; - Ok(Property { - name, - value, - signature, + let username = buf.get_string().unwrap(); + + // Read game profile properties + let properties = buf + .get_list(|data| { + let name = data.get_string()?; + let value = data.get_string()?; + let signature = data.get_option(|data| data.get_string())?; + + Ok(Property { + name, + value, + signature, + }) }) - }).unwrap(); + .unwrap(); client.send_packet(&CLoginSuccess { uuid: &uuid, @@ -90,5 +96,12 @@ pub fn receive_plugin_response( properties: &properties, strict_error_handling: false, }); + + *client.gameprofile.lock() = Some(GameProfile { + id: uuid, + name: username, + properties, + profile_actions: None, + }); } }