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

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

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

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