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

Revision 39, 5.3 kB (checked in by yumileroy, 17 years ago)

[svn] * Various small changes here and there.
* Implementing MangChat? IRC system.
* Added new config option, MAX_WHO, can be used to set the limit of characters being sent in a /who request from client.

Original author: XTZGZoReX
Date: 2008-10-12 14:03:38-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#include "../game/IRCConf.h"
29#include "../game/IRCClient.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[] = "mangosd";
44char serviceLongName[] = "MaNGOS world 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 mangos 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    char const* mc_cfg_file = _TRINITY_CORE_CONFIG;
81    int c=1;
82    while( c < argc )
83    {
84        if( strcmp(argv[c],"-c") == 0)
85        {
86            if( ++c >= argc )
87            {
88                sLog.outError("Runtime-Error: -c option requires an input argument");
89                usage(argv[0]);
90                return 1;
91            }
92            else
93                cfg_file = argv[c];
94        }
95
96        #ifdef WIN32
97        ////////////
98        //Services//
99        ////////////
100        if( strcmp(argv[c],"-s") == 0)
101        {
102            if( ++c >= argc )
103            {
104                sLog.outError("Runtime-Error: -s option requires an input argument");
105                usage(argv[0]);
106                return 1;
107            }
108            if( strcmp(argv[c],"install") == 0)
109            {
110                if (WinServiceInstall())
111                    sLog.outString("Installing service");
112                return 1;
113            }
114            else if( strcmp(argv[c],"uninstall") == 0)
115            {
116                if(WinServiceUninstall())
117                    sLog.outString("Uninstalling service");
118                return 1;
119            }
120            else
121            {
122                sLog.outError("Runtime-Error: unsupported option %s",argv[c]);
123                usage(argv[0]);
124                return 1;
125            }
126        }
127        if( strcmp(argv[c],"--service") == 0)
128        {
129            WinServiceRun();
130        }
131        ////
132        #endif
133        ++c;
134    }
135
136    if (!sConfig.SetSource(cfg_file))
137    {
138        sLog.outError("Could not find configuration file %s.", cfg_file);
139        return 1;
140    }
141
142    sIRC.SetCfg(mc_cfg_file);
143    sLog.outString("Using configuration file %s.", cfg_file);
144   
145    uint32 confVersion = sConfig.GetIntDefault("ConfVersion", 0);
146    if (confVersion < _TRINITY_CORE_CONFVER)
147    {
148        sLog.outError("*****************************************************************************");
149        sLog.outError(" WARNING: Your trinitycore.conf version indicates your conf file is out of date!");
150        sLog.outError("          Please check for updates, as your current default values may cause");
151        sLog.outError("          strange behavior.");
152        sLog.outError("*****************************************************************************");
153        clock_t pause = 3000 + clock();
154
155        while (pause > clock()) {}
156    }
157
158    ///- and run the 'Master'
159    /// \todo Why do we need this 'Master'? Can't all of this be in the Main as for Realmd?
160    return sMaster.Run();
161
162    // at sMaster return function exist with codes
163    // 0 - normal shutdown
164    // 1 - shutdown at error
165    // 2 - restart command used, this code can be used by restarter for restart mangosd
166}
167
168/// @}
Note: See TracBrowser for help on using the browser.