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

Replace direct uses of GameTicker dictionary with TryGetValue #33222

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ficcialfaint
Copy link
Member

About the PR

Why / Balance

Apparently if a player's SessionStatus stays on Connected for whatever reason, station events and antag selection might break in some way. The issue is some functions try to get a value from PlayerGameStatuses dictionary without checking if the player exists or not. For example:

var players = _playerManager.Sessions
    .Where(x => GameTicker.PlayerGameStatuses[x.UserId] == PlayerGameStatus.JoinedGame)
    .ToList();

The thing is that _playerManager.Sessions contains any sessions (including the Connected ones) while PlayerGameStatuses does not, meaning that if there's a player stuck (intentionally or not) on Connected, that specific line would throw an error The key 'blahblah' was not present in the dictionary.

And this possibly can lead to station events spam.
Not sure exactly this is the issue of events spam, but I've been reported about this and when looking at the logs the only errors I could find is The key 'blahblahblah' was not present in the dictionary and the stacktrace leading to UserHasJoinedGame(NetUserId userId) which is basically this:

public bool UserHasJoinedGame(NetUserId userId)
    => PlayerGameStatuses[userId] == PlayerGameStatus.JoinedGame;

Technical details

Replaced all* PlayerGameStatuses[user] == Something with PlayerGameStatuses.TryGetValue(user, out var status) && status == Something

* — except its usages in integration tests because I believe there is no chance to get the error in the tests (lmk if I'm wrong thinking that way)

Media

N/A

Requirements

Breaking changes

N/A

Changelog
N/A

@github-actions github-actions bot added the Status: Needs Review This PR requires new reviews before it can be merged. label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Review This PR requires new reviews before it can be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant