From f7b378647f019f7b84461b42b3e44d6317cad814 Mon Sep 17 00:00:00 2001 From: Jan Behrens Date: Sun, 18 Aug 2013 15:55:48 +0200 Subject: [PATCH] Make PlayerInfo parser work with current format --- qcsrc/common/playerstats.qc | 34 ++++++++++++++-------------------- qcsrc/common/playerstats.qh | 2 ++ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/qcsrc/common/playerstats.qc b/qcsrc/common/playerstats.qc index 7d6a713ba..b6654217b 100644 --- a/qcsrc/common/playerstats.qc +++ b/qcsrc/common/playerstats.qc @@ -503,13 +503,20 @@ void PlayerInfo_AddItem(entity e, string item_id, string val) string PlayerInfo_GetItem(entity e, string item_id) { if(playerinfo_db < 0) - return string_null; + return ""; string key; key = sprintf("#%d:%s", e.playerid, item_id); return db_get(playerinfo_db, key); } +string PlayerInfo_GetItemLocal(string item_id) +{ + entity p = spawn(); + p.playerid = 0; + return PlayerInfo_GetItem(p, item_id); +} + void PlayerInfo_ready(entity fh, entity p, float status) { float n; @@ -521,7 +528,6 @@ void PlayerInfo_ready(entity fh, entity p, float status) { case URL_READY_CANREAD: print("-- Got response from player stats server:\n"); - float in_group = FALSE; string gametype = string_null; while((s = url_fgets(fh))) { @@ -531,10 +537,7 @@ void PlayerInfo_ready(entity fh, entity p, float status) n = tokenizebyseparator(s, " "); // key (value) data if (n == 1) - { - if (argv(0) == "}") - in_group = FALSE; - } + continue; else if (n == 2) { key = argv(0); @@ -542,18 +545,9 @@ void PlayerInfo_ready(entity fh, entity p, float status) } else if (n == 3) { - if (argv(0) == "{") - { - in_group = TRUE; - key = argv(1); - data = argv(2); - } - else - { - key = argv(0); - value = argv(1); - data = argv(2); - } + key = argv(0); + value = argv(1); + data = argv(2); } else if (n == 4) { @@ -591,14 +585,14 @@ void PlayerInfo_ready(entity fh, entity p, float status) else if (key == "i") // xonstats id PlayerInfo_AddItem(p, "_playerid", data); - else if (key == "G" && in_group) + else if (key == "G") gametype = data; else if (key == "e" && value != "") { if (gametype == "") PlayerInfo_AddItem(p, value, data); else - PlayerInfo_AddItem(p, sprintf("%s-%s", gametype, value), data); + PlayerInfo_AddItem(p, sprintf("%s/%s", gametype, value), data); } else continue; diff --git a/qcsrc/common/playerstats.qh b/qcsrc/common/playerstats.qh index a29d69607..d7860a03f 100644 --- a/qcsrc/common/playerstats.qh +++ b/qcsrc/common/playerstats.qh @@ -67,6 +67,8 @@ void PlayerStats_EndMatch(float finished); const string playerinfo_uri = "http://localhost:6543"; // FIXME string PlayerInfo_GetItem(entity e, string item_id); +string PlayerInfo_GetItemLocal(string item_id); + void PlayerInfo_Init(); #ifdef SVQC void PlayerInfo_Basic(entity p); -- 2.39.2