]> git.stg.codes - stg.git/blobdiff - stglibs/srvconf.lib/parsers/get_user.cpp
Fixed error handling.
[stg.git] / stglibs / srvconf.lib / parsers / get_user.cpp
index e1f06e8b378a40d714e5b7beac638d628618032e..e796d45094cd249ca5a8933b7f78209ac0f1c7c6 100644 (file)
@@ -34,17 +34,17 @@ namespace STG
 {
 
 template <>
-bool GetValue<GET_USER::STAT>(const char ** attr, GET_USER::STAT & value)
+bool GetValue<GET_USER::STAT>(const char ** attr, GET_USER::STAT & value, const std::string & /*attrName*/)
 {
 if (!attr)
     return false;
 std::map<std::string, long long *> props;
 for (size_t i = 0; i < DIR_NUM; ++i)
     {
-    props.insert(std::pair<std::string, long long *>("su" + x2str(i), &value.su[i]));
-    props.insert(std::pair<std::string, long long *>("sd" + x2str(i), &value.sd[i]));
-    props.insert(std::pair<std::string, long long *>("mu" + x2str(i), &value.mu[i]));
-    props.insert(std::pair<std::string, long long *>("md" + x2str(i), &value.md[i]));
+    props.insert(std::pair<std::string, long long *>("su" + unsigned2str(i), &value.su[i]));
+    props.insert(std::pair<std::string, long long *>("sd" + unsigned2str(i), &value.sd[i]));
+    props.insert(std::pair<std::string, long long *>("mu" + unsigned2str(i), &value.mu[i]));
+    props.insert(std::pair<std::string, long long *>("md" + unsigned2str(i), &value.md[i]));
     }
 size_t pos = 0;
 while (attr[pos])
@@ -71,12 +71,13 @@ GET_USER::PARSER::PARSER(CALLBACK f, void * d)
     AddParser(propertyParsers, "cash", info.cash);
     AddParser(propertyParsers, "credit", info.credit);
     AddParser(propertyParsers, "creditExpire", info.creditExpire);
-    AddParser(propertyParsers, "lastCash", info.lastCash);
-    AddParser(propertyParsers, "prepaidTraff", info.prepaidTraff);
-    AddParser(propertyParsers, "down", info.down);
+    AddParser(propertyParsers, "lastCash", info.lastCashAdd);
+    AddParser(propertyParsers, "lastTimeCash", info.lastCashAddTime);
+    AddParser(propertyParsers, "freeMb", info.prepaidTraff);
+    AddParser(propertyParsers, "down", info.disabled);
     AddParser(propertyParsers, "passive", info.passive);
     AddParser(propertyParsers, "disableDetailStat", info.disableDetailStat);
-    AddParser(propertyParsers, "connected", info.connected);
+    AddParser(propertyParsers, "status", info.connected);
     AddParser(propertyParsers, "aonline", info.alwaysOnline);
     AddParser(propertyParsers, "currIP", info.ip, GetIPValue);
     AddParser(propertyParsers, "ip", info.ips);
@@ -88,9 +89,11 @@ GET_USER::PARSER::PARSER(CALLBACK f, void * d)
     AddParser(propertyParsers, "address", info.address, GetEncodedValue);
     AddParser(propertyParsers, "phone", info.phone, GetEncodedValue);
     AddParser(propertyParsers, "traff", info.stat);
+    AddParser(propertyParsers, "pingTime", info.pingTime);
+    AddParser(propertyParsers, "lastActivityTime", info.lastActivityTime);
 
     for (size_t i = 0; i < USERDATA_NUM; ++i)
-        AddParser(propertyParsers, "userData" + x2str(i), info.userData[i], GetEncodedValue);
+        AddParser(propertyParsers, "userData" + unsigned2str(i), info.userData[i], GetEncodedValue);
 }
 //-----------------------------------------------------------------------------
 GET_USER::PARSER::~PARSER()
@@ -127,6 +130,7 @@ if (depth == 0 && parsingAnswer)
 void GET_USER::PARSER::ParseUser(const char * el, const char ** attr)
 {
 if (strcasecmp(el, "user") == 0)
+    {
     if (attr && attr[0] && attr[1])
         {
         if (strcasecmp(attr[1], "error") == 0)
@@ -136,11 +140,11 @@ if (strcasecmp(el, "user") == 0)
             else
                 error = "User not found.";
             }
-        else
-            parsingAnswer = true;
+        else if (strcasecmp(attr[0], "login") == 0 && attr[1])
+            info.login = attr[1];
         }
-    else
-        parsingAnswer = true;
+    parsingAnswer = true;
+    }
 }
 //-----------------------------------------------------------------------------
 void GET_USER::PARSER::ParseUserParams(const char * el, const char ** attr)