From: Maxim Mamontov Date: Tue, 10 May 2011 12:26:11 +0000 (+0300) Subject: A map of ip-to-user replaced with vector of pairs X-Git-Tag: 2.407-p1~20 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/808b843774dc48afcd43652cfbf1da7ac4487c21?ds=inline A map of ip-to-user replaced with vector of pairs --- diff --git a/projects/sgauthstress/proto.cpp b/projects/sgauthstress/proto.cpp index 7c547daf..40762b13 100644 --- a/projects/sgauthstress/proto.cpp +++ b/projects/sgauthstress/proto.cpp @@ -7,6 +7,7 @@ #include #include "stg/common.h" +#include "stg/ia_packets.h" #include "proto.h" @@ -111,7 +112,7 @@ return true; void PROTO::AddUser(const USER & user) { - users.insert(std::make_pair(user.GetIP(), user)); + users.push_back(std::make_pair(user.GetIP(), user)); struct pollfd pfd; pfd.fd = user.GetSocket(); pfd.events = POLLIN; @@ -121,10 +122,10 @@ void PROTO::AddUser(const USER & user) bool PROTO::Connect(uint32_t ip) { -std::map::const_iterator it; +/*std::vector >::const_iterator it; it = users.find(ip); if (it == users.end()) - return false; + return false;*/ // Do something @@ -133,10 +134,10 @@ return true; bool PROTO::Disconnect(uint32_t ip) { -std::map::const_iterator it; +/*std::vector >::const_iterator it; it = users.find(ip); if (it == users.end()) - return false; + return false;*/ // Do something @@ -163,8 +164,8 @@ bool PROTO::RecvPacket() { bool result = true; std::vector::iterator it; -std::map::iterator userIt(users.begin()); -for (it = pollFds.begin(); it != pollFds.end(); ++it) +std::vector >::iterator userIt; +for (it = pollFds.begin(), userIt = users.begin(); it != pollFds.end() && userIt != users.end(); ++it, ++userIt) { if (it->revents) { @@ -173,18 +174,16 @@ for (it = pollFds.begin(); it != pollFds.end(); ++it) struct sockaddr_in addr; socklen_t fromLen = sizeof(addr); char buffer[2048]; - int res = recvfrom(userIt->second.GetSocket(), buffer, sizeof(buffer), 0, (struct sockaddr*)&addr, &fromLen); + int res = recvfrom(userIt->second.GetSocket(), buffer, sizeof(buffer), 0, (struct sockaddr *)&addr, &fromLen); if (res == -1) { result = false; - ++userIt; continue; } result = result && HandlePacket(buffer, &(userIt->second)); } - ++userIt; } return result; @@ -319,9 +318,10 @@ return true; bool PROTO::ERR_Proc(const void * buffer, USER * user) { const ERR_8 * packet = static_cast(buffer); +const char * ptr = static_cast(buffer); -for (int i = 0; i < len/8; i++) - Blowfish_Decrypt(&ctxPass, (uint32_t*)(buffer + i*8), (uint32_t*)(buffer + i*8 + 4)); +for (int i = 0; i < sizeof(packet) / 8; i++) + Blowfish_Decrypt(user->GetCtx(), (uint32_t *)(ptr + i * 8), (uint32_t *)(ptr + i * 8 + 4)); //uint32_t len = packet->len; @@ -435,7 +435,7 @@ assert(sizeof(hdr) + length < 2048 && "Packet length must not exceed 2048 bytes" strncpy((char *)hdr.magic, IA_ID, 6); hdr.protoVer[0] = 0; -hdr.protoVer[1] = IA_PROTO_VER; +hdr.protoVer[1] = 8; // IA_PROTO_VER unsigned char buffer[2048]; memcpy(buffer, &hdr, sizeof(hdr)); diff --git a/projects/sgauthstress/proto.h b/projects/sgauthstress/proto.h index 879e7a35..0a2fb2de 100644 --- a/projects/sgauthstress/proto.h +++ b/projects/sgauthstress/proto.h @@ -6,6 +6,7 @@ #include #include +#include #include #include "stg/os_int.h" @@ -40,7 +41,7 @@ class PROTO { struct sockaddr_in serverAddr; int timeout; - std::map users; + std::vector > users; std::vector pollFds; bool running;