1
0
mirror of https://github.com/irssi/irssi.git synced 2024-06-23 06:35:36 +00:00

CHANNEL_REC->get_join_data() - Returns the information needed to call

SERVER_REC->channels_join() for this channel. Usually just the channel name,
but may contain also the channel key.

If we receive PART-message to channel that hasn't received a JOIN yet,
don't destroy the channel. It's probably because we did quickly /PART +
/JOIN.

Moved /CYCLE to fe-common/core, it doesn't close the window for the cycled
channel anymore if you had autoclosing on.


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1484 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-05-11 16:08:48 +00:00 committed by cras
parent 7a1e526391
commit 1f23c05ee7
7 changed files with 74 additions and 43 deletions

View File

@ -23,3 +23,8 @@ unsigned int joined:1; /* Have we even received JOIN event for this channel? */
unsigned int left:1; /* You just left the channel */
unsigned int kicked:1; /* You just got kicked */
unsigned int destroying:1;
/* Return the information needed to call SERVER_REC->channels_join() for
this channel. Usually just the channel name, but may contain also the
channel key. */
char *(*get_join_data)(CHANNEL_REC *channel);

View File

@ -30,6 +30,11 @@
GSList *channels; /* List of all channels */
static char *get_join_data(CHANNEL_REC *channel)
{
return g_strdup(channel->name);
}
void channel_init(CHANNEL_REC *channel, int automatic)
{
g_return_if_fail(channel != NULL);
@ -45,6 +50,7 @@ void channel_init(CHANNEL_REC *channel, int automatic)
channel->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "CHANNEL");
channel->mode = g_strdup("");
channel->createtime = time(NULL);
channel->get_join_data = get_join_data;
signal_emit("channel created", 2, channel, GINT_TO_POINTER(automatic));
}

View File

@ -534,6 +534,36 @@ static void cmd_names(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
cmd_params_free(free_arg);
}
/* SYNTAX: CYCLE [<channel>] [<message>] */
static void cmd_cycle(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
CHANNEL_REC *chanrec;
char *channame, *msg, *joindata;
void *free_arg;
g_return_if_fail(data != NULL);
if (!IS_SERVER(server) || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTCHAN,
item, &channame, &msg))
return;
if (*channame == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
chanrec = channel_find(server, channame);
if (chanrec == NULL) cmd_param_error(CMDERR_CHAN_NOT_FOUND);
joindata = chanrec->get_join_data(chanrec);
window_bind_add(window_item_window(chanrec),
chanrec->server->tag, chanrec->name);
channel_destroy(chanrec);
server->channels_join(server, joindata, FALSE);
g_free(joindata);
cmd_params_free(free_arg);
}
void fe_channels_init(void)
{
settings_add_bool("lookandfeel", "autoclose_windows", TRUE);
@ -554,6 +584,7 @@ void fe_channels_init(void)
command_bind("channel remove", NULL, (SIGNAL_FUNC) cmd_channel_remove);
command_bind("channel list", NULL, (SIGNAL_FUNC) cmd_channel_list);
command_bind("names", NULL, (SIGNAL_FUNC) cmd_names);
command_bind("cycle", NULL, (SIGNAL_FUNC) cmd_cycle);
command_set_options("channel add", "auto noauto -bots -botcmd");
command_set_options("names", "ops halfops voices normal");
@ -576,4 +607,5 @@ void fe_channels_deinit(void)
command_unbind("channel remove", (SIGNAL_FUNC) cmd_channel_remove);
command_unbind("channel list", (SIGNAL_FUNC) cmd_channel_list);
command_unbind("names", (SIGNAL_FUNC) cmd_names);
command_unbind("cycle", (SIGNAL_FUNC) cmd_cycle);
}

View File

