]> git.stg.codes - stg.git/blobdiff - projects/stargazer/user_impl.cpp
Add verification exist parametr
[stg.git] / projects / stargazer / user_impl.cpp
index 95989c45361d8dd880dd12856cfffb16eef016fd..51637a1b88775a287bf6412a0f8128388053f6f4 100644 (file)
@@ -588,6 +588,7 @@ if (!fakeConnect)
             }
 
         std::string scriptOnConnectParams;
+
         strprintf(&scriptOnConnectParams,
                 "%s \"%s\" \"%s\" \"%f\" \"%d\" \"%s\"",
                 scriptOnConnect.c_str(),
@@ -597,6 +598,13 @@ if (!fakeConnect)
                 id,
                 dirsStr);
 
+        std::vector<std::string>::const_iterator it(settings->GetScriptParams().begin());
+        while (it != settings->GetScriptParams().end())
+            {
+            scriptOnConnectParams += " \"" + GetParamValue(it->c_str()) + "\"";
+            ++it;
+            }
+
         ScriptExec(scriptOnConnectParams.c_str());
         }
     else
@@ -654,6 +662,13 @@ if (!fakeDisconnect)
                 id,
                 dirsStr);
 
+        std::vector<std::string>::const_iterator it(settings->GetScriptParams().begin());
+        while (it != settings->GetScriptParams().end())
+            {
+            scriptOnDisonnectParams += " \"" + GetParamValue(it->c_str()) + "\"";
+            ++it;
+            }
+
         ScriptExec(scriptOnDisonnectParams.c_str());
         }
     else
@@ -808,7 +823,7 @@ if (settings->GetShowFeeInCash() || tariff == NULL)
 return (cash - tariff->GetFee() >= -credit);
 }
 //-----------------------------------------------------------------------------
-std::string USER_IMPL::GetEnabledDirs()
+std::string USER_IMPL::GetEnabledDirs() const
 {
 //STG_LOCKER lock(&mutex, __FILE__, __LINE__);
 
@@ -1457,120 +1472,27 @@ while (it != messages.end())
     }
 }
 //-----------------------------------------------------------------------------
-const std::string & USER_IMPL::GetParamValue(const std::string & name) const
+std::string USER_IMPL::GetParamValue(const std::string & name) const
+{
+if (property.Exists(name))
     {
-    std::string value;
-
-    if (name=="cash")
-        {
-        value=property.cash;
-        }
-    if (name=="freeMb")
-        {
-        value=property.freeMb;
-        }
-    if (name=="passive")
-        {
-        value=property.passive;
-        }
-    if (name=="disabled")
+    if (name == "id")
         {
-        value=property.disabled;
+        std::ostringstream stream;
+        stream << id;
+        return stream.str();
         }
-    if (name=="alwaysOnline")
-        {
-        value=property.alwaysOnline;
-        }
-    if (name=="tariffName")
-        {
-        value=property.tariffName;
-        }
-    if (name=="nextTariff")
-        {
-        value=property.nextTariff;
-        }
-    if (name=="address")
-        {
-        value=property.address;
-        }
-    if (name=="note")
-        {
-        value=property.note;
-        }
-    if (name=="group")
-        {
-        value=property.group;
-        }
-    if (name=="email")
-        {
-        value=property.email;
-        }
-    if (name=="phone")
-        {
-        value=property.phone;
-        }
-    if (name=="realName")
-        {
-        value=property.realName;
-        }
-    if (name=="credit")
-        {
-        value=property.credit;
-        }
-    if (name=="userdata0")
-        {
-        value=property.userdata0;
-        }
-    if (name=="userdata1")
-        {
-        value=property.userdata1;
-        }
-    if (name=="userdata2")
-        {
-        value=property.userdata2;
-        }
-    if (name=="userdata3")
-        {
-        value=property.userdata3;
-        }
-    if (name=="userdata4")
-        {
-        value=property.userdata4;
-        }
-    if (name=="userdata5")
-        {
-        value=property.userdata5;
-        }
-    if (name=="userdata6")
-        {
-        value=property.userdata6;
-        }
-    if (name=="userdata7")
-        {
-        value=property.userdata7;
-        }
-    if (name=="userdata8")
-        {
-        value=property.userdata8;
-        }
-    if (name=="userdata9")
-        {
-        value=property.userdata9;
-        }
-    if (name=="id")
-        {
-        value=id;
-        }
-    if (name=="login")
-        {
-        value=login;
-        }
-    if (name=="ip")
-        {
-        value=currIP;
-        }
-    return value;
+    if (name == "login")        return login;
+    if (name == "ip")           return currIP.ToString();
+    if (name == "enabledDirs")  return GetEnabledDirs();
+    return property.GetPropertyValue(name);
     }
+else
+    {
+    WriteServLog("Error getting parametr value", name.c_str());
+    return "";
+    }
+}
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------