aboutsummaryrefslogtreecommitdiff
path: root/Core/corerun.cpp
blob: c978026e7189736019cabb47d01eeffa7f6e47ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "core.h"

void Core::run()
{
    // randomize
    qsrand(static_cast<unsigned int>(QDateTime::currentMSecsSinceEpoch()));

    // announce startup
    logPrimitive() << "*** Starting 333networks Master Server v" << BUILD_VERSION << " ***" << endl;

    // can not set file paths
    if (_applicationPath.length() <= 0)
        this->shutdown();

    // debug info (hardcoded disable for releases)
    if ( false )
        logPrimitive() << "Using Qt " << qVersion() << endl;

    // set our own 12-byte identifier
    _coreObject->masterserverIdentity = genChallengeString(12, true);

    // load config settings from file
    _coreObject->Settings = loadSettings(_applicationPath);
    if ( ! _coreObject->Settings.init )
        this->shutdown();

    // initialise database
    if ( ! initDatabase(_applicationPath) )
        this->shutdown();

    // load game info from file and into database
    _coreObject->SupportedGames = loadSupportedGames(_applicationPath);
    if ( _coreObject->SupportedGames.count() <= 0 )
        this->shutdown();

    // logger init
    if ( ! _coreObject->Log.init(_applicationPath, _coreObject->Settings) )
        this->shutdown();

    /*
     * enter runmode
     */

    // udp beacon server
    if ( ! _udpBeaconServer->listen() )
        this->shutdown();

    // tcp listen server
    if ( ! _tcpListenServer->listen() )
        this->shutdown();

    /*
     * advanced functionality
     */

    // maintenance and statistics
    if ( _coreObject->Settings.MaintenanceSettings.doMaintenance )
        _maintenance->scheduleMaintenance();

    // udp uplink broadcast every X minutes
    if ( _coreObject->Settings.BeaconServerSettings.doUplink )
        _udpBeaconServer->uplink();

    // syncing with other masterservers
    if ( _coreObject->Settings.SyncerSettings.doSync )
        _syncUpdater->scheduleUpdater();

    // server checker
    if ( _coreObject->Settings.CheckerSettings.doCheck )
        _statusChecker->startTicker();

    /*
     * all services running
     */
}