From: Maxim Mamontov Date: Fri, 6 May 2011 14:59:33 +0000 (+0300) Subject: User info holder implemented X-Git-Tag: 2.407-p1~23 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/3271a865ea0cf4a74d41b97148ccc2356be756b7 User info holder implemented --- diff --git a/projects/sgauthstress/user.cpp b/projects/sgauthstress/user.cpp index bea1c6b7..15fb1ece 100644 --- a/projects/sgauthstress/user.cpp +++ b/projects/sgauthstress/user.cpp @@ -1,26 +1,28 @@ +#include + #include "user.h" USER::USER(const std::string & l, - const std::string & pwd) + const std::string & pwd, + uint32_t i) : login(l), + password(pwd), + ip(i), + aliveTimeout(0), + userTimeout(0), phase(1), - rnd(0), - sock(0) + phaseChangeTime(0), + rnd(0) { -char key[IA_PASSWD_LEN]; +unsigned char key[IA_PASSWD_LEN]; memset(key, 0, IA_PASSWD_LEN); -strncpy(key, password.c_str(), IA_PASSWD_LEN); +strncpy((char *)key, password.c_str(), IA_PASSWD_LEN); Blowfish_Init(&ctx, key, IA_PASSWD_LEN); -} - -USER::~USER() -{ -} -void USER::Connect() -{ +sock = socket(AF_INET, SOCK_DGRAM, 0); } -void USER::Disconnect() +USER::~USER() { +close(sock); } diff --git a/projects/sgauthstress/user.h b/projects/sgauthstress/user.h index 1ab31d93..f494e5db 100644 --- a/projects/sgauthstress/user.h +++ b/projects/sgauthstress/user.h @@ -1,6 +1,7 @@ #ifndef __USER_H__ #define __USER_H__ +#include #include #include "stg/os_int.h" @@ -9,15 +10,35 @@ class USER { public: USER(const std::string & login, - const std::string & password); + const std::string & password, + uint32_t ip); ~USER(); - void Connect(); - void Disconnect(); + const std::string & GetLogin() const { return login; } + uint32_t GetIP() const { return ip; } + uint32_t GetAliveTimeout() const { return aliveTimeout; } + uint32_t GetUserTimeout() const { return userTimeout; } + int GetPhase() const { return phase; } + int GetRnd() const { return rnd; } + int GetSocket() const { return sock; } + time_t GetPhaseChangeTime() const { return phaseChangeTime; } + + BLOWFISH_CTX * GetCtx() { return &ctx; } + + void SetPhase(int p) { phase = p; time(&phaseChangeTime); } + void SetRnd(int r) { rnd = r; } + int IncRnd() { return ++rnd; } + void SetAliveTimeout(uint32_t timeout) { aliveTimeout = timeout; } + void SetUserTimeout(uint32_t timeout) { userTimeout = timeout; } private: - const std::string login; + std::string login; + std::string password; + uint32_t ip; + uint32_t aliveTimeout; + uint32_t userTimeout; int phase; + time_t phaseChangeTime; int rnd; int sock; BLOWFISH_CTX ctx;