]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp
Introduced logger for plugins.
[stg.git] / projects / stargazer / plugins / authorization / inetaccess / inetaccess.cpp
index 1eac0ab1f7fc462bfe72556aec021aaecff17593..89ddd09c1553cf9f1afe8d579678e1c1b9c58adc 100644 (file)
@@ -321,9 +321,9 @@ AUTH_IA::AUTH_IA()
       fin6(),
       fin8(),
       packetTypes(),
-      WriteServLog(GetStgLogger()),
       enabledDirs(0xFFffFFff),
-      onDelUserNotifier(*this)
+      onDelUserNotifier(*this),
+      logger(GetPluginLogger(GetStgLogger(), "auth_ia"))
 {
 InitEncrypt(&ctxS, "pr7Hhen");
 
@@ -431,31 +431,6 @@ if (isRunningRun)
         struct timespec ts = {0, 200000000};
         nanosleep(&ts, NULL);
         }
-
-    //after 5 seconds waiting thread still running. now killing it
-    if (isRunningRun)
-        {
-        if (pthread_kill(recvThread, SIGINT))
-            {
-            errorStr = "Cannot kill thread.";
-            printfd(__FILE__, "Cannot kill thread\n");
-            return -1;
-            }
-        for (int i = 0; i < 25 && isRunningRun; ++i)
-            {
-            struct timespec ts = {0, 200000000};
-            nanosleep(&ts, NULL);
-            }
-        if (isRunningRun)
-            {
-            printfd(__FILE__, "Failed to stop recv thread\n");
-            }
-        else
-            {
-            pthread_join(recvThread, NULL);
-            }
-        printfd(__FILE__, "AUTH_IA killed Run\n");
-        }
     }
 
 FinalizeNet();
@@ -468,33 +443,14 @@ if (isRunningRunTimeouter)
         struct timespec ts = {0, 200000000};
         nanosleep(&ts, NULL);
         }
-
-    //after 5 seconds waiting thread still running. now killing it
-    if (isRunningRunTimeouter)
-        {
-        if (pthread_kill(timeouterThread, SIGINT))
-            {
-            errorStr = "Cannot kill thread.";
-            return -1;
-            }
-        for (int i = 0; i < 25 && isRunningRunTimeouter; ++i)
-            {
-            struct timespec ts = {0, 200000000};
-            nanosleep(&ts, NULL);
-            }
-        if (isRunningRunTimeouter)
-            {
-            printfd(__FILE__, "Failed to stop timeouter thread\n");
-            }
-        else
-            {
-            pthread_join(timeouterThread, NULL);
-            }
-        printfd(__FILE__, "AUTH_IA killed Timeouter\n");
-        }
     }
-printfd(__FILE__, "AUTH_IA::Stoped successfully.\n");
+
 users->DelNotifierUserDel(&onDelUserNotifier);
+
+if (isRunningRun || isRunningRunTimeouter)
+    return -1;
+
+printfd(__FILE__, "AUTH_IA::Stoped successfully.\n");
 return 0;
 }
 //-----------------------------------------------------------------------------
