mirror of
https://github.com/mangosfour/server.git
synced 2025-12-16 04:37:00 +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/opensslv.h>
|
||||||
#include <openssl/crypto.h>
|
#include <openssl/crypto.h>
|
||||||
#include <ace/Version.h>
|
#include <ace/Version.h>
|
||||||
|
#include <ace/Get_Opt.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include "ServiceWin32.h"
|
#include "ServiceWin32.h"
|
||||||
|
|
@ -56,11 +57,11 @@ uint32 realmID; ///< Id of the realm
|
||||||
void usage(const char *prog)
|
void usage(const char *prog)
|
||||||
{
|
{
|
||||||
sLog.outString("Usage: \n %s [<options>]\n"
|
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"
|
" -c config_file use config_file as configuration file\n\r"
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
" Running as service functions:\n\r"
|
" 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 install install service\n\r"
|
||||||
" -s uninstall uninstall service\n\r"
|
" -s uninstall uninstall service\n\r"
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -75,69 +76,69 @@ extern int main(int argc, char **argv)
|
||||||
|
|
||||||
//char *leak = new char[1000]; // test leak detection
|
//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;
|
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");
|
const char *mode = cmd_opts.opt_arg();
|
||||||
usage(argv[0]);
|
|
||||||
return 1;
|
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
|
#endif
|
||||||
cfg_file = argv[c];
|
case ':':
|
||||||
}
|
sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt());
|
||||||
|
|
||||||
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");
|
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
Log::WaitBeforeContinueIfNeed();
|
Log::WaitBeforeContinueIfNeed();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
default:
|
||||||
else if (strcmp(argv[c],"install") == 0)
|
sLog.outError("Runtime-Error: bad format of commandline arguments");
|
||||||
{
|
|
||||||
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]);
|
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
Log::WaitBeforeContinueIfNeed();
|
Log::WaitBeforeContinueIfNeed();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (strcmp(argv[c],"--service") == 0)
|
|
||||||
{
|
|
||||||
WinServiceRun();
|
|
||||||
}
|
|
||||||
////
|
|
||||||
#endif
|
|
||||||
++c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sConfig.SetSource(cfg_file))
|
if (!sConfig.SetSource(cfg_file))
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
#include <openssl/opensslv.h>
|
#include <openssl/opensslv.h>
|
||||||
#include <openssl/crypto.h>
|
#include <openssl/crypto.h>
|
||||||
|
|
||||||
|
#include <ace/Get_Opt.h>
|
||||||
#include <ace/Dev_Poll_Reactor.h>
|
#include <ace/Dev_Poll_Reactor.h>
|
||||||
#include <ace/TP_Reactor.h>
|
#include <ace/TP_Reactor.h>
|
||||||
#include <ace/ACE.h>
|
#include <ace/ACE.h>
|
||||||
|
|
@ -67,11 +68,11 @@ DatabaseType loginDatabase; ///< Accessor to the
|
||||||
void usage(const char *prog)
|
void usage(const char *prog)
|
||||||
{
|
{
|
||||||
sLog.outString("Usage: \n %s [<options>]\n"
|
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"
|
" -c config_file use config_file as configuration file\n\r"
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
" Running as service functions:\n\r"
|
" 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 install install service\n\r"
|
||||||
" -s uninstall uninstall service\n\r"
|
" -s uninstall uninstall service\n\r"
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -81,70 +82,69 @@ void usage(const char *prog)
|
||||||
/// Launch the realm server
|
/// Launch the realm server
|
||||||
extern int main(int argc, char **argv)
|
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;
|
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");
|
const char *mode = cmd_opts.opt_arg();
|
||||||
usage(argv[0]);
|
|
||||||
Log::WaitBeforeContinueIfNeed();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
cfg_file = argv[c];
|
|
||||||
}
|
|
||||||
|
|
||||||
if( strcmp(argv[c],"--version") == 0)
|
if (!strcmp(mode, "install"))
|
||||||
{
|
{
|
||||||
printf("%s\n", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID));
|
if (WinServiceInstall())
|
||||||
return 0;
|
sLog.outString("Installing service");
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
#ifdef WIN32
|
else if (!strcmp(mode, "uninstall"))
|
||||||
////////////
|
{
|
||||||
//Services//
|
if (WinServiceUninstall())
|
||||||
////////////
|
sLog.outString("Uninstalling service");
|
||||||
if( strcmp(argv[c],"-s") == 0)
|
return 1;
|
||||||
{
|
}
|
||||||
if( ++c >= argc )
|
else if (!strcmp(mode, "run"))
|
||||||
{
|
WinServiceRun();
|
||||||
sLog.outError("Runtime-Error: -s option requires an input argument");
|
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]);
|
usage(argv[0]);
|
||||||
Log::WaitBeforeContinueIfNeed();
|
Log::WaitBeforeContinueIfNeed();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
default:
|
||||||
if( strcmp(argv[c],"install") == 0)
|
sLog.outError("Runtime-Error: bad format of commandline arguments");
|
||||||
{
|
|
||||||
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]);
|
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
Log::WaitBeforeContinueIfNeed();
|
Log::WaitBeforeContinueIfNeed();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if( strcmp(argv[c],"--service") == 0)
|
|
||||||
{
|
|
||||||
WinServiceRun();
|
|
||||||
}
|
|
||||||
////
|
|
||||||
#endif
|
|
||||||
++c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sConfig.SetSource(cfg_file))
|
if (!sConfig.SetSource(cfg_file))
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ bool WinServiceInstall()
|
||||||
if (GetModuleFileName( 0, path, sizeof(path)/sizeof(path[0]) ) > 0)
|
if (GetModuleFileName( 0, path, sizeof(path)/sizeof(path[0]) ) > 0)
|
||||||
{
|
{
|
||||||
SC_HANDLE service;
|
SC_HANDLE service;
|
||||||
std::strcat(path, " --service");
|
std::strcat(path, " -s run");
|
||||||
service = CreateService(serviceControlManager,
|
service = CreateService(serviceControlManager,
|
||||||
serviceName, // name of service
|
serviceName, // name of service
|
||||||
serviceLongName, // service name to display
|
serviceLongName, // service name to display
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "10090"
|
#define REVISION_NR "10091"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue