From 49b9cf71355b6b042233d4367d2847fc0d940c88 Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Mon, 17 Apr 2006 13:59:54 +0200 Subject: [PATCH] mod_halflife: use parsed ip --- gameentry.cpp | 7 +++---- gameentry.h | 4 ++-- gamelist.cpp | 7 ++++++- gamelist.h | 3 +++ mod_halflife.cpp | 4 +--- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/gameentry.cpp b/gameentry.cpp index 6e2e558..865be7c 100644 --- a/gameentry.cpp +++ b/gameentry.cpp @@ -24,11 +24,10 @@ #include "gameentry.h" -GameEntry::GameEntry(int gameid, NetPkt* pkt, int port2) -: port2(port2), gameid(gameid) +GameEntry::GameEntry(int gameid, struct in_addr *addr, int port1, int port2) +: port1(port1), port2(port2), gameid(gameid) { - memcpy(&addr, &pkt->getAddress()->sin_addr, sizeof(addr)); - this->port1 = pkt->getPort(); + memcpy(&this->addr, addr, sizeof(this->addr)); if (port2 != 0) { this->port2 = this->port1; diff --git a/gameentry.h b/gameentry.h index aca553a..3763e97 100644 --- a/gameentry.h +++ b/gameentry.h @@ -3,11 +3,11 @@ #include -#include "netpkt.h" +#include "list.h" class GameEntry : private ListEntry { public: - GameEntry(int gameid, NetPkt* pkt, int port2); + GameEntry(int gameid, struct in_addr *addr, int port1, int port2); ~GameEntry() {} int compare(const GameEntry* ge); diff --git a/gamelist.cpp b/gamelist.cpp index d2748a3..a2e3498 100644 --- a/gamelist.cpp +++ b/gamelist.cpp @@ -59,7 +59,12 @@ void GameList::cleanup() void GameList::addGame(int gameid, NetPkt* pkt, int port2) { - GameEntry* ge = new GameEntry(gameid, pkt, port2); + addGame(gameid, &pkt->getAddress()->sin_addr, pkt->getPort(), port2); +} + +void GameList::addGame(int gameid, struct in_addr *addr, int port1, int port2) +{ + GameEntry* ge = new GameEntry(gameid, addr, port1, port2); int hash = ge->hash(MAX_BUCKETS); bool found = false; diff --git a/gamelist.h b/gamelist.h index 01017f2..b5c2c3f 100644 --- a/gamelist.h +++ b/gamelist.h @@ -1,6 +1,8 @@ #ifndef _GAMELIST_H_ #define _GAMELIST_H_ +#include + #include "config.h" #include "netpkt.h" #include "gameentry.h" @@ -18,6 +20,7 @@ public: void cleanup(); void addGame(int gameid, NetPkt* pkt, int port2 = 0); + void addGame(int gameid, struct in_addr *addr, int port1, int port2 = 0); Iterator* createIterator(); protected: diff --git a/mod_halflife.cpp b/mod_halflife.cpp index 455dd48..082ef59 100644 --- a/mod_halflife.cpp +++ b/mod_halflife.cpp @@ -83,9 +83,7 @@ int ModHalfLife::parse(NetPkt* pkt, GameList* glist) glist->addGame(ID_HL, pkt); } else { - // TODO: implement - glist->addGame(ID_HL, pkt); - //glist->add(ID_HL, &tmp, port, false); + glist->addGame(ID_HL, &tmp, port); } return PARSE_ACCEPT;