@@ -638,9 +594,9 @@ uint16_t sport = htons(outerAddr.sin_port);
 USER_PTR user;
 if (users->FindByName(login, &user))
     {
-    WriteServLog("User's connect failed: user '%s' not found. IP %s",
-                 login,
-                 inet_ntostring(sip).c_str());
+    logger("User's connect failed: user '%s' not found. IP %s",
+           login,
+           inet_ntostring(sip).c_str());
     printfd(__FILE__, "User '%s' NOT found!\n", login);
     SendError(sip, sport, protoVer, "îÅÐÒÁ×ÉÌØÎÙÊ ÌÏÇÉÎ!");
     return -1;
@@ -664,8 +620,8 @@ if (!user->GetProperty().ips.Get().IsIPInIPS(sip))
     {
     printfd(__FILE__, "User %s. IP address is incorrect. IP %s\n",
             user->GetLogin().c_str(), inet_ntostring(sip).c_str());
-    WriteServLog("User %s. IP address is incorrect. IP %s",
-                 user->GetLogin().c_str(), inet_ntostring(sip).c_str());
+    logger("User %s. IP address is incorrect. IP %s",
+           user->GetLogin().c_str(), inet_ntostring(sip).c_str());
     SendError(sip, sport, protoVer, "ðÏÌØÚÏ×ÁÔÅÌØ ÎÅ ÏÐÏÚÎÁÎ! ðÒÏ×ÅÒØÔÅ IP ÁÄÒÅÓ.");
     return 0;
     }
@@ -802,10 +758,10 @@ if (it == ip2user.end())
                     userPtr->GetLogin().c_str(),
                     inet_ntostring(sip).c_str(),
                    login.c_str());
-            WriteServLog("IP address already in use by user '%s'. IP %s, login: '%s'",
-                         userPtr->GetLogin().c_str(),
-                         inet_ntostring(sip).c_str(),
-                         login.c_str());
+            logger("IP address already in use by user '%s'. IP %s, login: '%s'",
+                   userPtr->GetLogin().c_str(),
+                   inet_ntostring(sip).c_str(),
+                   login.c_str());
             SendError(sip, sport, protoVer, "÷ÁÛ IP ÁÄÒÅÓ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!");
             return 0;
             }
@@ -827,10 +783,10 @@ else if (user->GetID() != it->second.user->GetID())
             it->second.user->GetLogin().c_str(),
             inet_ntostring(sip).c_str(),
             user->GetLogin().c_str());
-    WriteServLog("IP address already in use by user '%s'. IP %s, login: '%s'",
-                 it->second.user->GetLogin().c_str(),
-                 inet_ntostring(sip).c_str(),
-                 user->GetLogin().c_str());
+    logger("IP address already in use by user '%s'. IP %s, login: '%s'",
+           it->second.user->GetLogin().c_str(),
+           inet_ntostring(sip).c_str(),
+           user->GetLogin().c_str());
     SendError(sip, sport, protoVer, "÷ÁÛ IP ÁÄÒÅÓ ÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!");
     return 0;
     }
@@ -855,9 +811,9 @@ if (pi == packetTypes.end())
     {
     SendError(sip, sport, protoVer, "îÅÐÒÁ×ÉÌØÎÙÊ ÌÏÇÉΠÉÌÉ ÐÁÒÏÌØ!");
     printfd(__FILE__, "Login or password is wrong!\n");
-    WriteServLog("User's connect failed. User: '%s', ip %s. Wrong login or password",
-                 login.c_str(),
-                 inet_ntostring(sip).c_str());
+    logger("User's connect failed. User: '%s', ip %s. Wrong login or password",
+           login.c_str(),
+           inet_ntostring(sip).c_str());
     ip2user.erase(it);
     return 0;
     }
@@ -867,10 +823,10 @@ if (user->IsAuthorizedBy(this) && user->GetCurrIP() != sip)
     printfd(__FILE__, "Login %s already in use from ip %s. IP %s\n",
             login.c_str(), inet_ntostring(user->GetCurrIP()).c_str(),
             inet_ntostring(sip).c_str());
-    WriteServLog("Login %s already in use from ip %s. IP %s",
-                 login.c_str(),
-                 inet_ntostring(user->GetCurrIP()).c_str(),
-                 inet_ntostring(sip).c_str());
+    logger("Login %s already in use from ip %s. IP %s",
+           login.c_str(),
+           inet_ntostring(user->GetCurrIP()).c_str(),
+           inet_ntostring(sip).c_str());
     SendError(sip, sport, protoVer, "÷ÁÛ ÌÏÇÉΠÕÖÅ ÉÓÐÏÌØÚÕÅÔÓÑ!");
     ip2user.erase(it);
     return 0;