diff --git a/src/mangosd/Main.cpp b/src/mangosd/Main.cpp index 049d2b6f1..abd5daebd 100644 --- a/src/mangosd/Main.cpp +++ b/src/mangosd/Main.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #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 []\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)) diff --git a/src/realmd/Main.cpp b/src/realmd/Main.cpp index 3243b7fc2..e83fe15e6 100644 --- a/src/realmd/Main.cpp +++ b/src/realmd/Main.cpp @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -67,11 +68,11 @@ DatabaseType loginDatabase; ///< Accessor to the void usage(const char *prog) { sLog.outString("Usage: \n %s []\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)) diff --git a/src/shared/ServiceWin32.cpp b/src/shared/ServiceWin32.cpp index 843b6b074..36ba014f6 100644 --- a/src/shared/ServiceWin32.cpp +++ b/src/shared/ServiceWin32.cpp @@ -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 diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 3b9ed240d..d1f9f0c75 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "10090" + #define REVISION_NR "10091" #endif // __REVISION_NR_H__