void
network_init (void)
{
  GGZMod *mod;
  GIOChannel *channel;
  int ret, ggzmodfd;

  if (!ggzmod_is_ggz_mode ())
    return;

  mod = ggzmod_new (GGZMOD_GAME);
  ggzmod_set_handler (mod, GGZMOD_EVENT_SERVER, handle_ggzmod_server);

  ret = ggzmod_connect (mod);
  if (ret != 0) {
    /* Error: GGZ core client error (e.g. faked GGZMODE env variable) */
    return;
  }

  ggzmodfd = ggzmod_get_fd (mod);
  channel = g_io_channel_unix_new (ggzmodfd);
  g_io_add_watch (channel, G_IO_IN, handle_ggzmod, mod);

  ggzcomm_set_notifier_callback (network_message_cb);
  ggzcomm_set_error_callback (network_error_cb);

  init_chat (mod);
  init_player_list (mod);

  ggz_network_mode = TRUE;

}
示例#2
0
/****************************************************************************
  Connect to the GGZ client.
****************************************************************************/
void ggz_begin(void)
{
  int ggz_socket;

  /* We're in GGZ mode */
  ggzmod = ggzmod_new(GGZMOD_GAME);
  ggzmod_set_handler(ggzmod, GGZMOD_EVENT_SERVER, &handle_ggzmod_server);
  ggzmod_set_handler(ggzmod, GGZMOD_EVENT_STATS, &handle_ggzmod_stats);
  if (ggzmod_connect(ggzmod) < 0) {
    exit(EXIT_FAILURE);
  }
  ggz_socket = ggzmod_get_fd(ggzmod);
  if (ggz_socket < 0) {
    fc_fprintf(stderr, _("Only the GGZ client must call freeciv-client"
			 " in ggz mode!\n"));
    exit(EXIT_FAILURE);
  }
  add_ggz_input(ggz_socket);
}