2000-04-26 04:03:38 -04:00
|
|
|
/*
|
2000-08-26 11:39:44 -04:00
|
|
|
irc-channels.c : irssi
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
#include "bans.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "irc-channels.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "channels-setup.h"
|
|
|
|
#include "irc.h"
|
|
|
|
#include "modes.h"
|
|
|
|
#include "levels.h"
|
|
|
|
#include "mode-lists.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "irc-nicklist.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-04-27 06:31:14 -04:00
|
|
|
void channels_query_init(void);
|
|
|
|
void channels_query_deinit(void);
|
|
|
|
|
|
|
|
void channel_events_init(void);
|
|
|
|
void channel_events_deinit(void);
|
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
void channel_rejoin_init(void);
|
|
|
|
void channel_rejoin_deinit(void);
|
|
|
|
|
2000-04-27 06:31:14 -04:00
|
|
|
void massjoin_init(void);
|
|
|
|
void massjoin_deinit(void);
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
IRC_CHANNEL_REC *irc_channel_create(IRC_SERVER_REC *server,
|
|
|
|
const char *name, int automatic)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-08-26 11:39:44 -04:00
|
|
|
IRC_CHANNEL_REC *rec;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
g_return_val_if_fail(server == NULL || IS_IRC_SERVER(server), NULL);
|
|
|
|
g_return_val_if_fail(name != NULL, NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
rec = g_new0(IRC_CHANNEL_REC, 1);
|
2000-08-31 20:26:46 -04:00
|
|
|
rec->chat_type = IRC_PROTOCOL;
|
2000-08-26 11:39:44 -04:00
|
|
|
rec->name = g_strdup(name);
|
2000-04-26 04:03:38 -04:00
|
|
|
rec->server = server;
|
2000-08-26 11:39:44 -04:00
|
|
|
if (*name == '+') rec->no_modes = TRUE;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
channel_init((CHANNEL_REC *) rec, automatic);
|
2000-04-26 04:03:38 -04:00
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
static void sig_channel_create(IRC_CHANNEL_REC **channel,
|
|
|
|
void *chat_type, IRC_SERVER_REC *server,
|
|
|
|
const char *name, void *automatic)
|
|
|
|
{
|
|
|
|
if (chat_protocol_lookup("IRC") != GPOINTER_TO_INT(chat_type))
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_return_if_fail(server == NULL || IS_IRC_SERVER(server));
|
|
|
|
g_return_if_fail(channel != NULL);
|
|
|
|
g_return_if_fail(name != NULL);
|
|
|
|
|
|
|
|
*channel = irc_channel_create(server, name,
|
|
|
|
GPOINTER_TO_INT(automatic));
|
|
|
|
signal_stop();
|
|
|
|
}
|
|
|
|
|
2000-08-27 19:07:01 -04:00
|
|
|
static void sig_channel_destroyed(IRC_CHANNEL_REC *channel)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-08-26 11:39:44 -04:00
|
|
|
if (!IS_IRC_CHANNEL(channel))
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
if (channel->server != NULL && !channel->left && !channel->kicked) {
|
2000-08-26 11:39:44 -04:00
|
|
|
/* destroying channel record without actually
|
|
|
|
having left the channel yet */
|
2000-04-26 04:03:38 -04:00
|
|
|
irc_send_cmdv(channel->server, "PART %s", channel->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define get_join_key(key) \
|
|
|
|
(((key) == NULL || *(key) == '\0') ? "x" : (key))
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
void irc_channels_join(IRC_SERVER_REC *server, const char *data, int automatic)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-08-26 11:39:44 -04:00
|
|
|
CHANNEL_SETUP_REC *schannel;
|
|
|
|
IRC_CHANNEL_REC *chanrec;
|
2000-04-26 04:03:38 -04:00
|
|
|
GString *outchans, *outkeys;
|
2000-06-17 21:18:12 -04:00
|
|
|
char *channels, *keys, *key;
|
2000-04-26 04:03:38 -04:00
|
|
|
char **chanlist, **keylist, **tmp, **tmpkey, *channel;
|
2000-06-17 21:18:12 -04:00
|
|
|
void *free_arg;
|
2000-05-04 06:32:42 -04:00
|
|
|
int use_keys;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
2000-08-26 11:39:44 -04:00
|
|
|
if (!IS_IRC_SERVER(server) || !server->connected)
|
2000-04-26 04:03:38 -04:00
|
|
|
cmd_return_error(CMDERR_NOT_CONNECTED);
|
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &channels, &keys))
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
if (*channels == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
|
|
|
|
|
|
|
chanlist = g_strsplit(channels, ",", -1);
|
|
|
|
keylist = g_strsplit(keys, ",", -1);
|
|
|
|
|
|
|
|
outchans = g_string_new(NULL);
|
|
|
|
outkeys = g_string_new(NULL);
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
use_keys = *keys != '\0';
|
2000-04-26 04:03:38 -04:00
|
|
|
tmpkey = keylist;
|
|
|
|
for (tmp = chanlist; *tmp != NULL; tmp++) {
|
|
|
|
channel = ischannel(**tmp) ? g_strdup(*tmp) :
|
|
|
|
g_strdup_printf("#%s", *tmp);
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
chanrec = irc_channel_find(server, channel);
|
2000-05-04 06:32:42 -04:00
|
|
|
if (chanrec == NULL) {
|
2000-08-26 11:39:44 -04:00
|
|
|
schannel = channels_setup_find(channel, server->connrec->chatnet);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
g_string_sprintfa(outchans, "%s,", channel);
|
2000-07-20 08:35:54 -04:00
|
|
|
if (*tmpkey != NULL && **tmpkey != '\0')
|
|
|
|
key = *tmpkey;
|
|
|
|
else if (schannel != NULL && schannel->password != NULL) {
|
2000-05-04 06:32:42 -04:00
|
|
|
/* get password from setup record */
|
|
|
|
use_keys = TRUE;
|
2000-05-15 04:25:45 -04:00
|
|
|
key = schannel->password;
|
2000-07-20 08:35:54 -04:00
|
|
|
} else key = NULL;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-05-15 04:25:45 -04:00
|
|
|
g_string_sprintfa(outkeys, "%s,", get_join_key(key));
|
2000-08-26 11:39:44 -04:00
|
|
|
chanrec = irc_channel_create(server, channel + (channel[0] == '!' && channel[1] == '!'), automatic);
|
2000-05-15 04:25:45 -04:00
|
|
|
if (key != NULL) chanrec->key = g_strdup(key);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
g_free(channel);
|
|
|
|
|
|
|
|
if (*tmpkey != NULL)
|
|
|
|
tmpkey++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outchans->len > 0) {
|
2000-05-15 04:25:45 -04:00
|
|
|
g_string_truncate(outchans, outchans->len-1);
|
|
|
|
g_string_truncate(outkeys, outkeys->len-1);
|
2000-05-04 06:32:42 -04:00
|
|
|
irc_send_cmdv(server, use_keys ? "JOIN %s %s" : "JOIN %s",
|
2000-04-26 04:03:38 -04:00
|
|
|
outchans->str, outkeys->str);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_free(outchans, TRUE);
|
|
|
|
g_string_free(outkeys, TRUE);
|
|
|
|
|
|
|
|
g_strfreev(chanlist);
|
|
|
|
g_strfreev(keylist);
|
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
/* function for finding IRC channels - adds support for !channels */
|
|
|
|
static CHANNEL_REC *irc_channel_find_server(SERVER_REC *server,
|
|
|
|
const char *channel)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-08-26 11:39:44 -04:00
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
|
|
|
|
CHANNEL_REC *rec = tmp->data;
|
|
|
|
|
2000-08-31 20:26:46 -04:00
|
|
|
if (rec->chat_type != server->chat_type)
|
2000-08-26 11:39:44 -04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (g_strcasecmp(channel, rec->name) == 0)
|
|
|
|
return rec;
|
|
|
|
|
|
|
|
/* check after removing ABCDE from !ABCDEchannel */
|
|
|
|
if (*channel == '!' && *rec->name == '!' &&
|
|
|
|
g_strcasecmp(channel+1, rec->name+6) == 0)
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_connected(SERVER_REC *server)
|
|
|
|
{
|
|
|
|
if (!IS_IRC_SERVER(server))
|
|
|
|
return;
|
|
|
|
|
|
|
|
server->channel_find_func = (void *) irc_channel_find_server;
|
|
|
|
}
|
|
|
|
|
|
|
|
void irc_channels_init(void)
|
|
|
|
{
|
2000-09-02 14:53:58 -04:00
|
|
|
signal_add("channel create", (SIGNAL_FUNC) sig_channel_create);
|
2000-08-26 11:39:44 -04:00
|
|
|
signal_add("server connected", (SIGNAL_FUNC) sig_connected);
|
2000-08-30 18:29:55 -04:00
|
|
|
signal_add("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
|
2000-08-26 11:39:44 -04:00
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
channel_events_init();
|
2000-05-15 04:25:45 -04:00
|
|
|
channel_rejoin_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
channels_query_init();
|
|
|
|
channels_setup_init();
|
|
|
|
|
|
|
|
bans_init();
|
|
|
|
modes_init();
|
|
|
|
mode_lists_init();
|
|
|
|
massjoin_init();
|
2000-08-26 11:39:44 -04:00
|
|
|
irc_nicklist_init();
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-08-26 11:39:44 -04:00
|
|
|
void irc_channels_deinit(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-09-02 14:53:58 -04:00
|
|
|
signal_remove("channel create", (SIGNAL_FUNC) sig_channel_create);
|
2000-08-26 11:39:44 -04:00
|
|
|
signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
|
2000-08-30 18:29:55 -04:00
|
|
|
signal_remove("channel destroyed", (SIGNAL_FUNC) sig_channel_destroyed);
|
2000-08-26 11:39:44 -04:00
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
channel_events_deinit();
|
2000-05-15 04:25:45 -04:00
|
|
|
channel_rejoin_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
channels_query_deinit();
|
|
|
|
channels_setup_deinit();
|
|
|
|
|
|
|
|
bans_deinit();
|
|
|
|
modes_deinit();
|
|
|
|
mode_lists_deinit();
|
|
|
|
massjoin_deinit();
|
2000-08-26 11:39:44 -04:00
|
|
|
irc_nicklist_deinit();
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|