@ -140,7 +140,7 @@ FORMAT_REC fecommon_irc_formats[] = {
{ "ctcp_reply", "CTCP {hilight $0} reply from {nick $1}: $2", 3, { 0, 0, 0 } },
{ "ctcp_reply_channel", "CTCP {hilight $0} reply from {nick $1} in channel {channel $3}: $2", 4, { 0, 0, 0, 0 } },
{ "ctcp_ping_reply", "CTCP {hilight PING} reply from {nick $0}: $1.$[-3.0]2 seconds", 3, { 0, 2, 2 } },
{ "ctcp_requested", "{ctcp >>> {hilight $0} {comment $1} requested {hilight $2} from {nick $3}}", 4, { 0, 0, 0, 0 } },
{ "ctcp_requested", "{ctcp {hilight $0} {comment $1} requested {hilight $2} from {nick $3}}", 4, { 0, 0, 0, 0 } },
/* ---- */
{ NULL, "Other server events", 0 },

View File

@ -249,7 +249,7 @@ static void event_part(IRC_SERVER_REC *server, const char *data, const char *nic
params = event_get_params(data, 2, &channel, &reason);
chanrec = channel_find(SERVER(server), channel);
if (chanrec != NULL) {
if (chanrec != NULL && chanrec->joined) {
chanrec->left = TRUE;
channel_destroy(chanrec);
}

View File

@ -62,18 +62,6 @@ IRC_CHANNEL_REC *irc_channel_create(IRC_SERVER_REC *server,
return rec;
}
static void sig_channel_destroyed(IRC_CHANNEL_REC *channel)
{
if (!IS_IRC_CHANNEL(channel))
return;
if (channel->server != NULL && !channel->left && !channel->kicked) {
/* destroying channel record without actually
having left the channel yet */
signal_emit("command part", 3, "", channel->server, channel);
}
}
#define get_join_key(key) \
(((key) == NULL || *(key) == '\0') ? "x" : (key))
@ -185,9 +173,36 @@ static void sig_server_looking(SERVER_REC *server)
irc_channels_join;
}
static char *irc_get_join_data(CHANNEL_REC *channel)
{
IRC_CHANNEL_REC *irc_channel = (IRC_CHANNEL_REC *) channel;
return irc_channel->key == NULL ? g_strdup(irc_channel->name) :
g_strconcat(irc_channel->name, " ", irc_channel->key, NULL);
}
static void sig_channel_created(IRC_CHANNEL_REC *channel)
{
if (IS_IRC_CHANNEL(channel))
channel->get_join_data = irc_get_join_data;
}
static void sig_channel_destroyed(IRC_CHANNEL_REC *channel)
{
if (!IS_IRC_CHANNEL(channel))
return;
if (channel->server != NULL && !channel->left && !channel->kicked) {
/* destroying channel record without actually
having left the channel yet */
signal_emit("command part", 3, "", channel->server, channel);
}
}
void irc_channels_init(void)
{
signal_add("server looking", (SIGNAL_FUNC) sig_server_looking);
signal_add("channel created", (SIGNAL_FUNC) sig_channel_created);
signal_add("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
channel_events_init();
@ -205,6 +220,7 @@ void irc_channels_init(void)
void irc_channels_deinit(void)
{
signal_remove("server looking", (SIGNAL_FUNC) sig_server_looking);
signal_remove("channel created", (SIGNAL_FUNC) sig_channel_created);
signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
channel_events_deinit();

View File

@ -664,32 +664,6 @@ static void cmd_wall(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item
cmd_params_free(free_arg);
}
/* SYNTAX: CYCLE [<channel>] [<message>] */
static void cmd_cycle(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{
IRC_CHANNEL_REC *chanrec;
char *channame, *msg;
void *free_arg;
g_return_if_fail(data != NULL);
if (!IS_IRC_SERVER(server) || !server->connected)
cmd_return_error(CMDERR_NOT_CONNECTED);
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTCHAN, item, &channame, &msg))
return;
if (*channame == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
chanrec = irc_channel_find(server, channame);
if (chanrec == NULL) cmd_param_error(CMDERR_CHAN_NOT_FOUND);
irc_send_cmdv(server, *msg == '\0' ? "PART %s" : "PART %s :%s",
channame, msg);
irc_send_cmdv(server, chanrec->key == NULL ? "JOIN %s" : "JOIN %s %s",
channame, chanrec->key);
cmd_params_free(free_arg);
}
/* SYNTAX: KICKBAN [<channel>] <nicks> <reason> */
static void cmd_kickban(const char *data, IRC_SERVER_REC *server,
WI_ITEM_REC *item)
@ -733,7 +707,7 @@ static void cmd_kickban(const char *data, IRC_SERVER_REC *server,
}
g_free(kickcmd);
g_free(bancmd);
cmd_params_free(free_arg);
}
@ -1074,7 +1048,6 @@ void irc_commands_init(void)
command_bind("wallops", NULL, (SIGNAL_FUNC) command_1self);
/* SYNTAX: WALLCHOPS <channel> <message> */
command_bind("wallchops", NULL, (SIGNAL_FUNC) command_2self);
command_bind("cycle", NULL, (SIGNAL_FUNC) cmd_cycle);
command_bind("kickban", NULL, (SIGNAL_FUNC) cmd_kickban);
command_bind("knockout", NULL, (SIGNAL_FUNC) cmd_knockout);
@ -1146,7 +1119,6 @@ void irc_commands_deinit(void)
command_unbind("wait", (SIGNAL_FUNC) cmd_wait);
command_unbind("wallops", (SIGNAL_FUNC) command_1self);
command_unbind("wallchops", (SIGNAL_FUNC) command_2self);
command_unbind("cycle", (SIGNAL_FUNC) cmd_cycle);
command_unbind("kickban", (SIGNAL_FUNC) cmd_kickban);
command_unbind("knockout", (SIGNAL_FUNC) cmd_knockout);
signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);