]> git.stg.codes - stg.git/blobdiff - projects/sgauthstress/main.cpp
Fixed stupid bug in case conversion functions.
[stg.git] / projects / sgauthstress / main.cpp
index 7138847723966a02d3d0c79c0f9e8cf9b8de8380..b0819c3c016bad9a2e163c6c96cc70f250fef511 100644 (file)
 
 #include <csignal>
 #include <iostream>
 
 #include <csignal>
 #include <iostream>
+#include <vector>
+#include <list>
 
 
-#include "stg/ia.h"
 #include "stg/common.h"
 #include "stg/store.h"
 #include "stg/common.h"
 #include "stg/store.h"
+#include "stg/user_conf.h"
 
 #include "settings.h"
 #include "store_loader.h"
 
 #include "settings.h"
 #include "store_loader.h"
+#include "proto.h"
+#include "user.h"
 
 time_t stgTime;
 bool running;
 
 time_t stgTime;
 bool running;
@@ -47,22 +51,6 @@ void Usage()
 std::cout << "Usage:\n\nsgauth <path_to_config>" << std::endl;
 }
 //-----------------------------------------------------------------------------
 std::cout << "Usage:\n\nsgauth <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 *)
-{
-}
-//-----------------------------------------------------------------------------
 void CatchTERM(int)
 {
 running = false;
 void CatchTERM(int)
 {
 running = false;
@@ -109,6 +97,11 @@ if (settings.ReadSettings())
 
 SetSignalHandlers();
 
 
 SetSignalHandlers();
 
+PROTO proto(settings.GetServerName(),
+            settings.GetServerPort(),
+            settings.GetLocalPort(),
+            10);
+
 STORE_LOADER storeLoader(settings.GetModulesPath(), settings.GetStoreModuleSettings());
 if (storeLoader.Load())
     {
 STORE_LOADER storeLoader(settings.GetModulesPath(), settings.GetStoreModuleSettings());
 if (storeLoader.Load())
     {
@@ -125,30 +118,49 @@ if (dataStore->GetUsersList(&userList))
     return -1;
     }
 
     return -1;
     }
 
-std::cout << "Successfully loaded " << userList.size() << " users" << std::endl;
-
-IA_CLIENT_PROT proto(settings.GetServerName(), settings.GetServerPort(), settings.GetLocalPort());
-
-proto.SetLogin(settings.GetLogin());
-proto.SetPassword(settings.GetPassword());
+std::list<uint32_t> ips;
+    {
+    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;
+            }
+        proto.AddUser(
+                USER(
+                    *it,
+                    userConf.password,
+                    userConf.ips[0].ip
+                )
+        );
+        ips.push_back(userConf.ips[0].ip);
+        }
+    }
 
 
-proto.SetStatusChangedCb(StatusChanged, NULL);
-proto.SetInfoCb(ShowMessage, NULL);
-proto.SetErrorCb(ShowError, NULL);
-proto.SetStatChangedCb(StatUpdate, NULL);
+if (!proto.Start())
+    {
+    std::cerr << "Failed to start listening thread: '" << proto.GetStrError() << "'" << std::endl;
+    return -1;
+    }
 
 
-proto.Start();
+std::list<uint32_t>::const_iterator it;
+for (it = ips.begin(); it != ips.end(); ++it)
+    {
+    proto.Connect(*it);
+    }
 
 
-proto.Connect();
+std::cout << "Successfully loaded " << proto.UserCount() << " users" << std::endl;
 
 running = true;
 while (running)
     {
 
 running = true;
 while (running)
     {
-    usleep(200000);
+    struct timespec ts = {0, 200000000};
+    nanosleep(&ts, NULL);
     }
 
     }
 
-proto.Disconnect();
-
 proto.Stop();
 
 storeLoader.Unload();
 proto.Stop();
 
 storeLoader.Unload();