-
Notifications
You must be signed in to change notification settings - Fork 248
Send all the player options in auto lobby when host receives them #6995
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
Garanas
wants to merge
2
commits into
FAForever:develop
Choose a base branch
from
Garanas:Fix/autolobby-player-options
base: develop
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.
+9
−0
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: FAForever/fa
Length of output: 286
🏁 Script executed:
Repository: FAForever/fa
Length of output: 298
🏁 Script executed:
Repository: FAForever/fa
Length of output: 102
🏁 Script executed:
Repository: FAForever/fa
Length of output: 4321
🏁 Script executed:
Repository: FAForever/fa
Length of output: 2538
🏁 Script executed:
Repository: FAForever/fa
Length of output: 8540
🏁 Script executed:
Repository: FAForever/fa
Length of output: 5447
Fix Army value inconsistency: use calculated army index, not StartSpot.
This implementation has critical issues:
Army value bug: Line 631 sends
playerOptions.StartSpotas the Army value, but LaunchThread (line 562) explicitly documents that "Army numbers need to be calculated: they are numbered incrementally in slot order" and correctly uses a calculatedarmyIndexat line 574. Sending StartSpot as Army will cause the server to receive inconsistent and incorrect Army values.Inefficient synchronization: The loop sends ALL player options every time ANY single player is added, resulting in O(N²) messages for N sequential players (1+2+3+...+N = 36 messages for an 8-player game instead of 8).
Variable shadowing: The loop variable
playerOptions(line 628) shadows the function parameterplayerOptions(line 618), reducing clarity.If the intent is to ensure the server knows about all connected players early, that's reasonable. However, the Army value must be calculated consistently. Consider sending only the newly added player's options, or if all-player sync is necessary, compute Army values the same way as LaunchThread does.
💡 Suggested fix if sending only the new player
Note: If sending only the new player, you still need to compute the correct Army index. This requires calculating the position of this player in the sorted slot order, similar to LaunchThread lines 563-576.
Uh oh!
There was an error while loading. Please reload this page.
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.
This is actually a good point 😃 ! How do we know what the actual start spot is for a player? We can't exactly trust on the user input here.
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.
The suggested fix is wrong, since then the host would never sent their own player options with the current changes.
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.
🧩 Analysis chain
🏁 Script executed:
Length of output: 7969
@Garanas, excellent security question! You're absolutely right to be concerned about trusting client-provided
StartSpotvalues. Currently, no validation exists — the code directly uses the client's StartSpot as an array index at line 625, which is unsafe.Missing Validations
The TODO comment at line 623 flags this, but here's what needs to be validated before line 625:
Host Authority Model
Since this is
ProcessAddPlayerMessage(which only the host receives), the host should have full authority to:The autolobby appears to be designed for matchmaker-controlled games where slot assignments come from the server via command-line args, but validation is still needed for defensive programming.
The Original Army Value Bug
Separately, the critical issue from my original comment remains: line 631 sends
playerOptions.StartSpotas the Army value, but LaunchThread (lines 563-576) correctly calculates Army as an incrementally numbered index in sorted slot order. This inconsistency will cause the server to receive wrong Army values, regardless of whether StartSpot validation is added.Both issues need fixing:
Would you like me to provide a more complete code suggestion that addresses both concerns?
🧬 Code Graph Analysis Results
engine/User.lua
lua/simInit.lua
lua/userInit.lua
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.
@Garanas You're absolutely right! I apologize for the incorrect suggestion. The host creates their own player options in the
Hostingfunction but never goes throughProcessAddPlayerMessage, so they would indeed never send their options if we only sent the newly added player.The loop sending all player options makes sense — it ensures the server has complete information about all connected players (including the host) whenever anyone joins.
However, the Army value bug remains critical: Line 631 still sends
playerOptions.StartSpotas the Army value, but Army indices must be calculated incrementally in sorted slot order (as LaunchThread correctly does on lines 563-576).Here's a corrected fix that preserves the all-player synchronization while fixing the Army calculation:
This also addresses the variable shadowing issue by using
playerOptsin the loop instead of reusingplayerOptions.Regarding your earlier question about trusting start spots: that's a good security concern. The current code accepts whatever StartSpot the joining player claims (line 624). Should there be validation to ensure the StartSpot is not already occupied and within valid range [1, PlayerCount]?