Skip to content

Commit

Permalink
Added configuration state logic for player login
Browse files Browse the repository at this point in the history
#6
- Send Registry Data (Configuration)
- Send Finish Configuration (Clientbound)
- Receive Finish Configuration (Serverbound)
  • Loading branch information
ya7on committed Nov 30, 2023
1 parent 50183d2 commit 4520d58
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 5 deletions.
45 changes: 45 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ clap = { version = "4.4.8", features = ["derive", "env"] }
darling = { version = "0.20.3" }
flate2 = { version = "1.0.28" }
lazy_static = { version = "1.4.0" }
serde = { version = "1.0.193", features = ["derive"] }
serde_json = { version = "1.0.108" }
syn = { version = "2.0.39" }
tracing = { version = "0.1.40" }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
Expand All @@ -33,6 +35,8 @@ mclib = { workspace = true }

clap = { workspace = true }
lazy_static = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
uuid = { workspace = true }
3 changes: 3 additions & 0 deletions mclib/main/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ pub use mclib_protocol::packets::base::MCPacket;
pub use mclib_protocol::types::base::MCType;
pub mod packets {
pub mod server {
pub use mclib_protocol::packets::server::finish_configuration::FinishConfigurationServerbound;
pub use mclib_protocol::packets::server::handshake::{Handshake, HandshakeNextState};
pub use mclib_protocol::packets::server::login_acknowledged::LoginAcknowledged;
pub use mclib_protocol::packets::server::login_start::LoginStart;
pub use mclib_protocol::packets::server::ping::PingRequest;
pub use mclib_protocol::packets::server::status_request::StatusRequest;
}
pub mod client {
pub use mclib_protocol::packets::client::finish_configuration::FinishConfigurationClientbound;
pub use mclib_protocol::packets::client::login_success::{
LoginSuccess, LoginSuccessProperty,
};
pub use mclib_protocol::packets::client::registry_data::RegistryData;
pub use mclib_protocol::packets::client::status_response::StatusResponse;
}
}
Expand Down
1 change: 1 addition & 0 deletions mclib/protocol/src/packets/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod finish_configuration;
pub mod login_success;
pub mod registry_data;
pub mod status_response;
8 changes: 8 additions & 0 deletions mclib/protocol/src/packets/client/finish_configuration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use crate::packets::base::MCPacket;
use crate::types::base::MCType;
use crate::types::varint::MCVarInt;
use mclib_macros::MCPacket;

#[derive(MCPacket, Debug, Clone)]
#[packet(packet_id = 0x02)]
pub struct FinishConfigurationClientbound {}
2 changes: 1 addition & 1 deletion mclib/protocol/src/packets/client/registry_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ use mclib_macros::MCPacket;
#[derive(MCPacket, Debug, Clone)]
#[packet(packet_id = 0x05)]
pub struct RegistryData {
registry_codec: MCNBT,
pub registry_data: MCNBT,
}
1 change: 1 addition & 0 deletions mclib/protocol/src/packets/server.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod finish_configuration;
pub mod handshake;
pub mod login_acknowledged;
pub mod login_start;
Expand Down
8 changes: 8 additions & 0 deletions mclib/protocol/src/packets/server/finish_configuration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use crate::packets::base::MCPacket;
use crate::types::base::MCType;
use crate::types::varint::MCVarInt;
use mclib_macros::MCPacket;

#[derive(MCPacket, Debug, Clone)]
#[packet(packet_id = 0x02)]
pub struct FinishConfigurationServerbound {}
38 changes: 34 additions & 4 deletions src/server/thread/tcp_listener.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use crate::conf::conf;
use crate::registry;
use crate::server::communicator::WriteCommunicator;
use crate::server::net::tcp::{NativeRead, TCPRead};
use crate::server::thread::tcp_writer::TCPWriterAPI;
use mclib::packets::client::{LoginSuccess, StatusResponse};
use mclib::nbt::NBT;
use mclib::packets::client::{
FinishConfigurationClientbound, LoginSuccess, RegistryData, StatusResponse,
};
use mclib::packets::server::{
Handshake, HandshakeNextState, LoginAcknowledged, LoginStart, PingRequest, StatusRequest,
FinishConfigurationServerbound, Handshake, HandshakeNextState, LoginAcknowledged, LoginStart,
PingRequest, StatusRequest,
};
use mclib::types::MCVarInt;
use mclib::types::{MCVarInt, MCNBT};
use mclib::MCPacket;

pub struct TCPListenerThread {
Expand Down Expand Up @@ -80,9 +85,33 @@ impl TCPListenerThread {
}

pub fn handle_configuration(&mut self) {
todo!()
let registry_data = serde_json::from_str::<registry::RegistryData>(include_str!(
"../../../assets/registry_data_1.20.2.json"
))
.unwrap();
let registry_data_nbt = NBT::from(registry_data);
let registry_data_packet = RegistryData {
registry_data: MCNBT::from(registry_data_nbt),
};
self.tcp_writer_api.send(TCPWriterAPI::SendMessageRaw {
uid: self.uid,
body: registry_data_packet.pack(),
});

let finish_configuration = FinishConfigurationClientbound {};
self.tcp_writer_api.send(TCPWriterAPI::SendMessageRaw {
uid: self.uid,
body: finish_configuration.pack(),
});

let _ = self
.tcp_read
.read_packet()
.parse_packet::<FinishConfigurationServerbound>();
}

pub fn handle_play(&mut self) {}

pub fn execute(&mut self) {
match self.handle_handshake() {
HandshakeNextState::Status => {
Expand All @@ -91,6 +120,7 @@ impl TCPListenerThread {
HandshakeNextState::Login => {
self.handle_login();
self.handle_configuration();
self.handle_play();
}
HandshakeNextState::Unknown => {
error!("Unknown next state for handshake");
Expand Down

0 comments on commit 4520d58

Please sign in to comment.