diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2006-03-19 12:15:27 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2006-03-19 12:15:27 +0000 |
commit | e499c1cb32fc400dac7b3061318a298055eeec0b (patch) | |
tree | 2a999a6fb024c26b41bfa9631249df96b105d1bb /src/irc | |
parent | 12b0742668d64f8175b8aa10f2a8f2347782b8e0 (diff) | |
download | weechat-e499c1cb32fc400dac7b3061318a298055eeec0b.zip |
Added /cycle command, /part command does close buffer any more
Diffstat (limited to 'src/irc')
-rw-r--r-- | src/irc/irc-channel.c | 4 | ||||
-rw-r--r-- | src/irc/irc-commands.c | 5 | ||||
-rw-r--r-- | src/irc/irc-recv.c | 94 | ||||
-rw-r--r-- | src/irc/irc-send.c | 101 | ||||
-rw-r--r-- | src/irc/irc.h | 5 |
5 files changed, 176 insertions, 33 deletions
diff --git a/src/irc/irc-channel.c b/src/irc/irc-channel.c index c10295dbd..547a8075f 100644 --- a/src/irc/irc-channel.c +++ b/src/irc/irc-channel.c @@ -67,6 +67,8 @@ channel_new (t_irc_server *server, int channel_type, char *channel_name) new_channel->nicks_count = 0; new_channel->checking_away = 0; new_channel->away_message = NULL; + new_channel->cycle = 0; + new_channel->close = 0; new_channel->nicks = NULL; new_channel->last_nick = NULL; @@ -493,6 +495,8 @@ channel_print_log (t_irc_channel *channel) weechat_log_printf (" key. . . . . : '%s'\n", channel->key); weechat_log_printf (" checking_away: %d\n", channel->checking_away); weechat_log_printf (" away_message : '%s'\n", channel->away_message); + weechat_log_printf (" cycle. . . . : %d\n", channel->cycle); + weechat_log_printf (" close. . . . : %d\n", channel->close); weechat_log_printf (" nicks. . . . : 0x%X\n", channel->nicks); weechat_log_printf (" last_nick. . : 0x%X\n", channel->last_nick); weechat_log_printf (" buffer . . . : 0x%X\n", channel->buffer); diff --git a/src/irc/irc-commands.c b/src/irc/irc-commands.c index 5df7b645e..9bd4685be 100644 --- a/src/irc/irc-commands.c +++ b/src/irc/irc-commands.c @@ -59,6 +59,11 @@ t_irc_command irc_commands[] = " type: CTCP type (examples: \"version\", \"ping\", ..)\n" "arguments: arguments for CTCP"), "%n action|ping|version", 2, MAX_ARGS, 1, NULL, irc_cmd_send_ctcp, NULL }, + { "cycle", N_("leave and rejoin a channel"), + N_("[channel[,channel]] [part_message]"), + N_(" channel: channel name for cycle\n" + "part_message: part message (displayed to other users)"), + "%p", 0, MAX_ARGS, 1, NULL, irc_cmd_send_cycle, NULL }, { "dcc", N_("starts DCC (file or chat) or close chat"), N_("action [nickname [file]]"), N_(" action: 'send' (file) or 'chat' or 'close' (chat)\n" diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c index 6a77bbb61..51d3ed7ad 100644 --- a/src/irc/irc-recv.c +++ b/src/irc/irc-recv.c @@ -1414,7 +1414,8 @@ irc_cmd_recv_notice (t_irc_server *server, char *host, char *nick, char *argumen int irc_cmd_recv_part (t_irc_server *server, char *host, char *nick, char *arguments) { - char *pos, *pos_args; + char *pos, *pos_args, *join_string; + int join_length; t_irc_channel *ptr_channel; t_irc_nick *ptr_nick; @@ -1446,46 +1447,75 @@ irc_cmd_recv_part (t_irc_server *server, char *host, char *nick, char *arguments ptr_nick = nick_search (ptr_channel, nick); if (ptr_nick) { - if (strcmp (ptr_nick->nick, server->nick) == 0) + /* display part message */ + if (!command_ignored) { - /* part request was issued by local client */ - gui_buffer_free (ptr_channel->buffer, 1); - channel_free (server, ptr_channel); - gui_draw_buffer_status (gui_current_window->buffer, 1); - gui_draw_buffer_input (gui_current_window->buffer, 1); + pos = strchr (host, '!'); + irc_display_prefix (server, ptr_channel->buffer, PREFIX_PART); + gui_printf (ptr_channel->buffer, _("%s%s %s(%s%s%s)%s has left %s%s"), + GUI_COLOR(COLOR_WIN_CHAT_NICK), + nick, + GUI_COLOR(COLOR_WIN_CHAT_DARK), + GUI_COLOR(COLOR_WIN_CHAT_HOST), + (pos) ? pos + 1 : "", + GUI_COLOR(COLOR_WIN_CHAT_DARK), + GUI_COLOR(COLOR_WIN_CHAT), + GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), + ptr_channel->name); + if (pos_args && pos_args[0]) + gui_printf (ptr_channel->buffer, " %s(%s%s%s)\n", + GUI_COLOR(COLOR_WIN_CHAT_DARK), + GUI_COLOR(COLOR_WIN_CHAT), + pos_args, + GUI_COLOR(COLOR_WIN_CHAT_DARK)); + else + gui_printf (ptr_channel->buffer, "\n"); } - else - { - /* remove nick from nick list and display message */ - nick_free (ptr_channel, ptr_nick); - if (!command_ignored) + /* part request was issued by local client ? */ + if (strcmp (ptr_nick->nick, server->nick) == 0) + { + nick_free_all (ptr_channel); + + /* cycling ? => rejoin channel immediately */ + if (ptr_channel->cycle) { - pos = strchr (host, '!'); - irc_display_prefix (server, ptr_channel->buffer, PREFIX_PART); - gui_printf (ptr_channel->buffer, _("%s%s %s(%s%s%s)%s has left %s%s"), - GUI_COLOR(COLOR_WIN_CHAT_NICK), - nick, - GUI_COLOR(COLOR_WIN_CHAT_DARK), - GUI_COLOR(COLOR_WIN_CHAT_HOST), - (pos) ? pos + 1 : "", - GUI_COLOR(COLOR_WIN_CHAT_DARK), - GUI_COLOR(COLOR_WIN_CHAT), - GUI_COLOR(COLOR_WIN_CHAT_CHANNEL), - ptr_channel->name); - if (pos_args && pos_args[0]) - gui_printf (ptr_channel->buffer, " %s(%s%s%s)\n", - GUI_COLOR(COLOR_WIN_CHAT_DARK), - GUI_COLOR(COLOR_WIN_CHAT), - pos_args, - GUI_COLOR(COLOR_WIN_CHAT_DARK)); + ptr_channel->cycle = 0; + if (ptr_channel->key) + { + join_length = strlen (ptr_channel->name) + 1 + + strlen (ptr_channel->key) + 1; + join_string = (char *)malloc (join_length); + if (join_string) + { + snprintf (join_string, join_length, "%s %s", + ptr_channel->name, + ptr_channel->key); + irc_cmd_send_join(server, ptr_channel, join_string); + free (join_string); + } + else + irc_cmd_send_join(server, ptr_channel, ptr_channel->name); + } else - gui_printf (ptr_channel->buffer, "\n"); + irc_cmd_send_join(server, ptr_channel, ptr_channel->name); } - + if (ptr_channel->close) + { + gui_buffer_free (ptr_channel->buffer, 1); + channel_free (server, ptr_channel); + ptr_channel = NULL; + } + } + else + nick_free (ptr_channel, ptr_nick); + + if (ptr_channel) + { gui_draw_buffer_nick (ptr_channel->buffer, 1); gui_draw_buffer_status (ptr_channel->buffer, 1); } + gui_draw_buffer_input (gui_current_window->buffer, 1); } } else diff --git a/src/irc/irc-send.c b/src/irc/irc-send.c index b021714cf..b928124b4 100644 --- a/src/irc/irc-send.c +++ b/src/irc/irc-send.c @@ -503,6 +503,107 @@ irc_cmd_send_ctcp (t_irc_server *server, t_irc_channel *channel, } /* + * irc_cmd_send_cycle: leave and rejoin a channel + */ + +int +irc_cmd_send_cycle (t_irc_server *server, t_irc_channel *channel, + char *arguments) +{ + t_gui_buffer *buffer; + char *channel_name, *pos_args, *ptr_arg, *buf; + t_irc_channel *ptr_channel; + char **channels; + int i, argc; + + irc_find_context (server, channel, NULL, &buffer); + + if (arguments) + { + if (string_is_channel (arguments)) + { + channel_name = arguments; + pos_args = strchr (arguments, ' '); + if (pos_args) + { + pos_args[0] = '\0'; + pos_args++; + while (pos_args[0] == ' ') + pos_args++; + } + channels = explode_string (channel_name, ",", 0, &argc); + if (channels) + { + for (i = 0; i < argc; i++) + { + ptr_channel = channel_search (server, channels[i]); + /* mark channal as cycling */ + if (ptr_channel && + (ptr_channel->type == CHANNEL_TYPE_CHANNEL)) + ptr_channel->cycle = 1; + } + free_exploded_string (channels); + } + } + else + { + if (BUFFER_IS_SERVER(buffer)) + { + irc_display_prefix (NULL, server->buffer, PREFIX_ERROR); + gui_printf_nolog (server->buffer, + _("%s \"%s\" command can not be executed on a server buffer\n"), + WEECHAT_ERROR, "cycle"); + return -1; + } + + /* does nothing on private buffer (cycle has no sense!) */ + if (BUFFER_IS_PRIVATE(buffer)) + return 0; + + channel_name = CHANNEL(buffer)->name; + pos_args = arguments; + CHANNEL(buffer)->cycle = 1; + } + } + else + { + if (BUFFER_IS_SERVER(buffer)) + { + irc_display_prefix (NULL, server->buffer, PREFIX_ERROR); + gui_printf_nolog (server->buffer, + _("%s \"%s\" command can not be executed on a server buffer\n"), + WEECHAT_ERROR, "part"); + return -1; + } + + /* does nothing on private buffer (cycle has no sense!) */ + if (BUFFER_IS_PRIVATE(buffer)) + return 0; + + channel_name = CHANNEL(buffer)->name; + pos_args = NULL; + CHANNEL(buffer)->cycle = 1; + } + + ptr_arg = (pos_args) ? pos_args : + (cfg_irc_default_msg_part && cfg_irc_default_msg_part[0]) ? + cfg_irc_default_msg_part : NULL; + + if (ptr_arg) + { + buf = weechat_strreplace (ptr_arg, "%v", PACKAGE_VERSION); + server_sendf (server, "PART %s :%s\r\n", channel_name, + (buf) ? buf : ptr_arg); + if (buf) + free (buf); + } + else + server_sendf (server, "PART %s\r\n", channel_name); + + return 0; +} + +/* * irc_cmd_send_dcc: start DCC (file or chat) */ diff --git a/src/irc/irc.h b/src/irc/irc.h index 297f5ca48..94a116318 100644 --- a/src/irc/irc.h +++ b/src/irc/irc.h @@ -111,6 +111,8 @@ struct t_irc_channel int nicks_count; /* # nicks on channel (0 if dcc/pv) */ int checking_away; /* = 1 if checking away with WHO cmd */ char *away_message; /* to display away only once in private */ + int cycle; /* currently cycling (/part then /join) */ + int close; /* close request (/buffer close) */ t_irc_nick *nicks; /* nicks on the channel */ t_irc_nick *last_nick; /* last nick on the channel */ t_gui_buffer *buffer; /* GUI buffer allocated for channel */ @@ -189,7 +191,7 @@ struct t_irc_command char *completion_template; /* template for completion */ /* NULL=no completion, ""=default (nick) */ int min_arg, max_arg; /* min & max number of arguments */ - int need_connection; /* = 1 if cmd needs server connection */ + int needs_connection; /* = 1 if cmd needs server connection */ int (*cmd_function_args)(t_irc_server *, t_irc_channel *, int, char **); /* function called when user enters cmd */ int (*cmd_function_1arg)(t_irc_server *, t_irc_channel *, char *); @@ -414,6 +416,7 @@ extern int irc_cmd_send_amsg (t_irc_server *, t_irc_channel *, char *); extern int irc_cmd_send_away (t_irc_server *, t_irc_channel *, char *); extern int irc_cmd_send_ban (t_irc_server *, t_irc_channel *, char *); extern int irc_cmd_send_ctcp (t_irc_server *, t_irc_channel *, char *); +extern int irc_cmd_send_cycle (t_irc_server *, t_irc_channel *, char *); extern int irc_cmd_send_dcc (t_irc_server *, t_irc_channel *, char *); extern int irc_cmd_send_dehalfop (t_irc_server *, t_irc_channel *, int, char **); extern int irc_cmd_send_deop (t_irc_server *, t_irc_channel *, int, char **); |