]> git.stg.codes - stg.git/blobdiff - projects/rscriptd/listener.cpp
More std::jthread
[stg.git] / projects / rscriptd / listener.cpp
index 2761d7f75a5cbe83ea44fefdb254e5de04203a90..3d8fd48e0c8b5da6f4763870de5069967d2d1c70 100644 (file)
@@ -36,6 +36,7 @@
 #include "stg/scriptexecuter.h"
 #include "stg/locker.h"
 #include "stg/common.h"
 #include "stg/scriptexecuter.h"
 #include "stg/locker.h"
 #include "stg/common.h"
+#include "stg/const.h"
 #include "listener.h"
 
 void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password);
 #include "listener.h"
 
 void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password);
@@ -43,16 +44,15 @@ void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8);
 
 //-----------------------------------------------------------------------------
 LISTENER::LISTENER()
 
 //-----------------------------------------------------------------------------
 LISTENER::LISTENER()
-    : WriteServLog(GetStgLogger()),
+    : WriteServLog(STG::Logger::get()),
       port(0),
       running(false),
       receiverStopped(true),
       processorStopped(true),
       userTimeout(0),
       port(0),
       running(false),
       receiverStopped(true),
       processorStopped(true),
       userTimeout(0),
-      listenSocket(0)
+      listenSocket(0),
+      version("rscriptd listener v.1.2")
 {
 {
-version = "rscriptd listener v.1.2";
-
 pthread_mutex_init(&mutex, NULL);
 }
 //-----------------------------------------------------------------------------
 pthread_mutex_init(&mutex, NULL);
 }
 //-----------------------------------------------------------------------------
@@ -312,7 +312,7 @@ else if (packetHead.packetType == RS_DISCONNECT_PACKET)
         }
     }
 
         }
     }
 
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
 pending.push_back(data);
 
 return false;
 pending.push_back(data);
 
 return false;
@@ -356,40 +356,64 @@ while (it != pending.end() && count < 256)
             );
     if (it->type == PendingData::CONNECT)
         {
             );
     if (it->type == PendingData::CONNECT)
         {
+        printfd(__FILE__, "Connect packet\n");
         if (uit == users.end() || uit->login != it->login)
             {
         if (uit == users.end() || uit->login != it->login)
             {
+            printfd(__FILE__, "Connect new user '%s'\n", it->login.c_str());
             // Add new user
             Connect(*it);
             users.insert(uit, AliveData(static_cast<UserData>(*it)));
             }
         else if (uit->login == it->login)
             {
             // Add new user
             Connect(*it);
             users.insert(uit, AliveData(static_cast<UserData>(*it)));
             }
         else if (uit->login == it->login)
             {
+            printfd(__FILE__, "Update existing user '%s'\n", it->login.c_str());
             // Update already existing user
             time(&uit->lastAlive);
             uit->params = it->params;
             }
             // Update already existing user
             time(&uit->lastAlive);
             uit->params = it->params;
             }
+        else
+            {
+            printfd(__FILE__, "Hmmm... Strange connect for '%s'\n", it->login.c_str());
+            }
         }
     else if (it->type == PendingData::ALIVE)
         {
         }
     else if (it->type == PendingData::ALIVE)
         {
+        printfd(__FILE__, "Alive packet\n");
         if (uit != users.end() && uit->login == it->login)
             {
         if (uit != users.end() && uit->login == it->login)
             {
+            printfd(__FILE__, "Alive user '%s'\n", it->login.c_str());
             // Update existing user
             time(&uit->lastAlive);
             }
             // Update existing user
             time(&uit->lastAlive);
             }
+        else
+            {
+            printfd(__FILE__, "Alive user '%s' is not found\n", it->login.c_str());
+            }
         }
     else if (it->type == PendingData::DISCONNECT)
         {
         }
     else if (it->type == PendingData::DISCONNECT)
         {
+        printfd(__FILE__, "Disconnect packet\n");
         if (uit != users.end() && uit->login == it->login.c_str())
             {
         if (uit != users.end() && uit->login == it->login.c_str())
             {
+            printfd(__FILE__, "Disconnect user '%s'\n", it->login.c_str());
             // Disconnect existing user
             // Disconnect existing user
+            uit->params = it->params;
             Disconnect(*uit);
             users.erase(uit);
             }
             Disconnect(*uit);
             users.erase(uit);
             }
+        else
+            {
+            printfd(__FILE__, "Cannot find user '%s' for disconnect\n", it->login.c_str());
+            }
+        }
+    else
+        {
+        printfd(__FILE__, "Unknown packet type\n");
         }
     ++it;
     ++count;
     }
         }
     ++it;
     ++count;
     }
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
 pending.erase(pending.begin(), it);
 }
 //-----------------------------------------------------------------------------
 pending.erase(pending.begin(), it);
 }
 //-----------------------------------------------------------------------------