]> git.stg.codes - stg.git/blobdiff - projects/stargazer/user_impl.cpp
Added notifiers for the "disabled" property.
[stg.git] / projects / stargazer / user_impl.cpp
index 1278afa2de947124d604681a7617349cb3fa28f5..f01ba563482ba1b9155e2d6acb5925b0fc8e9f2f 100644 (file)
@@ -132,6 +132,7 @@ lastWriteDetailedStat = stgTime;
 
 property.tariffName.AddBeforeNotifier(&tariffNotifier);
 property.passive.AddBeforeNotifier(&passiveNotifier);
+property.disabled.AddAfterNotifier(&disabledNotifier);
 property.cash.AddBeforeNotifier(&cashNotifier);
 ips.AddAfterNotifier(&ipNotifier);
 
@@ -210,6 +211,7 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s,
       sessionUpload(),
       sessionDownload(),
       passiveNotifier(this),
+      disabledNotifier(this),
       tariffNotifier(this),
       cashNotifier(this),
       ipNotifier(this),
@@ -224,6 +226,7 @@ lastWriteDetailedStat = stgTime;
 
 property.tariffName.AddBeforeNotifier(&tariffNotifier);
 property.passive.AddBeforeNotifier(&passiveNotifier);
+property.disabled.AddAfterNotifier(&disabledNotifier);
 property.cash.AddBeforeNotifier(&cashNotifier);
 ips.AddAfterNotifier(&ipNotifier);
 
@@ -299,6 +302,7 @@ USER_IMPL::USER_IMPL(const USER_IMPL & u)
       sessionUpload(),
       sessionDownload(),
       passiveNotifier(this),
+      disabledNotifier(this),
       tariffNotifier(this),
       cashNotifier(this),
       ipNotifier(this),
@@ -310,6 +314,7 @@ if (&u == this)
 
 property.tariffName.AddBeforeNotifier(&tariffNotifier);
 property.passive.AddBeforeNotifier(&passiveNotifier);
+property.disabled.AddAfterNotifier(&disabledNotifier);
 property.cash.AddBeforeNotifier(&cashNotifier);
 ips.AddAfterNotifier(&ipNotifier);
 
@@ -323,8 +328,10 @@ pthread_mutex_init(&mutex, &attr);
 //-----------------------------------------------------------------------------
 USER_IMPL::~USER_IMPL()
 {
-property.passive.DelBeforeNotifier(&passiveNotifier);
 property.tariffName.DelBeforeNotifier(&tariffNotifier);
+property.passive.DelBeforeNotifier(&passiveNotifier);
+property.disabled.DelAfterNotifier(&disabledNotifier);
+property.cash.DelBeforeNotifier(&cashNotifier);
 pthread_mutex_destroy(&mutex);
 }
 //-----------------------------------------------------------------------------
@@ -1243,11 +1250,15 @@ switch (settings->GetFeeChargeType())
         property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
         break;
     case 1:
-        if (c > 0)
+        if (c + credit >= 0)
             property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
         break;
     case 2:
-        if (c > fee)
+        if (c + credit >= fee)
+            property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
+        break;
+    case 3:
+        if (c >= 0)
             property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
         break;
     }
@@ -1285,8 +1296,10 @@ if (fee == 0.0)
     }
 
 double c = cash;
-printfd(__FILE__, "login: %8s   Fee=%f PassiveTimePart=%f fee=%f\n",
+printfd(__FILE__, "login: %8s Cash=%f Credit=%f  Fee=%f PassiveTimePart=%f fee=%f\n",
         login.c_str(),
+        cash.ConstData(),
+        credit.ConstData(),
         tariff->GetFee(),
         passiveTimePart,
         fee);
@@ -1297,14 +1310,21 @@ switch (settings->GetFeeChargeType())
         SetPrepaidTraff();
         break;
     case 1:
-        if (c > 0)
+        if (c + credit >= 0)
             {
             property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
             SetPrepaidTraff();
             }
         break;
     case 2:
-        if (c > fee)
+        if (c + credit >= fee)
+            {
+            property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
+            SetPrepaidTraff();
+            }
+        break;
+    case 3:
+        if (c >= 0)
             {
             property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge");
             SetPrepaidTraff();
@@ -1447,6 +1467,19 @@ if (newPassive && !oldPassive && user->tariff != NULL)
                             "Freeze");
 }
 //-----------------------------------------------------------------------------
+void CHG_DISABLED_NOTIFIER::Notify(const int & oldValue, const int & newValue)
+{
+if (oldValue && !newValue && user->GetConnected())
+    {
+    user->Disconnect(false, "disabled");
+    }
+else if (!oldValue && newValue && user->IsInetable())
+    {
+    user->Connect(false);
+    }
+
+}
+//-----------------------------------------------------------------------------
 void CHG_TARIFF_NOTIFIER::Notify(const string &, const string & newTariff)
 {
 if (user->settings->GetReconnectOnTariffChange() && user->connected)