1
0
mirror of https://github.com/irssi/irssi.git synced 2024-08-04 03:34:18 -04:00

Move to a single /join function, avoiding confusion on "/join -window".

patch by exg
bug #644, thanks for the useful bug report


git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@5023 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Jilles Tjoelker 2009-02-27 14:32:33 +00:00 committed by jilles
parent d979a991c8
commit c57f58dea5
3 changed files with 33 additions and 111 deletions

View File

@ -314,37 +314,6 @@ static void cmd_quit(const char *data)
signal_emit("gui exit", 0); signal_emit("gui exit", 0);
} }
/* SYNTAX: JOIN [-window] [-invite] [-<server tag>] <channels> [<keys>] */
static void cmd_join(const char *data, SERVER_REC *server)
{
GHashTable *optlist;
char *channels;
void *free_arg;
g_return_if_fail(data != NULL);
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
"join", &optlist, &channels))
return;
/* -<server tag> */
server = cmd_options_get_server("join", optlist, server);
if (server == NULL || !server->connected)
cmd_param_error(CMDERR_NOT_CONNECTED);
if (g_hash_table_lookup(optlist, "invite"))
channels = server->last_invite;
else {
if (*channels == '\0')
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
}
if (channels != NULL)
server->channels_join(server, channels, FALSE);
cmd_params_free(free_arg);
}
/* SYNTAX: MSG [-<server tag>] [-channel | -nick] <targets> <message> */ /* SYNTAX: MSG [-<server tag>] [-channel | -nick] <targets> <message> */
static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item) static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{ {
@ -475,7 +444,6 @@ void chat_commands_init(void)
command_bind("connect", NULL, (SIGNAL_FUNC) cmd_connect); command_bind("connect", NULL, (SIGNAL_FUNC) cmd_connect);
command_bind("disconnect", NULL, (SIGNAL_FUNC) cmd_disconnect); command_bind("disconnect", NULL, (SIGNAL_FUNC) cmd_disconnect);
command_bind("quit", NULL, (SIGNAL_FUNC) cmd_quit); command_bind("quit", NULL, (SIGNAL_FUNC) cmd_quit);
command_bind("join", NULL, (SIGNAL_FUNC) cmd_join);
command_bind("msg", NULL, (SIGNAL_FUNC) cmd_msg); command_bind("msg", NULL, (SIGNAL_FUNC) cmd_msg);
command_bind("foreach", NULL, (SIGNAL_FUNC) cmd_foreach); command_bind("foreach", NULL, (SIGNAL_FUNC) cmd_foreach);
command_bind("foreach server", NULL, (SIGNAL_FUNC) cmd_foreach_server); command_bind("foreach server", NULL, (SIGNAL_FUNC) cmd_foreach_server);
@ -486,7 +454,6 @@ void chat_commands_init(void)
signal_add("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg); signal_add("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg);
command_set_options("connect", "4 6 !! -network ssl +ssl_cert +ssl_pkey ssl_verify +ssl_cafile +ssl_capath +host noproxy -rawlog"); command_set_options("connect", "4 6 !! -network ssl +ssl_cert +ssl_pkey ssl_verify +ssl_cafile +ssl_capath +host noproxy -rawlog");
command_set_options("join", "invite");
command_set_options("msg", "channel nick"); command_set_options("msg", "channel nick");
} }
@ -497,7 +464,6 @@ void chat_commands_deinit(void)
command_unbind("connect", (SIGNAL_FUNC) cmd_connect); command_unbind("connect", (SIGNAL_FUNC) cmd_connect);
command_unbind("disconnect", (SIGNAL_FUNC) cmd_disconnect); command_unbind("disconnect", (SIGNAL_FUNC) cmd_disconnect);
command_unbind("quit", (SIGNAL_FUNC) cmd_quit); command_unbind("quit", (SIGNAL_FUNC) cmd_quit);
command_unbind("join", (SIGNAL_FUNC) cmd_join);
command_unbind("msg", (SIGNAL_FUNC) cmd_msg); command_unbind("msg", (SIGNAL_FUNC) cmd_msg);
command_unbind("foreach", (SIGNAL_FUNC) cmd_foreach); command_unbind("foreach", (SIGNAL_FUNC) cmd_foreach);
command_unbind("foreach server", (SIGNAL_FUNC) cmd_foreach_server); command_unbind("foreach server", (SIGNAL_FUNC) cmd_foreach_server);

