gameserver.c 1.3 KB
#include <string.h>     /* for memset and stuff */
#include <syslog.h>     /* for logging */

#include "include/server.h"
#include "include/monitor.h"
#include "include/signalHandling.h"
#include "include/appConfig.h"
#include "include/daemonize.h"

/* some global configurations */
/* TODO: make this whole stuff work without these globals */
unsigned char verbose;
unsigned char doGzip;


int
main(int argc, char *argv[])
{
    tVirtualItemServer server;

    tAppConfig appConfig = {
        0,             // no verbose
        0,             // no daemon
        0,             // no gzip
        MAXPENDING,
        DEFAULTPORT,
        DEFAULTPATH,
        LOGNAMEPATTERN
    };

    memset(&server, 0, sizeof(server));

    handleCmdLine(&appConfig, argc, argv);
    verbose = appConfig.verbose;
    doGzip  = appConfig.doGzip;

    /* decouple procss from controlling shell and make it session leader */
    if (appConfig.doDaemon) {
        daemonize();
    }
    init_signals();
    openlog(argv[0], LOG_PID, LOG_USER);

    syslogMonitor(LOG_INFO, MON_INFO, "startup", "service started");

    serverInit(
            &server,
            appConfig.port,
            appConfig.maxPending,
            appConfig.logPath,
            appConfig.namePat);
    serverRun(&server);
    serverShutdown(&server);

    return 0;
}