From 190be1be3cdc2808f43454e0e907960b85b76f7f Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Mon, 20 Feb 2006 12:31:34 +0100 Subject: [PATCH] daily work --- gameids.h | 63 ------------------------------------------ gamelist.cpp | 13 +++++---- gamelist.h | 3 +- gameparser.cpp | 6 ++-- gamescanner.cpp | 2 +- hlswmaster.conf | 2 +- hlswmaster.cpp | 5 ++-- mod_d3engine.cpp | 17 ++++++++---- mod_q3engine.cpp | 2 +- module.h | 71 +++++++++++++++++++++++++++++++++++++++++++++--- modulelist.cpp | 4 +-- multisock.cpp | 2 +- multisock.h | 2 +- netpkt.cpp | 29 +++++++++++++++++++- netpkt.h | 10 ++++--- recvqueue.cpp | 4 +-- recvqueue.h | 2 +- 17 files changed, 138 insertions(+), 99 deletions(-) delete mode 100644 gameids.h diff --git a/gameids.h b/gameids.h deleted file mode 100644 index 03b67d6..0000000 --- a/gameids.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef _GAMEIDS_H_ -#define _GAMEIDS_H_ - -enum { - ID_UNKNOWN = 0, // "Unknown" - ID_HL, // "Halflife" - ID_Q1, // "Quake 1" - ID_Q2, // "Quake 2" - ID_Q3COMP, // "Q3Comp" - ID_UT = 5, // "Unreal Tournament" - ID_Q3A, // "Quake 3 Arena" - ID_EF, // "Elite Force" - ID_RTCW, // "Return to Castle Wolfenstein" - ID_GS1PROT, // "GSProt" - ID_CCR = 10, // "Command & Conquer Renegade" - ID_MOHAA, // "Medal of Honor: Allied Assault" - ID_JK2, // "Jedi Knight 2" - ID_SOF, // "Soldier of Fortune" - ID_UT2K3, // "Unreal Tournament 2003" - ID_AAO = 15, // "America's Army: Operations" - ID_BF1942, // "Battlefield 1942" - ID_AVP2, // "Alien vs. Predator 2" - ID_RUNE, // "Rune" - ID_IGI2, // "Project IGI2: Covert Strike" - ID_NWN = 20, // "Never Winter Nights" - ID_MOHAA_S, // "Medal of Honor: Allied Assault Spearhead" - ID_OPFP, // "Operation Flashpoint" - ID_OPFPR, // "Operation Flashpoint Resistance" - ID_DEVA, // "Devastation" - ID_ET = 25, // "Wolfenstein - Enemy Territory" - ID_EF2, // "Elite Force 2" - ID_JK3, // "Jedi Knight 3" - ID_MOHAA_B, // "Medal of Honor: Allied Assault Breakthrough" - ID_TRIBES2, // "Tribes 2" - ID_HALO = 30, // "Halo" - ID_COD, // "Call of Duty" - ID_SAVAGE, // "Savage: The Battle for Newerth" - ID_UT2K4, // "Unreal Tournament 2004" - ID_HLSTEAM, // "HLSteam" - ID_BFV = 35, // "Battlefield Vietnam" - ID_GS2PROT, // "GS2Prot" - ID_PK, // "Pain Killer" - ID_D3, // "Doom 3" - ID_OGPPROT, // "OGPProt" - ID_HL2 = 40, // "Halflife 2" - ID_TRIBES_V, // "Tribes Vengeance" - ID_COD_UO, // "Call of Duty: United Offensive" - ID_SW_BF, // "Starwars: Battlefront (?)" - ID_SWAT4, // "SWAT 4" - ID_BF2 = 45, // "Battlefield 2" - ID_xxx, // "???" - ID_Q4, // "Quake 4" - ID_COD2 // "Call of Duty 2" -}; - -struct game_ports { - int portlo; - int porthi; - int id; -}; - -#endif // _GAMEIDS_H_ - diff --git a/gamelist.cpp b/gamelist.cpp index 121fb15..d17211c 100644 --- a/gamelist.cpp +++ b/gamelist.cpp @@ -1,3 +1,4 @@ +#include "logging.h" #include "gamelist.h" #define DEFAULT_TIMEOUT 180 @@ -16,11 +17,6 @@ void GameList::cleanup() { } -void GameList::addGame() -{ -} - - long GameList::getLastMod() { return 0; @@ -30,3 +26,10 @@ Iterator* GameList::createIterator() { return new NullIterator(); } + +void GameList::addGame(int gameid, NetPkt* pkt) +{ + char buf[64]; + pkt->show(buf, sizeof(buf)); + LogSystem::log(LOG_NOTICE, "Adding Game %d: %s", gameid, buf); +} diff --git a/gamelist.h b/gamelist.h index 404c5e5..9594457 100644 --- a/gamelist.h +++ b/gamelist.h @@ -3,6 +3,7 @@ #include "config.h" #include "list.h" +#include "netpkt.h" #include "timerservice.h" class GameEntry { @@ -28,7 +29,7 @@ public: ~GameList(); void cleanup(); - void addGame(); + void addGame(int gameid, NetPkt* pkt); long getLastMod(); Iterator* createIterator(); diff --git a/gameparser.cpp b/gameparser.cpp index bdb5c37..75d6a0c 100644 --- a/gameparser.cpp +++ b/gameparser.cpp @@ -18,15 +18,15 @@ int GameParser::execute(void* arg) int ret = modList.parse(pkt, &gameList); switch (ret) { - case PKT_REJECT: + case PARSE_REJECT: char buf[64]; pkt->show(buf, sizeof(buf)); LogSystem::log(LOG_NOTICE, "unknown Packet: %s", buf); - case PKT_ACCEPT: + case PARSE_ACCEPT: delete pkt; - case PKT_ACCEPT_FREED: + case PARSE_ACCEPT_FREED: break; } } diff --git a/gamescanner.cpp b/gamescanner.cpp index 26e8e95..519e15d 100644 --- a/gamescanner.cpp +++ b/gamescanner.cpp @@ -5,7 +5,7 @@ #define DEFAULT_INTERVAL 30 -GameScanner::GameScanner(Config& conf, ModuleList& modList, RecvQueue& rxqueue) +GameScanner::GameScanner(Config& conf, ModuleList& modList, RecvQueue& rxQueue) : modList(modList), rxQueue(rxQueue) { msock = new MultiSock(conf); diff --git a/hlswmaster.conf b/hlswmaster.conf index 440bd84..39c0f32 100644 --- a/hlswmaster.conf +++ b/hlswmaster.conf @@ -6,7 +6,7 @@ scan_port 7130 scan_interval 10 # use this interface(s) -scan_deny_iface lo sit0 +scan_deny_iface # server timeout after X seconds game_timeout 30 diff --git a/hlswmaster.cpp b/hlswmaster.cpp index 946416a..7c04c4d 100644 --- a/hlswmaster.cpp +++ b/hlswmaster.cpp @@ -6,11 +6,12 @@ #include "logging.h" #include "config.h" #include "recvqueue.h" +#include "modulelist.h" +#include "gamelist.h" #include "gamescanner.h" #include "gameparser.h" #include "hlswserver.h" #include "timerservice.h" -#include "modulelist.h" #include "mod_halflife.h" #include "mod_q3engine.h" @@ -90,7 +91,7 @@ int main(int argc, char *argv[]) HlswServer server(conf); // modList.reg(new ModHalfLife()); -// modList.reg(new ModQ3Engine()); + modList.reg(new ModQ3Engine()); // modList.reg(new ModD3Engine()); // modList.reg(new ModGameSpy1()); // modList.reg(new ModGameSpy2()); diff --git a/mod_d3engine.cpp b/mod_d3engine.cpp index eff240f..398174b 100644 --- a/mod_d3engine.cpp +++ b/mod_d3engine.cpp @@ -1,4 +1,5 @@ #include +#include "netpkt.h" #include "mod_d3engine.h" static struct game_ports port_arr[] = { @@ -15,12 +16,16 @@ void ModD3Engine::scan(MultiSock* msock) msock->send(port_arr, scanmsg, strlen(scanmsg)); } -int ModD3Engine::parse(NetPkt* pkt, GameList* slist) +int ModD3Engine::parse(NetPkt* pkt, GameList* glist) { -// pkt->check_array(arr) -// pkt->check_range(min, max) -// pkt->check_port(port) -// pkt->memcmp(0, buf, len) + int gameid; + + if (!(gameid = pkt->checkPortArray(port_arr))) + return PARSE_REJECT; + + if (pkt->compare(0, replyhead, strlen(replyhead))) + return PARSE_REJECT; - return 0; + glist->addGame(gameid, pkt); + return PARSE_ACCEPT; } diff --git a/mod_q3engine.cpp b/mod_q3engine.cpp index 5131aa3..f936e89 100644 --- a/mod_q3engine.cpp +++ b/mod_q3engine.cpp @@ -19,5 +19,5 @@ void ModQ3Engine::scan(MultiSock* msock) int ModQ3Engine::parse(NetPkt* pkt, GameList* slist) { - return 0; + return PARSE_ACCEPT; } diff --git a/module.h b/module.h index 3fdb467..b3768b3 100644 --- a/module.h +++ b/module.h @@ -2,22 +2,85 @@ #define _MODULE_H_ #include "config.h" -#include "multisock.h" #include "netpkt.h" #include "gamelist.h" +/* avoid cyclic deps, include this later.. */ +//#include "multisock.h" +class MultiSock; + +enum { + ID_UNKNOWN = 0, // "Unknown" + ID_HL, // "Halflife" + ID_Q1, // "Quake 1" + ID_Q2, // "Quake 2" + ID_Q3COMP, // "Q3Comp" + ID_UT = 5, // "Unreal Tournament" + ID_Q3A, // "Quake 3 Arena" + ID_EF, // "Elite Force" + ID_RTCW, // "Return to Castle Wolfenstein" + ID_GS1PROT, // "GSProt" + ID_CCR = 10, // "Command & Conquer Renegade" + ID_MOHAA, // "Medal of Honor: Allied Assault" + ID_JK2, // "Jedi Knight 2" + ID_SOF, // "Soldier of Fortune" + ID_UT2K3, // "Unreal Tournament 2003" + ID_AAO = 15, // "America's Army: Operations" + ID_BF1942, // "Battlefield 1942" + ID_AVP2, // "Alien vs. Predator 2" + ID_RUNE, // "Rune" + ID_IGI2, // "Project IGI2: Covert Strike" + ID_NWN = 20, // "Never Winter Nights" + ID_MOHAA_S, // "Medal of Honor: Allied Assault Spearhead" + ID_OPFP, // "Operation Flashpoint" + ID_OPFPR, // "Operation Flashpoint Resistance" + ID_DEVA, // "Devastation" + ID_ET = 25, // "Wolfenstein - Enemy Territory" + ID_EF2, // "Elite Force 2" + ID_JK3, // "Jedi Knight 3" + ID_MOHAA_B, // "Medal of Honor: Allied Assault Breakthrough" + ID_TRIBES2, // "Tribes 2" + ID_HALO = 30, // "Halo" + ID_COD, // "Call of Duty" + ID_SAVAGE, // "Savage: The Battle for Newerth" + ID_UT2K4, // "Unreal Tournament 2004" + ID_HLSTEAM, // "HLSteam" + ID_BFV = 35, // "Battlefield Vietnam" + ID_GS2PROT, // "GS2Prot" + ID_PK, // "Pain Killer" + ID_D3, // "Doom 3" + ID_OGPPROT, // "OGPProt" + ID_HL2 = 40, // "Halflife 2" + ID_TRIBES_V, // "Tribes Vengeance" + ID_COD_UO, // "Call of Duty: United Offensive" + ID_SW_BF, // "Starwars: Battlefront (?)" + ID_SWAT4, // "SWAT 4" + ID_BF2 = 45, // "Battlefield 2" + ID_xxx, // "???" + ID_Q4, // "Quake 4" + ID_COD2 // "Call of Duty 2" +}; + +struct game_ports { + int portlo; + int porthi; + int gameid; +}; + class Module { public: virtual ~Module() {}; virtual void init(Config* conf) {} virtual void scan(MultiSock* msock) =0; - virtual int parse(NetPkt* pkt, GameList* slist) =0; + virtual int parse(NetPkt* pkt, GameList* glist) =0; virtual const char* getName() =0; protected: Module() {}; - Module(const Module& ml); - Module& operator=(const Module& ml); + Module(const Module& m); + Module& operator=(const Module& m); }; +#include "multisock.h" + #endif // _MODULE_H_ diff --git a/modulelist.cpp b/modulelist.cpp index ec8ecdc..252dd44 100644 --- a/modulelist.cpp +++ b/modulelist.cpp @@ -30,12 +30,12 @@ void ModuleList::scan(MultiSock* msock) int ModuleList::parse(NetPkt* pkt, GameList* slist) { - int retval = PKT_REJECT; + int retval = PARSE_REJECT; Iterator *it = mlist.createIterator(); while (it->hasNext()) { retval = it->next()->parse(pkt, slist); - if (retval != PKT_REJECT) + if (retval != PARSE_REJECT) break; } diff --git a/multisock.cpp b/multisock.cpp index d5c71c7..bae0169 100644 --- a/multisock.cpp +++ b/multisock.cpp @@ -15,7 +15,7 @@ #define DEFAULT_PORT 7130 #define DEVFILE "/proc/net/dev" -#define BUFSIZE 256 +#define BUFSIZE 1024 MultiSock::Socket::Socket() diff --git a/multisock.h b/multisock.h index b4c140b..e674078 100644 --- a/multisock.h +++ b/multisock.h @@ -6,7 +6,7 @@ #include "list.h" #include "config.h" -#include "gameids.h" +#include "module.h" class MultiSock { public: diff --git a/netpkt.cpp b/netpkt.cpp index 4a02130..8c3a833 100644 --- a/netpkt.cpp +++ b/netpkt.cpp @@ -10,6 +10,7 @@ #include #include "logging.h" +#include "module.h" #include "netpkt.h" NetPkt::NetPkt(int size) @@ -39,7 +40,7 @@ int NetPkt::show(char* buf, int size) NetPkt* NetPkt::createFromSocket(int fd) { - int recvsize = 0; + int recvsize; if (ioctl(fd, FIONREAD, &recvsize) == -1) { LogSystem::log(LOG_ERROR, "NetPkt::createFromSocket()"); @@ -51,3 +52,29 @@ NetPkt* NetPkt::createFromSocket(int fd) return retval; } + +int NetPkt::checkPortArray(struct game_ports* portarr) +{ + int myport = ntohs(this->addr.sin_port); + while (portarr && portarr->portlo) { + int port; + for (port = portarr->portlo; port <= portarr->porthi; port++) + if (port == myport) + return portarr->gameid; + + portarr++; + } + return 0; +} + +bool NetPkt::compare(int offset, const char* buf, int len) +{ + if (offset >= this->size) + return false; + + /* nicht ueber das paket hinaus vergleichen */ + if (offset + len >= this->size) + len = this->size - offset; + + return (memcmp(this->data + offset, buf, len) == 0); +} diff --git a/netpkt.h b/netpkt.h index 3adcc94..2dfbce1 100644 --- a/netpkt.h +++ b/netpkt.h @@ -4,18 +4,20 @@ #include #include -#define PKT_ACCEPT 1 -#define PKT_ACCEPT_FREED 2 -#define PKT_REJECT 4 +#define PARSE_ACCEPT 1 +#define PARSE_ACCEPT_FREED 2 +#define PARSE_REJECT 4 class NetPkt { public: ~NetPkt(); static NetPkt* createFromSocket(int fd); - NetPkt* append(NetPkt* pkt); int show(char* buf, int size); + int checkPortArray(struct game_ports* arr); + bool compare(int offset, const char* buf, int len); + protected: NetPkt(const NetPkt& x); NetPkt& operator=(const NetPkt& x); diff --git a/recvqueue.cpp b/recvqueue.cpp index 98671e3..707629b 100644 --- a/recvqueue.cpp +++ b/recvqueue.cpp @@ -14,12 +14,12 @@ void RecvQueue::addPkt(NetPkt* pkt) { if (pkt != NULL) { pktList.addTail(pkt); - pktCount->post(); + pktCount.post(); } } NetPkt* RecvQueue::getPkt() { - pktCount->wait(); + pktCount.wait(); return pktList.get(); } diff --git a/recvqueue.h b/recvqueue.h index 4a742d1..261d58e 100644 --- a/recvqueue.h +++ b/recvqueue.h @@ -18,7 +18,7 @@ protected: RecvQueue& operator=(const RecvQueue& rq); private: - Semaphore* pktCount; + Semaphore pktCount; List pktList; };