]> git.stg.codes - stg.git/blobdiff - projects/stargazer/user_impl.cpp
Simplify notifiers.
[stg.git] / projects / stargazer / user_impl.cpp
index 2b7cc3a9d750187d32770d9d85112847be0d1495..60e801b98144c58c2fe3275cc9429a855d9f87f0 100644 (file)
@@ -47,6 +47,7 @@
 
 #include <algorithm>
 #include <functional>
+#include <array>
 
 #include <cassert>
 #include <cstdlib>
@@ -641,7 +642,7 @@ void UserImpl::Run()
 {
 STG_LOCKER lock(&mutex);
 
-if (stgTime > static_cast<time_t>(lastWriteStat + settings->GetStatWritePeriod()))
+if (stgTime > lastWriteStat + settings->GetStatWritePeriod())
     {
     printfd(__FILE__, "UserImpl::WriteStat user=%s\n", GetLogin().c_str());
     WriteStat();
@@ -1046,8 +1047,7 @@ double UserImpl::GetPassiveTimePart() const
 {
 STG_LOCKER lock(&mutex);
 
-static int daysInMonth[12] =
-{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+static const std::array<unsigned, 12> daysInMonth{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 
 struct tm tms;
 time_t t = stgTime;
@@ -1493,7 +1493,7 @@ std::string UserImpl::GetParamValue(const std::string & name) const
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-void STG::CHG_PASSIVE_NOTIFIER::Notify(const int & oldPassive, const int & newPassive)
+void STG::CHG_PASSIVE_NOTIFIER::notify(const int & oldPassive, const int & newPassive)
 {
 if (newPassive && !oldPassive && user->tariff != NULL)
     user->properties.cash.Set(user->cash - user->tariff->GetPassiveCost(),
@@ -1503,7 +1503,7 @@ if (newPassive && !oldPassive && user->tariff != NULL)
                             "Freeze");
 }
 //-----------------------------------------------------------------------------
-void STG::CHG_DISABLED_NOTIFIER::Notify(const int & oldValue, const int & newValue)
+void STG::CHG_DISABLED_NOTIFIER::notify(const int & oldValue, const int & newValue)
 {
 if (oldValue && !newValue && user->GetConnected())
     user->Disconnect(false, "disabled");
@@ -1511,7 +1511,7 @@ else if (!oldValue && newValue && user->IsInetable())
     user->Connect(false);
 }
 //-----------------------------------------------------------------------------
-void STG::CHG_TARIFF_NOTIFIER::Notify(const std::string &, const std::string & newTariff)
+void STG::CHG_TARIFF_NOTIFIER::notify(const std::string &, const std::string & newTariff)
 {
 STG_LOCKER lock(&user->mutex);
 if (user->settings->GetReconnectOnTariffChange() && user->connected)
@@ -1527,13 +1527,13 @@ if (user->settings->GetReconnectOnTariffChange() &&
     }
 }
 //-----------------------------------------------------------------------------
-void STG::CHG_CASH_NOTIFIER::Notify(const double & oldCash, const double & newCash)
+void STG::CHG_CASH_NOTIFIER::notify(const double & oldCash, const double & newCash)
 {
 user->lastCashAddTime = *const_cast<time_t *>(&stgTime);
 user->lastCashAdd = newCash - oldCash;
 }
 //-----------------------------------------------------------------------------
-void STG::CHG_IPS_NOTIFIER::Notify(const UserIPs & from, const UserIPs & to)
+void STG::CHG_IPS_NOTIFIER::notify(const UserIPs & from, const UserIPs & to)
 {
 printfd(__FILE__, "Change IP from '%s' to '%s'\n", from.toString().c_str(), to.toString().c_str());
 if (user->connected)