-
-
Notifications
You must be signed in to change notification settings - Fork 68
feat: Player Data Storage #205
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
Open
KingTimer12
wants to merge
33
commits into
ferrumc-rs:master
Choose a base branch
from
KingTimer12:feature/player-state
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+828
−161
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e823b3e
feat: player data storage initialized
KingTimer12 cae8c54
fix: cargo fmt and cargo audit
KingTimer12 2eeab0e
fix: cargo clippy
KingTimer12 4f8db95
feat: added sqlite support
KingTimer12 ed2e353
fix: cargo clippy
KingTimer12 67a9bf5
fix: benches test of storage
KingTimer12 4fff8d3
chore: changed to sqlite
KingTimer12 d9b0bfa
fix: cargo audit error
KingTimer12 400d746
fix: cargo fmt
KingTimer12 b7bea43
fix: cargo clippy
KingTimer12 a2b92ff
fix: cargo clippy
KingTimer12 234fb78
Merge branch 'master' of github.com:KingTimer12/ferrumc into feature/…
KingTimer12 64491ab
feat: player data storage initialized
KingTimer12 8ac0648
fix: cargo fmt and cargo audit
KingTimer12 cbfa307
fix: cargo clippy
KingTimer12 7fc22ef
feat: added sqlite support
KingTimer12 6d3c4c5
fix: cargo clippy
KingTimer12 9f0d3aa
fix: benches test of storage
KingTimer12 e093a28
chore: changed to sqlite
KingTimer12 cc4d935
fix: cargo audit error
KingTimer12 c383f0c
fix: cargo fmt
KingTimer12 813e9a3
fix: cargo clippy
KingTimer12 b35c2f5
fix: cargo clippy
KingTimer12 1ad2bca
Merge branch 'feature/player-state' of github.com:KingTimer12/ferrumc…
KingTimer12 b0e6aa7
chore: now is updating player data
KingTimer12 c408791
fix: i forgot fmt :p
KingTimer12 1a5ca03
chore: updated the way playerdata is used
KingTimer12 c31ee14
chore: saving data through event
KingTimer12 01f24fb
Merge branch 'master' of github.com:KingTimer12/ferrumc into feature/…
KingTimer12 b70b7b2
fix: problem in my gitignore; fix: cargo.toml with old dep;
KingTimer12 dcd5148
chore: added player disconnect event in connection killer
KingTimer12 3d8d02c
chore: removed PlayerState
KingTimer12 d386bd8
chore: added Display to player data
KingTimer12 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ result-* | |
| profile.json.gz | ||
| .DS_Store | ||
|
|
||
| world/ | ||
| /world/ | ||
| whitelist.txt | ||
|
|
||
| logs/ | ||
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,7 +1,8 @@ | ||
| pub(crate) mod play_packets; | ||
| mod player; | ||
| pub mod player; | ||
|
|
||
| pub fn register_player_systems(schedule: &mut bevy_ecs::schedule::Schedule) { | ||
| schedule.add_systems(player::head_rot::handle_player_move); | ||
| schedule.add_systems(player::send_inventory_updates::handle_inventory_updates); | ||
| schedule.add_systems(player::player_disconnect::handle); | ||
| } |
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,2 +1,3 @@ | ||
| pub mod head_rot; | ||
| pub mod player_disconnect; | ||
| pub(crate) mod send_inventory_updates; |
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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| use bevy_ecs::{event::EventReader, prelude::Res, system::Commands}; | ||
| use ferrumc_core::conn::player_disconnect_event::PlayerDisconnectEvent; | ||
| use ferrumc_state::GlobalStateResource; | ||
|
|
||
| pub fn handle( | ||
| mut cmd: Commands, | ||
| mut events: EventReader<PlayerDisconnectEvent>, | ||
| state: Res<GlobalStateResource>, | ||
| ) { | ||
| for event in events.read() { | ||
| let uuid = event.identity.uuid.as_u128(); | ||
| let username = &event.identity.username; | ||
| if let Err(e) = state.0.world.save_player_state(uuid, &event.data) { | ||
| tracing::error!("Failed to save player state for {}: {}", username, e); | ||
| } else { | ||
| tracing::info!("Player state saved for {}", username); | ||
| } | ||
| cmd.entity(event.entity).despawn(); | ||
| } | ||
| } | ||
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,5 +1,15 @@ | ||
| use bevy_ecs::schedule::IntoScheduleConfigs; | ||
|
|
||
| use crate::packet_handlers::player; | ||
|
|
||
| mod send_shutdown_packet; | ||
|
|
||
| pub fn register_shutdown_systems(schedule: &mut bevy_ecs::schedule::Schedule) { | ||
| schedule.add_systems(send_shutdown_packet::handle); | ||
| schedule.add_systems( | ||
| ( | ||
| send_shutdown_packet::handle, | ||
| player::player_disconnect::handle, | ||
| ) | ||
| .chain(), | ||
| ); | ||
| } |
31 changes: 26 additions & 5 deletions
31
src/bin/src/systems/shutdown_systems/send_shutdown_packet.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,19 +1,40 @@ | ||
| use bevy_ecs::prelude::{Entity, Query, Res}; | ||
| use ferrumc_core::identity::player_identity::PlayerIdentity; | ||
| use bevy_ecs::{ | ||
| event::EventWriter, | ||
| prelude::{Entity, Query, Res}, | ||
| }; | ||
| use ferrumc_core::{ | ||
| conn::player_disconnect_event::PlayerDisconnectEvent, | ||
| data::player::PlayerData, | ||
| identity::player_identity::PlayerIdentity, | ||
| transform::{grounded::OnGround, position::Position, rotation::Rotation}, | ||
| }; | ||
| use ferrumc_net::connection::StreamWriter; | ||
| use ferrumc_state::GlobalStateResource; | ||
| use ferrumc_text::TextComponent; | ||
|
|
||
| pub fn handle( | ||
KingTimer12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| query: Query<(Entity, &StreamWriter, &PlayerIdentity)>, | ||
| query: Query<( | ||
| Entity, | ||
| &StreamWriter, | ||
| &PlayerIdentity, | ||
| &Position, | ||
| &OnGround, | ||
| &Rotation, | ||
| )>, | ||
| mut dispatch_events: EventWriter<PlayerDisconnectEvent>, | ||
| state: Res<GlobalStateResource>, | ||
| ) { | ||
| let packet = ferrumc_net::packets::outgoing::disconnect::DisconnectPacket { | ||
| reason: TextComponent::from("Server is shutting down"), | ||
| }; | ||
|
|
||
| for (entity, conn, identity) in query.iter() { | ||
| for (entity, conn, identity, position, on_ground, rotation) in query.iter() { | ||
| if state.0.players.is_connected(entity) { | ||
| let player_disconnect = PlayerDisconnectEvent { | ||
| data: PlayerData::new(position, on_ground.0, "overworld", rotation), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we including this data here? The event handler can just fetch this data if you give it the entity |
||
| identity: identity.to_owned(), | ||
| entity, | ||
| }; | ||
| dispatch_events.write(player_disconnect); | ||
| if let Err(e) = conn.send_packet_ref(&packet) { | ||
| tracing::error!( | ||
| "Failed to send shutdown packet to player {}: {}", | ||
|
|
||
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,3 +1,4 @@ | ||
| pub mod force_player_recount_event; | ||
| pub mod keepalive; | ||
| pub mod player_count_update_cooldown; | ||
| pub mod player_disconnect_event; |
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 |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| use bevy_ecs::{entity::Entity, event::Event}; | ||
|
|
||
| use crate::{data::player::PlayerData, identity::player_identity::PlayerIdentity}; | ||
|
|
||
| #[derive(Event)] | ||
| pub struct PlayerDisconnectEvent { | ||
| pub entity: Entity, | ||
| pub identity: PlayerIdentity, | ||
| pub data: PlayerData, | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| pub mod player; |
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.
from what i see, this is an event handler, why is this in the packet handler dir? is confusing if its the disconnect event received from connection killer and server kill.
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.
Honestly, I didn't know where to put it, after all, we didn't have a folder called events and I didn't know whether to put it inside systems or packets (the reason for putting packets is because of the "head_rot" event)
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.
head rot event is most likely being called from a packet. on the other hand the event you made has nothing to do with packets. why not make a separate module specifically for events? i reckon it'd be best?
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.
I agree, having it here makes little sense