14 #include <fc_config.h>
21 #ifdef FREECIV_MSWINDOWS
28 #include <QCommandLineParser>
29 #include <QCoreApplication>
51 #define save_and_exit(sig) \
52 if (S_S_RUNNING == server_state()) { \
53 save_game_auto(#sig, AS_INTERRUPT); \
55 QCoreApplication::exit(EXIT_SUCCESS);
71 qInfo(
_(
"Setting timeout to 0. Autogame will stop."));
75 qInfo(
_(
"You must interrupt Freeciv21 twice "
76 "within one second to make it exit."));
100 fprintf(stderr,
"\nFailed to reset SIGPIPE handler "
101 "while handling SIGPIPE.\n");
114 int main(
int argc,
char *argv[])
117 fc_fprintf(stderr,
_(
"Failed to install SIGINT handler: %s\n"),
124 fc_fprintf(stderr,
_(
"Failed to install SIGHUP handler: %s\n"),
131 fc_fprintf(stderr,
_(
"Failed to install SIGTERM handler: %s\n"),
140 fc_fprintf(stderr,
_(
"Failed to ignore SIGPIPE: %s\n"),
146 QCoreApplication app(argc, argv);
157 QCommandLineParser parser;
158 parser.addHelpOption();
159 parser.addVersionOption();
162 bool ok = parser.addOptions({
165 _(
"Announce game in LAN using protocol PROTO (IPv4/IPv6/none)."),
170 _(
"Connect to metaserver from this address."),
174 _(
"Listen for clients on ADDR."),
177 {QStringLiteral(
"local"),
_(
"Listens to the local socket NAME"),
183 _(
"Set debug log level (fatal/critical/warning/info/debug)."),
185 QStringLiteral(
"info")},
186 {{
"e",
"exit-on-end"},
187 _(
"When a game ends, exit instead of restarting.")},
188 {{
"F",
"Fatal"},
_(
"Raise a signal on failed assertion.")},
190 _(
"Load saved game."),
194 _(
"Be known as ADDR at metaserver or LAN client."),
198 _(
"Keep updating game information on metaserver even after "
201 _(
"Use FILE as logfile."),
204 {{
"M",
"Metaserver"},
205 _(
"Set ADDR as metaserver address."),
208 {{
"m",
"meta"},
_(
"Notify metaserver and send server's info.")},
210 _(
"Listen for clients on port PORT."),
214 _(
"Quit if no players for TIME seconds."),
218 _(
"Use FILE as ranking logfile."),
222 _(
"Read startup file FILE."),
226 _(
"Sets the server id to ID."),
230 _(
"Save games to directory DIR."),
234 _(
"Prints stats about elapsed time on misc tasks.")},
235 {{
"w",
"warnings"},
_(
"Warn about deprecated modpack constructs.")},
236 {
"ruleset",
_(
"Load ruleset RULESET."),
239 {
"scenarios",
_(
"Save scenarios to directory DIR."),
243 _(
"Enable database authentication (requires --Database).")},
245 _(
"Enable database connection with configuration from FILE."),
248 {{
"G",
"Guests"},
_(
"Allow guests to login if auth is enabled.")},
249 {{
"N",
"Newusers"},
_(
"Allow new users to login if auth is enabled.")},
251 {
"LoadAI",
_(
"Load ai module MODULE. Can appear multiple times."),
257 qCritical(
"Adding command line arguments failed.");
265 if (!
log_init(parser.value(QStringLiteral(
"debug")))) {
268 if (parser.isSet(QStringLiteral(
"file"))) {
271 if (parser.isSet(QStringLiteral(
"log"))) {
275 if (parser.isSet(QStringLiteral(
"Ranklog"))) {
278 if (parser.isSet(QStringLiteral(
"keep"))) {
283 if (parser.isSet(QStringLiteral(
"meta"))) {
286 if (parser.isSet(QStringLiteral(
"Metaserver"))) {
291 if (parser.isSet(QStringLiteral(
"identity"))) {
294 if (parser.isSet(QStringLiteral(
"local"))) {
297 if (parser.isSet(QStringLiteral(
"port"))) {
299 qCritical(
_(
"Cannot use --port with --local"));
304 parser.value(QStringLiteral(
"port")).toUInt(&conversion_ok);
306 if (!conversion_ok) {
307 qCritical(
_(
"Invalid port number %s"),
308 qUtf8Printable(parser.value(
"port")));
312 if (parser.isSet(QStringLiteral(
"bind"))) {
313 auto addr = parser.value(QStringLiteral(
"bind"));
316 qCritical(
_(
"Not a valid IP address: %s"), qUtf8Printable(addr));
320 qCritical(
_(
"Cannot use --bind with --local"));
324 if (parser.isSet(QStringLiteral(
"Bind-meta"))) {
327 if (parser.isSet(QStringLiteral(
"read"))) {
330 if (parser.isSet(QStringLiteral(
"quitidle"))) {
333 parser.value(QStringLiteral(
"quitidle")).toUInt(&conversion_ok);
334 if (!conversion_ok) {
335 qCritical(
_(
"Invalid number %s"),
336 qUtf8Printable(parser.value(
"quitidle")));
340 if (parser.isSet(QStringLiteral(
"exit-on-end"))) {
343 if (parser.isSet(QStringLiteral(
"timetrack"))) {
345 log_time(QStringLiteral(
"Time tracking enabled"),
true);
347 if (parser.isSet(
"Database")) {
351 if (parser.isSet(
"auth")) {
354 if (parser.isSet(
"Guests")) {
357 if (parser.isSet(
"Newusers")) {
360 if (parser.isSet(QStringLiteral(
"Serverid"))) {
363 if (parser.isSet(QStringLiteral(
"saves"))) {
366 if (parser.isSet(QStringLiteral(
"scenarios"))) {
369 if (parser.isSet(QStringLiteral(
"ruleset"))) {
372 if (parser.isSet(QStringLiteral(
"Announce"))) {
373 auto value = parser.value(QStringLiteral(
"Announce")).toLower();
374 if (value == QLatin1String(
"ipv4")) {
376 }
else if (value == QLatin1String(
"ipv6")) {
378 }
else if (value == QLatin1String(
"none")) {
381 qCritical(
_(
"Illegal value \"%s\" for --Announce"),
382 qUtf8Printable(parser.value(
"Announce")));
385 if (parser.isSet(QStringLiteral(
"warnings"))) {
386 qCWarning(deprecations_category,
388 _(
"The --warnings option is deprecated."));
391 if (parser.isSet(
"LoadAI")) {
392 for (
const auto &mod : parser.values(
"LoadAI")) {
407 fc_fprintf(stderr,
_(
"Requested authentication with --auth, "
408 "but no --Database given\n"));
419 if (!
server->is_ready()) {
423 QObject::connect(&app, &QCoreApplication::aboutToQuit,
server,
424 &QObject::deleteLater);
bool load_ai_module(const char *modname)
void init_our_capability()
Setup our internal network capability string.
int main(int argc, char *argv[])
Entry point for Freeciv21 server.
#define save_and_exit(sig)
static void signal_handler(int sig)
This function is called when a SIGINT (ctrl-c) is received.
void con_write(enum rfc_status rfc_status, const char *message,...)
Write to console and add line-break, and show prompt if required.
void fc_fprintf(FILE *stream, const char *format,...)
Do a fprintf from the internal charset into the local charset.
void log_time(const QString &msg, bool log)
bool log_init(const QString &level_str, const QStringList &extra_rules)
Parses a log level string as provided by the user on the command line, and installs the corresponding...
void fc_assert_set_fatal(bool fatal)
Set what signal the assert* macros should raise on failed assertion (-1 to disable).
void dont_run_as_root(const char *argv0, const char *fallback)
If we have root privileges, die with an error.
struct server_arguments srvarg
void srv_init()
Initialize freeciv server.
struct civ_game::@28::@32 server
struct packet_game_info info
The base class for options.
bool metaconnection_persistent
enum announce_type announce
QString scenarios_pathname
const char * fc_strerror(fc_errno err)
Return a string which describes a given error (errno-style.) The string is converted as necessary fro...
fc_errno fc_get_errno()
Returns last error code.
double timer_read_seconds(civtimer *t)
Read value from timer.
void timer_start(civtimer *t)
Start timing, adding to previous accumulated time if timer has not been cleared.
civtimer * timer_renew(civtimer *t, enum timer_timetype type, enum timer_use use)
Allocate a new timer, or reuse t, with specified "type" and "use".
const char * freeciv21_version()
Returns the raw version string.
const char * freeciv_name_version()
Return string containing both name of Freeciv21 and version.