diff options
Diffstat (limited to 'src/irc')
-rw-r--r-- | src/irc/core/irc-chatnets.c | 5 | ||||
-rw-r--r-- | src/irc/core/irc-chatnets.h | 3 | ||||
-rw-r--r-- | src/irc/core/irc-servers-reconnect.c | 32 | ||||
-rw-r--r-- | src/irc/core/irc-servers-setup.c | 7 | ||||
-rw-r--r-- | src/irc/core/irc-servers.c | 29 |
5 files changed, 35 insertions, 41 deletions
diff --git a/src/irc/core/irc-chatnets.c b/src/irc/core/irc-chatnets.c index b4e97e08..5d375869 100644 --- a/src/irc/core/irc-chatnets.c +++ b/src/irc/core/irc-chatnets.c @@ -38,6 +38,8 @@ static void sig_chatnet_read(IRC_CHATNET_REC *rec, CONFIG_NODE *node) if (!IS_IRC_CHATNET(rec)) return; + rec->usermode = g_strdup(config_node_get_str(node, "usermode", NULL)); + rec->max_cmds_at_once = config_node_get_int(node, "cmdmax", 0); rec->cmd_queue_speed = config_node_get_int(node, "cmdspeed", 0); rec->max_query_chans = config_node_get_int(node, "max_query_chans", 0); @@ -53,6 +55,9 @@ static void sig_chatnet_saved(IRC_CHATNET_REC *rec, CONFIG_NODE *node) if (!IS_IRC_CHATNET(rec)) return; + if (rec->usermode != NULL) + iconfig_node_set_str(node, "usermode", rec->usermode); + if (rec->max_cmds_at_once > 0) iconfig_node_set_int(node, "cmdmax", rec->max_cmds_at_once); if (rec->cmd_queue_speed > 0) diff --git a/src/irc/core/irc-chatnets.h b/src/irc/core/irc-chatnets.h index b8d6fb9f..22da90c5 100644 --- a/src/irc/core/irc-chatnets.h +++ b/src/irc/core/irc-chatnets.h @@ -16,6 +16,9 @@ struct _IRC_CHATNET_REC { #include "chatnet-rec.h" + + char *usermode; + int max_cmds_at_once; int cmd_queue_speed; int max_query_chans; /* when syncing, max. number of channels to diff --git a/src/irc/core/irc-servers-reconnect.c b/src/irc/core/irc-servers-reconnect.c index fc77c77c..71a3718e 100644 --- a/src/irc/core/irc-servers-reconnect.c +++ b/src/irc/core/irc-servers-reconnect.c @@ -62,34 +62,6 @@ static void sig_server_reconnect_save_status(IRC_SERVER_CONNECT_REC *conn, conn->usermode = g_strdup(server->wanted_usermode); } -static int sig_set_user_mode(IRC_SERVER_REC *server) -{ - const char *mode; - char *newmode, *args; - - if (g_slist_find(servers, server) == NULL) - return 0; /* got disconnected */ - - mode = server->connrec->usermode; - if (mode == NULL) return 0; - - newmode = server->usermode == NULL ? NULL : - modes_join(server->usermode, mode, FALSE); - - if (server->usermode == NULL) { - /* server didn't set user mode, just set the new one */ - irc_send_cmdv(server, "MODE %s %s", server->nick, mode); - } else if (strcmp(newmode, server->usermode) != 0) { - args = g_strdup_printf("%s -%s+%s", server->nick, - server->usermode, mode); - signal_emit("command mode", 3, server, args, NULL); - g_free(args); - } - - g_free_not_null(newmode); - return 0; -} - static void sig_connected(IRC_SERVER_REC *server) { if (!IS_IRC_SERVER(server) || !server->connrec->reconnection) @@ -97,10 +69,6 @@ static void sig_connected(IRC_SERVER_REC *server) if (server->connrec->away_reason != NULL) signal_emit("command away", 2, server->connrec->away_reason, server, NULL); - if (server->connrec->usermode != NULL) { - /* wait a second and then send the user mode */ - g_timeout_add(1000, (GSourceFunc) sig_set_user_mode, server); - } } static void event_nick_collision(IRC_SERVER_REC *server, const char *data) diff --git a/src/irc/core/irc-servers-setup.c b/src/irc/core/irc-servers-setup.c index 536ea310..8606a470 100644 --- a/src/irc/core/irc-servers-setup.c +++ b/src/irc/core/irc-servers-setup.c @@ -51,6 +51,7 @@ static void sig_server_setup_fill_connect(IRC_SERVER_CONNECT_REC *conn) return; conn->alternate_nick = g_strdup(settings_get_str("alternate_nick")); + conn->usermode = g_strdup(settings_get_str("usermode")); } static void sig_server_setup_fill_chatnet(IRC_SERVER_CONNECT_REC *conn, @@ -60,7 +61,11 @@ static void sig_server_setup_fill_chatnet(IRC_SERVER_CONNECT_REC *conn, return; g_return_if_fail(IS_IRCNET(ircnet)); - if (ircnet->nick) g_free_and_null(conn->alternate_nick); + if (ircnet->nick != NULL) g_free_and_null(conn->alternate_nick); + if (ircnet->usermode != NULL) { + g_free_and_null(conn->usermode); + conn->usermode = g_strdup(ircnet->usermode); + } if (ircnet->max_kicks > 0) conn->max_kicks = ircnet->max_kicks; if (ircnet->max_msgs > 0) conn->max_msgs = ircnet->max_msgs; diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c index 1a082e82..f678777b 100644 --- a/src/irc/core/irc-servers.c +++ b/src/irc/core/irc-servers.c @@ -407,16 +407,32 @@ char *irc_server_get_channels(IRC_SERVER_REC *server) static int sig_set_user_mode(IRC_SERVER_REC *server) { const char *mode; - char *newmode; + char *newmode, *args; if (g_slist_find(servers, server) == NULL) return 0; /* got disconnected */ - mode = settings_get_str("usermode"); + mode = server->connrec->usermode; newmode = server->usermode == NULL ? NULL : modes_join(server->usermode, mode, FALSE); - if (server->usermode == NULL || strcmp(newmode, server->usermode) != 0) + + if (server->usermode == NULL) { + /* server didn't set user mode, just set the new one */ irc_send_cmdv(server, "MODE %s %s", server->nick, mode); + } else if (strcmp(newmode, server->usermode) != 0) { + if (server->connrec->reconnection) { + /* when reconnecting, we want to set exactly the + same mode we had before reconnect */ + args = g_strdup_printf("%s -%s+%s", server->nick, + server->usermode, mode); + } else { + /* allow using modes the server gave us */ + args = g_strdup_printf("%s -%s", server->nick, mode); + } + signal_emit("command mode", 3, server, args, NULL); + g_free(args); + } + g_free_not_null(newmode); return 0; } @@ -424,7 +440,6 @@ static int sig_set_user_mode(IRC_SERVER_REC *server) static void event_connected(IRC_SERVER_REC *server, const char *data, const char *from) { char *params, *nick; - const char *mode; g_return_if_fail(server != NULL); @@ -447,11 +462,9 @@ static void event_connected(IRC_SERVER_REC *server, const char *data, const char server->connected = 1; server->real_connect_time = time(NULL); - if (!server->connrec->reconnection) { + if (server->connrec->usermode != NULL) { /* wait a second and then send the user mode */ - mode = settings_get_str("usermode"); - if (*mode != '\0') - g_timeout_add(1000, (GSourceFunc) sig_set_user_mode, server); + g_timeout_add(1000, (GSourceFunc) sig_set_user_mode, server); } signal_emit("event connected", 1, server); |