]> git.stg.codes - stg.git/blobdiff - projects/stargazer/user_impl.cpp
Implemented IA protocol errors logging.
[stg.git] / projects / stargazer / user_impl.cpp
index ac8399cabe77cf7149267dcdc71562eab1ac7563..37178dd696d0bb3f77ad8776c17f7b490426fddb 100644 (file)
@@ -38,6 +38,8 @@
 #include <cassert>
 #include <cstdlib>
 #include <cmath>
+#include <algorithm>
+#include <functional>
 
 #include "stg/users.h"
 #include "stg/common.h"
@@ -542,7 +544,7 @@ ScanMessage();
 return 0;
 }
 //-----------------------------------------------------------------------------
-void USER_IMPL::Unauthorize(const AUTH * auth)
+void USER_IMPL::Unauthorize(const AUTH * auth, const std::string & reason)
 {
 STG_LOCKER lock(&mutex, __FILE__, __LINE__);
 /*
@@ -553,6 +555,7 @@ if (!authorizedBy.erase(auth))
 
 if (authorizedBy.empty())
     {
+    lastDisconnectReason = reason;
     lastIPForDisconnect = currIP;
     currIP = 0; // DelUser in traffcounter
     return;
@@ -566,6 +569,13 @@ STG_LOCKER lock(&mutex, __FILE__, __LINE__);
 return authorizedBy.find(auth) != authorizedBy.end();
 }
 //-----------------------------------------------------------------------------
+std::vector<std::string> USER_IMPL::GetAuthorizers() const
+{
+    std::vector<std::string> list;
+    std::transform(authorizedBy.begin(), authorizedBy.end(), std::back_inserter(list), std::mem_fun(&AUTH::GetVersion));
+    return list;
+}
+//-----------------------------------------------------------------------------
 void USER_IMPL::Connect(bool fakeConnect)
 {
 /*
@@ -664,7 +674,12 @@ if (!fakeDisconnect)
     connected = false;
     }
 
-if (store->WriteUserDisconnect(login, up, down, sessionUpload, sessionDownload, cash, freeMb, reason))
+std::string reasonMessage(reason);
+if (!lastDisconnectReason.empty())
+    reasonMessage += ": " + lastDisconnectReason;
+
+if (store->WriteUserDisconnect(login, up, down, sessionUpload, sessionDownload,
+                               cash, freeMb, reasonMessage))
     {
     WriteServLog("Cannot write disconnect for user %s.", login.c_str());
     WriteServLog("%s", store->GetStrError().c_str());