View File

@ -110,47 +110,31 @@ static void sig_channel_joined(CHANNEL_REC *channel)
fe_channels_nicklist(channel, CHANNEL_NICKLIST_FLAG_ALL); fe_channels_nicklist(channel, CHANNEL_NICKLIST_FLAG_ALL);
} }
static void cmd_wjoin_pre(const char *data, SERVER_REC *server) /* SYNTAX: JOIN [-window] [-invite] [-<server tag>] <channels> [<keys>] */
{
GHashTable *optlist;
char *nick;
void *free_arg;
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
"join", &optlist, &nick))
return;
/* kludge for /join -invite -window if there is no invite */
if (g_hash_table_lookup(optlist, "invite") &&
server != NULL && server->last_invite == NULL) {
cmd_params_free(free_arg);
return;
}
if (g_hash_table_lookup(optlist, "window") != NULL) {
signal_add("channel created",
(SIGNAL_FUNC) signal_channel_created_curwin);
}
cmd_params_free(free_arg);
}
static void cmd_join(const char *data, SERVER_REC *server) static void cmd_join(const char *data, SERVER_REC *server)
{ {
WINDOW_REC *window; WINDOW_REC *window;
CHANNEL_REC *channel; CHANNEL_REC *channel;
GHashTable *optlist; GHashTable *optlist;
char *channelname; char *pdata;
int invite;
int samewindow;
void *free_arg; void *free_arg;
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS | if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
PARAM_FLAG_UNKNOWN_OPTIONS, PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
"join", &optlist, &channelname)) "join", &optlist, &pdata))
return; return;
invite = g_hash_table_lookup(optlist, "invite") != NULL;
samewindow = g_hash_table_lookup(optlist, "window") != NULL;
if (!invite && *pdata == '\0')
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
/* -<server tag> */ /* -<server tag> */
server = cmd_options_get_server("join", optlist, server); server = cmd_options_get_server("join", optlist, server);
channel = channel_find(server, channelname); channel = channel_find(server, pdata);
if (channel != NULL) { if (channel != NULL) {
/* already joined to channel, set it active */ /* already joined to channel, set it active */
window = window_item_window(channel); window = window_item_window(channel);
@ -159,23 +143,25 @@ static void cmd_join(const char *data, SERVER_REC *server)
window_item_set_active(active_win, (WI_ITEM_REC *) channel); window_item_set_active(active_win, (WI_ITEM_REC *) channel);
} }
cmd_params_free(free_arg); else {
} if (server == NULL || !server->connected)
cmd_param_error(CMDERR_NOT_CONNECTED);
static void cmd_wjoin_post(const char *data) if (invite) {
{ if (server->last_invite == NULL) {
GHashTable *optlist; printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_NOT_INVITED);
char *nick; signal_stop();
void *free_arg; cmd_params_free(free_arg);
return;
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS | }
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST, pdata = server->last_invite;
"join", &optlist, &nick)) }
return; if (samewindow)
signal_add("channel created",
if (g_hash_table_lookup(optlist, "window") != NULL) { (SIGNAL_FUNC) signal_channel_created_curwin);
signal_remove("channel created", server->channels_join(server, pdata, FALSE);
(SIGNAL_FUNC) signal_channel_created_curwin); if (samewindow)
signal_remove("channel created",
(SIGNAL_FUNC) signal_channel_created_curwin);
} }
cmd_params_free(free_arg); cmd_params_free(free_arg);
} }
@ -632,9 +618,7 @@ void fe_channels_init(void)
signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected); signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected);
signal_add_last("channel joined", (SIGNAL_FUNC) sig_channel_joined); signal_add_last("channel joined", (SIGNAL_FUNC) sig_channel_joined);
command_bind_first("join", NULL, (SIGNAL_FUNC) cmd_wjoin_pre);
command_bind("join", NULL, (SIGNAL_FUNC) cmd_join); command_bind("join", NULL, (SIGNAL_FUNC) cmd_join);
command_bind_last("join", NULL, (SIGNAL_FUNC) cmd_wjoin_post);
command_bind("channel", NULL, (SIGNAL_FUNC) cmd_channel); command_bind("channel", NULL, (SIGNAL_FUNC) cmd_channel);
command_bind("channel add", NULL, (SIGNAL_FUNC) cmd_channel_add); command_bind("channel add", NULL, (SIGNAL_FUNC) cmd_channel_add);
command_bind("channel remove", NULL, (SIGNAL_FUNC) cmd_channel_remove); command_bind("channel remove", NULL, (SIGNAL_FUNC) cmd_channel_remove);
@ -644,7 +628,7 @@ void fe_channels_init(void)
command_set_options("channel add", "auto noauto -bots -botcmd"); command_set_options("channel add", "auto noauto -bots -botcmd");
command_set_options("names", "count ops halfops voices normal"); command_set_options("names", "count ops halfops voices normal");
command_set_options("join", "window"); command_set_options("join", "invite window");
} }
void fe_channels_deinit(void) void fe_channels_deinit(void)
@ -655,9 +639,7 @@ void fe_channels_deinit(void)
signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected); signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
signal_remove("channel joined", (SIGNAL_FUNC) sig_channel_joined); signal_remove("channel joined", (SIGNAL_FUNC) sig_channel_joined);
command_unbind("join", (SIGNAL_FUNC) cmd_wjoin_pre);
command_unbind("join", (SIGNAL_FUNC) cmd_join); command_unbind("join", (SIGNAL_FUNC) cmd_join);
command_unbind("join", (SIGNAL_FUNC) cmd_wjoin_post);
command_unbind("channel", (SIGNAL_FUNC) cmd_channel); command_unbind("channel", (SIGNAL_FUNC) cmd_channel);
command_unbind("channel add", (SIGNAL_FUNC) cmd_channel_add); command_unbind("channel add", (SIGNAL_FUNC) cmd_channel_add);
command_unbind("channel remove", (SIGNAL_FUNC) cmd_channel_remove); command_unbind("channel remove", (SIGNAL_FUNC) cmd_channel_remove);

