2006-04-16 21:37:00 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 04/2006 by Olaf Rempel *
|
|
|
|
* razzor@kopf-tisch.de *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
2006-02-02 16:55:44 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
|
|
|
|
#include "logging.h"
|
|
|
|
#include "config.h"
|
2006-02-20 12:31:34 +01:00
|
|
|
#include "modulelist.h"
|
|
|
|
#include "gamelist.h"
|
2006-02-02 16:55:44 +01:00
|
|
|
#include "gamescanner.h"
|
|
|
|
#include "gameparser.h"
|
|
|
|
#include "hlswserver.h"
|
|
|
|
#include "timerservice.h"
|
|
|
|
|
2006-02-05 16:44:38 +01:00
|
|
|
#include "mod_d3engine.h"
|
|
|
|
#include "mod_gamespy1.h"
|
|
|
|
#include "mod_gamespy2.h"
|
2006-03-07 20:30:11 +01:00
|
|
|
#include "mod_halflife.h"
|
|
|
|
#include "mod_q3engine.h"
|
|
|
|
#include "mod_quake2.h"
|
|
|
|
#include "mod_ut.h"
|
2006-02-02 16:55:44 +01:00
|
|
|
|
|
|
|
#define DEFAULT_CONFIG "hlswmaster.conf"
|
|
|
|
#define DEFAULT_LOGFILE "hlswmaster.log"
|
2006-02-05 16:44:38 +01:00
|
|
|
#define DEFAULT_LOGPRIO "WARN"
|
2006-02-02 16:55:44 +01:00
|
|
|
|
|
|
|
static struct option opts[] = {
|
|
|
|
{"config", 1, 0, 'c'},
|
|
|
|
{"debug", 0, 0, 'd'},
|
|
|
|
{"help", 0, 0, 'h'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2006-02-05 12:00:47 +01:00
|
|
|
LogSystem::init(DEFAULT_LOGPRIO, new StdErrLog());
|
2006-02-02 16:55:44 +01:00
|
|
|
|
|
|
|
int arg = 0, code = 0, debug = 0;
|
|
|
|
char *configfile = DEFAULT_CONFIG;
|
|
|
|
while (code != -1) {
|
|
|
|
code = getopt_long(argc, argv, "c:dh", opts, &arg);
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
case 'c': /* config */
|
|
|
|
configfile = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd': /* debug */
|
|
|
|
debug = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h': /* help */
|
|
|
|
printf("Usage: hlsw-master [options]\n"
|
|
|
|
"Options: \n"
|
|
|
|
" --config -c configfile use this configfile\n"
|
|
|
|
" --debug -d do not fork and log to stderr\n"
|
|
|
|
" --help -h this help\n"
|
|
|
|
"\n");
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?': /* error */
|
|
|
|
exit(-1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* unknown / all options parsed */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-03-05 02:28:19 +01:00
|
|
|
|
2006-02-02 16:55:44 +01:00
|
|
|
Config conf;
|
|
|
|
conf.parseFile(configfile);
|
|
|
|
|
2006-02-05 16:44:38 +01:00
|
|
|
const char* logfile = conf.getString("global", "logfile", DEFAULT_LOGFILE);
|
|
|
|
const char* logprio = conf.getString("global", "logprio", DEFAULT_LOGPRIO);
|
|
|
|
if (!debug) {
|
|
|
|
LogSystem::init(logprio, new FileLog(logfile));
|
|
|
|
daemon(0, 0);
|
|
|
|
} else {
|
|
|
|
LogSystem::init(logprio, new StdErrLog());
|
|
|
|
}
|
2006-03-05 02:28:19 +01:00
|
|
|
|
2006-04-15 20:09:55 +02:00
|
|
|
LogSystem::log(LOG_EVERYTIME, "hlswmaster-ng %s startup (pid:%d)", VERSION, getpid());
|
2006-02-05 16:44:38 +01:00
|
|
|
conf.show();
|
2006-02-02 16:55:44 +01:00
|
|
|
|
2006-02-05 16:44:38 +01:00
|
|
|
ModuleList modList(conf);
|
2006-02-19 18:45:56 +01:00
|
|
|
GameList gameList(conf);
|
2006-02-02 16:55:44 +01:00
|
|
|
|
2006-04-16 20:26:01 +02:00
|
|
|
GameScanner scanner(conf, modList);
|
|
|
|
GameParser parser(scanner, modList, gameList);
|
2006-02-20 21:58:59 +01:00
|
|
|
HlswServer server(conf, gameList);
|
2006-02-02 16:55:44 +01:00
|
|
|
|
2006-03-07 20:30:11 +01:00
|
|
|
modList.reg(new ModD3Engine());
|
2006-03-06 20:13:26 +01:00
|
|
|
modList.reg(new ModGameSpy1());
|
2006-03-07 20:30:11 +01:00
|
|
|
modList.reg(new ModGameSpy2());
|
|
|
|
modList.reg(new ModHalfLife());
|
|
|
|
modList.reg(new ModQ3Engine());
|
|
|
|
modList.reg(new ModQuake2());
|
|
|
|
modList.reg(new ModUT());
|
2006-03-05 02:28:19 +01:00
|
|
|
|
2006-02-02 16:55:44 +01:00
|
|
|
server.start();
|
|
|
|
parser.start();
|
|
|
|
scanner.start();
|
|
|
|
|
2006-03-07 20:30:11 +01:00
|
|
|
LogSystem::log(LOG_EVERYTIME, "hlswmaster-ng running...");
|
|
|
|
|
2006-02-02 16:55:44 +01:00
|
|
|
while (1) {
|
|
|
|
TimerService::checkTimers();
|
|
|
|
usleep(500000);
|
|
|
|
|
|
|
|
if (!scanner.isRunning()) {
|
|
|
|
LogSystem::log(LOG_CRIT, "Scanner aborted!");
|
|
|
|
break;
|
|
|
|
}
|
2006-03-05 02:28:19 +01:00
|
|
|
|
2006-02-02 16:55:44 +01:00
|
|
|
if (!parser.isRunning()) {
|
|
|
|
LogSystem::log(LOG_CRIT, "RecvParser aborted!");
|
|
|
|
break;
|
|
|
|
}
|
2006-03-05 02:28:19 +01:00
|
|
|
|
2006-02-02 16:55:44 +01:00
|
|
|
if (!server.isRunning()) {
|
|
|
|
LogSystem::log(LOG_CRIT, "HlswServer aborted!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|