X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/0d1120fd953249ad6292b8684a2accb8890fb4ef..807369965afc3210e6bb01ff5f325cbfa27d2782:/projects/sgauthstress/main.cpp?ds=sidebyside diff --git a/projects/sgauthstress/main.cpp b/projects/sgauthstress/main.cpp index 3460457a..f4e94b4f 100644 --- a/projects/sgauthstress/main.cpp +++ b/projects/sgauthstress/main.cpp @@ -29,10 +29,14 @@ #include #include -#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 "proto.h" +#include "user.h" time_t stgTime; bool running; @@ -42,23 +46,7 @@ bool running; //----------------------------------------------------------------------------- void Usage() { -std::cout << "sgauth " << 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 " << std::endl; } //----------------------------------------------------------------------------- void CatchTERM(int) @@ -99,27 +87,54 @@ 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()); +PROTO proto(settings.GetServerName(), + settings.GetServerPort(), + settings.GetLocalPort(), + 1); -proto.SetLogin(settings.GetLogin()); -proto.SetPassword(settings.GetPassword()); +STORE_LOADER storeLoader(settings.GetModulesPath(), settings.GetStoreModuleSettings()); +if (storeLoader.Load()) + { + std::cerr << "Failed to load storage plugin: '" << storeLoader.GetStrError() << "'" << std::endl; + return -1; + } -proto.SetStatusChangedCb(StatusChanged, NULL); -proto.SetInfoCb(ShowMessage, NULL); -proto.SetErrorCb(ShowError, NULL); -proto.SetStatChangedCb(StatUpdate, NULL); +STORE * dataStore = storeLoader.GetStore(); -proto.Start(); +std::vector userList; +if (dataStore->GetUsersList(&userList)) + { + std::cerr << "Failed to get user list: '" << dataStore->GetStrError() << "'" << std::endl; + return -1; + } -proto.Connect(); +std::vector::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 + ) + ); + } + +std::cout << "Successfully loaded " << proto.UserCount() << " users" << std::endl; running = true; while (running) @@ -127,9 +142,7 @@ while (running) usleep(200000); } -proto.Disconnect(); - -proto.Stop(); +storeLoader.Unload(); return 0; }