Skip to content

Commit

Permalink
Merge pull request #45 from banchen19/main
Browse files Browse the repository at this point in the history
Implementing Partial Data Packets and Types
  • Loading branch information
theaddonn authored Aug 9, 2024
2 parents 070de5d + bf50de0 commit abf77b0
Show file tree
Hide file tree
Showing 37 changed files with 1,041 additions and 62 deletions.
2 changes: 2 additions & 0 deletions crates/proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ flate2 = "1.0"
snap = "1.1"

x509-cert = "0.2"

bitflags = "2.6.0"
70 changes: 46 additions & 24 deletions crates/proto/src/gamepacket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
use std::io::{Cursor, Write};
use std::sync::Arc;

use crate::packets::add_actor_packet::AddActorPacket;
use crate::packets::animate::AnimatePacket;
use crate::packets::chunk_radius_updated::ChunkRadiusUpdatedPacket;
use crate::packets::client_cache_status::ClientCacheStatusPacket;
use crate::packets::command_request_packet::CommandRequestPacket;
use crate::packets::container_close_packet::ContainerClosePacket;
use crate::packets::correct_player_move_prediction_packet::CorrectPlayerMovePredictionPacket;
use crate::packets::disconnect::DisconnectPacket;
use crate::packets::emote_list::EmoteListPacket;
use crate::packets::handshake_server_to_client::HandshakeServerToClientPacket;
Expand All @@ -18,6 +22,7 @@ use crate::packets::network_settings::NetworkSettingsPacket;
use crate::packets::network_settings_request::NetworkSettingsRequestPacket;
use crate::packets::packet_violation_warning::PacketViolationWarningPacket;
use crate::packets::play_status::PlayStatusPacket;
use crate::packets::player_action::PlayerActionPacket;
use crate::packets::player_auth_input::PlayerAuthInputPacket;
use crate::packets::player_move::MovePlayerPacket;
use crate::packets::request_chunk_radius::RequestChunkRadiusPacket;
Expand All @@ -27,8 +32,10 @@ use crate::packets::resource_packs_stack::ResourcePacksStackPacket;
use crate::packets::server_settings_request::ServerSettingsRequestPacket;
use crate::packets::server_settings_response::ServerSettingsResponsePacket;
use crate::packets::set_local_player_as_initialized::SetLocalPlayerAsInitializedPacket;
use crate::packets::set_title_packet::SetTitlePacket;
use crate::packets::start_game::StartGamePacket;
use crate::packets::text_message::TextMessagePacket;
use crate::packets::toast_request_packet::ToastRequestPacket;
use bedrockrs_core::int::VAR;
use bedrockrs_proto_core::error::ProtoCodecError;
use bedrockrs_proto_core::ProtoCodec;
Expand All @@ -48,7 +55,7 @@ pub enum GamePacket {
SetTime(),
StartGame(StartGamePacket),
AddPlayer(),
AddEntity(),
AddEntity(AddActorPacket),
RemoveEntity(),
AddItemEntity(),
TakeItemEntity(),
Expand All @@ -70,7 +77,7 @@ pub enum GamePacket {
Interact(InteractPacket),
BlockPickRequest(),
EntityPickRequest(),
PlayerAction(),
PlayerAction(PlayerActionPacket),
HurtArmor(),
SetEntityData(),
SetEntityMotion(),
Expand All @@ -80,7 +87,7 @@ pub enum GamePacket {
Animate(AnimatePacket),
Respawn(),
ContainerOpen(),
ContainerClose(),
ContainerClose(ContainerClosePacket),
PlayerHotbar(),
InventoryContent(),
InventorySlot(),
Expand Down Expand Up @@ -110,7 +117,7 @@ pub enum GamePacket {
BossEvent(),
ShowCredits(),
AvailableCommands(),
CommandRequest(),
CommandRequest(CommandRequestPacket),
CommandBlockUpdate(),
CommandOutput(),
UpdateTrade(),
Expand All @@ -121,7 +128,7 @@ pub enum GamePacket {
Transfer(),
PlaySound(),
StopSound(),
SetTitle(),
SetTitle(SetTitlePacket),
AddBehaviorTree(),
StructureBlockUpdate(),
ShowStoreOffer(),
Expand Down Expand Up @@ -176,12 +183,14 @@ pub enum GamePacket {
UpdatePlayerGameType(),
EmoteList(EmoteListPacket),
PacketViolationWarning(PacketViolationWarningPacket),
CorrectPlayerMovePredictionPacket(CorrectPlayerMovePredictionPacket),
ItemComponent(),
FilterTextPacket(),
UpdateSubChunkBlocksPacket(),
SubChunkPacket(),
SubChunkRequestPacket(),
DimensionData(),
ToastRequestPacket(ToastRequestPacket),
RequestNetworkSettings(NetworkSettingsRequestPacket),
AlexEntityAnimation(),
}
Expand Down Expand Up @@ -327,12 +336,14 @@ impl GamePacket {
const UpdatePlayerGameTypeID: u16 = 151;
const EmoteListID: u16 = 152;
const PacketViolationWarningID: u16 = 156;
const CorrectPlayerMovePredictionPacketID: u16 = 161;
const ItemComponentID: u16 = 162;
const FilterTextPacketID: u16 = 163;
const UpdateSubChunkBlocksPacketID: u16 = 172;
const SubChunkPacketID: u16 = 174;
const SubChunkRequestPacketID: u16 = 175;
const DimensionDataID: u16 = 180;
const ToastRequestPackeID: u16 = 186;
const RequestNetworkSettingsID: u16 = 193;
const AlexEntityAnimationID: u16 = 224;
}
Expand Down Expand Up @@ -429,8 +440,8 @@ impl GamePacket {
GamePacket::AddPlayer() => {
unimplemented!()
}
GamePacket::AddEntity() => {
unimplemented!()
GamePacket::AddEntity(pk) => {
ser_packet!(stream, GamePacket::AddEntityID, pk)
}
GamePacket::RemoveEntity() => {
unimplemented!()
Expand Down Expand Up @@ -495,8 +506,8 @@ impl GamePacket {
GamePacket::EntityPickRequest() => {
unimplemented!()
}
GamePacket::PlayerAction() => {
unimplemented!()
GamePacket::PlayerAction(pk) => {
ser_packet!(stream, GamePacket::PlayerActionID, pk)
}
GamePacket::HurtArmor() => {
unimplemented!()
Expand Down Expand Up @@ -525,8 +536,8 @@ impl GamePacket {
GamePacket::ContainerOpen() => {
unimplemented!()
}
GamePacket::ContainerClose() => {
unimplemented!()
GamePacket::ContainerClose(pk) => {
ser_packet!(stream, GamePacket::ContainerCloseID, pk)
}
GamePacket::PlayerHotbar() => {
unimplemented!()
Expand Down Expand Up @@ -615,8 +626,8 @@ impl GamePacket {
GamePacket::AvailableCommands() => {
unimplemented!()
}
GamePacket::CommandRequest() => {
unimplemented!()
GamePacket::CommandRequest(pk) => {
ser_packet!(stream, GamePacket::CommandRequestID, pk)
}
GamePacket::CommandBlockUpdate() => {
unimplemented!()
Expand Down Expand Up @@ -648,8 +659,8 @@ impl GamePacket {
GamePacket::StopSound() => {
unimplemented!()
}
GamePacket::SetTitle() => {
unimplemented!()
GamePacket::SetTitle(pk) => {
ser_packet!(stream, GamePacket::SetTitleID, pk)
}
GamePacket::AddBehaviorTree() => {
unimplemented!()
Expand Down Expand Up @@ -813,6 +824,9 @@ impl GamePacket {
GamePacket::PacketViolationWarning(pk) => {
ser_packet!(stream, GamePacket::PacketViolationWarningID, pk)
}
GamePacket::CorrectPlayerMovePredictionPacket(pk) => {
ser_packet!(stream, GamePacket::CorrectPlayerMovePredictionPacketID, pk)
}
GamePacket::ItemComponent() => {
unimplemented!()
}
Expand All @@ -831,6 +845,9 @@ impl GamePacket {
GamePacket::DimensionData() => {
unimplemented!()
}
GamePacket::ToastRequestPacket(pk) => {
ser_packet!(stream, GamePacket::ToastRequestPackeID, pk)
}
GamePacket::RequestNetworkSettings(pk) => {
ser_packet!(stream, GamePacket::RequestNetworkSettingsID, pk)
}
Expand Down Expand Up @@ -900,9 +917,7 @@ impl GamePacket {
GamePacket::AddPlayerID => {
unimplemented!()
}
GamePacket::AddEntityID => {
unimplemented!()
}
GamePacket::AddEntityID => GamePacket::AddEntity(de_packet!(stream, AddActorPacket)),
GamePacket::RemoveEntityID => {
unimplemented!()
}
Expand Down Expand Up @@ -965,7 +980,7 @@ impl GamePacket {
unimplemented!()
}
GamePacket::PlayerActionID => {
unimplemented!()
GamePacket::PlayerAction(de_packet!(stream, PlayerActionPacket))
}
GamePacket::HurtArmorID => {
unimplemented!()
Expand Down Expand Up @@ -993,7 +1008,7 @@ impl GamePacket {
unimplemented!()
}
GamePacket::ContainerCloseID => {
unimplemented!()
GamePacket::ContainerClose(de_packet!(stream, ContainerClosePacket))
}
GamePacket::PlayerHotbarID => {
unimplemented!()
Expand Down Expand Up @@ -1083,7 +1098,7 @@ impl GamePacket {
unimplemented!()
}
GamePacket::CommandRequestID => {
unimplemented!()
GamePacket::CommandRequest(de_packet!(stream, CommandRequestPacket))
}
GamePacket::CommandBlockUpdateID => {
unimplemented!()
Expand Down Expand Up @@ -1115,9 +1130,7 @@ impl GamePacket {
GamePacket::StopSoundID => {
unimplemented!()
}
GamePacket::SetTitleID => {
unimplemented!()
}
GamePacket::SetTitleID => GamePacket::SetTitle(de_packet!(stream, SetTitlePacket)),
GamePacket::AddBehaviorTreeID => {
unimplemented!()
}
Expand Down Expand Up @@ -1278,6 +1291,12 @@ impl GamePacket {
GamePacket::PacketViolationWarningID => {
GamePacket::PacketViolationWarning(de_packet!(stream, PacketViolationWarningPacket))
}
GamePacket::CorrectPlayerMovePredictionPacketID => {
GamePacket::CorrectPlayerMovePredictionPacket(de_packet!(
stream,
CorrectPlayerMovePredictionPacket
))
}
GamePacket::ItemComponentID => {
unimplemented!()
}
Expand All @@ -1296,6 +1315,9 @@ impl GamePacket {
GamePacket::DimensionDataID => {
unimplemented!()
}
GamePacket::ToastRequestPackeID => {
GamePacket::ToastRequestPacket(de_packet!(stream, ToastRequestPacket))
}
GamePacket::RequestNetworkSettingsID => {
GamePacket::RequestNetworkSettings(de_packet!(stream, NetworkSettingsRequestPacket))
}
Expand Down
63 changes: 63 additions & 0 deletions crates/proto/src/login/add_actor.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use bedrockrs_core::{int::LE, Vec2, Vec3};
use bedrockrs_shared::{actor_runtime_id::ActorRuntimeID, actor_unique_id::ActorUniqueID};

use crate::{
connection::ConnectionShard,
error::LoginError,
gamepacket::GamePacket,
packets::add_actor_packet::AddActorPacket,
types::{
actor_type::ActorType,
property_sync_data::{FloatEntriesList, IntEntriesList, PropertySyncData},
},
};

use super::provider::LoginProviderServer;

pub async fn add_actor(
conn: &mut ConnectionShard,
provider: &mut impl LoginProviderServer,
) -> Result<(), LoginError> {
//////////////////////////////////////
// todo: AddActorPacket
//////////////////////////////////////

let add_actor = AddActorPacket {
target_actor_id: ActorUniqueID(610),
target_runtime_id: ActorRuntimeID(403),
actor_type: ActorType::Pig.to_string(),
position: Vec3 {
x: LE::new(4.0),
y: LE::new(8.0),
z: LE::new(7.0),
},
velocity: Vec3 {
x: LE::new(4.0),
y: LE::new(8.0),
z: LE::new(7.0),
},
rotation: Vec2 {
x: LE::new(270.0),
y: LE::new(90.0),
},
y_head_rotation: LE::new(45.0),
y_body_rotation: LE::new(90.0),
attributes: vec![],
actor_data: vec![],
synched_properties: PropertySyncData {
int: IntEntriesList { entries: vec![] },
float: FloatEntriesList { entries: vec![] },
},
actor_links: vec![],
};

conn.send(GamePacket::AddEntity(add_actor))
.await
.map_err(|e| LoginError::ConnectionError(e))?;

conn.flush()
.await
.map_err(|e| LoginError::ConnectionError(e))?;

Ok(())
}
3 changes: 2 additions & 1 deletion crates/proto/src/login/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::login::play_status::play_status_login;
use crate::login::provider::{LoginProviderClient, LoginProviderServer};
use crate::login::start_game::start_game;

use super::set_title::set_title;

pub async fn login_to_server(
conn: &mut ConnectionShard,
mut provider: impl LoginProviderServer,
Expand All @@ -22,7 +24,6 @@ pub async fn login_to_server(
packs(conn, &mut provider).await?;

start_game(conn, &mut provider).await?;

Ok(())
}

Expand Down
2 changes: 2 additions & 0 deletions crates/proto/src/login/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pub use handle::*;

mod add_actor;
pub mod handle;
mod handshake;
mod login;
mod network_settings;
mod packs;
mod play_status;
pub mod provider;
mod set_title;
mod start_game;
2 changes: 1 addition & 1 deletion crates/proto/src/login/provider/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Default for DefaultLoginProvider {

impl LoginProviderServer for DefaultLoginProvider {
fn compression(&self) -> Compression {
Compression::Snappy { threshold: 1 }
Compression::None
}
fn encryption_enabled(&self) -> bool {
false
Expand Down
Loading

0 comments on commit abf77b0

Please sign in to comment.