root/trunk/src/trinitycore/Main.cpp @ 102

Revision 102, 5.2 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/// \addtogroup Trinityd Trinity Daemon
22/// @{
23/// \file
24
25#include "Common.h"
26#include "Database/DatabaseEnv.h"
27#include "Config/ConfigEnv.h"
28#include "Log.h"
29#include "Master.h"
30
31#ifndef _TRINITY_CORE_CONFIG
32# define _TRINITY_CORE_CONFIG  "trinitycore.conf"
33#endif //_TRINITY_CORE_CONFIG
34
35// Format is YYYYMMDDRR where RR is the change in the conf file
36// for that day.
37#ifndef _TRINITY_CORE_CONFVER
38# define _TRINITY_CORE_CONFVER 2008022901
39#endif //_TRINITY_CORE_CONFVER
40
41#ifdef WIN32
42#include "ServiceWin32.h"
43char serviceName[] = "Trinityd";
44char serviceLongName[] = "Trinity core service";
45char serviceDescription[] = "Massive Network Game Object Server";
46/*
47 * -1 - not in service mode
48 *  0 - stopped
49 *  1 - running
50 *  2 - paused
51 */
52int m_ServiceStatus = -1;
53#endif
54
55DatabaseType WorldDatabase;                                 ///< Accessor to the world database
56DatabaseType CharacterDatabase;                             ///< Accessor to the character database
57DatabaseType loginDatabase;                                 ///< Accessor to the realm/login database
58
59uint32 realmID;                                             ///< Id of the realm
60
61/// Print out the usage string for this program on the console.
62void usage(const char *prog)
63{
64    sLog.outString("Usage: \n %s [<options>]\n"
65        "    -c config_file           use config_file as configuration file\n\r"
66        #ifdef WIN32
67        "    Running as service functions:\n\r"
68        "    --service                run as service\n\r"
69        "    -s install               install service\n\r"
70        "    -s uninstall             uninstall service\n\r"
71        #endif
72        ,prog);
73}
74
75/// Launch the Trinity server
76extern int main(int argc, char **argv)
77{
78    ///- Command line parsing to get the configuration file name
79    char const* cfg_file = _TRINITY_CORE_CONFIG;
80    int c=1;
81    while( c < argc )
82    {
83        if( strcmp(argv[c],"-c") == 0)
84        {
85            if( ++c >= argc )
86            {
87                sLog.outError("Runtime-Error: -c option requires an input argument");
88                usage(argv[0]);
89                return 1;
90            }
91            else
92                cfg_file = argv[c];
93        }
94
95        #ifdef WIN32
96        ////////////
97        //Services//
98        ////////////
99        if( strcmp(argv[c],"-s") == 0)
100        {
101            if( ++c >= argc )
102            {
103                sLog.outError("Runtime-Error: -s option requires an input argument");
104                usage(argv[0]);
105                return 1;
106            }
107            if( strcmp(argv[c],"install") == 0)
108            {
109                if (WinServiceInstall())
110                    sLog.outString("Installing service");
111                return 1;
112            }
113            else if( strcmp(argv[c],"uninstall") == 0)
114            {
115                if(WinServiceUninstall())
116                    sLog.outString("Uninstalling service");
117                return 1;
118            }
119            else
120            {
121                sLog.outError("Runtime-Error: unsupported option %s",argv[c]);
122                usage(argv[0]);
123                return 1;
124            }
125        }
126        if( strcmp(argv[c],"--service") == 0)
127        {
128            WinServiceRun();
129        }
130        ////
131        #endif
132        ++c;
133    }
134
135    if (!sConfig.SetSource(cfg_file))
136    {
137        sLog.outError("Could not find configuration file %s.", cfg_file);
138        return 1;
139    }
140
141    sLog.outString("Using configuration file %s.", cfg_file);
142   
143    uint32 confVersion = sConfig.GetIntDefault("ConfVersion", 0);
144    if (confVersion < _TRINITY_CORE_CONFVER)
145    {
146        sLog.outError("*****************************************************************************");
147        sLog.outError(" WARNING: Your trinitycore.conf version indicates your conf file is out of date!");
148        sLog.outError("          Please check for updates, as your current default values may cause");
149        sLog.outError("          strange behavior.");
150        sLog.outError("*****************************************************************************");
151        clock_t pause = 3000 + clock();
152
153        while (pause > clock()) {}
154    }
155
156    ///- and run the 'Master'
157    /// \todo Why do we need this 'Master'? Can't all of this be in the Main as for Realmd?
158    return sMaster.Run();
159
160    // at sMaster return function exist with codes
161    // 0 - normal shutdown
162    // 1 - shutdown at error
163    // 2 - restart command used, this code can be used by restarter for restart Trinityd
164}
165
166/// @}
Note: See TracBrowser for help on using the browser.