Replay client handshake when lobby connects to real server

This commit is contained in:
timvisee 2021-11-18 12:02:06 +01:00
parent 78a36978f5
commit e23a61ab0f
No known key found for this signature in database
GPG Key ID: B8DB720BC383E172
5 changed files with 15 additions and 21 deletions

4
Cargo.lock generated
View File

@ -869,7 +869,7 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]] [[package]]
name = "minecraft-protocol" name = "minecraft-protocol"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/timvisee/rust-minecraft-protocol?rev=356ea54#356ea5424374c5a7249be2f0f13fd3e0e2db5b58" source = "git+https://github.com/timvisee/rust-minecraft-protocol?rev=6d1ef0b#6d1ef0b27d7d49ee25109256e2c6b7a095ef255d"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"minecraft-protocol-derive", "minecraft-protocol-derive",
@ -882,7 +882,7 @@ dependencies = [
[[package]] [[package]]
name = "minecraft-protocol-derive" name = "minecraft-protocol-derive"
version = "0.0.0" version = "0.0.0"
source = "git+https://github.com/timvisee/rust-minecraft-protocol?rev=356ea54#356ea5424374c5a7249be2f0f13fd3e0e2db5b58" source = "git+https://github.com/timvisee/rust-minecraft-protocol?rev=6d1ef0b#6d1ef0b27d7d49ee25109256e2c6b7a095ef255d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

View File

@ -42,7 +42,7 @@ dotenv = "0.15"
flate2 = { version = "1.0", default-features = false, features = ["default"] } flate2 = { version = "1.0", default-features = false, features = ["default"] }
futures = { version = "0.3", default-features = false, features = ["executor"] } futures = { version = "0.3", default-features = false, features = ["executor"] }
log = "0.4" log = "0.4"
minecraft-protocol = { git = "https://github.com/timvisee/rust-minecraft-protocol", rev = "356ea54" } minecraft-protocol = { git = "https://github.com/timvisee/rust-minecraft-protocol", rev = "6d1ef0b" }
notify = "4.0" notify = "4.0"
pretty_env_logger = "0.4" pretty_env_logger = "0.4"
proxy-protocol = "0.5" proxy-protocol = "0.5"

View File

@ -8,7 +8,6 @@ use bytes::BytesMut;
use futures::FutureExt; use futures::FutureExt;
use minecraft_protocol::data::chat::{Message, Payload}; use minecraft_protocol::data::chat::{Message, Payload};
use minecraft_protocol::decoder::Decoder; use minecraft_protocol::decoder::Decoder;
use minecraft_protocol::version::v1_14_4::handshake::Handshake;
use minecraft_protocol::version::v1_14_4::login::{LoginStart, LoginSuccess, SetCompression}; use minecraft_protocol::version::v1_14_4::login::{LoginStart, LoginSuccess, SetCompression};
use minecraft_protocol::version::v1_17_1::game::{ use minecraft_protocol::version::v1_17_1::game::{
ClientBoundKeepAlive, ClientBoundPluginMessage, JoinGame, NamedSoundEffect, ClientBoundKeepAlive, ClientBoundPluginMessage, JoinGame, NamedSoundEffect,
@ -608,18 +607,13 @@ async fn connect_to_server_no_timeout(
let (mut reader, mut writer) = outbound.split(); let (mut reader, mut writer) = outbound.split();
// Handshake packet // Replay client handshake packet
packet::write_packet( assert_eq!(
Handshake { client_info.handshake.as_ref().unwrap().next_state,
protocol_version: client_info.protocol_version.unwrap(), ClientState::Login.to_id(),
server_addr: config.server.address.ip().to_string(), "Client handshake should have login as next state"
server_port: config.server.address.port(), );
next_state: ClientState::Login.to_id(), packet::write_packet(client_info.handshake.unwrap(), &tmp_client, &mut writer).await?;
},
&tmp_client,
&mut writer,
)
.await?;
// Request login start // Request login start
packet::write_packet( packet::write_packet(

View File

@ -2,6 +2,8 @@ use std::net::SocketAddr;
use std::sync::atomic::{AtomicI32, Ordering}; use std::sync::atomic::{AtomicI32, Ordering};
use std::sync::Mutex; use std::sync::Mutex;
use minecraft_protocol::version::v1_14_4::handshake::Handshake;
/// Client state. /// Client state.
/// ///
/// Note: this does not keep track of encryption states. /// Note: this does not keep track of encryption states.
@ -113,8 +115,8 @@ impl Default for ClientState {
/// Client info, useful during connection handling. /// Client info, useful during connection handling.
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct ClientInfo { pub struct ClientInfo {
/// Client protocol version. /// Handshake as received from client.
pub protocol_version: Option<i32>, pub handshake: Option<Handshake>,
/// Client username. /// Client username.
pub username: Option<String>, pub username: Option<String>,

View File

@ -84,9 +84,7 @@ pub async fn serve(
}; };
// Update client info and client state // Update client info and client state
client_info client_info.handshake.replace(handshake);
.protocol_version
.replace(handshake.protocol_version);
client.set_state(new_state); client.set_state(new_state);
// If loggin in with handshake, remember inbound // If loggin in with handshake, remember inbound