hlswmaster-ng/gamelist.cpp

46 lines
826 B
C++
Raw Normal View History

2006-02-20 12:31:34 +01:00
#include "logging.h"
2006-02-19 18:45:56 +01:00
#include "gamelist.h"
#define DEFAULT_TIMEOUT 180
2006-03-05 02:28:19 +01:00
/*
** TODO: replace list with sorted list, or even better with a hash
*/
2006-02-19 18:45:56 +01:00
GameList::GameList(Config& conf)
2006-02-20 21:58:59 +01:00
: lastUpdate(0)
2006-02-19 18:45:56 +01:00
{
int interval = conf.getInteger("global", "game_timeout", DEFAULT_TIMEOUT);
2006-02-20 21:58:59 +01:00
TimerService::registerTimer(new Timer(new CleanupEvent(*this), interval));
2006-02-19 18:45:56 +01:00
}
GameList::~GameList()
{
2006-03-05 02:28:19 +01:00
while (!glist.isEmpty())
delete glist.get();
2006-02-19 18:45:56 +01:00
}
void GameList::cleanup()
{
}
2006-02-20 21:58:59 +01:00
long GameList::getLastUpdate()
2006-02-19 18:45:56 +01:00
{
2006-02-20 21:58:59 +01:00
lastUpdate++;
return lastUpdate;
2006-02-19 18:45:56 +01:00
}
Iterator<GameEntry>* GameList::createIterator()
{
2006-02-20 21:58:59 +01:00
return glist.createIterator();
2006-02-19 18:45:56 +01:00
}
2006-02-20 12:31:34 +01:00
2006-03-05 02:28:19 +01:00
void GameList::addGame(int gameid, NetPkt* pkt, int port2)
2006-02-20 12:31:34 +01:00
{
char buf[64];
pkt->show(buf, sizeof(buf));
2006-03-05 02:28:19 +01:00
LogSystem::log(LOG_NOTICE, "Adding Game %d: %s %d", gameid, buf, port2);
2006-02-20 21:58:59 +01:00
glist.add(new GameEntry());
2006-02-20 12:31:34 +01:00
}