fix(event-match): fix towers and barracks statuses parsing #3029
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.
Fixes #2880
Description
https://wiki.teamfortress.com/wiki/WebAPI/GetMatchDetails states that Tower Status is a 16-bit unsigned integer and Barracks Status is a 8-bit unsigned integer.
It also states that the first 5 bits of the Tower status are unused and the same goes for the first 2 bits of Barracks Status.
The code meanwhile was assuming that these bits will always be unused
web/src/components/Match/BuildingMap/BuildingMap.jsx
Lines 262 to 265 in 283309c
In the case of this event match that was causing the issue the barracks_status_radiant was
11111111
(the full 8-bits), so when passed to thepad
function which pads to 6, there was nothing to do and thepad
function was returning the an 8 character string (as expected because 8 > 6).What we end up with is bits.length = 38:
11 tower_status_radiant + 8 barracks_status_radiant + 11 tower_status_dire + 6 barracks_status_dire + 2 match_win
buildingData on the other hand is only 36 items long so this will obviously fail
web/src/components/Match/BuildingMap/BuildingMap.jsx
Lines 272 to 273 in 283309c
Changes
This PR fixes the issue by padding to full bit length specified by the docs 16 for Tower Status and 8 for Barracks Status and then remove the unused bits.
Note
#2882 missed the issue as there was no problem with the padding function, opened this PR instead as work seemed stale there.