Skip to content

Commit

Permalink
fix(q2): Xonotic with gametype CA (#111)
Browse files Browse the repository at this point in the history
Fix q2 parsing for Xonotic with gametype CA which has a leading float
for damage not int for frags.

Fixes #89
  • Loading branch information
stevenh authored Sep 28, 2021
1 parent 72346f3 commit 02f3fb9
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions qstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -6433,7 +6433,7 @@ deal_with_q2_packet(struct qserver *server, char *rawpkt, int pktlen)
debug(2, "deal_with_q2_packet %p, %d", server, pktlen);

while (*pkt && pkt - rawpkt < pktlen) {
// we have variable, value pairs seperated by slash
// we have variable, value pairs separated by slash
if (*pkt == '\\') {
pkt++;
if ((*pkt == '\n') && (server->type->id == SOF_SERVER)) {
Expand Down Expand Up @@ -6521,7 +6521,22 @@ player_info: debug(3, "player info");
break;
}

rc = sscanf(pkt, "%d %n", &frags, &len);
// Detect if we have a leading float or int?
rc = sscanf(pkt, "%d.%d %n", &frags, &ping, &len);
ping = 0; // Just a temp variable so reset.
if (rc == 2) {
// Xonotic in CA mode shows damage (float) instead of frags (int)
// 1.0 == 100 dmg.
float frags_f;

if ((rc = sscanf(pkt, "%f %n", &frags_f, &len)) == 1) {
frags = (int)(frags_f*100);
}
} else {
// Just an int.
rc = sscanf(pkt, "%d %n", &frags, &len);
}

if ((rc == 1) && (pkt[len] != '"')) {
pkt += len;
rc = sscanf(pkt, "%d %n", &ping, &len);
Expand Down

0 comments on commit 02f3fb9

Please sign in to comment.