Unity-Technologies/qstat

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

arena-sh opened this issue · 8 comments

Conditions:
At least 1 player(s) playing
Gametype is CA
Qstat version: 2.15

Following errors out:

$ qstat -R -json -xonotics 136.243.145.236:30142
[
	{
		"protocol": "xonotics",
		"address": "136.243.145.236:30142",
		"status": "error",
		"hostname": "136.243.145.236:30142",
		"error": ".297794 49 2 \"Kano\""
	}
]

This one works:

$ qstat -json -xonotics 136.243.145.236:30142
[
	{
		"protocol": "xonotics",
		"address": "136.243.145.236:30142",
		"status": "online",
		"hostname": "136.243.145.236:30142",
		"name": "[WTWRP] Votable (2)",
		"gametype": "Xonotic",
		"map": "bloodrun_a3",
		"numplayers": 12,
		"maxplayers": 24,
		"numspectators": 0,
		"maxspectators": 0,
		"ping": 20,
		"retries": 0
	}
]

Reported by:
martin-t ramses nmc tommy @ xonotic discord/irc

My guess is that CA servers report "damage dealt" rather than "frags" and thus the value is a float and qstat expects an int and errors out because of that.

Edit: https://github.com/multiplay/qstat/blob/d1469ab30a5b550a7696857ca1ff49579127dc9e/qstat.h#L3812

For anyone craving for a crappy workaround:

diff --git a/qstat.c b/qstat.c
index f797960..ad78580 100644
--- a/qstat.c
+++ b/qstat.c
@@ -6521,7 +6521,21 @@ player_info:            debug(3, "player info");
 				break;
 			}
 
-			rc = sscanf(pkt, "%d %n", &frags, &len);
+			// Xonotic in CA mode shows damage (float) instead of frags (int)
+			// 1.0 == 100 dmg
+			// https://github.com/multiplay/qstat/issues/89
+			float frags_f;
+			char tmp_frags[16];
+
+			sscanf(pkt, "%s", (char *)&tmp_frags);
+
+			if (strstr(tmp_frags, ".") != NULL) {
+				rc = sscanf(pkt, "%f %n", &frags_f, &len);
+				frags = (int)(frags_f*100);
+			} else {
+				rc = sscanf(pkt, "%d %n", &frags, &len);
+			}
+
 			if ((rc == 1) && (pkt[len] != '"')) {
 				pkt += len;
 				rc = sscanf(pkt, "%d %n", &ping, &len);

@incognico 's solution worked well in our case

Does anyone have a server to test against?

You can check live servers at https://xonotic.lifeisabug.com/ and use the address of a populated one where gametype is CA.

Just for info I'm a xonotic contributor and #89 (comment) is not a guess but verified meanwhile. Using my patch since I posted it without any problems.

Thanks @incognico if you could test #111, which takes a slightly different approach, to confirm it still works that would be great.

Confirmed working.