]> git.stg.codes - stg.git/blobdiff - projects/sgauthstress/main.cpp
A map of ip-to-user replaced with vector of pairs
[stg.git] / projects / sgauthstress / main.cpp
index 3460457a6f1d0e67ee4786173f194b044652f4d4..3d0adb49b96aac8464786aa4735a53251a73db8c 100644 (file)
 #include <csignal>
 #include <iostream>
 
-#include "stg/ia.h"
 #include "stg/common.h"
+#include "stg/store.h"
+#include "stg/user_conf.h"
 
 #include "settings.h"
+#include "store_loader.h"
+#include "user.h"
 
 time_t stgTime;
 bool running;
@@ -42,23 +45,7 @@ bool running;
 //-----------------------------------------------------------------------------
 void Usage()
 {
-std::cout << "sgauth <path_to_config>" << std::endl;
-}
-//-----------------------------------------------------------------------------
-void StatUpdate(const LOADSTAT &, void *)
-{
-}
-//-----------------------------------------------------------------------------
-void StatusChanged(int, void *)
-{
-}
-//-----------------------------------------------------------------------------
-void ShowMessage(const string &, int, int, int, void *)
-{
-}
-//-----------------------------------------------------------------------------
-void ShowError(const string &, int, void *)
-{
+std::cout << "Usage:\n\nsgauth <path_to_config>" << std::endl;
 }
 //-----------------------------------------------------------------------------
 void CatchTERM(int)
@@ -99,27 +86,52 @@ if (argc == 2)
 
 if (settings.ReadSettings())
     {
-    std::cerr << "Failed to read settings\n"
-              << settings.GetStrError() << std::endl;
+    std::cerr << "Failed to read settings: '"
+              << settings.GetStrError() << "'" << std::endl;
     Usage();
     return -1;
     }
 
 SetSignalHandlers();
 
-IA_CLIENT_PROT proto(settings.GetServerName(), settings.GetServerPort(), settings.GetLocalPort());
+STORE_LOADER storeLoader(settings.GetModulesPath(), settings.GetStoreModuleSettings());
+if (storeLoader.Load())
+    {
+    std::cerr << "Failed to load storage plugin: '" << storeLoader.GetStrError() << "'" << std::endl;
+    return -1;
+    }
 
-proto.SetLogin(settings.GetLogin());
-proto.SetPassword(settings.GetPassword());
+STORE * dataStore = storeLoader.GetStore();
 
-proto.SetStatusChangedCb(StatusChanged, NULL);
-proto.SetInfoCb(ShowMessage, NULL);
-proto.SetErrorCb(ShowError, NULL);
-proto.SetStatChangedCb(StatUpdate, NULL);
+std::vector<std::string> userList;
+if (dataStore->GetUsersList(&userList))
+    {
+    std::cerr << "Failed to get user list: '" << dataStore->GetStrError() << "'" << std::endl;
+    return -1;
+    }
 
-proto.Start();
+std::vector<USER> users;
+std::vector<std::string>::const_iterator it;
+for (it = userList.begin(); it != userList.end(); ++it)
+    {
+    USER_CONF userConf;
+    if (dataStore->RestoreUserConf(&userConf, *it))
+        {
+        std::cerr << "Failed to read user conf: '" << dataStore->GetStrError() << "'" << std::endl;
+        return -1;
+        }
+    users.push_back(
+            USER(
+                settings.GetServerName(),
+                settings.GetServerPort(),
+                settings.GetLocalPort(),
+                *it,
+                userConf.password
+            )
+    );
+    }
 
-proto.Connect();
+std::cout << "Successfully loaded " << users.size() << " users" << std::endl;
 
 running = true;
 while (running)
@@ -127,9 +139,7 @@ while (running)
     usleep(200000);
     }
 
-proto.Disconnect();
-
-proto.Stop();
+storeLoader.Unload();
 
 return 0;
 }