X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/641204dfbdb9fc870cdd2e7f9e3169a44693e7bf..c1a020a6bf83da0186278491af2d0bfa8d917b44:/projects/stargazer/users.cpp?ds=inline diff --git a/projects/stargazer/users.cpp b/projects/stargazer/users.cpp index 1b710baa..84a10227 100644 --- a/projects/stargazer/users.cpp +++ b/projects/stargazer/users.cpp @@ -144,7 +144,7 @@ if (store->AddUser(login)) USER u(settings, store, tariffs, sysAdmin, &ipIndex); -struct tm * tms; +/*struct tm * tms; time_t t = stgTime; tms = localtime(&t); @@ -156,7 +156,7 @@ tms->tm_sec = 0; if (settings->GetDayResetTraff() > tms->tm_mday) tms->tm_mon -= 1; -tms->tm_mday = settings->GetDayResetTraff(); +tms->tm_mday = settings->GetDayResetTraff();*/ u.SetLogin(login); @@ -276,12 +276,12 @@ void * USERS::Run(void * d) printfd(__FILE__, "=====================| pid: %d |===================== \n", getpid()); USERS * us = (USERS*) d; -struct tm * t; +struct tm t; time_t tt = stgTime; -t = localtime(&tt); +localtime_r(&tt, &t); -int min = t->tm_min; -int day = t->tm_mday; +int min = t.tm_min; +int day = t.tm_mday; printfd(__FILE__,"Day = %d Min = %d\n", day, min); @@ -298,23 +298,22 @@ while (us->nonstop) for_each(us->users.begin(), us->users.end(), mem_fun_ref(&USER::Run)); tt = stgTime; - t = localtime(&tt); + localtime_r(&tt, &t); - if (min != t->tm_min) + if (min != t.tm_min) { printfd(__FILE__,"Sec = %d\n", stgTime); - printfd(__FILE__,"New Minute. old = %d current = %d\n", min, t->tm_min); - min = t->tm_min; + printfd(__FILE__,"New Minute. old = %d current = %d\n", min, t.tm_min); + min = t.tm_min; us->NewMinute(t); } - t = localtime(&tt); - if (day != t->tm_mday) + if (day != t.tm_mday) { printfd(__FILE__,"Sec = %d\n", stgTime); - printfd(__FILE__,"New Day. old = %d current = %d\n", day, t->tm_mday); - day = t->tm_mday; + printfd(__FILE__,"New Day. old = %d current = %d\n", day, t.tm_mday); + day = t.tm_mday; us->NewDay(t); } @@ -350,13 +349,10 @@ us->isRunning = false; return NULL; } //----------------------------------------------------------------------------- -void USERS::NewMinute(const struct tm * t) +void USERS::NewMinute(const struct tm & t) { -int usersCnt = 0; -list::iterator usr; - //Write traff, reset session traff. Fake disconnect-connect -if (t->tm_hour == 23 && t->tm_min == 59) +if (t.tm_hour == 23 && t.tm_min == 59) { printfd(__FILE__,"MidnightResetSessionStat\n"); for_each(users.begin(), users.end(), mem_fun_ref(&USER::MidnightResetSessionStat)); @@ -365,11 +361,10 @@ if (t->tm_hour == 23 && t->tm_min == 59) if (TimeToWriteDetailStat(t)) { //printfd(__FILE__, "USER::WriteInetStat\n"); - for_each(users.begin(), users.end(), mem_fun_ref(&USER::SwapDetailStat)); - usersCnt = 0; + int usersCnt = 0; // ðÉÛÅÍ ÀÚÅÒÏ× ÞÁÓÔÑÍÉ. ÷ ÐÅÒÅÒÙ×ÁÈ ×ÙÚÙ×ÁÅÍ USER::Run - usr = users.begin(); + list::iterator usr = users.begin(); while (usr != users.end()) { usersCnt++; @@ -378,25 +373,23 @@ if (TimeToWriteDetailStat(t)) if (usersCnt % 10 == 0) for_each(users.begin(), users.end(), mem_fun_ref(&USER::Run)); } - - for_each(users.begin(), users.end(), mem_fun_ref(&USER::ResetDetailStat)); } RealDelUser(); } //----------------------------------------------------------------------------- -void USERS::NewDay(const struct tm * t) +void USERS::NewDay(const struct tm & t) { -struct tm * t1; +struct tm t1; time_t tt = stgTime; -t1 = localtime(&tt); +localtime_r(&tt, &t1); int dayFee = settings->GetDayFee(); if (dayFee == 0) dayFee = DaysInCurrentMonth(); printfd(__FILE__, "DayFee = %d\n", dayFee); -printfd(__FILE__, "Today = %d DayResetTraff = %d\n", t1->tm_mday, settings->GetDayResetTraff()); +printfd(__FILE__, "Today = %d DayResetTraff = %d\n", t1.tm_mday, settings->GetDayResetTraff()); printfd(__FILE__, "DayFeeIsLastDay = %d\n", settings->GetDayFeeIsLastDay()); if (!settings->GetDayFeeIsLastDay()) @@ -413,7 +406,7 @@ if (settings->GetSpreadFee()) } else { - if (t->tm_mday == dayFee) + if (t.tm_mday == dayFee) { printfd(__FILE__, "DayFee\n"); for_each(users.begin(), users.end(), mem_fun_ref(&USER::ProcessDayFee)); @@ -427,12 +420,12 @@ if (settings->GetDayFeeIsLastDay()) } } //----------------------------------------------------------------------------- -void USERS::DayResetTraff(const struct tm * t1) +void USERS::DayResetTraff(const struct tm & t1) { int dayResetTraff = settings->GetDayResetTraff(); if (dayResetTraff == 0) dayResetTraff = DaysInCurrentMonth(); -if (t1->tm_mday == dayResetTraff) +if (t1.tm_mday == dayResetTraff) { printfd(__FILE__, "ResetTraff\n"); for_each(users.begin(), users.end(), mem_fun_ref(&USER::ProcessNewMonth)); @@ -495,8 +488,13 @@ if (isRunning) printfd(__FILE__, "Before USERS::Run()\n"); for_each(users.begin(), users.end(), mem_fun_ref(&USER::Run)); -for_each(users.begin(), users.end(), mem_fun_ref(&USER::SwapDetailStat)); -for_each(users.begin(), users.end(), mem_fun_ref(&USER::WriteDetailStat)); + +// 'cause bind2st accepts only constant first param +for (list::iterator it = users.begin(); + it != users.end(); + ++it) + it->WriteDetailStat(true); + for_each(users.begin(), users.end(), mem_fun_ref(&USER::WriteStat)); for_each(users.begin(), users.end(), mem_fun_ref(&USER::WriteConf)); @@ -728,41 +726,28 @@ STG_LOCKER lock(&mutex, __FILE__, __LINE__); loginIndex.erase(user->GetLogin()); } //----------------------------------------------------------------------------- -bool USERS::TimeToWriteDetailStat(const struct tm * t) +bool USERS::TimeToWriteDetailStat(const struct tm & t) { int statTime = settings->GetDetailStatWritePeriod(); switch (statTime) { case dsPeriod_1: - if (t->tm_min == 0) + if (t.tm_min == 0) return true; break; case dsPeriod_1_2: - if (t->tm_min % 30 == 0) + if (t.tm_min % 30 == 0) return true; break; case dsPeriod_1_4: - if (t->tm_min % 15 == 0) + if (t.tm_min % 15 == 0) return true; break; case dsPeriod_1_6: - if (t->tm_min % 10 == 0) + if (t.tm_min % 10 == 0) return true; break; } return false; } -//----------------------------------------------------------------------------- -/*int USERS::SendMessage(const string & login, - time_t sndTtime, - time_t showTime, - char type, - const string & text) const -{ -return 0; -}*/ -//----------------------------------------------------------------------------- - - -