Finish server login and stub configuration

This commit is contained in:
Garen Tyler 2025-06-06 19:56:00 -06:00
parent d5a87ed4f5
commit 7fc1c70292
Signed by: garentyler
SSH Key Fingerprint: SHA256:G4ke7blZMdpWPbkescyZ7IQYE4JAtwpI85YoJdq+S7U
5 changed files with 38 additions and 5 deletions

2
asn1der.txt Normal file
View File

@ -0,0 +1,2 @@
reference 30819F300D06092A864886F70D010101050003818D0030818902818100E74798B642B8B855C6C24C32E49B7B842F02739F74BDC0F206C606D28B95BE63B4CC0BB263A038A27B9D2BCDA1375A2E91D3106938FCDC735DE8639C67FC03C8F45E1937390EAE7B358F39DC0C731627B614A61CB6B37F51FD4068149E9A29A854B913FA2DBA529D651BEAF67EEE65BF1019720F0D000C777DB4CE61062E911D0203010001
ours 30819506092A864886F70D0101010500028180A43795E1BF36BDA93EFAE6EC1EBF638BBA0B3075F0FCA2B54A822C756BE9B6A9F959D64EB1EB32EC54179A659D3D25A16DF7258CCFCD886C2BDA3556455073D0282C25CED058FDAC7AA9C99631D071CAAFA1D2D7AD178C6DFE480D9B5D9BF7485F136F0AE07653851D48323D614EB72EE6559895AF1D695467A0D90D2469D4510203010001

View File

@ -10,3 +10,5 @@ services:
environment:
EULA: "TRUE"
VERSION: "1.21.1"
ONLINE_MODE: "false"
NETWORK_COMPRESSION_THRESHOLD: "-1"

View File

@ -10,6 +10,7 @@ use crate::{
},
};
use tokio::net::TcpStream;
use tracing::trace;
/// The connection's current state.
/// Similar to crate::protocol::ClientState,
@ -126,7 +127,7 @@ impl DownstreamConnection {
let login_start = self.read_specific_packet::<LoginStart>().await?;
// Enable encryption and authenticate with Mojang.
self.enable_encryption().await?;
// self.enable_encryption().await?;
// Enable compression.
self.enable_compression().await?;
@ -193,6 +194,8 @@ impl DownstreamConnection {
.expect("failed to decrypt shared secret");
// Enable encryption on the connection.
trace!("Enabling encryption for connection {}", self.inner.id);
todo!("Fix AES encryption implementation");
let encryptor =
Aes128Cfb8Encryptor::new((&(*shared_secret)).into(), (&(*shared_secret)).into());
let decryptor =
@ -212,7 +215,10 @@ impl DownstreamConnection {
self.inner.send_packet(packet).await
}
pub async fn disconnect(&mut self, reason: Option<Chat>) -> Result<(), Error> {
use packets::{login::clientbound::LoginDisconnect, play::clientbound::PlayDisconnect};
use packets::{
configuration::clientbound::ConfigurationDisconnect,
login::clientbound::LoginDisconnect, play::clientbound::PlayDisconnect,
};
// let reason = reason.unwrap_or(serde_json::json!({
// "text": "You have been disconnected!"
@ -226,6 +232,9 @@ impl DownstreamConnection {
ClientState::Login => {
let _ = self.send_packet(LoginDisconnect { reason }).await;
}
ClientState::Configuration => {
let _ = self.send_packet(ConfigurationDisconnect { reason }).await;
}
ClientState::Play => {
let _ = self.send_packet(PlayDisconnect { reason }).await;
}

View File

@ -40,6 +40,8 @@ pub enum ClientState {
///
/// The `Login` state includes authentication, encryption, compression, and plugins.
Login,
/// The client is in the `Configuration` state.
Configuration,
/// The main connection state. The client has authenticated and is playing on the server.
Play,
/// The client has disconnected, and the connection struct should be removed. No packets should be sent or received.

View File

@ -110,7 +110,7 @@ macro_rules! packets {
pub fn state_change(&self) -> Option<ClientState> {
match self {
Packet::Handshake(handshake) => Some(handshake.next_state),
Packet::LoginSuccess(_) => Some(ClientState::Play),
Packet::LoginAcknowledged(_) => Some(ClientState::Configuration),
Packet::LoginDisconnect(_) => Some(ClientState::Disconnected),
Packet::PlayDisconnect(_) => Some(ClientState::Disconnected),
Packet::PingResponse(_) => Some(ClientState::Disconnected),
@ -205,7 +205,12 @@ packets!(
}
packet LoginPluginResponse 0x02 {
field message_id: VarInt,
field successful: bool,
// TODO: Implement
rest data,
}
packet LoginAcknowledged 0x03 {}
packet LoginCookieResponse 0x04 {
// TODO: Implement
rest data,
}
}
@ -222,7 +227,7 @@ packets!(
packet LoginSuccess 0x02 {
field uuid: Uuid,
field username: String,
// TODO: Re-implement CL02LoginSuccessProperty
// TODO: Implement
rest properties,
}
packet SetCompression 0x03 {
@ -231,8 +236,21 @@ packets!(
packet LoginPluginRequest 0x04 {
field message_id: VarInt,
field channel: String,
// TODO: Implement
rest data,
}
packet LoginCookieRequest 0x05 {
// TODO: Implement
rest data,
}
}
}
configuration Configuration {
serverbound Serverbound {}
clientbound Clientbound {
packet ConfigurationDisconnect 0x02 {
field reason: Chat,
}
}
}
play Play {