From 07bd133ff9a290ff7475c94c1578db3d0d91b853 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Tue, 10 May 2011 18:03:28 +0300 Subject: [PATCH] Copy constructor, assignement operator and network initialization added to USER --- projects/sgauthstress/user.cpp | 55 +++++++++++++++++++++++++++++++++- projects/sgauthstress/user.h | 5 ++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/projects/sgauthstress/user.cpp b/projects/sgauthstress/user.cpp index c2092c26..b36da5e1 100644 --- a/projects/sgauthstress/user.cpp +++ b/projects/sgauthstress/user.cpp @@ -2,9 +2,12 @@ #include #include +#include +#include #include "user.h" #include "stg/ia_packets.h" +#include "stg/common.h" USER::USER(const std::string & l, const std::string & pwd, @@ -22,11 +25,61 @@ unsigned char key[IA_PASSWD_LEN]; memset(key, 0, IA_PASSWD_LEN); strncpy((char *)key, password.c_str(), IA_PASSWD_LEN); Blowfish_Init(&ctx, key, IA_PASSWD_LEN); +} -sock = socket(AF_INET, SOCK_DGRAM, 0); +USER::USER(const USER & rvalue) + : login(rvalue.login), + password(rvalue.password), + ip(rvalue.ip), + aliveTimeout(rvalue.aliveTimeout), + userTimeout(rvalue.userTimeout), + phase(1), + phaseChangeTime(0), + rnd(0) +{ +unsigned char key[IA_PASSWD_LEN]; +memset(key, 0, IA_PASSWD_LEN); +strncpy((char *)key, password.c_str(), IA_PASSWD_LEN); +Blowfish_Init(&ctx, key, IA_PASSWD_LEN); } USER::~USER() { close(sock); } + +const USER & USER::operator=(const USER & rvalue) +{ +login = rvalue.login; +password = rvalue.password; +ip = rvalue.ip; +aliveTimeout = rvalue.aliveTimeout; +userTimeout = rvalue.userTimeout; +phase = 1; +phaseChangeTime = 0; +rnd = 0; + +unsigned char key[IA_PASSWD_LEN]; +memset(key, 0, IA_PASSWD_LEN); +strncpy((char *)key, password.c_str(), IA_PASSWD_LEN); +Blowfish_Init(&ctx, key, IA_PASSWD_LEN); + +return *this; +} + +bool USER::InitNetwork() +{ +sock = socket(AF_INET, SOCK_DGRAM, 0); + +struct sockaddr_in addr; + +addr.sin_family = AF_INET; +addr.sin_addr.s_addr = ip; +addr.sin_port = htons(5554); // :( + +int res = bind(sock, (struct sockaddr *)&addr, sizeof(addr)); +if (res == -1) + { + throw std::runtime_error(std::string("USER::USER() - bind error: '") + strerror(errno) + "', ip: " + inet_ntostring(ip) + ", login: " + login); + } +} diff --git a/projects/sgauthstress/user.h b/projects/sgauthstress/user.h index 0bf53345..1aa6f9e3 100644 --- a/projects/sgauthstress/user.h +++ b/projects/sgauthstress/user.h @@ -12,8 +12,13 @@ class USER { USER(const std::string & login, const std::string & password, uint32_t ip); + USER(const USER & rvalue); ~USER(); + const USER & operator=(const USER & rvalue); + + bool InitNetwork(); + const std::string & GetLogin() const { return login; } uint32_t GetIP() const { return ip; } uint32_t GetAliveTimeout() const { return aliveTimeout; } -- 2.43.2