Randomize the location in svs.clients array for new clients #148
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.
Players are assigned the first available spot in the svs.clients array when they connect. On an empty server, this means that player1 is placed at svs.clients[0], player2 at svs.clients[1], and so on.
KTX iterates over svs.clients at the start of a match to decide where each player will spawn. This becomes problematic when there are fewer spawn points than players. A good example is dm3, which only has six spawns.
In the scenario where players connect to an empty server, they occupy the indexes 0 through 7 in the svs.clients array and are processed in this predictable order. This means player1 gets a random spawn before player2, player2 before player3, and so forth.
When it reaches player7, all spawn points are occupied. A random spawn is selected, and the player at that spawn point will be telefragged. Similarly, player8, the last to be processed, will also cause a telefrag.
By randomizing where new players are placed in the svs.clients array, we eliminate the possibility of predicting where in the array a player will be located, and thus also remove the possibility of manipulating the telefrag outcomes.