Skip to content
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

Fix/keep alive stuff #128

Merged

Conversation

AnonymousBit0111
Copy link

@AnonymousBit0111 AnonymousBit0111 commented Nov 17, 2024

This PR kicks inactive players and remove them from the universe

Description
Keep alives are now stored in the Incoming and Outgoing Keep alive packet, if the last incoming keep alive is not the same as the last outgoing one the client should be kicked and if a client fails to send a keep alive for 30 its also kicked, also now if it takes more than 2 seconds to read a packet the connection loop will skip to the next iteration to prevent the loop from hanging.

Motivation and Context
This change was implemented to make sure inactive or invalid clients are kicked

How has this been tested?
Ive connected to the server with two clients and disconnected them by turning off their internet, if I turn the interned back on within 30 seconds nothing happens, otherwise the client is kicked.

Screenshots (if appropriate):
Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.

  • I have added tests to cover my changes.

  • All new and existing tests passed.

  • Clippy passes with no warnings.


if matches!(*conn_state, ConnectionState::Play)
&& (current_time - keep_alive.id) >= fifteen_seconds_ms
&& (current_time - keep_alive.id) >= 15000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename the field id to timestamp instead? Since I feel like it'd make more sense in the future when looking at this code. Since right now it looks like a quite weird calculation between an id and timestamp :)

.ok()
.unwrap();

if (current_time - keep_alive.id) >= 30000 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are well. id -> timestamp

Comment on lines 10 to 11
pub struct IncomingKeepAlivePacket {
pub struct IncomingKeepAlive {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep packets have a prefix Packet since they're publicly exported and it'd be confusing.


#[derive(NetEncode)]
#[packet(packet_id = 0x1D)]
pub struct Disconnect {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Suffix with Packet

Ok(control) => {
control
.should_disconnect
.store(true, std::sync::atomic::Ordering::Relaxed);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there an atomic inside of a component? Components' are already protected with read-write locks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didnt know, will change

@Sweattypalms Sweattypalms merged commit ca7ce8c into ferrumc-rs:rewrite/v3 Nov 17, 2024
3 checks passed
@Sweattypalms
Copy link
Member

thanks bbg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants