1
0

Use the new style command line parameters for Windows Service support.

Ignore invalid or malformed command line parameters, prevent unhandled exceptions.
NOTE: Users will need to reinstall the service, now uses "-d" instead of "/service" in the start parameters.
This commit is contained in:
Anthony Birkett 2015-06-01 14:41:06 +01:00
parent a54fa15bc6
commit 65a62601dc
3 changed files with 11 additions and 11 deletions

View File

@ -3,6 +3,7 @@ Many people have contributed to MCServer, and this list attempts to broadcast at
BasedDoge (Donated AlchemistVillage prefabs) BasedDoge (Donated AlchemistVillage prefabs)
bearbin (Alexander Harkness) bearbin (Alexander Harkness)
beeduck beeduck
birkett (Anthony Birkett)
derouinw derouinw
Diusrex Diusrex
Duralex Duralex

View File

@ -3,5 +3,5 @@ rem Alter this if you need to install multiple instances.
set SERVICENAME="MCServer" set SERVICENAME="MCServer"
set CURRENTDIR=%CD% set CURRENTDIR=%CD%
sc create %SERVICENAME% binPath= "%CURRENTDIR%\MCServer.exe /service" start= auto DisplayName= %SERVICENAME% sc create %SERVICENAME% binPath= "%CURRENTDIR%\MCServer.exe -d" start= auto DisplayName= %SERVICENAME%
sc description %SERVICENAME% "Minecraft server instance" sc description %SERVICENAME% "Minecraft server instance"

View File

@ -382,6 +382,10 @@ std::unique_ptr<cMemorySettingsRepository> parseArguments(int argc, char **argv)
TCLAP::SwitchArg noBufArg("", "no-output-buffering", "Disable output buffering", cmd); TCLAP::SwitchArg noBufArg("", "no-output-buffering", "Disable output buffering", cmd);
TCLAP::SwitchArg runAsServiceArg("d", "run-as-service", "Run as a service on Windows", cmd);
cmd.ignoreUnmatched(true);
cmd.parse(argc, argv); cmd.parse(argc, argv);
auto repo = cpp14::make_unique<cMemorySettingsRepository>(); auto repo = cpp14::make_unique<cMemorySettingsRepository>();
@ -420,6 +424,11 @@ std::unique_ptr<cMemorySettingsRepository> parseArguments(int argc, char **argv)
setvbuf(stdout, nullptr, _IONBF, 0); setvbuf(stdout, nullptr, _IONBF, 0);
} }
if (runAsServiceArg.getValue())
{
cRoot::m_RunAsService = true;
}
repo->SetReadOnly(); repo->SetReadOnly();
return repo; return repo;
@ -493,16 +502,6 @@ int main(int argc, char **argv)
auto argsRepo = parseArguments(argc, argv); auto argsRepo = parseArguments(argc, argv);
// Check if comm logging is to be enabled:
for (int i = 0; i < argc; i++)
{
AString Arg(argv[i]);
if (NoCaseCompare(Arg, "/service") == 0)
{
cRoot::m_RunAsService = true;
}
} // for i - argv[]
#if defined(_WIN32) #if defined(_WIN32)
// Attempt to run as a service // Attempt to run as a service
if (cRoot::m_RunAsService) if (cRoot::m_RunAsService)