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

Issue/#786 send player update on disconnect #832

Merged

Conversation

Askaholic
Copy link
Collaborator

This should let the client more accurately determine when a player has disconnected. It could also be used to rewrite the player state determination to be more accurate (for displaying swords and blocking certain actions).

The state names could change if someone has better ideas. I just didn't want to make them too long since they will already add quite a few bytes to the network traffic. We could save the most bytes by using integer codes, but I think it's ok to sacrifice some bytes to have a more expressive protocol.

Closes #786

@Askaholic Askaholic requested a review from Sheikah45 September 6, 2021 23:35
@codecov
Copy link

codecov bot commented Sep 6, 2021

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ea2b7d3) 94.61% compared to head (66287f9) 96.68%.

❗ Current head 66287f9 differs from pull request most recent head 76d7944. Consider uploading reports for the commit 76d7944 to get more accurate results

Additional details and impacted files
Files Coverage Δ
server/player_service.py 99.21% <100.00%> (+2.10%) ⬆️
server/players.py 100.00% <100.00%> (ø)

... and 65 files with indirect coverage changes

Copy link
Member

@Sheikah45 Sheikah45 left a comment

Choose a reason for hiding this comment

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

When I was testing on the test server I ended up seeing a few player_info messages without a state and it also seemed like the state did not always match with the game status. Should the state always be included?

@Askaholic
Copy link
Collaborator Author

Yea the state should always be there. If it happens again in future testing we'll need to look in the server logs to see what's going on as the contents of the messages is logged there.

@Askaholic Askaholic force-pushed the issue/#786-player-state-updates branch 2 times, most recently from af7f884 to 391148f Compare October 31, 2021 03:33
Comment on lines 141 to 149
assert self.state is not None and self.state.value is not None

cmd = {
"id": self.id,
"login": self.login,
"avatar": self.avatar,
"country": self.country,
"clan": self.clan,
"state": self.state.value if self.lobby_connection else "offline",
Copy link
Member

Choose a reason for hiding this comment

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

This seems a little counterintuitive as to what the expected value of self.state is when the player is offline. Might it not be better to add a playerState offline?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What is counterintuitive about it? If the player is offline then the state is "offline". If I add an "OFFLINE" state to the enum then I have to make sure that's kept in sync with the value of lobby_connection which complicates things and introduces the possibility of weird bugs.

Copy link
Member

@Sheikah45 Sheikah45 Nov 6, 2021

Choose a reason for hiding this comment

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

Couldn't you just do it the line after you delete the lobby_connection? How does it complicate things more than that?
And it would also be sufficient I think to just at least add the offline to the enum. As I had expected that to define all possible states a player could be in but then you find out there is another state hidden in the dict method. So it makes it harder to be sure what the allowable values are

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe, but I really don't want any other places in the code suddenly getting a player state of 'OFFLINE', since that isn't really a state... Internally you are offline when your LobbyConnection is gone which will cause an exception to be thrown when the server tries to send a message to you, thats how the code expects to be signaled. But I needed something to signal to the client that the player isn't connected anymore, and putting that in state seemed to make sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its the same with the game_info message. The states that we send to the client aren't actually the same as the internal states.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe for now it would be better to simplify things and just have 'online' and 'offline'. Unless you are actually planning on making use of the other states in the client. That's probably safer too because otherwise the internal state tracking becomes kindof part of the server protocol, which makes changing it a lot more annoying.

Copy link
Member

Choose a reason for hiding this comment

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

Well with the addition of the states I would probably switch to using those to determine things like is a player available to join a queue or host or join a game as I would be trusting those are more consistent than perusing the games list in the client because the client may not necessarily even see all the game messages

@Askaholic Askaholic force-pushed the issue/#786-player-state-updates branch from 391148f to 66287f9 Compare November 6, 2021 20:06
@Eternal-ll
Copy link

Any updates on that? I am missing this feature =)

@Askaholic
Copy link
Collaborator Author

I can take another look at this. I think the main thing for me is I didn't like the state names and I am not quite comfortable with exposing the internal state over the protocol. But we might be able to start with just two state 'offline' and 'online', then you will at least be able to tell when people disconnect.

@Sheikah45
Copy link
Member

As an update we are soon going to turn on always-on for the irc client to facilitate offline messages. This will make state tracking using the irc server much harder so it would be nice if something like this could be added.

@Askaholic Askaholic force-pushed the issue/#786-player-state-updates branch 3 times, most recently from 76d7944 to c740206 Compare December 26, 2023 20:00
@Sheikah45
Copy link
Member

Tested on the test server and this works for me

@Askaholic Askaholic force-pushed the issue/#786-player-state-updates branch from 61185eb to 1aade7b Compare December 27, 2023 18:26
@Askaholic Askaholic merged commit d0152da into FAForever:develop Dec 27, 2023
8 checks passed
@Askaholic Askaholic deleted the issue/#786-player-state-updates branch December 27, 2023 19:47
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.

Send player update when player disconnects
3 participants