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

Check if player is still online #196

Open
Mraucin opened this issue Mar 16, 2022 · 2 comments · May be fixed by #467
Open

Check if player is still online #196

Mraucin opened this issue Mar 16, 2022 · 2 comments · May be fixed by #467

Comments

@Mraucin
Copy link

Mraucin commented Mar 16, 2022

Hi, how shall I check if player is still online? Should I use onTick method to send heartbeat signal (for example with ctx.broadcastEvent) and wait for response and store it?
Thanks in advance :>

@hpx7
Copy link
Member

hpx7 commented Mar 16, 2022

I think the easiest way to do this would be to have a latestHeartbeatTimestamp field in your internal state per player, and have the client call a heartbeat method which sets the timestamp.

Then in getUserState you can compute whether someone is online or not based on the difference between the current time and the latestHeartbeatTimestamp per player. How does that sound?

@hpx7
Copy link
Member

hpx7 commented Mar 16, 2022

If you wanted to specifically remove a player from the internal state if they haven't sent a timestamp for a certain period of time, then I would do that inside onTick

@francislavoie francislavoie linked a pull request Jun 21, 2023 that will close this issue
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 a pull request may close this issue.

2 participants