X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/5c19a000ed76d49fae019ed50955a1a530d161f0..5fcfdfaf6d4c57d398d011fd100f2f12b7b6859d:/projects/stargazer/user_impl.cpp?ds=inline diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index 7153012a..4cb4467e 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -68,7 +68,7 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, sysAdmin(a), store(st), tariffs(t), - tariff(tariffs->GetNoTariff()), + tariff(NULL), cash(property.cash), up(property.up), down(property.down), @@ -113,7 +113,6 @@ settings = s; password = "*_EMPTY_PASSWORD_*"; tariffName = NO_TARIFF_NAME; connected = 0; -tariff = tariffs->GetNoTariff(); ips = StrToIPS("*"); deleted = false; lastWriteStat = stgTime + random() % settings->GetStatWritePeriod(); @@ -152,7 +151,7 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s, sysAdmin(a), store(st), tariffs(t), - tariff(tariffs->GetNoTariff()), + tariff(NULL), cash(property.cash), up(property.up), down(property.down), @@ -197,7 +196,6 @@ settings = s; password = "*_EMPTY_PASSWORD_*"; tariffName = NO_TARIFF_NAME; connected = 0; -tariff = tariffs->GetNoTariff(); ips = StrToIPS("*"); deleted = false; lastWriteStat = stgTime + random() % settings->GetStatWritePeriod(); @@ -767,7 +765,7 @@ if (settings->GetFreeMbAllowInet()) return true; } -if (settings->GetShowFeeInCash()) +if (settings->GetShowFeeInCash() || tariff == NULL) { return (cash >= -credit); } @@ -793,7 +791,7 @@ void USER_IMPL::AddTraffStatU(int dir, uint32_t ip, uint32_t len) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -if (!connected) +if (!connected || tariff == NULL) return; double cost = 0; @@ -885,7 +883,7 @@ void USER_IMPL::AddTraffStatD(int dir, uint32_t ip, uint32_t len) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -if (!connected) +if (!connected || tariff == NULL) return; double cost = 0; @@ -1192,7 +1190,7 @@ if (nextTariff.ConstData() != "") else { property.tariffName.Set(nextTariff, sysAdmin, login, store); - tariff = nt; + //tariff = nt; } ResetNextTariff(); WriteConf(); @@ -1203,7 +1201,7 @@ void USER_IMPL::ProcessDayFeeSpread() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -if (passive.ConstData()) +if (passive.ConstData() || tariff == NULL) return; double fee = tariff->GetFee() / DaysInCurrentMonth(); @@ -1233,6 +1231,9 @@ void USER_IMPL::ProcessDayFee() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); +if (tariff == NULL) + return; + double passiveTimePart = 1.0; if (!settings->GetFullFee()) { @@ -1251,7 +1252,10 @@ double fee = tariff->GetFee() * passiveTimePart; ResetPassiveTime(); if (fee == 0.0) + { + SetPrepaidTraff(); return; + } double c = cash; printfd(__FILE__, "login: %8s Fee=%f PassiveTimePart=%f fee=%f\n", @@ -1263,23 +1267,29 @@ switch (settings->GetFeeChargeType()) { case 0: property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + SetPrepaidTraff(); break; case 1: if (c > 0) + { property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + SetPrepaidTraff(); + } break; case 2: if (c > fee) + { property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + SetPrepaidTraff(); + } break; } } //----------------------------------------------------------------------------- void USER_IMPL::SetPrepaidTraff() { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); - -property.freeMb.Set(tariff->GetFree(), sysAdmin, login, store, "Prepaid traffic"); +if (tariff != NULL) + property.freeMb.Set(tariff->GetFree(), sysAdmin, login, store, "Prepaid traffic"); } //----------------------------------------------------------------------------- int USER_IMPL::AddMessage(STG_MSG * msg) @@ -1402,7 +1412,7 @@ while (it != messages.end()) //----------------------------------------------------------------------------- void CHG_PASSIVE_NOTIFIER::Notify(const int & oldPassive, const int & newPassive) { -if (newPassive && !oldPassive) +if (newPassive && !oldPassive && user->tariff != NULL) user->property.cash.Set(user->cash - user->tariff->GetPassiveCost(), user->sysAdmin, user->login, @@ -1412,7 +1422,11 @@ if (newPassive && !oldPassive) //----------------------------------------------------------------------------- void CHG_TARIFF_NOTIFIER::Notify(const string &, const string & newTariff) { +if (user->settings->GetReconnectOnTariffChange() && user->connected) + user->Disconnect(true, "Change tariff"); user->tariff = user->tariffs->FindByName(newTariff); +if (user->settings->GetReconnectOnTariffChange() && user->IsInetable()) + user->Connect(true); } //----------------------------------------------------------------------------- void CHG_CASH_NOTIFIER::Notify(const double & oldCash, const double & newCash)