X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/436fa7f75542e619096c6fad7f05029083743102..a0a797f9b859198af09531f6dbeacf6800385392:/projects/stargazer/user_impl.cpp diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index e832c669..afd70b60 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -77,7 +77,8 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, const STORE * st, const TARIFFS * t, const ADMIN * a, - const USERS * u) + const USERS * u, + const SERVICES & svcs) : users(u), property(s->GetScriptsDir()), WriteServLog(GetStgLogger()), @@ -93,6 +94,7 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, store(st), tariffs(t), tariff(NULL), + m_services(svcs), settings(s), authorizedModificationTime(0), deleted(false), @@ -145,7 +147,8 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s, const STORE * st, const TARIFFS * t, const ADMIN * a, - const USERS * u) + const USERS * u, + const SERVICES & svcs) : users(u), property(s->GetScriptsDir()), WriteServLog(GetStgLogger()), @@ -161,6 +164,7 @@ USER_IMPL::USER_IMPL(const SETTINGS_IMPL * s, store(st), tariffs(t), tariff(NULL), + m_services(svcs), settings(s), authorizedModificationTime(0), deleted(false), @@ -249,6 +253,7 @@ USER_IMPL::USER_IMPL(const USER_IMPL & u) store(u.store), tariffs(u.tariffs), tariff(u.tariff), + m_services(u.m_services), traffStat(u.traffStat), traffStatSaved(u.traffStatSaved), settings(u.settings), @@ -552,6 +557,8 @@ if (authorizedBy.empty()) lastDisconnectReason = reason; lastIPForDisconnect = currIP; currIP = 0; // DelUser in traffcounter + if (connected) + Disconnect(false, "not authorized"); return; } } @@ -1174,7 +1181,47 @@ if (nextTariff.ConstData() != "") WriteServLog("Cannot change tariff for user %s. Tariff %s not exist.", login.c_str(), property.tariffName.Get().c_str()); else - property.tariffName.Set(nextTariff, sysAdmin, login, store); + { + switch (tariff->GetChangePolicy()) + { + case TARIFF::ALLOW: + { + property.tariffName.Set(nextTariff, sysAdmin, login, store); + break; + } + case TARIFF::TO_CHEAP: + { + if (nt->GetFee() < tariff->GetFee()) + property.tariffName.Set(nextTariff, sysAdmin, login, store); + else + WriteServLog("Tariff change is prohibited for user %s due to the policy %s. Current tariff %s is more cheap than new tariff %s.", + login.c_str(), + TARIFF::ChangePolicyToString(tariff->GetChangePolicy()).c_str(), + property.tariffName.Get().c_str(), + property.nextTariff.Get().c_str()); + break; + } + case TARIFF::TO_EXPENSIVE: + { + if (nt->GetFee() > tariff->GetFee()) + property.tariffName.Set(nextTariff, sysAdmin, login, store); + else + WriteServLog("Tariff change is prohibited for user %s due to the policy %s. Current tariff %s is more expensive than new tariff %s.", + login.c_str(), + TARIFF::ChangePolicyToString(tariff->GetChangePolicy()).c_str(), + property.tariffName.Get().c_str(), + property.nextTariff.Get().c_str()); + break; + } + case TARIFF::DENY: + { + WriteServLog("Tariff change is prohibited for user %s. Tariff %s.", + login.c_str(), + property.tariffName.Get().c_str()); + break; + } + } + } ResetNextTariff(); WriteConf(); }