Skip to content

Conversation

@stevenh
Copy link
Contributor

@stevenh stevenh commented Sep 23, 2021

Fix q2 parsing for Xonotic with gametype CA which has a leading float for damage not int for frags.

Fixes #89

Fix q2 parsing for Xonotic with gametype CA which has a leading float
for damage not int for frags.

Fixes #89
Comment on lines +6532 to +6534
if ((rc = sscanf(pkt, "%f %n", &frags_f, &len)) == 1) {
frags = (int)(frags_f*100);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you simply not reset ping and instead skip the second sscanf by doing frags = (frags * 100) + ping (assuming ping is always going to be at most 2 decimal places, if it isn't, you could use a while loop to do an integer divide by ten to truncate it until the value was =< 99 and then add it, though at that point it's probably more complicated than a second sscanf)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decimals aren't limited to two, so as you say this is still the clearest way to do this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also that it may be that the decimal part of the number could not be loaded into a int, and in this case i believe sscanf would set ping to -1. So +1 to reloading with sscanf into a float

Copy link
Contributor

@lwaddicor lwaddicor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@stevenh stevenh merged commit 02f3fb9 into master Sep 28, 2021
@stevenh stevenh deleted the fix-xonotic-ca-mode branch September 28, 2021 11:14
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.

Xonotic servers with CA gametype with >0 players, returns error

3 participants