Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress error message after connection fails once #386

Merged
merged 2 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions src/core/app_irc_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ static void irc_event_connect(SircSession *sirc, const char *event, const SircMe
srv->registered = FALSE;
srv->loggedin = FALSE;
srv->negotiated = FALSE;
srv->conn_fail_once = FALSE;

srn_chat_add_misc_message_fmt(srv->chat, context,
_("Connected to %1$s(%2$s:%3$d)"),
Expand Down Expand Up @@ -217,6 +218,12 @@ static void irc_event_connect_fail(SircSession *sirc, const char *event,
const char *msg;
SrnRet ret;
SrnServer *srv;
const char *conn_fail_msg;
const char *reconn_msg;
bool conn_fail_once;

conn_fail_msg = _("Failed to connect to %1$s(%2$s:%3$d): %4$s");
reconn_msg = _("Trying to reconnect to %1$s(%2$s:%3$d) after %4$.1lfs...");

g_return_if_fail(count == 1);
msg = params[0];
Expand All @@ -234,17 +241,22 @@ static void irc_event_connect_fail(SircSession *sirc, const char *event,
return;
}

// Save previous conn_fail_once state for later usage.
conn_fail_once = srv->conn_fail_once;
// If the connection fails for the first time, filp the state.
if (!conn_fail_once) {
srv->conn_fail_once = TRUE;
}

list = srv->chat_list;
while (list){
SrnChat *chat;

chat = list->data;
srn_chat_add_misc_message_fmt(chat, context,
_("Failed to connect to %1$s(%2$s:%3$d): %4$s"),
srn_chat_add_misc_message_fmt(chat, context, conn_fail_msg,
srv->name, srv->addr->host, srv->addr->port, msg);
if (srv->state == SRN_SERVER_STATE_RECONNECTING){
srn_chat_add_misc_message_fmt(chat, context,
_("Trying reconnect to %1$s(%2$s:%3$d) after %4$.1lfs..."),
srn_chat_add_misc_message_fmt(chat, context, reconn_msg,
srv->name,
srv->addr->host,
srv->addr->port,
Expand All @@ -254,20 +266,29 @@ static void irc_event_connect_fail(SircSession *sirc, const char *event,
list = g_list_next(list);
}

srn_chat_add_error_message_fmt(srv->chat, context,
_("Failed to connect to %1$s(%2$s:%3$d): %4$s"),
srv->name, srv->addr->host, srv->addr->port, msg);
if (!conn_fail_once) {
srn_chat_add_error_message_fmt(srv->chat, context, conn_fail_msg,
srv->name, srv->addr->host, srv->addr->port, msg);
} else {
srn_chat_add_misc_message_fmt(srv->chat, context, conn_fail_msg,
srv->name, srv->addr->host, srv->addr->port, msg);
}

/* If user trying connect to a TLS port via non-TLS connection, it will
* be reset, give user some hints. */
if (!srv->cfg->irc->tls
&& (srv->addr->port == 6697 || srv->addr->port == 7000)) {
srn_chat_add_error_message_fmt(srv->chat, context,
_("It seems that you connect to a TLS port(%1$d) without enable TLS connection, try to enable it and reconnect"),
srv->addr->port);
const char *tls_hint_msg;

tls_hint_msg = _("It seems that you connect to a TLS port(%1$d) without enable TLS connection, try to enable it and reconnect");
if (!conn_fail_once) {
srn_chat_add_error_message_fmt(srv->chat, context, tls_hint_msg, srv->addr->port);
} else {
srn_chat_add_misc_message_fmt(srv->chat, context, tls_hint_msg, srv->addr->port);
}
}
if (srv->state == SRN_SERVER_STATE_RECONNECTING){
srn_chat_add_misc_message_fmt(srv->chat, context,
_("Trying reconnect to %1$s(%2$s:%3$d) after %4$.1lfs..."),
srn_chat_add_misc_message_fmt(srv->chat, context, reconn_msg,
srv->name,
srv->addr->host,
srv->addr->port,
Expand Down Expand Up @@ -329,7 +350,7 @@ static void irc_event_disconnect(SircSession *sirc, const char *event,
srv->name, srv->addr->host, srv->addr->port, msg);
if (srv->state == SRN_SERVER_STATE_RECONNECTING){
srn_chat_add_misc_message_fmt(chat, context,
_("Trying reconnect to %1$s(%2$s:%3$d) after %4$.1lfs..."),
_("Trying to reconnect to %1$s(%2$s:%3$d) after %4$.1lfs..."),
srv->name,
srv->addr->host,
srv->addr->port,
Expand All @@ -344,7 +365,7 @@ static void irc_event_disconnect(SircSession *sirc, const char *event,
srv->name, srv->addr->host, srv->addr->port, msg);
if (srv->state == SRN_SERVER_STATE_RECONNECTING){
srn_chat_add_misc_message_fmt(srv->chat, context,
_("Trying reconnect to %1$s(%2$s:%3$d) after %4$.1lfs..."),
_("Trying to reconnect to %1$s(%2$s:%3$d) after %4$.1lfs..."),
srv->name,
srv->addr->host,
srv->addr->port,
Expand Down
1 change: 1 addition & 0 deletions src/core/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ SrnServer* srn_server_new(const char *name, SrnServerConfig *cfg){
srv->last_action = SRN_SERVER_ACTION_DISCONNECT; // It should be OK
srv->negotiated = FALSE;
srv->registered = FALSE;
srv->conn_fail_once = FALSE;

srv->cap = srn_server_cap_new();
srv->cap->srv = srv;
Expand Down
9 changes: 6 additions & 3 deletions src/inc/core/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ struct _SrnServer {
/* Status */
SrnServerState state;
SrnServerAction last_action;
bool negotiated; // Client capability negotiation has finished
bool registered; // User has a nickname
bool loggedin; // User has identified as a certain account
bool negotiated; // Client capability negotiation has finished
bool registered; // User has a nickname
bool loggedin; // User has identified as a certain account
bool conn_fail_once; // Default be TRUE,
// If the connection failed once, set to TRUE;
// If connection established, set to FALSE.

/* Keep alive */
unsigned long last_pong; // Last pong time, in ms
Expand Down