daily work
This commit is contained in:
parent
fc57caaa6d
commit
190be1be3c
63
gameids.h
63
gameids.h
|
@ -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_
|
||||
|
13
gamelist.cpp
13
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<GameEntry>* GameList::createIterator()
|
|||
{
|
||||
return new NullIterator<GameEntry>();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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<GameEntry>* createIterator();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <string.h>
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -19,5 +19,5 @@ void ModQ3Engine::scan(MultiSock* msock)
|
|||
|
||||
int ModQ3Engine::parse(NetPkt* pkt, GameList* slist)
|
||||
{
|
||||
return 0;
|
||||
return PARSE_ACCEPT;
|
||||
}
|
||||
|
|
71
module.h
71
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_
|
||||
|
|
|
@ -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<Module> *it = mlist.createIterator();
|
||||
while (it->hasNext()) {
|
||||
retval = it->next()->parse(pkt, slist);
|
||||
if (retval != PKT_REJECT)
|
||||
if (retval != PARSE_REJECT)
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#define DEFAULT_PORT 7130
|
||||
|
||||
#define DEVFILE "/proc/net/dev"
|
||||
#define BUFSIZE 256
|
||||
#define BUFSIZE 1024
|
||||
|
||||
|
||||
MultiSock::Socket::Socket()
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include "list.h"
|
||||
#include "config.h"
|
||||
#include "gameids.h"
|
||||
#include "module.h"
|
||||
|
||||
class MultiSock {
|
||||
public:
|
||||
|
|
29
netpkt.cpp
29
netpkt.cpp
|
@ -10,6 +10,7 @@
|
|||
#include <arpa/inet.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
|
10
netpkt.h
10
netpkt.h
|
@ -4,18 +4,20 @@
|
|||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ protected:
|
|||
RecvQueue& operator=(const RecvQueue& rq);
|
||||
|
||||
private:
|
||||
Semaphore* pktCount;
|
||||
Semaphore pktCount;
|
||||
List<NetPkt> pktList;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue