mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 19:37:02 +00:00
[10091] Use ACE for command line options parse.
Note: "--service run" renamed to "-s run" in consistence with other serrvice options. Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
parent
9d8dd578ca
commit
78400f8406
4 changed files with 110 additions and 109 deletions
|
|
@ -31,6 +31,7 @@
|
|||
#include <openssl/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <ace/Version.h>
|
||||
#include <ace/Get_Opt.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include "ServiceWin32.h"
|
||||
|
|
@ -56,11 +57,11 @@ uint32 realmID; ///< Id of the realm
|
|||
void usage(const char *prog)
|
||||
{
|
||||
sLog.outString("Usage: \n %s [<options>]\n"
|
||||
" --version print version and exist\n\r"
|
||||
" -v, --version print version and exist\n\r"
|
||||
" -c config_file use config_file as configuration file\n\r"
|
||||
#ifdef WIN32
|
||||
" Running as service functions:\n\r"
|
||||
" --service run as service\n\r"
|
||||
" -s run run as service\n\r"
|
||||
" -s install install service\n\r"
|
||||
" -s uninstall uninstall service\n\r"
|
||||
#endif
|
||||
|
|
@ -75,69 +76,69 @@ extern int main(int argc, char **argv)
|
|||
|
||||
//char *leak = new char[1000]; // test leak detection
|
||||
|
||||
///- Command line parsing to get the configuration file name
|
||||
///- Command line parsing
|
||||
char const* cfg_file = _MANGOSD_CONFIG;
|
||||
int c=1;
|
||||
while(c < argc)
|
||||
|
||||
#ifdef WIN32
|
||||
char const *options = ":c:s:";
|
||||
#else
|
||||
char const *options = ":c:";
|
||||
#endif
|
||||
|
||||
ACE_Get_Opt cmd_opts(argc, argv, options);
|
||||
cmd_opts.long_option("version", 'v');
|
||||
|
||||
int option;
|
||||
while ((option = cmd_opts()) != EOF)
|
||||
{
|
||||
if (strcmp(argv[c],"-c") == 0)
|
||||
switch (option)
|
||||
{
|
||||
if (++c >= argc)
|
||||
case 'c':
|
||||
cfg_file = cmd_opts.opt_arg();
|
||||
break;
|
||||
case 'v':
|
||||
printf("%s\n", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID));
|
||||
return 0;
|
||||
#ifdef WIN32
|
||||
case 's':
|
||||
{
|
||||
sLog.outError("Runtime-Error: -c option requires an input argument");
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
const char *mode = cmd_opts.opt_arg();
|
||||
|
||||
if (!strcmp(mode, "install"))
|
||||
{
|
||||
if (WinServiceInstall())
|
||||
sLog.outString("Installing service");
|
||||
return 1;
|
||||
}
|
||||
else if (!strcmp(mode, "uninstall"))
|
||||
{
|
||||
if (WinServiceUninstall())
|
||||
sLog.outString("Uninstalling service");
|
||||
return 1;
|
||||
}
|
||||
else if (!strcmp(mode, "run"))
|
||||
WinServiceRun();
|
||||
else
|
||||
{
|
||||
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
|
||||
usage(argv[0]);
|
||||
Log::WaitBeforeContinueIfNeed();
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
cfg_file = argv[c];
|
||||
}
|
||||
|
||||
if (strcmp(argv[c],"--version") == 0)
|
||||
{
|
||||
printf("%s\n", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
////////////
|
||||
//Services//
|
||||
////////////
|
||||
if (strcmp(argv[c],"-s") == 0)
|
||||
{
|
||||
if (++c >= argc)
|
||||
{
|
||||
sLog.outError("Runtime-Error: -s option requires an input argument");
|
||||
#endif
|
||||
case ':':
|
||||
sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt());
|
||||
usage(argv[0]);
|
||||
Log::WaitBeforeContinueIfNeed();
|
||||
return 1;
|
||||
}
|
||||
else if (strcmp(argv[c],"install") == 0)
|
||||
{
|
||||
if (WinServiceInstall())
|
||||
sLog.outString("Installing service");
|
||||
return 1;
|
||||
}
|
||||
else if ( strcmp(argv[c],"uninstall") == 0)
|
||||
{
|
||||
if(WinServiceUninstall())
|
||||
sLog.outString("Uninstalling service");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sLog.outError("Runtime-Error: unsupported option %s",argv[c]);
|
||||
default:
|
||||
sLog.outError("Runtime-Error: bad format of commandline arguments");
|
||||
usage(argv[0]);
|
||||
Log::WaitBeforeContinueIfNeed();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (strcmp(argv[c],"--service") == 0)
|
||||
{
|
||||
WinServiceRun();
|
||||
}
|
||||
////
|
||||
#endif
|
||||
++c;
|
||||
}
|
||||
|
||||
if (!sConfig.SetSource(cfg_file))
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
#include <openssl/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
#include <ace/Get_Opt.h>
|
||||
#include <ace/Dev_Poll_Reactor.h>
|
||||
#include <ace/TP_Reactor.h>
|
||||
#include <ace/ACE.h>
|
||||
|
|
@ -67,11 +68,11 @@ DatabaseType loginDatabase; ///< Accessor to the
|
|||
void usage(const char *prog)
|
||||
{
|
||||
sLog.outString("Usage: \n %s [<options>]\n"
|
||||
" --version print version and exist\n\r"
|
||||
" -v, --version print version and exist\n\r"
|
||||
" -c config_file use config_file as configuration file\n\r"
|
||||
#ifdef WIN32
|
||||
" Running as service functions:\n\r"
|
||||
" --service run as service\n\r"
|
||||
" -s run run as service\n\r"
|
||||
" -s install install service\n\r"
|
||||
" -s uninstall uninstall service\n\r"
|
||||
#endif
|
||||
|
|
@ -81,70 +82,69 @@ void usage(const char *prog)
|
|||
/// Launch the realm server
|
||||
extern int main(int argc, char **argv)
|
||||
{
|
||||
///- Command line parsing to get the configuration file name
|
||||
///- Command line parsing
|
||||
char const* cfg_file = _REALMD_CONFIG;
|
||||
int c=1;
|
||||
while( c < argc )
|
||||
|
||||
#ifdef WIN32
|
||||
char const *options = ":c:s:";
|
||||
#else
|
||||
char const *options = ":c:";
|
||||
#endif
|
||||
|
||||
ACE_Get_Opt cmd_opts(argc, argv, options);
|
||||
cmd_opts.long_option("version", 'v');
|
||||
|
||||
int option;
|
||||
while ((option = cmd_opts()) != EOF)
|
||||
{
|
||||
if( strcmp(argv[c],"-c") == 0)
|
||||
switch (option)
|
||||
{
|
||||
if( ++c >= argc )
|
||||
case 'c':
|
||||
cfg_file = cmd_opts.opt_arg();
|
||||
break;
|
||||
case 'v':
|
||||
printf("%s\n", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID));
|
||||
return 0;
|
||||
#ifdef WIN32
|
||||
case 's':
|
||||
{
|
||||
sLog.outError("Runtime-Error: -c option requires an input argument");
|
||||
usage(argv[0]);
|
||||
Log::WaitBeforeContinueIfNeed();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
cfg_file = argv[c];
|
||||
}
|
||||
const char *mode = cmd_opts.opt_arg();
|
||||
|
||||
if( strcmp(argv[c],"--version") == 0)
|
||||
{
|
||||
printf("%s\n", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
////////////
|
||||
//Services//
|
||||
////////////
|
||||
if( strcmp(argv[c],"-s") == 0)
|
||||
{
|
||||
if( ++c >= argc )
|
||||
{
|
||||
sLog.outError("Runtime-Error: -s option requires an input argument");
|
||||
if (!strcmp(mode, "install"))
|
||||
{
|
||||
if (WinServiceInstall())
|
||||
sLog.outString("Installing service");
|
||||
return 1;
|
||||
}
|
||||
else if (!strcmp(mode, "uninstall"))
|
||||
{
|
||||
if (WinServiceUninstall())
|
||||
sLog.outString("Uninstalling service");
|
||||
return 1;
|
||||
}
|
||||
else if (!strcmp(mode, "run"))
|
||||
WinServiceRun();
|
||||
else
|
||||
{
|
||||
sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode);
|
||||
usage(argv[0]);
|
||||
Log::WaitBeforeContinueIfNeed();
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case ':':
|
||||
sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt());
|
||||
usage(argv[0]);
|
||||
Log::WaitBeforeContinueIfNeed();
|
||||
return 1;
|
||||
}
|
||||
if( strcmp(argv[c],"install") == 0)
|
||||
{
|
||||
if (WinServiceInstall())
|
||||
sLog.outString("Installing service");
|
||||
return 1;
|
||||
}
|
||||
else if( strcmp(argv[c],"uninstall") == 0)
|
||||
{
|
||||
if(WinServiceUninstall())
|
||||
sLog.outString("Uninstalling service");
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sLog.outError("Runtime-Error: unsupported option %s",argv[c]);
|
||||
default:
|
||||
sLog.outError("Runtime-Error: bad format of commandline arguments");
|
||||
usage(argv[0]);
|
||||
Log::WaitBeforeContinueIfNeed();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if( strcmp(argv[c],"--service") == 0)
|
||||
{
|
||||
WinServiceRun();
|
||||
}
|
||||
////
|
||||
#endif
|
||||
++c;
|
||||
}
|
||||
|
||||
if (!sConfig.SetSource(cfg_file))
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ bool WinServiceInstall()
|
|||
if (GetModuleFileName( 0, path, sizeof(path)/sizeof(path[0]) ) > 0)
|
||||
{
|
||||
SC_HANDLE service;
|
||||
std::strcat(path, " --service");
|
||||
std::strcat(path, " -s run");
|
||||
service = CreateService(serviceControlManager,
|
||||
serviceName, // name of service
|
||||
serviceLongName, // service name to display
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "10090"
|
||||
#define REVISION_NR "10091"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue