9 #include "tclap/CmdLine.h"
35 TCLAP::CmdLine cmd(
"Cuberite");
36 TCLAP::ValueArg<int> slotsArg (
"s",
"max-players",
"Maximum number of slots for the server to use, overrides setting in setting.ini",
false, -1,
"number", cmd);
37 TCLAP::ValueArg<AString> confArg (
"c",
"config-file",
"Config file to use",
false,
"settings.ini",
"string", cmd);
38 TCLAP::MultiArg<int> portsArg (
"p",
"port",
"The port number the server should listen to",
false,
"port", cmd);
39 TCLAP::SwitchArg commLogArg (
"",
"log-comm",
"Log server client communications to file", cmd);
40 TCLAP::SwitchArg commLogInArg (
"",
"log-comm-in",
"Log inbound server client communications to file", cmd);
41 TCLAP::SwitchArg commLogOutArg (
"",
"log-comm-out",
"Log outbound server client communications to file", cmd);
42 TCLAP::SwitchArg crashDumpFull (
"",
"crash-dump-full",
"Crashdumps created by the server will contain full server memory", cmd);
43 TCLAP::SwitchArg crashDumpGlobals(
"",
"crash-dump-globals",
"Crashdumps created by the server will contain the global variables' values", cmd);
44 TCLAP::SwitchArg noBufArg (
"",
"no-output-buffering",
"Disable output buffering", cmd);
45 TCLAP::SwitchArg noFileLogArg (
"",
"no-log-file",
"Disable logging to file", cmd);
46 TCLAP::SwitchArg runAsServiceArg (
"d",
"service",
"Run as a service on Windows, or daemon on UNIX like systems", cmd);
47 cmd.parse(argc, argv);
52 AString conf_file = confArg.getValue();
53 a_Settings.
AddValue(
"Server",
"ConfigFile", conf_file);
57 int slots = slotsArg.getValue();
58 a_Settings.
AddValue(
"Server",
"MaxPlayers",
static_cast<Int64>(slots));
62 for (
auto port: portsArg.getValue())
64 a_Settings.
AddValue(
"Server",
"Ports", std::to_string(port));
67 if (noFileLogArg.getValue())
69 a_Settings.
AddValue(
"Server",
"DisableLogFile",
true);
71 if (commLogArg.getValue())
81 if (noBufArg.getValue())
83 setvbuf(stdout,
nullptr, _IONBF, 0);
87 if (runAsServiceArg.getValue())
93 if (crashDumpGlobals.getValue())
97 if (crashDumpFull.getValue())
110 static int UniversalMain(
int argc,
char * argv[],
const bool a_RunningAsService)
112 const struct MiniDumpWriterRAII
120 ~MiniDumpWriterRAII()
126 const struct SleepResolutionBoosterRAII
128 SleepResolutionBoosterRAII()
134 ~SleepResolutionBoosterRAII()
155 if (StartAsService::MakeIntoService<&UniversalMain>())
163 const struct NetworkRAII
179 if (!Root.
Run(Settings))
187 catch (
const fmt::format_error & Oops)
189 std::cerr <<
"Formatting exception: " << Oops.what() <<
'\n';
191 catch (
const TCLAP::ArgException & Oops)
193 std::cerr << fmt::sprintf(
"Error reading command line {} for argument {}\n", Oops.error(), Oops.argId());
195 catch (
const std::exception & Oops)
197 std::cerr <<
"Standard exception: " << Oops.what() <<
'\n';
201 std::cerr <<
"Unknown exception!\n";
211 int main(
int argc,
char ** argv)
213 #if !defined(NDEBUG) && defined(_MSC_VER)
214 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
bool g_ShouldLogCommOut
If set to true, the protocols will log each player's outgoing (S->C) communication to a per-connectio...
int main(int argc, char **argv)
static void ParseArguments(int argc, char **argv, cMemorySettingsRepository &a_Settings)
bool g_RunAsService
If set to true, binary will attempt to run as a service.
bool g_ShouldLogCommIn
If set to true, the protocols will log each player's incoming (C->S) communication to a per-connectio...
static int UniversalMain(int argc, char *argv[], const bool a_RunningAsService)
static void AddDumpFlags(const MiniDumpFlags)
static void InitiateMultithreading()
virtual void AddValue(const AString &a_KeyName, const AString &a_ValueName, const AString &a_Value) override
Adds a new value to the specified key.
void Terminate(void)
Terminates all network-related threads.
static cNetworkSingleton & Get(void)
Returns the singleton instance of this class.
void Initialise(void)
Initialises all network-related threads.
The root of the object hierarchy.
bool Run(cSettingsRepositoryInterface &a_OverridesRepo)
Run the server.