void lag_check (void) { GSList *list = serv_list; unsigned long tim; char tbuf[128]; time_t now = time (0); int lag; tim = make_ping_time (); while (list) { server *serv; serv = list->data; if (serv->connected && serv->end_of_motd) { lag = now - serv->ping_recv; if (prefs.pchat_net_ping_timeout && lag > prefs.pchat_net_ping_timeout && lag > 0) { sprintf (tbuf, "%d", lag); EMIT_SIGNAL (XP_TE_PINGTIMEOUT, serv->server_session, tbuf, NULL, NULL, NULL, 0); if (prefs.pchat_net_auto_reconnect) serv->auto_reconnect (serv, FALSE, -1); } else { g_snprintf (tbuf, sizeof (tbuf), "LAG%lu", tim); serv->p_ping (serv, "", tbuf); if (!serv->lag_sent) { serv->lag_sent = tim; fe_set_lag (serv, -1); } } } list = list->next; } }
void inbound_ping_reply (session * sess, char *timestring, char *from) { unsigned long tim, nowtim, dif; int lag = 0; char outbuf[64]; if (strncmp (timestring, "LAG", 3) == 0) { timestring += 3; lag = 1; } tim = strtoul (timestring, NULL, 10); nowtim = make_ping_time (); dif = nowtim - tim; sess->server->ping_recv = time (0); if (lag) { sess->server->lag_sent = 0; sess->server->lag = dif / 1000; fe_set_lag (sess->server, dif / 100000); return; } if (atol (timestring) == 0) { if (sess->server->lag_sent) sess->server->lag_sent = 0; else EMIT_SIGNAL (XP_TE_PINGREP, sess, from, "?", NULL, NULL, 0); } else { snprintf (outbuf, sizeof (outbuf), "%ld.%ld%ld", dif / 1000000, (dif / 100000) % 10, dif % 10); EMIT_SIGNAL (XP_TE_PINGREP, sess, from, outbuf, NULL, NULL, 0); } }
void fe_set_lag (server *serv, int lag) { GSList *list = sess_list; session *sess; gdouble per; char tip[64]; unsigned long nowtim; if (lag == -1) { if (!serv->lag_sent) return; nowtim = make_ping_time (); lag = (nowtim - serv->lag_sent) / 100000; } per = (double)((double)lag / (double)40); if (per > 1.0) per = 1.0; while (list) { sess = list->data; if (sess->server == serv) { if (sess->gui->lagometer) { gtk_progress_bar_update ((GtkProgressBar *) sess->gui->lagometer, per); } if (sess->gui->laginfo) { snprintf (tip, sizeof(tip) - 1, "%s%d.%ds", serv->lag_sent ? "+" : "", lag / 10, lag % 10); gtk_label_set_text ((GtkLabel *) sess->gui->laginfo, tip); } } list = list->next; } }
void fe_set_lag (server *serv, int lag) { unsigned long now; float seconds; if (gui.quit) { return; } if (lag == -1) { if (!serv->lag_sent) { return; } now = make_ping_time (); seconds = (now - serv->lag_sent) / 1000000.0f; } else { seconds = lag / 10.0f; } status_bar_set_lag (STATUS_BAR (gui.status_bar), serv, seconds, (serv->lag_sent != 0.0f)); }