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

Fix client sending the wrong team to the server in some cases #2206

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

HoeenCoder
Copy link
Member

@HoeenCoder HoeenCoder commented Jan 3, 2024

Bug fix for this report: https://www.smogon.com/forums/threads/bug-report-team-selector-after-creating-teams.3733626/

Teams are stored as an array in Storage.teams. The team selection dropdown determines which team to send to the server when a player hits "Battle!" by using its value attribute as an index for the teams array. When a new team is created at the top of the team list, its placed at the front of this array becoming index 0 and shifting all other indexes up by 1. However, the team selection drop down's value was not updated resulting in the client sending the wrong team to the server. This fixes this by incrementing the value when a new team is added to the top of the list.

@urkerab
Copy link
Contributor

urkerab commented Jan 3, 2024

obj.curTeamIndex is never used for some reason. Maybe it was originally supposed to have the team index, but the code to use it was never written, and it needs to be (!)

If not, there are several other places where obj.curTeamIndex is changed, and those should probably be updated too.

@HoeenCoder
Copy link
Member Author

HoeenCoder commented Jan 4, 2024

obj.curTeamIndex is never used for some reason. Maybe it was originally supposed to have the team index, but the code to use it was never written, and it needs to be (!)

If not, there are several other places where obj.curTeamIndex is changed, and those should probably be updated too.

I did some digging, its used (outside of the teambuilder code) to determine the value of the team selection buttons (including tournament ones). I should of checked that originally, my bad. Regardless, a simple call to updateTeams on the room object in question fixes the issue, so I've updated my code to do just that.

@urkerab
Copy link
Contributor

urkerab commented Jan 4, 2024

That certainly looks much nicer but I'm still worried about the other cases of obj.curTeamIndex in this file.

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.

None yet

2 participants