diff options
Diffstat (limited to 'src/irc')
-rw-r--r-- | src/irc/core/irc-commands.c | 64 | ||||
-rw-r--r-- | src/irc/core/irc-servers.c | 15 | ||||
-rw-r--r-- | src/irc/core/irc.c | 3 |
3 files changed, 22 insertions, 60 deletions
diff --git a/src/irc/core/irc-commands.c b/src/irc/core/irc-commands.c index bd1de2f9..2027fe46 100644 --- a/src/irc/core/irc-commands.c +++ b/src/irc/core/irc-commands.c @@ -102,39 +102,10 @@ static void cmd_connect(const char *data) irc_connect_server(data); } - -/* SYNTAX: DISCONNECT *|<tag> [<message>] */ -static void cmd_disconnect(const char *data, IRC_SERVER_REC *server) -{ - char *tag, *msg, *str; - void *free_arg; - - g_return_if_fail(data != NULL); - - if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &tag, &msg)) - return; - - if (*tag != '\0' && strcmp(tag, "*") != 0) - server = (IRC_SERVER_REC *) server_find_tag(tag); - if (server == NULL || !IS_IRC_SERVER(server)) - cmd_param_error(CMDERR_NOT_CONNECTED); - - if (*msg == '\0') msg = (char *) settings_get_str("quit_message"); - signal_emit("server quit", 2, server, msg); - - if (server->handle != NULL && server->buffer != NULL) { - str = g_strdup_printf("QUIT :%s", msg); - irc_send_cmd_now(server, str); - g_free(str); - } - cmd_params_free(free_arg); - - server_disconnect((SERVER_REC *) server); -} - /* SYNTAX: SERVER [-ircnet <ircnet>] [-host <hostname>] [+]<address>|<ircnet> [<port> [<password> [<nick>]]] */ -static void cmd_server(const char *data, IRC_SERVER_REC *server) +static void cmd_server(const char *data, IRC_SERVER_REC *server, + void *item) { GHashTable *optlist; char *addr, *channels, *away_reason, *usermode, *ircnet; @@ -161,7 +132,8 @@ static void cmd_server(const char *data, IRC_SERVER_REC *server) usermode = g_strdup(server->usermode); away_reason = !server->usermode_away ? NULL : g_strdup(server->away_reason); - cmd_disconnect("* Changing server", server); + signal_emit("command disconnect", 3, + "* Changing server", server, item); } server = IRC_SERVER(irc_connect_server(data)); @@ -181,30 +153,6 @@ static void cmd_server(const char *data, IRC_SERVER_REC *server) cmd_params_free(free_arg); } -/* SYNTAX: QUIT [<message>] */ -static void cmd_quit(const char *data) -{ - GSList *tmp, *next; - const char *quitmsg; - char *str; - - g_return_if_fail(data != NULL); - - quitmsg = *data != '\0' ? data : - settings_get_str("quit_message"); - - /* disconnect from every server */ - for (tmp = servers; tmp != NULL; tmp = next) { - next = tmp->next; - - str = g_strdup_printf("* %s", quitmsg); - cmd_disconnect(str, tmp->data); - g_free(str); - } - - signal_emit("gui exit", 0); -} - /* SYNTAX: MSG [-<server tag>] <targets> <message> */ static void cmd_msg(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) { @@ -995,12 +943,10 @@ void irc_commands_init(void) signal_add("server connected", (SIGNAL_FUNC) sig_connected); command_bind("server", NULL, (SIGNAL_FUNC) cmd_server); command_bind("connect", NULL, (SIGNAL_FUNC) cmd_connect); - command_bind("disconnect", NULL, (SIGNAL_FUNC) cmd_disconnect); command_bind("msg", NULL, (SIGNAL_FUNC) cmd_msg); command_bind("notice", NULL, (SIGNAL_FUNC) cmd_notice); command_bind("ctcp", NULL, (SIGNAL_FUNC) cmd_ctcp); command_bind("nctcp", NULL, (SIGNAL_FUNC) cmd_nctcp); - command_bind("quit", NULL, (SIGNAL_FUNC) cmd_quit); command_bind("join", NULL, (SIGNAL_FUNC) cmd_join); command_bind("part", NULL, (SIGNAL_FUNC) cmd_part); command_bind("kick", NULL, (SIGNAL_FUNC) cmd_kick); @@ -1097,12 +1043,10 @@ void irc_commands_deinit(void) signal_remove("server connected", (SIGNAL_FUNC) sig_connected); command_unbind("server", (SIGNAL_FUNC) cmd_server); command_unbind("connect", (SIGNAL_FUNC) cmd_connect); - command_unbind("disconnect", (SIGNAL_FUNC) cmd_disconnect); command_unbind("msg", (SIGNAL_FUNC) cmd_msg); command_unbind("notice", (SIGNAL_FUNC) cmd_notice); command_unbind("ctcp", (SIGNAL_FUNC) cmd_ctcp); command_unbind("nctcp", (SIGNAL_FUNC) cmd_nctcp); - command_unbind("quit", (SIGNAL_FUNC) cmd_quit); command_unbind("join", (SIGNAL_FUNC) cmd_join); command_unbind("part", (SIGNAL_FUNC) cmd_part); command_unbind("kick", (SIGNAL_FUNC) cmd_kick); diff --git a/src/irc/core/irc-servers.c b/src/irc/core/irc-servers.c index be6bd809..9dfd7ae1 100644 --- a/src/irc/core/irc-servers.c +++ b/src/irc/core/irc-servers.c @@ -172,6 +172,19 @@ static void sig_disconnected(IRC_SERVER_REC *server) g_free_not_null(server->last_invite); } +static void sig_server_quit(IRC_SERVER_REC *server, const char *msg) +{ + char *str; + + if (!IS_IRC_SERVER(server) || server->handle == NULL || + server->buffer == NULL) + return; + + str = g_strdup_printf("QUIT :%s", msg); + irc_send_cmd_now(server, str); + g_free(str); +} + static void server_cmd_timeout(IRC_SERVER_REC *server, GTimeVal *now) { long usecs; @@ -387,6 +400,7 @@ void irc_servers_init(void) signal_add("server connect", (SIGNAL_FUNC) sig_server_connect); signal_add_first("server connected", (SIGNAL_FUNC) sig_connected); signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected); + signal_add_last("server quit", (SIGNAL_FUNC) sig_server_quit); signal_add("event 001", (SIGNAL_FUNC) event_connected); signal_add("event 004", (SIGNAL_FUNC) event_server_info); signal_add("event 465", (SIGNAL_FUNC) event_server_banned); @@ -412,6 +426,7 @@ void irc_servers_deinit(void) signal_remove("server connect", (SIGNAL_FUNC) sig_server_connect); signal_remove("server connected", (SIGNAL_FUNC) sig_connected); signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected); + signal_remove("server quit", (SIGNAL_FUNC) sig_server_quit); signal_remove("event 001", (SIGNAL_FUNC) event_connected); signal_remove("event 004", (SIGNAL_FUNC) event_server_info); signal_remove("event 465", (SIGNAL_FUNC) event_server_banned); diff --git a/src/irc/core/irc.c b/src/irc/core/irc.c index 00c70581..583c55b9 100644 --- a/src/irc/core/irc.c +++ b/src/irc/core/irc.c @@ -348,6 +348,9 @@ static void irc_init_server(IRC_SERVER_REC *server) { g_return_if_fail(server != NULL); + if (!IS_IRC_SERVER(server)) + return; + server->readtag = g_input_add(net_sendbuffer_handle(server->handle), G_INPUT_READ, |