Ejemplo n.º 1
0
int Sessionx::open(void * p)
{
	m_session_state = SS_OPEN;

	if (super::open(p) == -1)
	{
		return -1;
	}

	this->peer().enable(ACE_NONBLOCK);

	int flag = 1;
	this->peer().set_option(IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));

	return net_connected();
}
/* dlg_init_detect_links:
 *	returns:
 *		FALSE, if detection has not started
 */
static void
dlg_init_detect_links(struct netselect_dlg * dlg)
{
    guint16 port;
    qcs_msg * msg;

    /* setup network query msg */
    msg = qcs_newmsg();
    msg->msg = QCS_MSG_REFRESH_REQUEST;
    qcs_msgset(msg, QCS_SRC, DETECT_NICKNAME);

    /* open link and send query msg for each link opened */
    for(port = dlg->range_current_begin; port <= dlg->range_current_end; port++) {
        int num = port - dlg->range_current_begin;

        if(net_connected() && prefs_int(PREFS_NET_TYPE)==dlg->detect_net_type
                && prefs_int(PREFS_NET_PORT)==port) {
            /*
             * this is the network we're currently connected to;
             * don't try to connect to it as the listening socket
             * is already taken by the application
             */
            dlg->detect_links[num] = NULL;
        } else {
            dlg->detect_links[num] = qcs_open(
                                         dlg->detect_net_type==NET_TYPE_VYPRESS
                                         ? QCS_PROTO_VYPRESS: QCS_PROTO_QCHAT,
                                         dlg->detect_use_multicast ? QCS_PROTO_OPT_MULTICAST: 0,
                                         dlg->detect_use_multicast
                                         ? dlg->detect_multicast_addr
                                         : dlg->detect_broadcast_mask,
                                         port);

            if(dlg->detect_links[num])
                qcs_send(dlg->detect_links[num], msg);
        }
    }

    qcs_deletemsg(msg);
}
Ejemplo n.º 3
0
int main(int argc, char *argv[]) {
  int c = 0;
  unsigned char k;
  int opt;
#ifndef WINDOWS
  char fname[1024];
#endif

  cfg_init(argv[0]);

#ifdef WINDOWS
  if (cfg_readconfig("cgchat.cfg") < 0) {
    return(1);
  }
  if (cfg_read == 0) {
    cfg_writeconfig(default_cgchat_cfg, "cgchat.cfg");
    if (cfg_readconfig("cgchat.cfg") < 0) {
      return(1);
    }
  }
#else
  strncpy(fname, cfg_homedir, 1000);
  strcat(fname, "/.cgchatrc");
  if (cfg_file_exists(fname)) {
    if (cfg_readconfig(fname) < 0) {
      return(1);
    }
  } else {
    strncpy(fname, cfg_prefix, 1000);
    strcat(fname, "/etc/cgchat.cfg");
    if (cfg_readconfig(fname) < 0) {
      return(1);
    }
  }
  if (cfg_read == 0) {
    strncpy(fname, cfg_homedir, 1000);
    strcat(fname, "/.cgchatrc");
    cfg_writeconfig(default_cgchat_cfg, fname);
  }
#endif

  while ((opt = getopt(argc, argv, "z:k:fs48")) != -1) {
    switch (opt) {

    case '4':
      cfg_columns = 40;
      break;

    case '8':
      cfg_columns = 80;
      break;

    case 'f':
      cfg_fullscreen = 1;
      break;

    case 'k':
      cfg_keyboard = optarg;
      break;

    case 's':
      cfg_sound = 0;
      break;

    case 'z':
      if ((cfg_zoom = strtol(optarg, (char **)NULL, 10)) == 0) {
	usage();
	return(1);
      }
      break;

    case 'h':
    default:
      usage();
      return(1);

    }
  }
  argc -= optind;
  argv += optind;

  if (crc_init()) {
    return(1);
  }
  if (gfx_init(cfg_fullscreen, "CGChat")) {
    return(1);
  }
  if (kbd_init(cfg_keyboard)) {
    return(1);
  }
  if (kernal_init()) {
    return(1);
  }
  if (cfg_sound && sound_init()) {
    printf("Sound init failed, sound disabled\n");
  } else {
#ifdef WINDOWS
    if ((sound_bell = sound_load_sample("bell.wav")) < 0) {
      printf("Couldn't load bell.wav\n");
      return(1);
    }
#else
    strncpy(fname, cfg_prefix, 1000);
    strcat(fname, "/share/cgterm/bell.wav");
    if ((sound_bell = sound_load_sample(fname)) < 0) {
      printf("Couldn't load %s\n", fname);
      return(1);
    }
#endif
  }

  print_banner(cfg_columns);

  if (argc == 0) {

    if (!cfg_host) {
      if (cfg_columns == 80) {
	print("                    ");
      }
      print("           \x96pRESS\x9e eSC\x96 FOR MENU\x05\x0d\x0d");
    }

  } else if (argc == 1 || argc == 2) {

    if (strchr(argv[0], '.') == NULL) {
      printf("Invalid hostname: %s\n", argv[0]);
      return(1);
    }

    cfg_host = argv[0];
    if (argc == 2) {
      cfg_port = (int)strtol(argv[1], (char **)NULL, 10);
    }

  } else {

    usage();
    return(1);

  }

  cfg_rows = 24;
  chat_init();

  if (cfg_host) {
    net_connect(cfg_host, cfg_port, &chat_print_net_status);
    cfg_nextreconnect = timer_get_ticks() + cfg_reconnect * 1000;
  }


  data_len = 0;
  data_buffer[0] = 0;

  for (;;) {

    if (timer_get_ticks() > lastvbl + 20) {
      if (timer_get_ticks() > lastvbl + 40) {
	lastvbl = timer_get_ticks();
      } else {
	lastvbl += 20;
      }
      gfx_vbl();
    }

    if (!net_connected() && cfg_host && cfg_reconnect && cfg_nextreconnect) {
      if (timer_get_ticks() > cfg_nextreconnect) {
	net_connect(cfg_host, cfg_port, &chat_print_net_status);
	cfg_nextreconnect = timer_get_ticks() + cfg_reconnect * 1000;
      }
    }

    k = ffe4();

    c = -1;
    if (net_connected()) {
      c = net_receive();
    }

    if (c == -2) {
      if (timer_get_ticks() < cfg_nextreconnect) {
	cfg_nextreconnect = timer_get_ticks() + cfg_reconnect * 1000;
      } else {
	cfg_nextreconnect = 0;
      }
    }

    if (k || c >= 0) {

      if (k) {
	chat_inputkey(k);
      }

      if (c >= 0) {
	if (data_len == data_maxlen) {
	  chat_print_msg("locl:lINEBUFFER FULL");
	  data_len = 0;
	}
	if (c == 13) {
	  if (data_len) {
	    chat_print_msg(data_buffer);
	    data_len = 0;
	  }
	} else {
	  data_buffer[data_len++] = c;
	  data_buffer[data_len] = 0;
	}
      }

    } else {

      timer_delay(1);

    }

  }

}
static void
dlg_start_detection(struct netselect_dlg * dlg)
{
    gint range_begin, range_end;

    range_begin = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(dlg->detect_begin_spin));
    range_end = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(dlg->detect_end_spin));

    if(!util_parse_ipv4(
                gtk_entry_get_text(GTK_ENTRY(dlg->detect_broadcast_mask_w)),
                &dlg->detect_broadcast_mask))
    {
#if(HAVE_EXPANDER_WIDGET)
        gtk_expander_set_expanded(GTK_EXPANDER(dlg->detect_expander_w), TRUE);
#endif
        gtk_widget_grab_focus(dlg->detect_broadcast_mask_w);
        gtk_editable_select_region(GTK_EDITABLE(dlg->detect_broadcast_mask_w), 0, -1);
        return;
    }

    if(!util_parse_ipv4(
                gtk_entry_get_text(GTK_ENTRY(dlg->detect_multicast_addr_w)),
                &dlg->detect_multicast_addr))
    {
#if(HAVE_EXPANDER_WIDGET)
        gtk_expander_set_expanded(GTK_EXPANDER(dlg->detect_expander_w), TRUE);
#endif
        gtk_widget_grab_focus(dlg->detect_multicast_addr_w);
        gtk_editable_select_region(GTK_EDITABLE(dlg->detect_multicast_addr_w), 0, -1);
        return;
    }

    /* put dialog in search mode (disable some of the controls) */
    dlg_search_mode(dlg, TRUE);

    /* cleanup current list */
    gtk_list_store_clear(dlg->list);

    if(net_connected()
            && prefs_int(PREFS_NET_PORT) >= range_begin
            && prefs_int(PREFS_NET_PORT) <= range_end)
    {
        /* add current network to the list as it won't get detected
         * due to the socket already held by the application
         */
        dlg_add_detected_network(
            dlg, prefs_int(PREFS_NET_TYPE), prefs_int(PREFS_NET_PORT),
            prefs_int(PREFS_NET_TYPE)==NET_TYPE_VYPRESS
            ? prefs_bool(PREFS_NET_USE_MULTICAST) : FALSE
        );
    }

    /* init progress bar */
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dlg->detect_progress), 0.0);

    /* start it */
    dlg->range_begin = range_begin;
    dlg->range_end = range_end;
    dlg->range_current_begin = range_begin;
    dlg->range_current_end = MIN(
                                 dlg->range_end,
                                 dlg->range_current_begin + DETECT_PORT_STEP - 1);
    dlg->detect_net_type = NET_TYPE_FIRST;
    dlg->detect_use_multicast = FALSE;
    dlg->detect_num_steps =
        ((dlg->range_end - dlg->range_begin + 1 + DETECT_PORT_STEP - 1) / DETECT_PORT_STEP)
        * (NET_TYPE_NUM + 1);
    dlg->detect_step = 0;
    memset(&dlg->detect_links, 0, sizeof(qcs_link) * DETECT_PORT_STEP);

    dlg_init_detect_links(dlg);

    dlg->detect_timeout_id = g_timeout_add(
                                 DETECT_DURATION, (GSourceFunc)detection_timeout, (gpointer)dlg);
}
Ejemplo n.º 5
0
gboolean sm_is_connected(StateMachine * sm)
{
	return sm->ses != NULL && net_connected(sm->ses);
}