-
-
Notifications
You must be signed in to change notification settings - Fork 93
Adds position and entity selectors as command arguments #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
afa7ebd
Added position as a command arg
ReCore-sys d80ab41
Add entity selector
ReCore-sys ee1c168
Added entity selector, needs fixing
ReCore-sys 5c83066
Fixed selector
ReCore-sys 026ed1d
Cleanup
ReCore-sys e924476
Add entity to tp command
ReCore-sys c177214
Fix chunk load timeout
ReCore-sys efbaf2b
Disable annoying encryption spam in the logs
ReCore-sys 45c2a1a
Add teleport tracking
ReCore-sys 8aa793f
wtf
ReCore-sys 8e5550f
fixed janky teleports
ReCore-sys 6b46213
Remove some debug spam
ReCore-sys a86cd95
fmt
ReCore-sys 970e1bf
Entity selector tests
ReCore-sys bc6e5dc
Fix broken test
ReCore-sys ce6f03f
fmt
ReCore-sys 973bcdf
Add better docs
ReCore-sys 3f7da2c
Fix requested changes
ReCore-sys 81bfc90
Fix unit test and parsing
ReCore-sys 1a14398
Merge branch 'master' into feature/better-command-args
ReCore-sys e143be5
Fix compile error
ReCore-sys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 14 additions & 2 deletions
16
src/bin/src/packet_handlers/play_packets/confirm_player_teleport.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,15 @@ | ||
| pub fn handle() { | ||
| // TODO | ||
| use bevy_ecs::prelude::{Query, Res}; | ||
| use ferrumc_components::player::teleport_tracker::TeleportTracker; | ||
| use ferrumc_net::ConfirmPlayerTeleportReceiver; | ||
|
|
||
| pub fn handle( | ||
| receiver: Res<ConfirmPlayerTeleportReceiver>, | ||
| mut query: Query<&mut TeleportTracker>, | ||
| ) { | ||
| for (_, eid) in receiver.0.try_iter() { | ||
| let Ok(mut tracker) = query.get_mut(eid) else { | ||
| continue; | ||
| }; | ||
| tracker.waiting_for_confirm = false; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,82 @@ | ||
| use bevy_ecs::prelude::{MessageReader, MessageWriter, Query}; | ||
| use bevy_ecs::prelude::{Entity, MessageReader, MessageWriter, Query}; | ||
| use ferrumc_components::player::teleport_tracker::TeleportTracker; | ||
| use ferrumc_core::identity::player_identity::PlayerIdentity; | ||
| use ferrumc_core::transform::position::Position; | ||
| use ferrumc_core::transform::rotation::Rotation; | ||
| use ferrumc_messages::chunk_calc::ChunkCalc; | ||
| use ferrumc_messages::entity_update::SendEntityUpdate; | ||
| use ferrumc_messages::teleport_player::TeleportPlayer; | ||
| use ferrumc_net::connection::StreamWriter; | ||
| use ferrumc_net::packets::outgoing::entity_position_sync::TeleportEntityPacket; | ||
| use ferrumc_net::packets::outgoing::synchronize_player_position::SynchronizePlayerPositionPacket; | ||
| use tracing::error; | ||
|
|
||
| pub fn teleport_player( | ||
| mut query: Query<(&StreamWriter, &mut Position, &Rotation)>, | ||
| mut query: Query<(Entity, &StreamWriter, &mut Position, &mut TeleportTracker)>, | ||
| id_query: Query<&PlayerIdentity>, | ||
| mut message_reader: MessageReader<TeleportPlayer>, | ||
| mut chunk_calc_msg: MessageWriter<ChunkCalc>, | ||
| mut player_update_msg: MessageWriter<SendEntityUpdate>, | ||
| ) { | ||
| for message in message_reader.read() { | ||
| let entity = message.entity; | ||
|
|
||
| // Notify the chunk calculation system to recalculate chunks for this player | ||
| chunk_calc_msg.write(ChunkCalc(entity)); | ||
|
|
||
| // Notify the player update system to send the new position to the client | ||
| player_update_msg.write(SendEntityUpdate(entity)); | ||
| let Ok((conn, mut pos, rot)) = query.get_mut(entity) else { | ||
| continue; | ||
| let message_entity = message.entity; | ||
| let id = match id_query.get(message_entity) { | ||
| Ok(id) => id, | ||
| Err(err) => { | ||
| error!( | ||
| "Failed to get PlayerIdentity for entity {:?}: {}", | ||
| message_entity, err | ||
| ); | ||
| continue; | ||
| } | ||
| }; | ||
| pos.x = message.x; | ||
| pos.y = message.y; | ||
| pos.z = message.z; | ||
| if let Err(err) = conn.send_packet(SynchronizePlayerPositionPacket { | ||
| teleport_id: rand::random::<i32>().into(), | ||
| x: message.x, | ||
| y: message.y, | ||
| z: message.z, | ||
| vel_x: message.vel_x, | ||
| vel_y: message.vel_y, | ||
| vel_z: message.vel_z, | ||
| yaw: rot.yaw, | ||
| pitch: rot.pitch, | ||
| flags: 0, | ||
| }) { | ||
| error!("Failed to send teleport packet: {}", err); | ||
| continue; | ||
| for (entity, conn, mut pos, mut tracker) in query.iter_mut() { | ||
| if entity == message_entity { | ||
| // Block movement tracking until the player has been teleported | ||
| tracker.waiting_for_confirm = true; | ||
| pos.x = message.x; | ||
| pos.y = message.y; | ||
| pos.z = message.z; | ||
| // If it's the entity we are trying to teleport, send the sync player pos packet | ||
| if let Err(err) = conn.send_packet(SynchronizePlayerPositionPacket { | ||
| teleport_id: rand::random::<i32>().into(), | ||
| x: message.x, | ||
| y: message.y, | ||
| z: message.z, | ||
| vel_x: message.vel_x, | ||
| vel_y: message.vel_y, | ||
| vel_z: message.vel_z, | ||
| yaw: message.yaw, | ||
| pitch: message.pitch, | ||
| flags: 0, | ||
| }) { | ||
| error!("Failed to send teleport packet: {}", err); | ||
| continue; | ||
| } | ||
| } else { | ||
| // Otherwise send teleport entity packet. This ideally should be handled by the send | ||
| // entity updates system, but it seems to be a bit buggy | ||
| if let Err(err) = conn.send_packet(TeleportEntityPacket { | ||
| entity_id: id.short_uuid.into(), | ||
| x: message.x, | ||
| y: message.y, | ||
| z: message.z, | ||
| vel_x: 0.0, | ||
| vel_y: 0.0, | ||
| vel_z: 0.0, | ||
| yaw: message.yaw, | ||
| pitch: message.pitch, | ||
| on_ground: false, | ||
| }) { | ||
| error!("Failed to send teleport packet: {}", err); | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Notify the player update system to send the new position to the client | ||
| player_update_msg.write(SendEntityUpdate(message_entity)); | ||
|
|
||
| // Notify the chunk calculation system to recalculate chunks for this player | ||
| chunk_calc_msg.write(ChunkCalc(message_entity)); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ignore teleport_id from client? Malicious client could send fake confirmations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sending malicious confirmations doesn't really do anything, the vanilla server doesn't even handle them.