mirror of
https://github.com/weechat/weechat.git
synced 2026-06-29 06:16:40 +02:00
Improve irc lag indicator: two colors (counting and finished), update item even when pong has not been received, lag_min_show is now in milliseconds
This commit is contained in:
@@ -365,7 +365,7 @@ char *
|
||||
irc_bar_item_lag (void *data, struct t_gui_bar_item *item,
|
||||
struct t_gui_window *window)
|
||||
{
|
||||
char buf[32];
|
||||
char buf[128];
|
||||
struct t_gui_buffer *buffer;
|
||||
struct t_irc_server *server;
|
||||
|
||||
@@ -380,11 +380,14 @@ irc_bar_item_lag (void *data, struct t_gui_bar_item *item,
|
||||
irc_buffer_get_server_and_channel (buffer, &server, NULL);
|
||||
|
||||
if (server
|
||||
&& (server->lag >= weechat_config_integer (irc_config_network_lag_min_show) * 1000))
|
||||
&& (server->lag >= weechat_config_integer (irc_config_network_lag_min_show)))
|
||||
{
|
||||
snprintf (buf, sizeof (buf),
|
||||
"%s: %.1f",
|
||||
((server->lag_check_time.tv_sec == 0) || (server->lag < 1000)) ?
|
||||
"%s: %s%.3f" : "%s: %s%.0f",
|
||||
_("Lag"),
|
||||
(server->lag_check_time.tv_sec == 0) ?
|
||||
IRC_COLOR_ITEM_LAG_FINISHED : IRC_COLOR_ITEM_LAG_COUNTING,
|
||||
((float)(server->lag)) / 1000);
|
||||
return strdup (buf);
|
||||
}
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
#define IRC_COLOR_INPUT_NICK weechat_color(weechat_config_string(irc_config_color_input_nick))
|
||||
#define IRC_COLOR_ITEM_AWAY weechat_color(weechat_config_string(irc_config_color_item_away))
|
||||
#define IRC_COLOR_ITEM_CHANNEL_MODES weechat_color(weechat_config_string(irc_config_color_item_channel_modes))
|
||||
#define IRC_COLOR_ITEM_LAG_COUNTING weechat_color(weechat_config_string(irc_config_color_item_lag_counting))
|
||||
#define IRC_COLOR_ITEM_LAG_FINISHED weechat_color(weechat_config_string(irc_config_color_item_lag_finished))
|
||||
#define IRC_COLOR_NICK_IN_SERVER_MESSAGE(nick) \
|
||||
((nick && weechat_config_boolean(irc_config_look_color_nicks_in_server_messages)) ? \
|
||||
nick->color : IRC_COLOR_CHAT_NICK)
|
||||
|
||||
@@ -96,6 +96,8 @@ struct t_config_option *irc_config_color_notice;
|
||||
struct t_config_option *irc_config_color_input_nick;
|
||||
struct t_config_option *irc_config_color_item_away;
|
||||
struct t_config_option *irc_config_color_item_channel_modes;
|
||||
struct t_config_option *irc_config_color_item_lag_counting;
|
||||
struct t_config_option *irc_config_color_item_lag_finished;
|
||||
struct t_config_option *irc_config_color_reason_quit;
|
||||
|
||||
/* IRC config, network section */
|
||||
@@ -110,6 +112,7 @@ struct t_config_option *irc_config_network_away_check_max_nicks;
|
||||
struct t_config_option *irc_config_network_lag_check;
|
||||
struct t_config_option *irc_config_network_lag_min_show;
|
||||
struct t_config_option *irc_config_network_lag_disconnect;
|
||||
struct t_config_option *irc_config_network_lag_refresh_interval;
|
||||
struct t_config_option *irc_config_network_anti_flood[2];
|
||||
struct t_config_option *irc_config_network_colors_receive;
|
||||
struct t_config_option *irc_config_network_colors_send;
|
||||
@@ -416,6 +419,22 @@ irc_config_change_color_item_buffer_name (void *data,
|
||||
weechat_bar_item_update ("buffer_name");
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_config_change_color_item_lag: called when the color of lag item is
|
||||
* changed
|
||||
*/
|
||||
|
||||
void
|
||||
irc_config_change_color_item_lag (void *data,
|
||||
struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
weechat_bar_item_update ("lag");
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_config_change_color_nick_prefix: called when the color of a nick prefix
|
||||
* is changed
|
||||
@@ -490,6 +509,21 @@ irc_config_change_network_lag_check (void *data,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_config_change_network_lag_min_show: called when lag min show is changed
|
||||
*/
|
||||
|
||||
void
|
||||
irc_config_change_network_lag_min_show (void *data,
|
||||
struct t_config_option *option)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
(void) option;
|
||||
|
||||
weechat_bar_item_update ("lag");
|
||||
}
|
||||
|
||||
/*
|
||||
* irc_config_change_network_send_unknown_commands: called when "send_unknown_commands"
|
||||
* is changed
|
||||
@@ -1725,6 +1759,19 @@ irc_config_init ()
|
||||
N_("color for channel modes, near channel name"),
|
||||
NULL, -1, 0, "default", NULL, 0, NULL, NULL,
|
||||
&irc_config_change_color_item_buffer_name, NULL, NULL, NULL);
|
||||
irc_config_color_item_lag_counting = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"item_lag_counting", "color",
|
||||
N_("color for lag indicator, when counting (pong not received from "
|
||||
"server, lag is increasing)"),
|
||||
NULL, -1, 0, "default", NULL, 0, NULL, NULL,
|
||||
&irc_config_change_color_item_lag, NULL, NULL, NULL);
|
||||
irc_config_color_item_lag_finished = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"item_lag_finished", "color",
|
||||
N_("color for lag indicator, when pong has been received from server"),
|
||||
NULL, -1, 0, "yellow", NULL, 0, NULL, NULL,
|
||||
&irc_config_change_color_item_lag, NULL, NULL, NULL);
|
||||
irc_config_color_reason_quit = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"reason_quit", "color",
|
||||
@@ -1782,33 +1829,40 @@ irc_config_init ()
|
||||
"away_check", "integer",
|
||||
N_("interval between two checks for away (in minutes, 0 = never "
|
||||
"check)"),
|
||||
NULL, 0, INT_MAX, "0", NULL, 0, NULL, NULL,
|
||||
NULL, 0, 60 * 24 * 7, "0", NULL, 0, NULL, NULL,
|
||||
&irc_config_change_network_away_check, NULL, NULL, NULL);
|
||||
irc_config_network_away_check_max_nicks = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"away_check_max_nicks", "integer",
|
||||
N_("do not check away nicks on channels with high number of nicks "
|
||||
"(0 = unlimited)"),
|
||||
NULL, 0, INT_MAX, "25", NULL, 0, NULL, NULL,
|
||||
NULL, 0, 1000000, "25", NULL, 0, NULL, NULL,
|
||||
&irc_config_change_network_away_check, NULL, NULL, NULL);
|
||||
irc_config_network_lag_check = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"lag_check", "integer",
|
||||
N_("interval between two checks for lag (in seconds, 0 = never "
|
||||
"check)"),
|
||||
NULL, 0, INT_MAX, "60", NULL, 0, NULL, NULL,
|
||||
NULL, 0, 3600 * 24 * 7, "60", NULL, 0, NULL, NULL,
|
||||
&irc_config_change_network_lag_check, NULL, NULL, NULL);
|
||||
irc_config_network_lag_min_show = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"lag_min_show", "integer",
|
||||
N_("minimum lag to show (in seconds)"),
|
||||
NULL, 0, INT_MAX, "1", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
N_("minimum lag to show (in milliseconds)"),
|
||||
NULL, 0, 1000 * 3600 * 24, "500", NULL, 0, NULL, NULL,
|
||||
&irc_config_change_network_lag_min_show, NULL, NULL, NULL);
|
||||
irc_config_network_lag_disconnect = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"lag_disconnect", "integer",
|
||||
N_("disconnect after important lag (in minutes, 0 = never "
|
||||
"disconnect)"),
|
||||
NULL, 0, INT_MAX, "0", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
NULL, 0, 60 * 24 * 7, "0", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
irc_config_network_lag_refresh_interval = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"lag_refresh_interval", "integer",
|
||||
N_("interval between two refreshs of lag item, when lag is increasing "
|
||||
"(in seconds)"),
|
||||
NULL, 1, 3600, "1", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
irc_config_network_anti_flood[0] = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"anti_flood_prio_high", "integer",
|
||||
|
||||
@@ -113,6 +113,8 @@ extern struct t_config_option *irc_config_color_notice;
|
||||
extern struct t_config_option *irc_config_color_input_nick;
|
||||
extern struct t_config_option *irc_config_color_item_away;
|
||||
extern struct t_config_option *irc_config_color_item_channel_modes;
|
||||
extern struct t_config_option *irc_config_color_item_lag_counting;
|
||||
extern struct t_config_option *irc_config_color_item_lag_finished;
|
||||
extern struct t_config_option *irc_config_color_reason_quit;
|
||||
|
||||
extern struct t_config_option *irc_config_network_autoreconnect_delay_growing;
|
||||
@@ -125,6 +127,7 @@ extern struct t_config_option *irc_config_network_away_check_max_nicks;
|
||||
extern struct t_config_option *irc_config_network_lag_check;
|
||||
extern struct t_config_option *irc_config_network_lag_min_show;
|
||||
extern struct t_config_option *irc_config_network_lag_disconnect;
|
||||
extern struct t_config_option *irc_config_network_lag_refresh_interval;
|
||||
extern struct t_config_option *irc_config_network_anti_flood[2];
|
||||
extern struct t_config_option *irc_config_network_colors_receive;
|
||||
extern struct t_config_option *irc_config_network_colors_send;
|
||||
|
||||
@@ -422,6 +422,7 @@ irc_server_alloc (const char *name)
|
||||
new_server->lag_check_time.tv_usec = 0;
|
||||
new_server->lag_next_check = time (NULL) +
|
||||
weechat_config_integer (irc_config_network_lag_check);
|
||||
new_server->lag_last_refresh = 0;
|
||||
new_server->cmd_list_regexp = NULL;
|
||||
new_server->last_user_message = 0;
|
||||
for (i = 0; i < IRC_SERVER_NUM_OUTQUEUES_PRIO; i++)
|
||||
@@ -1937,7 +1938,6 @@ irc_server_timer_cb (void *data, int remaining_calls)
|
||||
struct t_irc_server *ptr_server;
|
||||
time_t new_time;
|
||||
static struct timeval tv;
|
||||
int diff;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
@@ -1970,6 +1970,8 @@ irc_server_timer_cb (void *data, int remaining_calls)
|
||||
irc_server_sendf (ptr_server, 0, "PING %s",
|
||||
ptr_server->addresses_array[ptr_server->index_current_address]);
|
||||
gettimeofday (&(ptr_server->lag_check_time), NULL);
|
||||
ptr_server->lag = 0;
|
||||
ptr_server->lag_last_refresh = 0;
|
||||
}
|
||||
|
||||
/* check if it's time to autojoin channels (after command delay) */
|
||||
@@ -1981,14 +1983,23 @@ irc_server_timer_cb (void *data, int remaining_calls)
|
||||
ptr_server->command_time = 0;
|
||||
}
|
||||
|
||||
/* lag timeout => disconnect */
|
||||
if ((ptr_server->lag_check_time.tv_sec != 0)
|
||||
&& (weechat_config_integer (irc_config_network_lag_disconnect) > 0))
|
||||
/* compute lag */
|
||||
if (ptr_server->lag_check_time.tv_sec != 0)
|
||||
{
|
||||
gettimeofday (&tv, NULL);
|
||||
diff = (int) weechat_util_timeval_diff (&(ptr_server->lag_check_time),
|
||||
&tv);
|
||||
if (diff / 1000 > weechat_config_integer (irc_config_network_lag_disconnect) * 60)
|
||||
ptr_server->lag = (int) weechat_util_timeval_diff (&(ptr_server->lag_check_time),
|
||||
&tv);
|
||||
/* refresh lag item if needed */
|
||||
if (((ptr_server->lag_last_refresh == 0)
|
||||
|| (new_time >= ptr_server->lag_last_refresh + weechat_config_integer (irc_config_network_lag_refresh_interval)))
|
||||
&& (ptr_server->lag >= weechat_config_integer (irc_config_network_lag_min_show)))
|
||||
{
|
||||
ptr_server->lag_last_refresh = new_time;
|
||||
weechat_bar_item_update ("lag");
|
||||
}
|
||||
/* lag timeout? => disconnect */
|
||||
if ((weechat_config_integer (irc_config_network_lag_disconnect) > 0)
|
||||
&& (ptr_server->lag / 1000 > weechat_config_integer (irc_config_network_lag_disconnect) * 60))
|
||||
{
|
||||
weechat_printf (ptr_server->buffer,
|
||||
_("%s: lag is high, disconnecting "
|
||||
@@ -3074,6 +3085,7 @@ irc_server_disconnect (struct t_irc_server *server, int reconnect)
|
||||
server->lag_check_time.tv_usec = 0;
|
||||
server->lag_next_check = time (NULL) +
|
||||
weechat_config_integer (irc_config_network_lag_check);
|
||||
server->lag_last_refresh = 0;
|
||||
|
||||
if (reconnect
|
||||
&& IRC_SERVER_OPTION_BOOLEAN(server, IRC_SERVER_OPTION_AUTORECONNECT))
|
||||
@@ -3676,6 +3688,8 @@ irc_server_add_to_infolist (struct t_infolist *infolist,
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_time (ptr_item, "lag_next_check", server->lag_next_check))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_time (ptr_item, "lag_last_refresh", server->lag_last_refresh))
|
||||
return 0;
|
||||
if (!weechat_infolist_new_var_time (ptr_item, "last_user_message", server->last_user_message))
|
||||
return 0;
|
||||
|
||||
@@ -3905,6 +3919,7 @@ irc_server_print_log ()
|
||||
ptr_server->lag_check_time.tv_sec,
|
||||
ptr_server->lag_check_time.tv_usec);
|
||||
weechat_log_printf (" lag_next_check . . . : %ld", ptr_server->lag_next_check);
|
||||
weechat_log_printf (" lag_last_refresh . . : %ld", ptr_server->lag_last_refresh);
|
||||
weechat_log_printf (" cmd_list_regexp. . . : 0x%lx", ptr_server->cmd_list_regexp);
|
||||
weechat_log_printf (" last_user_message. . : %ld", ptr_server->last_user_message);
|
||||
for (i = 0; i < IRC_SERVER_NUM_OUTQUEUES_PRIO; i++)
|
||||
|
||||
@@ -149,6 +149,7 @@ struct t_irc_server
|
||||
int lag; /* lag (in milliseconds) */
|
||||
struct timeval lag_check_time; /* last time lag was checked (ping sent) */
|
||||
time_t lag_next_check; /* time for next check */
|
||||
time_t lag_last_refresh; /* last refresh of lag item */
|
||||
regex_t *cmd_list_regexp; /* compiled Regular Expression for /list */
|
||||
time_t last_user_message; /* time of last user message (anti flood)*/
|
||||
struct t_irc_outqueue *outqueue[2]; /* queue for outgoing messages */
|
||||
|
||||
@@ -274,6 +274,7 @@ irc_upgrade_read_cb (void *data,
|
||||
if (buf)
|
||||
memcpy (&(irc_upgrade_current_server->lag_check_time), buf, size);
|
||||
irc_upgrade_current_server->lag_next_check = weechat_infolist_time (infolist, "lag_next_check");
|
||||
irc_upgrade_current_server->lag_last_refresh = weechat_infolist_time (infolist, "lag_last_refresh");
|
||||
irc_upgrade_current_server->last_user_message = weechat_infolist_time (infolist, "last_user_message");
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user