Net read_data(char *file_name) { Net net = NULL; int readed = 0; uint edges_reserved = EDGES_RESERVED, nodes_reserved = NODES_RESERVED, x = 0,y = 0,c = 0; nodes_list nodes = NULL; edges_list edges = NULL; if (file_name != NULL) freopen (file_name, "r", stdin); net = net_new(); nodes = net_get_nodes(net); edges = net_get_edges(net); while ((readed=scanf("%u %u %u\n", &x, &y, &c))!=EOF && readed == 3 ){ net_add_nodes(net, &x, &y); net_add_edge(net, x, y, c); if (nodes_get_length(nodes)+1 >= nodes_reserved){ nodes_reserved *= 2; nodes_realloc(nodes, nodes_reserved); } if (nodes_get_length(nodes)*2+2 >= edges_reserved){ edges_reserved = edges_reserved * 2 + 2; edges_realloc(edges, edges_reserved); } } return net; }
static void admin_open_session(void) { _admin_session = net_new(admin_net_event, NULL); _admin_session->user_data = _admin_session; /* TODO: tie the connect dialog to this */ net_connect(_admin_session, "localhost", 5555); }
void sm_use_fd(StateMachine * sm, gint fd, gboolean do_ping) { if (sm->ses != NULL) net_free(&(sm->ses)); sm->ses = net_new((NetNotifyFunc) net_event, sm); net_use_fd(sm->ses, fd, do_ping); }
gboolean sm_connect(StateMachine * sm, const gchar * host, const gchar * port) { if (sm->ses != NULL) net_free(&(sm->ses)); sm->ses = net_new((NetNotifyFunc) net_event, sm); log_message(MSG_INFO, _("Connecting to %s, port %s\n"), host, port); if (net_connect(sm->ses, host, port)) return TRUE; net_free(&(sm->ses)); return FALSE; }
void meta_register(const gchar * server, const gchar * port, Game * game) { if (num_redirects > 0) log_message(MSG_INFO, _("" "Redirected to meta-server at %s, port %s\n"), server, port); else log_message(MSG_INFO, _("" "Register with meta-server at %s, port %s\n"), server, port); if (ses != NULL) net_free(&ses); ses = net_new((NetNotifyFunc) meta_event, game); if (net_connect(ses, server, port)) meta_mode = MODE_SIGNON; else { net_free(&ses); } }