[6822] Implement --version option for mangosd/realmd for output current binary versio...
[getmangos.git] / src / mangosd / Main.cpp
blobe116e7afa36526410159cbbbdf551251b2d6a641
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
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.
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.
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
19 /// \addtogroup mangosd Mangos Daemon
20 /// @{
21 /// \file
23 #include "Common.h"
24 #include "Database/DatabaseEnv.h"
25 #include "Config/ConfigEnv.h"
26 #include "Log.h"
27 #include "Master.h"
28 #include "SystemConfig.h"
29 #include "revision.h"
30 #include "revision_nr.h"
32 #ifdef WIN32
33 #include "ServiceWin32.h"
34 char serviceName[] = "mangosd";
35 char serviceLongName[] = "MaNGOS world service";
36 char serviceDescription[] = "Massive Network Game Object Server";
38 * -1 - not in service mode
39 * 0 - stopped
40 * 1 - running
41 * 2 - paused
43 int m_ServiceStatus = -1;
44 #endif
46 DatabaseType WorldDatabase; ///< Accessor to the world database
47 DatabaseType CharacterDatabase; ///< Accessor to the character database
48 DatabaseType loginDatabase; ///< Accessor to the realm/login database
50 uint32 realmID; ///< Id of the realm
52 /// Print out the usage string for this program on the console.
53 void usage(const char *prog)
55 sLog.outString("Usage: \n %s [<options>]\n"
56 " --version print version and exist\n\r"
57 " -c config_file use config_file as configuration file\n\r"
58 #ifdef WIN32
59 " Running as service functions:\n\r"
60 " --service run as service\n\r"
61 " -s install install service\n\r"
62 " -s uninstall uninstall service\n\r"
63 #endif
64 ,prog);
67 /// Launch the mangos server
68 extern int main(int argc, char **argv)
70 // - Construct Memory Manager Instance
71 MaNGOS::Singleton<MemoryManager>::Instance();
73 //char *leak = new char[1000]; // test leak detection
75 ///- Command line parsing to get the configuration file name
76 char const* cfg_file = _MANGOSD_CONFIG;
77 int c=1;
78 while( c < argc )
80 if( strcmp(argv[c],"-c") == 0)
82 if( ++c >= argc )
84 sLog.outError("Runtime-Error: -c option requires an input argument");
85 usage(argv[0]);
86 return 1;
88 else
89 cfg_file = argv[c];
92 if( strcmp(argv[c],"--version") == 0)
94 printf("%s\n", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID));
95 return 0;
98 #ifdef WIN32
99 ////////////
100 //Services//
101 ////////////
102 if( strcmp(argv[c],"-s") == 0)
104 if( ++c >= argc )
106 sLog.outError("Runtime-Error: -s option requires an input argument");
107 usage(argv[0]);
108 return 1;
110 if( strcmp(argv[c],"install") == 0)
112 if (WinServiceInstall())
113 sLog.outString("Installing service");
114 return 1;
116 else if( strcmp(argv[c],"uninstall") == 0)
118 if(WinServiceUninstall())
119 sLog.outString("Uninstalling service");
120 return 1;
122 else
124 sLog.outError("Runtime-Error: unsupported option %s",argv[c]);
125 usage(argv[0]);
126 return 1;
129 if( strcmp(argv[c],"--service") == 0)
131 WinServiceRun();
133 ////
134 #endif
135 ++c;
138 sLog.outString( "%s [world-daemon]", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID) );
139 sLog.outString( "<Ctrl-C> to stop.\n\n" );
141 sLog.outTitle( "MM MM MM MM MMMMM MMMM MMMMM");
142 sLog.outTitle( "MM MM MM MM MMM MMM MM MM MMM MMM");
143 sLog.outTitle( "MMM MMM MMM MM MMM MMM MM MM MMM");
144 sLog.outTitle( "MM M MM MMMM MM MMM MM MM MMM");
145 sLog.outTitle( "MM M MM MMMMM MM MMMM MMM MM MM MMM");
146 sLog.outTitle( "MM M MM M MMM MM MMM MMMMMMM MM MM MMM");
147 sLog.outTitle( "MM MM MMM MM MM MM MMM MM MM MMM");
148 sLog.outTitle( "MM MM MMMMMMM MM MM MMM MMM MM MM MMM MMM");
149 sLog.outTitle( "MM MM MM MMM MM MM MMMMMM MMMM MMMMM");
150 sLog.outTitle( " MM MMM http://getmangos.com");
151 sLog.outTitle( " MMMMMM\n\n");
153 if (!sConfig.SetSource(cfg_file))
155 sLog.outError("Could not find configuration file %s.", cfg_file);
156 return 1;
159 sLog.outString("Using configuration file %s.", cfg_file);
161 ///- and run the 'Master'
162 /// \todo Why do we need this 'Master'? Can't all of this be in the Main as for Realmd?
163 return sMaster.Run();
165 // at sMaster return function exist with codes
166 // 0 - normal shutdown
167 // 1 - shutdown at error
168 // 2 - restart command used, this code can be used by restarter for restart mangosd
171 /// @}