]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/store/files/file_store.cpp
Lots of stylistic fixes.
[stg.git] / projects / stargazer / plugins / store / files / file_store.cpp
index 4e4489adcaa86614d32aaa0b390e24b5e513506b..bf5d389a87f5f03ec66c9e201a6be3959cc1ce6f 100644 (file)
@@ -577,7 +577,6 @@ int FILES_STORE::RestoreUserConf(USER_CONF * conf, const std::string & login, co
 {
 CONFIGFILE cf(fileName);
 int e = cf.Error();
-std::string str;
 
 if (e)
     {
@@ -728,7 +727,7 @@ for (int i = 0; i < DIR_NUM; i++)
         printfd(__FILE__, "FILES_STORE::RestoreUserStat - download stat read failed for user '%s'\n", login.c_str());
         return -1;
         }
-    stat->down[i] = traff;
+    stat->monthDown[i] = traff;
 
     snprintf(s, 22, "U%d", i);
     if (cf.ReadULongLongInt(s, &traff, 0) != 0)
@@ -738,7 +737,7 @@ for (int i = 0; i < DIR_NUM; i++)
         printfd(__FILE__, "FILES_STORE::RestoreUserStat - upload stat read failed for user '%s'\n", login.c_str());
         return -1;
         }
-    stat->up[i] = traff;
+    stat->monthUp[i] = traff;
     }
 
 if (cf.ReadDouble("Cash", &stat->cash, 0) != 0)
@@ -850,7 +849,6 @@ return 0;
 //-----------------------------------------------------------------------------
 int FILES_STORE::SaveUserStat(const USER_STAT & stat, const std::string & login) const
 {
-char s[22];
 std::string fileName;
 fileName = storeSettings.GetUsersDir() + "/" + login + "/stat";
 
@@ -868,10 +866,11 @@ fileName = storeSettings.GetUsersDir() + "/" + login + "/stat";
 
     for (int i = 0; i < DIR_NUM; i++)
         {
+        char s[22];
         snprintf(s, 22, "D%d", i);
-        cfstat.WriteInt(s, stat.down[i]);
+        cfstat.WriteInt(s, stat.monthDown[i]);
         snprintf(s, 22, "U%d", i);
-        cfstat.WriteInt(s, stat.up[i]);
+        cfstat.WriteInt(s, stat.monthUp[i]);
         }
 
     cfstat.WriteDouble("Cash", stat.cash);
@@ -990,8 +989,8 @@ return WriteLog2String(logStr, login);
 }
 //-----------------------------------------------------------------------------
 int FILES_STORE::WriteUserDisconnect(const std::string & login,
-                                     const DIR_TRAFF & up,
-                                     const DIR_TRAFF & down,
+                                     const DIR_TRAFF & monthUp,
+                                     const DIR_TRAFF & monthDown,
                                      const DIR_TRAFF & sessionUp,
                                      const DIR_TRAFF & sessionDown,
                                      double cash,
@@ -1005,9 +1004,9 @@ logStr << "Disconnect, "
        << "\' session download: \'"
        << sessionDown
        << "\' month upload: \'"
-       << up
+       << monthUp
        << "\' month download: \'"
-       << down
+       << monthDown
        << "\' cash: \'"
        << cash
        << "\'";
@@ -1061,11 +1060,11 @@ for (size_t i = 0; i < DIR_NUM; i++)
     {
     char dirName[3];
     snprintf(dirName, 3, "U%llu", (unsigned long long)i);
-    s.WriteInt(dirName, stat.up[i]); // Classic
-    s2.WriteInt(dirName, stat.up[i]); // New
+    s.WriteInt(dirName, stat.monthUp[i]); // Classic
+    s2.WriteInt(dirName, stat.monthUp[i]); // New
     snprintf(dirName, 3, "D%llu", (unsigned long long)i);
-    s.WriteInt(dirName, stat.down[i]); // Classic
-    s2.WriteInt(dirName, stat.down[i]); // New
+    s.WriteInt(dirName, stat.monthDown[i]); // Classic
+    s2.WriteInt(dirName, stat.monthDown[i]); // New
     }
 
 // Classic
@@ -1115,10 +1114,6 @@ return 0;
 //-----------------------------------------------------------------------------*/
 int FILES_STORE::SaveAdmin(const ADMIN_CONF & ac) const
 {
-char passwordE[2 * ADM_PASSWD_LEN + 2];
-char pass[ADM_PASSWD_LEN + 1];
-char adminPass[ADM_PASSWD_LEN + 1];
-
 std::string fileName;
 
 strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), ac.login.c_str());
@@ -1136,7 +1131,10 @@ strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), ac.login
         return -1;
         }
 
+    char pass[ADM_PASSWD_LEN + 1];
     memset(pass, 0, sizeof(pass));
+
+    char adminPass[ADM_PASSWD_LEN + 1];
     memset(adminPass, 0, sizeof(adminPass));
 
     BLOWFISH_CTX ctx;
@@ -1151,6 +1149,7 @@ strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), ac.login
         }
 
     pass[ADM_PASSWD_LEN - 1] = 0;
+    char passwordE[2 * ADM_PASSWD_LEN + 2];
     Encode12(passwordE, pass, ADM_PASSWD_LEN);
 
     cf.WriteString("password", passwordE);
@@ -1483,6 +1482,11 @@ else
                 printfd(__FILE__, "FILES_STORE::RestoreTariff - invalid trafftype for tariff '%s'\n", tariffName.c_str());
                 return -1;
                 }
+
+if (conf.ReadString("Period", &str, "month") < 0)
+    td->tariffConf.period = TARIFF::MONTH;
+else
+    td->tariffConf.period = TARIFF::StringToPeriod(str);
 return 0;
 }
 //-----------------------------------------------------------------------------
@@ -1558,6 +1562,8 @@ std::string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf";
             cf.WriteString("TraffType", "max");
             break;
         }
+
+    cf.WriteString("Period", TARIFF::PeriodToString(td.tariffConf.period));
     }
 
 return 0;
@@ -1826,7 +1832,7 @@ if (!msgFile)
     }
 
 bool res = true;
-res &= (fprintf(msgFile, "%d\n", msg.header.type) >= 0);
+res &= (fprintf(msgFile, "%u\n", msg.header.type) >= 0);
 res &= (fprintf(msgFile, "%u\n", msg.header.lastSendTime) >= 0);
 res &= (fprintf(msgFile, "%u\n", msg.header.creationTime) >= 0);
 res &= (fprintf(msgFile, "%u\n", msg.header.showTime) >= 0);
@@ -1851,7 +1857,7 @@ if (rename((fileName + ".new").c_str(), fileName.c_str()) < 0)
     {
     STG_LOCKER lock(&mutex, __FILE__, __LINE__);
     errorStr = "Error moving dir from " + fileName + ".new to " + fileName;
-    printfd(__FILE__, "FILES_STORE::SaveTariff - rename failed. Message: '%s'\n", strerror(errno));
+    printfd(__FILE__, "FILES_STORE::EditMessage - rename failed. Message: '%s'\n", strerror(errno));
     return -1;
     }