From b9efa02c80b54e044326771bbffdddf206daef2e Mon Sep 17 00:00:00 2001 From: tycho Date: Thu, 14 May 2015 15:47:51 +0100 Subject: Initial implementation of IniFile overloading --- src/main.cpp | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 1c34b8f61..d37ff0b32 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Root.h" +#include "tclap/CmdLine.h" #include #include @@ -14,7 +15,7 @@ #include "OSSupport/NetworkSingleton.h" #include "BuildInfo.h" - +#include "MemorySettingsRepository.h" @@ -206,7 +207,7 @@ BOOL CtrlHandler(DWORD fdwCtrlType) //////////////////////////////////////////////////////////////////////////////// // universalMain - Main startup logic for both standard running and as a service -void universalMain() +void universalMain(std::unique_ptr overridesRepo) { #ifdef _WIN32 if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE)) @@ -226,7 +227,7 @@ void universalMain() #endif { cRoot Root; - Root.Start(); + Root.Start(std::move(overridesRepo)); } #if !defined(ANDROID_NDK) catch (std::exception & e) @@ -363,14 +364,39 @@ void WINAPI serviceMain(DWORD argc, TCHAR *argv[]) +std::unique_ptr parseArguments(int argc, char **argv) +{ + try + { + TCLAP::CmdLine cmd("MCServer"); + + TCLAP::ValueArg slotsArg("s", "max-players", "Maximum number of slots for the server to use, overrides setting in setting.ini", false, -1, "number", cmd); + + cmd.parse(argc, argv); + + int slots = slotsArg.getValue(); + + auto repo = make_unique(); + + repo->SetValueI("Server", "MaxPlayers", slots); + + repo->SetReadOnly(); + + return repo; + } + catch (TCLAP::ArgException &e) + { + printf("error reading command line %s for arg %s", e.error().c_str(), e.argId().c_str()); + return nullptr; + } +} + //////////////////////////////////////////////////////////////////////////////// // main: -int main( int argc, char **argv) +int main(int argc, char **argv) { - UNUSED(argc); - UNUSED(argv); #if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER) InitLeakFinder(); @@ -425,6 +451,8 @@ int main( int argc, char **argv) // DEBUG: test the dumpfile creation: // *((int *)0) = 0; + auto argsRepo = parseArguments(argc, argv); + // Check if comm logging is to be enabled: for (int i = 0; i < argc; i++) { @@ -483,7 +511,7 @@ int main( int argc, char **argv) #endif { // Not running as a service, do normal startup - universalMain(); + universalMain(std::move(argsRepo)); } #if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER) -- cgit v1.2.3 From c96849f431bb4152a4258d2480bef8cd272e0c6e Mon Sep 17 00:00:00 2001 From: tycho Date: Fri, 15 May 2015 13:57:27 +0100 Subject: Move make_unique into a namespace to avoid ADL issues this prevents VS finding std::make_unique for constructors that take types from std --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index d37ff0b32..9f57ad6bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -376,7 +376,7 @@ std::unique_ptr parseArguments(int argc, char **argv) int slots = slotsArg.getValue(); - auto repo = make_unique(); + auto repo = cpp14::make_unique(); repo->SetValueI("Server", "MaxPlayers", slots); -- cgit v1.2.3 From 0da8c7392e753b89b20dc0678e78ab3060e535ed Mon Sep 17 00:00:00 2001 From: worktycho Date: Fri, 15 May 2015 14:54:48 +0100 Subject: Fix service Main --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 9f57ad6bd..a0f51105a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -258,7 +258,7 @@ DWORD WINAPI serviceWorkerThread(LPVOID lpParam) UNREFERENCED_PARAMETER(lpParam); // Do the normal startup - universalMain(); + universalMain(cpp14::make_unique()); return ERROR_SUCCESS; } -- cgit v1.2.3 From c2303ac4cf072f8e273ba9ddf72f5ef88c4baf13 Mon Sep 17 00:00:00 2001 From: tycho Date: Mon, 18 May 2015 15:43:26 +0100 Subject: Fix max slots logic to only override if acctually present. --- src/main.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index a0f51105a..2cf4b383e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -373,12 +373,17 @@ std::unique_ptr parseArguments(int argc, char **argv) TCLAP::ValueArg slotsArg("s", "max-players", "Maximum number of slots for the server to use, overrides setting in setting.ini", false, -1, "number", cmd); cmd.parse(argc, argv); - - int slots = slotsArg.getValue(); auto repo = cpp14::make_unique(); - repo->SetValueI("Server", "MaxPlayers", slots); + if (slotsArg.isSet()) + { + + int slots = slotsArg.getValue(); + + repo->SetValueI("Server", "MaxPlayers", slots); + + } repo->SetReadOnly(); @@ -387,7 +392,7 @@ std::unique_ptr parseArguments(int argc, char **argv) catch (TCLAP::ArgException &e) { printf("error reading command line %s for arg %s", e.error().c_str(), e.argId().c_str()); - return nullptr; + return cpp14::make_unique(); } } -- cgit v1.2.3 From 2e98bfc4e98c1cb0730514628d501c2ca0326c4e Mon Sep 17 00:00:00 2001 From: tycho Date: Mon, 18 May 2015 16:04:27 +0100 Subject: Add support for setting ports through command line --- src/main.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 2cf4b383e..8a237b8ee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -372,6 +372,8 @@ std::unique_ptr parseArguments(int argc, char **argv) TCLAP::ValueArg slotsArg("s", "max-players", "Maximum number of slots for the server to use, overrides setting in setting.ini", false, -1, "number", cmd); + TCLAP::MultiArg portsArg("p", "port", "The port number the server should listen to", false, "port", cmd); + cmd.parse(argc, argv); auto repo = cpp14::make_unique(); @@ -381,8 +383,17 @@ std::unique_ptr parseArguments(int argc, char **argv) int slots = slotsArg.getValue(); - repo->SetValueI("Server", "MaxPlayers", slots); + repo->AddValue("Server", "MaxPlayers", static_cast(slots)); + + } + if (portsArg.isSet()) + { + std::vector ports = portsArg.getValue(); + for (auto port : ports) + { + repo->AddValue("Server", "Port", static_cast(port)); + } } repo->SetReadOnly(); -- cgit v1.2.3