]> git.stg.codes - stg.git/blobdiff - projects/sgauthstress/main.cpp
Missing headers added
[stg.git] / projects / sgauthstress / main.cpp
index 3d0adb49b96aac8464786aa4735a53251a73db8c..2388254dab91257ae235d096dff7f2922717f547 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <csignal>
 #include <iostream>
+#include <vector>
+#include <list>
 
 #include "stg/common.h"
 #include "stg/store.h"
@@ -35,6 +37,7 @@
 
 #include "settings.h"
 #include "store_loader.h"
+#include "proto.h"
 #include "user.h"
 
 time_t stgTime;
@@ -94,6 +97,11 @@ if (settings.ReadSettings())
 
 SetSignalHandlers();
 
+PROTO proto(settings.GetServerName(),
+            settings.GetServerPort(),
+            settings.GetLocalPort(),
+            10);
+
 STORE_LOADER storeLoader(settings.GetModulesPath(), settings.GetStoreModuleSettings());
 if (storeLoader.Load())
     {
@@ -110,28 +118,41 @@ if (dataStore->GetUsersList(&userList))
     return -1;
     }
 
-std::vector<USER> users;
-std::vector<std::string>::const_iterator it;
-for (it = userList.begin(); it != userList.end(); ++it)
+std::list<uint32_t> ips;
     {
-    USER_CONF userConf;
-    if (dataStore->RestoreUserConf(&userConf, *it))
+    std::vector<std::string>::const_iterator it;
+    for (it = userList.begin(); it != userList.end(); ++it)
         {
-        std::cerr << "Failed to read user conf: '" << dataStore->GetStrError() << "'" << std::endl;
-        return -1;
+        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);
         }
-    users.push_back(
-            USER(
-                settings.GetServerName(),
-                settings.GetServerPort(),
-                settings.GetLocalPort(),
-                *it,
-                userConf.password
-            )
-    );
     }
 
-std::cout << "Successfully loaded " << users.size() << " users" << std::endl;
+if (!proto.Start())
+    {
+    std::cerr << "Failed to start listening thread: '" << proto.GetStrError() << "'" << std::endl;
+    return -1;
+    }
+
+std::list<uint32_t>::const_iterator it;
+for (it = ips.begin(); it != ips.end(); ++it)
+    {
+    proto.Connect(*it);
+    }
+
+std::cout << "Successfully loaded " << proto.UserCount() << " users" << std::endl;
 
 running = true;
 while (running)
@@ -139,6 +160,8 @@ while (running)
     usleep(200000);
     }
 
+proto.Stop();
+
 storeLoader.Unload();
 
 return 0;