Exemple #1
0
void servers_setup_init(void)
{
	settings_add_int("server", "server_reconnect_time", 300);
	settings_add_str("server", "hostname", "");
	settings_add_bool("server", "skip_motd", FALSE);

	settings_add_str("server", "default_nick", NULL);
	settings_add_str("server", "alternate_nick", NULL);
	settings_add_str("server", "user_name", NULL);
	settings_add_str("server", "real_name", NULL);

	settings_add_bool("ircproxy", "use_ircproxy", FALSE);
	settings_add_str("ircproxy", "proxy_address", "");
	settings_add_int("ircproxy", "proxy_port", 6667);
	settings_add_str("ircproxy", "proxy_string", "CONNECT %s %d");

	init_userinfo();
	read_servers();

	source_host_ip = NULL;
	read_settings();

	signal_add("setup changed", (SIGNAL_FUNC) read_settings);
	signal_add("setup reread", (SIGNAL_FUNC) read_servers);
}
void NetConfigManager::load()
{
    YAML::Node config;
    if (!load_file(config))
        return;

    read_playername(config);
    read_servers(config);
}
Exemple #3
0
int
main (int argc, char *argv[])
{
	GtkWidget *dialog;
	char *command;
	char *version;
	char *ret;
	const char *message;
	GOptionContext *ctx;

	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	/* Option parsing */
	ctx = g_option_context_new ("- New mdm login");
	g_option_context_add_main_entries (ctx, options, _("main options"));
	g_option_context_parse (ctx, &argc, &argv, NULL);
	g_option_context_free (ctx);

	if (monte_carlo_pi) {
		calc_pi ();
		return 0;
	}

	mdm_log_init ();
	mdm_log_set_debug (debug_in);

	if (args_remaining != NULL && args_remaining[0] != NULL)
		server = args_remaining[0];

	if (send_command != NULL) {
		if ( ! mdmcomm_check (FALSE)) {
			mdm_common_error (_("Error: MDM (MDM Display Manager) is not running."));
			mdm_common_error (_("You might be using a different display manager."));
			return 1;
		}
	} else {
		/*
		 * The --command argument does not display anything, so avoid
		 * running gtk_init until it finishes.  Sometimes the
		 * --command argument is used when there is no display so it
		 * will fail and cause the program to exit, complaining about
		 * "no display".
		 */
		gtk_init (&argc, &argv);

		if ( ! mdmcomm_check (TRUE)) {
			return 1;
		}
	}

	/* Start reading config data in bulk */
	mdmcomm_comm_bulk_start ();

	/* Process --command option */

	g_type_init ();

	if (send_command != NULL) {

		/* gdk_init is needed for cookie code to get display */
		gdk_init (&argc, &argv);
		if (authenticate)
			auth_cookie = mdmcomm_get_auth_cookie ();

		/*
		 * If asking for a translatable config value, then try to get
		 * the translated value first.  If this fails, then go ahead
		 * and call the normal sockets command.
		 */
		if (strncmp (send_command, MDM_SUP_GET_CONFIG " ",
		    strlen (MDM_SUP_GET_CONFIG " ")) == 0) {
			gchar *value = NULL;
			const char *key = &send_command[strlen (MDM_SUP_GET_CONFIG " ")];

			if (is_key (MDM_KEY_WELCOME, key) ||
			    is_key (MDM_KEY_REMOTE_WELCOME, key)) {
				value = mdm_config_get_translated_string ((gchar *)key);
				if (value != NULL) {
					ret = g_strdup_printf ("OK %s", value);
				}
			}

			/*
			 * If the above didn't return a value, then must be a
			 * different key, so call mdmcomm_call_mdm.
			 */
			if (value == NULL)
				ret = mdmcomm_call_mdm (send_command, auth_cookie,
							"1.0.0.0", 5);
		} else {
			ret = mdmcomm_call_mdm (send_command, auth_cookie,
						"1.0.0.0", 5);
		}

		/* At this point we are done using the socket, so close it */
		mdmcomm_comm_bulk_stop ();

		if (ret != NULL) {
			g_print ("%s\n", ret);
			return 0;
		} else {
			dialog = hig_dialog_new (NULL /* parent */,
						 GTK_DIALOG_MODAL /* flags */,
						 GTK_MESSAGE_ERROR,
						 GTK_BUTTONS_OK,
						 _("Cannot communicate with MDM "
						   "(The MDM Display Manager)"),
						 _("Perhaps you have an old version "
						   "of MDM running."));
			gtk_widget_show_all (dialog);
			gtk_dialog_run (GTK_DIALOG (dialog));
			gtk_widget_destroy (dialog);
			return 1;
		}
	}

	/*
	 * Now process what mdmflexiserver is more frequently used to
	 * do, start VT (Virtual Terminal) sesions - at least on
	 * systems where it is supported.  On systems where it is not
	 * supporteed VT stands for "Very Tight" and will mess up your
	 * display if you use it.  Tight!  So do not use it.
	 *
	 * I would accept a patch to disable it on such systems, but it
	 * is easy to avoid not using it as long as your distro does not
	 * put the menu choice in the application launch button on the
	 * panel (don't ship the desktop file).
	 */

	/*
	 * Always attempt to get cookie and authenticate.  On remote
	 * servers
	 */
	auth_cookie = mdmcomm_get_auth_cookie ();

	if (use_xnest) {
		char *cookie = mdmcomm_get_a_cookie (FALSE /* binary */);

		if (cookie == NULL) {

			/* At this point we are done using the socket, so close it */
			mdmcomm_comm_bulk_stop ();

			dialog = hig_dialog_new (NULL /* parent */,
						 GTK_DIALOG_MODAL /* flags */,
						 GTK_MESSAGE_ERROR,
						 GTK_BUTTONS_OK,
						 _("You do not seem to have the "
						   "authentication needed for this "
						   "operation"),
						 _("Perhaps your .Xauthority "
						   "file is not set up correctly."));
			gtk_widget_show_all (dialog);
			gtk_dialog_run (GTK_DIALOG (dialog));
			gtk_widget_destroy (dialog);
			return 1;
		}
		command = g_strdup_printf (MDM_SUP_FLEXI_XNEST " %s %d %s %s",
					   mdmcomm_get_display (),
					   (int)getuid (),
					   cookie,
					   XauFileName ());
		g_free (cookie);
		version = "1.0.0.0";
		auth_cookie = NULL;
	} else {

		/* check for other displays/logged in users */
		check_for_users ();

		if (auth_cookie == NULL) {

			/* At this point we are done using the socket, so close it */
			mdmcomm_comm_bulk_stop ();

			dialog = hig_dialog_new (NULL /* parent */,
						 GTK_DIALOG_MODAL /* flags */,
						 GTK_MESSAGE_ERROR,
						 GTK_BUTTONS_OK,
						 _("You do not seem to be logged in on the "
						   "console"),
						 _("Starting a new login only "
						   "works correctly on the console."));
			gtk_dialog_set_has_separator (GTK_DIALOG (dialog),
						      FALSE);
			gtk_widget_show_all (dialog);
			gtk_dialog_run (GTK_DIALOG (dialog));
			gtk_widget_destroy (dialog);
			return 1;
		}

		read_servers ();
		server = choose_server ();
		if (server == NULL)
			command = g_strdup (MDM_SUP_FLEXI_XSERVER);
		else
			command = g_strdup_printf (MDM_SUP_FLEXI_XSERVER " %s",
						   server);
		version = "1.0.0.0";
	}

	ret = mdmcomm_call_mdm (command, auth_cookie, version, 5);
	g_free (command);
	g_free (auth_cookie);
	g_strfreev (args_remaining);

	/* At this point we are done using the socket, so close it */
	mdmcomm_comm_bulk_stop ();

	if (ret != NULL &&
	    strncmp (ret, "OK ", 3) == 0) {

		/* if we switched to a different screen as a result of this,
		 * lock the current screen */
		if ( ! no_lock && ! use_xnest) {
			maybe_lock_screen ();
		}

		/* all fine and dandy */
		g_free (ret);
		return 0;
	}

	message = mdmcomm_get_error_message (ret, use_xnest);

	dialog = hig_dialog_new (NULL /* parent */,
				 GTK_DIALOG_MODAL /* flags */,
				 GTK_MESSAGE_ERROR,
				 GTK_BUTTONS_OK,
				 _("Cannot start new display"),
				 message);

	gtk_widget_show_all (dialog);
	gtk_dialog_run (GTK_DIALOG (dialog));
	gtk_widget_destroy (dialog);
	g_free (ret);

	return 1;
}
Exemple #4
0
int main2(int argc, char **argv)
#endif
{
  int     usage = 0;
  int     err = 0;
  int     inplayback = 0;

  char   *name, *ptr;

#ifdef TOOLS
  char    url[1024];

#endif

#ifdef EXPIRE
  time_t  expday, daycomp, today;

#endif

#ifdef GATEWAY
  int     hset = 0;

#endif
  int     xtrekPort = -1;

  program = argv[0];

  setlocale(LC_ALL, "");
  bindtextdomain("netrek-client-cow", "po/");
  textdomain("netrek-client-cow");

#ifdef WINDOWMAKER
  wm_argv=argv;
  wm_argc=argc;
#endif

  name = *argv++;
  argc--;
  if ((ptr = RINDEX(name, '/')) != NULL)
    name = ptr + 1;

#ifdef GATEWAY
  netaddr = 0;
#endif

#ifdef EXPIRE
  daycomp = tv_ctime.tv_sec;
  expday = daycomp + EXPIRE * 24 * 3600;
  today = time(NULL);
  STRNCPY(exptime, ctime(&expday), sizeof(exptime));
#endif

#ifdef TOOLS
  url[0] = '\0';
#endif

  pseudo[0] = defpasswd[0] = '\0';

  while (*argv)
    {
      if (!strcmp(*argv, "--fast-guest")) {
	fastGuest++;
	argv++; argc--;
	continue;
      }

      if (!strcmp(*argv, "--server")) {
	argv++; argc--;
	if (*argv) {
	  servertmp = *argv;
	  argv++; argc--;
	  continue;
	}
      }

      if (!strcmp(*argv, "--port")) {
	argv++; argc--;
	if (*argv) {
	  xtrekPort = atoi(*argv);
	  argv++; argc--;
	  continue;
	}
      }

      if (**argv == '-')
	++ * argv;
      else
	break;

      argc--;
      ptr = *argv++;
      while (*ptr)
	{
	  switch (*ptr)
	    {

	    case 'C':				 /* character name */
	      (void) STRNCPY(pseudo, *argv, sizeof(pseudo));
	      argv++;
	      argc--;
	      break;

	    case 'A':				 /* authorization password */
	      (void) STRNCPY(defpasswd, *argv, sizeof(defpasswd));
	      argv++;
	      argc--;
	      break;

	    case 'u':
	      usage++;
	      break;
	    case 'c':
	      checking = 1;
	      break;
	    case 's':
	      if (*argv)
		{
		  xtrekPort = atoi(*argv);
		  passive = 1;
		  argv++;
		  argc--;
		}
	      break;

#ifdef RECORDGAME
	    case 'F':
	      inplayback = 1;
              if (*(ptr+1) == 'i')
                  pb_create_index = 1;
	      /* No break */
	    case 'f':
	      recordFileName = *argv;
	      argv++;
	      argc--;
	      break;
#endif

	    case 'l':
	      logFileName = *argv;
              logmess = 1;
	      argv++;
	      argc--;
	      break;
	    case 'p':
	      if (*argv)
		{
		  xtrekPort = atoi(*argv);
		  argv++;
		  argc--;
		}
	      break;
	    case 'd':
	      display_host = *argv;
	      argc--;
	      argv++;
	      break;

#ifdef META
	    case 'm': /* use multiple metaservers by UDP */
	      if (usemeta && usemeta != 1)
		{
		  fputs(_("The options -k and -m and -M are mutually exclusive\n"),
			stderr);
		  err++;
		}
	      usemeta = 1;
	      break;

	    case 'k': /* use metaserver cache from prior -M usage */
	      if (usemeta && usemeta != 2)
		{
		  fputs(_("The options -k and -m and -M are mutually exclusive\n"),
			stderr);
		  err++;
		}
	      usemeta = 2;
	      break;
 
           case 'M': /* use single metaserver by TCP */
             if (usemeta && usemeta != 3)
               {
                 fputs(_("The options -k, -m and -M are mutually exclusive\n"),
                       stderr);
                 err++;
               }
             usemeta = 3;
             break;
#endif

#ifdef RSA
	    case 'o':
	      RSA_Client = -1;			 /* will be reset leter, set
						  * * * negative here * to
						  * flag * * that it should
						  * override * * xtrekrc */
	      printf(_("Using standard binary verification\n"));
	      break;
	    case 'R':
	      RSA_Client = -2;			 /* will be reset leter, set
						  * * * negative here * to
						  * flag * * that it should
						  * override * * xtrekrc */
	      printf(_("Using RSA verification\n"));
	      break;
#else
	    case 'R':
	      printf(_("This client does not support RSA verification\n"));
	    case 'o':
	      printf(_("Using standard binary verification\n"));
	      break;
#endif

	    case 'h':
	      servertmp = *argv;

#ifdef GATEWAY
	      gw_mach = *argv;
#endif

	      argc--;
	      argv++;
	      break;

#ifdef GATEWAY
	    case 'H':
	      hset++;
              read_servers();
              serverName = gateway;
	      netaddr = strToNetaddr(*argv);
	      /* netaddrstr = *argv; */
	      argc--;
	      argv++;
	      break;
#endif

	    case 'U':
	      if ((baseLocalPort = atoi(*argv)) == 0)
		{
		  fprintf(stderr, _("Error: -U requires a port number\n"));
		  exit(1);
		}
	      argc--;
	      argv++;
	      break;

#ifdef PACKET_LOG
	    case 'P':
	      log_packets++;
	      break;
#endif

	    case 'G':
	      if (*argv)
		{
		  ghoststart++;
		  ghost_pno = atoi(*argv);
		  printf(_("Emergency restart being attempted...\n"));
		  argv++;
		  argc--;
		}
	      break;

	    case 't':
	      title = *argv;
	      argc--;
	      argv++;
	      break;
	    case 'r':
	      deffile = *argv;
	      argv++;
	      argc--;
	      break;

	    case 'D':
	      debug++;
	      break;
	    case 'v':
	      printf("%s\n", cowid);
	      printf(_("Compile options used: %s\n"), cflags);
	      printf(_("Compiled on %s by %s\n"), cdate, cwho);
	      printf("%s\n", cbugs);

#ifdef RSA
	      printf("RSA key installed: %s --- Created by: %s\n", key_name, client_creator);
	      printf("     Client type: %s\n", client_type);
	      printf("     Client arch: %s\n", client_arch);
	      printf("     Key permutation date: %s\n", client_key_date);
	      printf("     Comments: %s\n", client_comments);
#endif

#ifdef EXPIRE
	      printf("THIS CLIENT WILL EXPIRE ON %s\n", exptime);
#endif

	      exit(0);
	      break;

#ifdef IGNORE_SIGNALS_SEGV_BUS
	    case 'i':
	      printf(_("Ignoring signals SIGSEGV and SIGBUS\n"));
	      ignore_signals = -1;
	      break;
#endif

#ifndef WIN32
	    case 'n':
	      takeNearest = 1;
	      break;
#endif

	    case 'b':
	      pixMissing |= NO_PIXMAPS;
	      break;

#ifdef TOOLS
	    case 'L':
	      sprintf(url, upgradeURL, arch);
	      break;

	    case 'V':
	      sprintf(url, releaseURL, mvers, PATCHLEVEL);
	      break;

	    case 'B':
	      sprintf(url, bugURL, mvers, PATCHLEVEL, arch);
	      break;
#endif
	    case 'S': /* analyse a cambot recording for visualisation */
	      gather_stats++;
	      break;

	    default:
	      fprintf(stderr, _("%s: unknown option '%c'\n"), name, *ptr);
	      err++;
	      break;
	    }
	  ptr++;
	}
    }

#ifdef TOOLS
  if (*url)
    {
      char    webcall[1024];

      initDefaults(deffile);
      if (getdefault("wwwlink") != NULL)
	wwwlink = getdefault("wwwlink");

      snprintf(webcall, sizeof(webcall), wwwlink, url);
      if (system(webcall) == -1)
	printf("Running %s for URL %s failed\n", wwwlink, url);
      url[0] = '\0';
      exit(0);
    }
#endif

#ifdef EXPIRE
  daycomp = tv_ctime.tv_sec;
  expday = daycomp + EXPIRE * 24 * 3600;
  today = time(NULL);
  STRNCPY(exptime, ctime(&expday), sizeof(exptime));

  if ((expday - today) < 0.2 * (expday - daycomp) || (expday - today) / (24 * 3600) < 5)
    {
      printf("!!!!!!!!!!!!!!!!!!!!!!WARNING!!!!!!!!!!!!!!!!!!!!!!!\n");
      printf("This client will expire on %s\n", exptime);
      printf("Please obtain a newer version from your favourite ftp site.\n");
      printf("At the moment of writing http://cow.netrek.org/ is the COW home.\n");

#ifdef TOOLS
      printf("Or try the -L option to get a new version.\n");
#endif
    }
  if (today > expday)
    {
      printf("Sorry. This client has expired. It can no longer be used.\n");

#ifdef TOOLS
      printf("Try the -L option to get a new version.\n");
#endif

      exit(0);
    }
#endif

  if (usage || err)
    {
      printUsage(name);
      exit(err);
    }

#ifdef GATEWAY
  if (!hset)
    use_trekhopd = 0;				 /* allow use via normal * *
						  * connections */
  if (netaddr == 0)
    {
      fprintf(stderr,
	      "netrek: no remote address set (-H).  Restricted server will not work.\n");
    }
#endif

#ifdef RECORDGAME
  if (inplayback)
    err = pbmain(name);
  else
#endif

    err = cowmain(servertmp, xtrekPort, name);

  exit(err);
}