mirror of
https://github.com/weechat/weechat.git
synced 2026-07-07 10:13:12 +02:00
Added /cycle command, /part command does close buffer any more
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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"
|
||||
|
||||
+64
-34
@@ -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);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* remove nick from nick list and display message */
|
||||
nick_free (ptr_channel, ptr_nick);
|
||||
if (!command_ignored)
|
||||
{
|
||||
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 : "",
|
||||
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),
|
||||
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");
|
||||
}
|
||||
pos_args,
|
||||
GUI_COLOR(COLOR_WIN_CHAT_DARK));
|
||||
else
|
||||
gui_printf (ptr_channel->buffer, "\n");
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
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
|
||||
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
|
||||
|
||||
@@ -502,6 +502,107 @@ irc_cmd_send_ctcp (t_irc_server *server, t_irc_channel *channel,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
*/
|
||||
|
||||
+4
-1
@@ -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 **);
|
||||
|
||||
Reference in New Issue
Block a user