View File

@ -169,30 +169,6 @@ static void cmd_nick(const char *data, SERVER_REC *server)
signal_stop(); signal_stop();
} }
static void cmd_join(const char *data, SERVER_REC *server)
{
GHashTable *optlist;
char *channels;
void *free_arg;
g_return_if_fail(data != NULL);
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
"join", &optlist, &channels))
return;
server = cmd_options_get_server("join", optlist, server);
if (g_hash_table_lookup(optlist, "invite") &&
server != NULL && server->last_invite == NULL) {
/* ..all this trouble just to print this error message */
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_NOT_INVITED);
signal_stop();
}
cmd_params_free(free_arg);
}
/* SYNTAX: UPTIME */ /* SYNTAX: UPTIME */
static void cmd_uptime(char *data) static void cmd_uptime(char *data)
{ {
@ -344,7 +320,6 @@ void fe_core_commands_init(void)
command_bind("beep", NULL, (SIGNAL_FUNC) cmd_beep); command_bind("beep", NULL, (SIGNAL_FUNC) cmd_beep);
command_bind("uptime", NULL, (SIGNAL_FUNC) cmd_uptime); command_bind("uptime", NULL, (SIGNAL_FUNC) cmd_uptime);
command_bind_first("nick", NULL, (SIGNAL_FUNC) cmd_nick); command_bind_first("nick", NULL, (SIGNAL_FUNC) cmd_nick);
command_bind_first("join", NULL, (SIGNAL_FUNC) cmd_join);
signal_add("send command", (SIGNAL_FUNC) event_command); signal_add("send command", (SIGNAL_FUNC) event_command);
signal_add_last("send command", (SIGNAL_FUNC) event_command_last); signal_add_last("send command", (SIGNAL_FUNC) event_command_last);
@ -363,7 +338,6 @@ void fe_core_commands_deinit(void)
command_unbind("beep", (SIGNAL_FUNC) cmd_beep); command_unbind("beep", (SIGNAL_FUNC) cmd_beep);
command_unbind("uptime", (SIGNAL_FUNC) cmd_uptime); command_unbind("uptime", (SIGNAL_FUNC) cmd_uptime);
command_unbind("nick", (SIGNAL_FUNC) cmd_nick); command_unbind("nick", (SIGNAL_FUNC) cmd_nick);
command_unbind("join", (SIGNAL_FUNC) cmd_join);
signal_remove("send command", (SIGNAL_FUNC) event_command); signal_remove("send command", (SIGNAL_FUNC) event_command);
signal_remove("send command", (SIGNAL_FUNC) event_command_last); signal_remove("send command", (SIGNAL_FUNC) event_command_last);