37#ifdef FREECIV_MSWINDOWS
67static void Mac_options(
int argc);
71# define USE_INTERRUPT_HANDLERS
74#ifdef USE_INTERRUPT_HANDLERS
75#define save_and_exit(sig) \
76if (S_S_RUNNING == server_state()) { \
77 save_game_auto(#sig, AS_INTERRUPT); \
78 save_system_close(); \
86static void signal_handler(
int sig)
93 save_and_exit(SIGINT);
96 log_normal(
_(
"Setting timeout to 0. Autogame will stop."));
101 "within one second to make it exit."));
110 save_and_exit(SIGHUP);
115 save_and_exit(SIGTERM);
120 if (
signal(SIGPIPE, signal_handler) == SIG_ERR) {
125 fprintf(stderr,
"\nFailed to reset SIGPIPE handler "
126 "while handling SIGPIPE.\n");
140int main(
int argc,
char *argv[])
143 bool showhelp =
FALSE;
144 bool showvers =
FALSE;
148#ifdef FREECIV_MSWINDOWS
149# ifndef FREECIV_NDEBUG
150 if (LoadLibrary(
"exchndl.dll") == NULL) {
152 fprintf(stderr,
"exchndl.dll could not be loaded, no crash debugger\n");
158#ifdef USE_INTERRUPT_HANDLERS
159 if (SIG_ERR ==
signal(SIGINT, signal_handler)) {
160 fc_fprintf(stderr,
_(
"Failed to install SIGINT handler: %s\n"),
166 if (SIG_ERR ==
signal(SIGHUP, signal_handler)) {
167 fc_fprintf(stderr,
_(
"Failed to install SIGHUP handler: %s\n"),
173 if (SIG_ERR ==
signal(SIGTERM, signal_handler)) {
174 fc_fprintf(stderr,
_(
"Failed to install SIGTERM handler: %s\n"),
182 if (SIG_ERR ==
signal(SIGPIPE, signal_handler)) {
183 fc_fprintf(stderr,
_(
"Failed to ignore SIGPIPE: %s\n"),
211 }
else if (
is_option(
"--help", argv[inx])) {
216#ifndef FREECIV_NDEBUG
217 }
else if (
is_option(
"--Fatal", argv[inx])) {
218 if (inx + 1 >= argc ||
'-' == argv[inx + 1][0]) {
223 fc_fprintf(stderr,
_(
"Invalid signal number \"%s\".\n"),
231 }
else if (
is_option(
"--keep", argv[inx])) {
235 }
else if (
is_option(
"--nometa", argv[inx])) {
236 fc_fprintf(stderr,
_(
"Warning: the %s option is obsolete. "
237 "Use -m to enable the metaserver.\n"), argv[inx]);
239 }
else if (
is_option(
"--meta", argv[inx])) {
242 argv, &inx, argc,
FALSE))) {
247 argv, &inx, argc,
FALSE))) {
273 }
else if (
is_option(
"--exit-on-end", argv[inx])) {
286 }
else if (
is_option(
"--auth", argv[inx])) {
288 }
else if (
is_option(
"--Guests", argv[inx])) {
290 }
else if (
is_option(
"--Newusers", argv[inx])) {
302 }
else if (
is_option(
"--version", argv[inx])) {
309#ifdef FREECIV_IPV6_SUPPORT
317 }
else if (
is_option(
"--warnings", argv[inx])) {
328 fc_fprintf(stderr,
_(
"Error: unknown option '%s'\n"), argv[inx]);
335 if (showvers && !showhelp) {
350 _(
"Announce game in LAN using protocol PROTO "
351 "(IPv4/IPv6/none)"));
356 _(
"Enable database connection with configuration from "
359 _(
"Enable server authentication (requires --Database)."));
361 _(
"Allow guests to login if auth is enabled."));
363 _(
"Allow new users to login if auth is enabled."));
368 _(
"Listen for clients on ADDR"));
370 _(
"Connect to metaserver from this address"));
375 _(
"Set debug log level (one of f,e,w,n,v,d, or "
376 "d:file1,min,max:...)"));
381 _(
"Set debug log level (one of f,e,w,n,v)"));
383#ifndef FREECIV_NDEBUG
387 _(
"Raise a signal on failed assertion"));
392 _(
"Load saved game FILE"));
394 _(
"Print a summary of the options"));
398 _(
"Be known as ADDR at metaserver or LAN client"));
402 _(
"Use FILE as logfile"));
404 _(
"Notify metaserver and send server's info"));
407 _(
"Metaserver ADDR"),
408 _(
"Set ADDR as metaserver address"));
413 _(
"Set TYPE as server type in metaserver"));
416 _(
"Keep updating game information on metaserver even after "
421 _(
"Listen for clients on port PORT"));
425 _(
"Quit if no players for TIME seconds"));
427 _(
"When a game ends, exit instead of restarting"));
431 _(
"Save games to directory DIR"));
435 _(
"Save scenarios to directory DIR"));
439 _(
"Sets the server id to ID"));
443 _(
"Read startup script FILE"));
447 _(
"Use FILE as ranking logfile"));
450 _(
"ruleset RULESET"),
451 _(
"Load ruleset RULESET"));
456 _(
"Load ai module MODULE. Can appear multiple times"));
459 _(
"Print the version number"));
461 _(
"Warn about deprecated modpack constructs"));
474 _(
"Requested authentication with --auth, "
475 "but no --Database given\n"));
498static void Mac_options(
int argc)
515 short the_item, old_item=16;
520 storage = NewPtr(
sizeof(DialogRecord));
524 ditl = Get1Resource(
'DITL',200);
525 if ((ditl == 0) || (ResError())) {
528 dlog = Get1Resource(
'DLOG',200);
529 if ((dlog == 0) || (ResError())) {
533 optptr = GetNewDialog(200, storage, (WindowPtr)-1L);
535 err = SetDialogDefaultItem(optptr, 1);
540 err=SetDialogCancelItem(optptr, 2);
544 err=SetDialogTracksCursor(optptr,
true);
548 GetDItem(optptr, 16, &the_type, &the_handle, &the_rect);
549 SetCtlValue((ControlHandle)the_handle,
true);
553 ModalDialog(0L, &the_item);
564 GetDItem(optptr, 13, &the_type, &the_handle, &the_rect);
571 GetDItem(optptr, old_item, &the_type, &the_handle, &the_rect);
572 SetCtlValue((ControlHandle)the_handle,
false);
574 GetDItem(optptr, the_item, &the_type, &the_handle, &the_rect);
575 SetCtlValue((ControlHandle)the_handle,
true);
580 GetDItem( optptr, 4, &the_type, &the_handle, &the_rect);
582 GetDItem( optptr, 8, &the_type, &the_handle, &the_rect);
584 GetDItem( optptr, 12, &the_type, &the_handle, &the_rect);
585 GetIText( the_handle, the_string);
587 GetDItem( optptr, 10, &the_type, &the_handle, &the_rect);
589 GetDItem(optptr, 15, &the_type, &the_handle, &the_rect);
590 if (GetControlValue((ControlHandle)the_handle)) {
593 GetDItem(optptr, 16, &the_type, &the_handle, &the_rect);
594 if (GetControlValue((ControlHandle)the_handle)) {
597 GetDItem(optptr, 17, &the_type, &the_handle, &the_rect);
598 if (GetControlValue((ControlHandle)the_handle)) {
601 DisposeDialog(optptr);
bool load_ai_module(const char *modname)
void init_our_capability(void)
int main(int argc, char *argv[])
void con_write(enum rfc_status rfc_status, const char *message,...)
void deprecation_warnings_enable(void)
void cmdhelp_destroy(struct cmdhelp *pcmdhelp)
void cmdhelp_display(struct cmdhelp *pcmdhelp, bool sort, bool gui_options, bool report_bugs)
struct cmdhelp * cmdhelp_new(const char *cmdname)
void cmdhelp_add(struct cmdhelp *pcmdhelp, const char *shortarg, const char *longarg, const char *helpstr,...)
bool is_option(const char *option_name, char *option)
char * get_option_malloc(const char *option_name, char **argv, int *i, int argc, bool gc)
void fc_fprintf(FILE *stream, const char *format,...) fc__attribute((__format__(__printf__
bool log_parse_level_str(const char *level_str, enum log_level *ret_level)
#define log_normal(message,...)
#define log_error(message,...)
void dont_run_as_root(const char *argv0, const char *fallback)
bool str_to_int(const char *str, int *pint)
struct server_arguments srvarg
struct civ_game::@30::@34 server
struct packet_game_info info
struct civ_game::@30::@34::@37 meta_info
bool metaconnection_persistent
char metaserver_addr[256]
char * scenarios_pathname
enum announce_type announce
int fc_strcasecmp(const char *str0, const char *str1)
const char * fc_strerror(fc_errno err)
fc_errno fc_get_errno(void)
#define sz_strlcpy(dest, src)
void timer_start(struct timer *t)
double timer_read_seconds(struct timer *t)
struct timer * timer_renew(struct timer *t, enum timer_timetype type, enum timer_use use)
const char * freeciv_name_version(void)