#include <stdexcept>
#include "stg/common.h"
+#include "stg/ia_packets.h"
#include "proto.h"
uint16_t port,
uint16_t localPort,
int to)
- : running(false),
- stopped(true),
- timeout(to)
+ : timeout(to),
+ running(false),
+ stopped(true)
{
uint32_t ip = inet_addr(server.c_str());
if (ip == INADDR_NONE)
{
PROTO * protoPtr = static_cast<PROTO *>(data);
protoPtr->Run();
+return NULL;
}
bool PROTO::Start()
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;
bool PROTO::Connect(uint32_t ip)
{
-std::map<uint32_t, USER>::const_iterator it;
+/*std::vector<std::pair<uint32_t, USER> >::const_iterator it;
it = users.find(ip);
if (it == users.end())
- return false;
+ return false;*/
// Do something
bool PROTO::Disconnect(uint32_t ip)
{
-std::map<uint32_t, USER>::const_iterator it;
+/*std::vector<std::pair<uint32_t, USER> >::const_iterator it;
it = users.find(ip);
if (it == users.end())
- return false;
+ return false;*/
// Do something
{
bool result = true;
std::vector<struct pollfd>::iterator it;
-std::map<uint32_t, USER>::iterator userIt(users.begin());
-for (it = pollFds.begin(); it != pollFds.end(); ++it)
+std::vector<std::pair<uint32_t, USER> >::iterator userIt;
+for (it = pollFds.begin(), userIt = users.begin(); it != pollFds.end() && userIt != users.end(); ++it, ++userIt)
{
if (it->revents)
{
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;
if (it != processors.end())
return (this->*it->second)(buffer, user);
+printfd(__FILE__, "PROTO::HandlePacket() - invalid packet signature: '%s'\n", packetName.c_str());
+
return false;
}
bool PROTO::ERR_Proc(const void * buffer, USER * user)
{
const ERR_8 * packet = static_cast<const ERR_8 *>(buffer);
+const char * ptr = static_cast<const char *>(buffer);
-for (int i = 0; i < len/8; i++)
- Blowfish_Decrypt(&ctxPass, (uint32_t*)(buffer + i*8), (uint32_t*)(buffer + i*8 + 4));
+for (size_t i = 0; i < sizeof(ERR_8) / 8; i++)
+ Blowfish_Decrypt(user->GetCtx(), (uint32_t *)(ptr + i * 8), (uint32_t *)(ptr + i * 8 + 4));
//uint32_t len = packet->len;
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));