2000-04-26 04:03:38 -04:00
|
|
|
/*
|
|
|
|
fe-channels.c : irssi
|
|
|
|
|
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
|
|
|
|
|
|
|
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 "module-formats.h"
|
|
|
|
#include "modules.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "commands.h"
|
|
|
|
#include "levels.h"
|
2000-05-04 06:32:42 -04:00
|
|
|
#include "misc.h"
|
2000-06-17 08:22:56 -04:00
|
|
|
#include "settings.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-02-17 14:44:22 -05:00
|
|
|
#include "chat-protocols.h"
|
|
|
|
#include "chatnets.h"
|
2001-01-01 02:45:54 -05:00
|
|
|
#include "channels.h"
|
2000-05-04 06:32:42 -04:00
|
|
|
#include "channels-setup.h"
|
|
|
|
#include "nicklist.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-11-17 11:27:14 -05:00
|
|
|
#include "fe-windows.h"
|
2001-03-03 19:14:00 -05:00
|
|
|
#include "fe-channels.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "window-items.h"
|
2000-10-28 16:14:19 -04:00
|
|
|
#include "printtext.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-01 02:45:54 -05:00
|
|
|
static void signal_channel_created(CHANNEL_REC *channel, void *automatic)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-03-03 16:57:31 -05:00
|
|
|
if (window_item_window(channel) == NULL) {
|
|
|
|
window_item_create((WI_ITEM_REC *) channel,
|
|
|
|
GPOINTER_TO_INT(automatic));
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void signal_channel_created_curwin(CHANNEL_REC *channel)
|
|
|
|
{
|
|
|
|
g_return_if_fail(channel != NULL);
|
|
|
|
|
2000-12-02 14:08:21 -05:00
|
|
|
window_item_add(active_win, (WI_ITEM_REC *) channel, FALSE);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void signal_channel_destroyed(CHANNEL_REC *channel)
|
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
|
|
|
|
|
|
|
g_return_if_fail(channel != NULL);
|
|
|
|
|
|
|
|
window = window_item_window((WI_ITEM_REC *) channel);
|
2001-02-22 00:49:30 -05:00
|
|
|
if (window == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window_item_destroy((WI_ITEM_REC *) channel);
|
|
|
|
|
|
|
|
if (channel->joined && !channel->left &&
|
|
|
|
channel->server != NULL) {
|
|
|
|
/* kicked out from channel */
|
|
|
|
window_bind_add(window, channel->server->tag,
|
|
|
|
channel->name);
|
2001-03-03 17:03:00 -05:00
|
|
|
} else if (!channel->joined || channel->left)
|
|
|
|
window_auto_destroy(window);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-12-02 14:08:21 -05:00
|
|
|
static void signal_window_item_destroy(WINDOW_REC *window, WI_ITEM_REC *item)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-09-02 14:53:58 -04:00
|
|
|
CHANNEL_REC *channel;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
g_return_if_fail(window != NULL);
|
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
channel = CHANNEL(item);
|
|
|
|
if (channel != NULL) channel_destroy(channel);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
static void sig_disconnected(SERVER_REC *server)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
|
|
|
GSList *tmp;
|
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
g_return_if_fail(IS_SERVER(server));
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
|
|
|
|
CHANNEL_REC *channel = tmp->data;
|
|
|
|
|
|
|
|
window = window_item_window((WI_ITEM_REC *) channel);
|
2001-02-10 04:12:53 -05:00
|
|
|
window_bind_add(window, server->tag, channel->name);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void signal_window_item_changed(WINDOW_REC *window, WI_ITEM_REC *item)
|
|
|
|
{
|
2000-06-01 13:08:30 -04:00
|
|
|
g_return_if_fail(window != NULL);
|
|
|
|
if (item == NULL) return;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
if (g_slist_length(window->items) > 1 && IS_CHANNEL(item)) {
|
2000-04-26 04:03:38 -04:00
|
|
|
printformat(item->server, item->name, MSGLEVEL_CLIENTNOTICE,
|
2001-01-07 14:42:59 -05:00
|
|
|
TXT_TALKING_IN, item->name);
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-08-11 22:16:52 -04:00
|
|
|
static void cmd_wjoin_pre(const char *data)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-08-11 22:16:52 -04:00
|
|
|
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))
|
2000-12-02 01:08:31 -05:00
|
|
|
return;
|
2000-08-11 22:16:52 -04:00
|
|
|
|
|
|
|
if (g_hash_table_lookup(optlist, "window") != NULL) {
|
|
|
|
signal_add("channel created",
|
|
|
|
(SIGNAL_FUNC) signal_channel_created_curwin);
|
2000-12-02 01:08:31 -05:00
|
|
|
}
|
2000-08-11 22:16:52 -04:00
|
|
|
cmd_params_free(free_arg);
|
|
|
|
}
|
|
|
|
|
2000-12-02 01:08:31 -05:00
|
|
|
static void cmd_join(const char *data, SERVER_REC *server)
|
|
|
|
{
|
2001-03-03 16:51:57 -05:00
|
|
|
WINDOW_REC *window;
|
2000-12-02 01:08:31 -05:00
|
|
|
CHANNEL_REC *channel;
|
|
|
|
|
|
|
|
if (strchr(data, ' ') != NULL || strchr(data, ',') != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
channel = channel_find(server, data);
|
2001-03-03 16:51:57 -05:00
|
|
|
if (channel == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window = window_item_window(channel);
|
|
|
|
|
|
|
|
if (window == active_win) {
|
|
|
|
/* channel is in active window, set it active */
|
|
|
|
window_item_set_active(active_win,
|
|
|
|
(WI_ITEM_REC *) channel);
|
|
|
|
} else {
|
|
|
|
/* notify user how to move the channel to active
|
|
|
|
window. this was used to be done automatically
|
|
|
|
but it just confused everyone who did it
|
|
|
|
accidentally */
|
|
|
|
printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_CHANNEL_MOVE_NOTIFY, channel->name,
|
|
|
|
window->refnum);
|
|
|
|
}
|
2000-12-02 01:08:31 -05:00
|
|
|
}
|
|
|
|
|
2000-08-11 22:16:52 -04:00
|
|
|
static void cmd_wjoin_post(const char *data)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (g_hash_table_lookup(optlist, "window") != NULL) {
|
|
|
|
signal_remove("channel created",
|
|
|
|
(SIGNAL_FUNC) signal_channel_created_curwin);
|
|
|
|
}
|
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
static void cmd_channel_list_joined(void)
|
|
|
|
{
|
2000-09-02 14:53:58 -04:00
|
|
|
CHANNEL_REC *channel;
|
2000-05-04 06:32:42 -04:00
|
|
|
GString *nicks;
|
|
|
|
GSList *nicklist, *tmp, *ntmp;
|
|
|
|
|
|
|
|
if (channels == NULL) {
|
2001-01-07 14:42:59 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_NOT_IN_CHANNELS);
|
2000-05-04 06:32:42 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print active channel */
|
2000-09-02 14:53:58 -04:00
|
|
|
channel = CHANNEL(active_win->active);
|
2000-05-04 06:32:42 -04:00
|
|
|
if (channel != NULL)
|
2001-01-07 14:42:59 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CURRENT_CHANNEL, channel->name);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
/* print list of all channels, their modes, server tags and nicks */
|
2001-01-07 14:42:59 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_CHANLIST_HEADER);
|
2000-05-04 06:32:42 -04:00
|
|
|
for (tmp = channels; tmp != NULL; tmp = tmp->next) {
|
|
|
|
channel = tmp->data;
|
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
nicklist = nicklist_getnicks(channel);
|
2000-05-04 06:32:42 -04:00
|
|
|
nicks = g_string_new(NULL);
|
|
|
|
for (ntmp = nicklist; ntmp != NULL; ntmp = ntmp->next) {
|
|
|
|
NICK_REC *rec = ntmp->data;
|
|
|
|
|
|
|
|
g_string_sprintfa(nicks, "%s ", rec->nick);
|
|
|
|
}
|
|
|
|
|
2000-06-15 15:34:54 -04:00
|
|
|
if (nicks->len > 1) g_string_truncate(nicks, nicks->len-1);
|
2001-01-07 14:42:59 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_CHANLIST_LINE,
|
2000-08-20 03:17:13 -04:00
|
|
|
channel->name, channel->mode, channel->server->tag, nicks->str);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
g_slist_free(nicklist);
|
|
|
|
g_string_free(nicks, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: CHANNEL LIST */
|
2000-05-04 06:32:42 -04:00
|
|
|
static void cmd_channel_list(void)
|
|
|
|
{
|
|
|
|
GString *str;
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
str = g_string_new(NULL);
|
2001-01-07 14:42:59 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_CHANSETUP_HEADER);
|
2000-05-04 06:32:42 -04:00
|
|
|
for (tmp = setupchannels; tmp != NULL; tmp = tmp->next) {
|
2000-08-26 11:39:44 -04:00
|
|
|
CHANNEL_SETUP_REC *rec = tmp->data;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
|
|
|
g_string_truncate(str, 0);
|
|
|
|
if (rec->autojoin)
|
2000-06-04 10:52:47 -04:00
|
|
|
g_string_append(str, "autojoin, ");
|
2000-05-04 06:32:42 -04:00
|
|
|
if (rec->botmasks != NULL && *rec->botmasks != '\0')
|
2000-06-04 10:52:47 -04:00
|
|
|
g_string_sprintfa(str, "bots: %s, ", rec->botmasks);
|
2000-05-04 06:32:42 -04:00
|
|
|
if (rec->autosendcmd != NULL && *rec->autosendcmd != '\0')
|
2000-06-04 10:52:47 -04:00
|
|
|
g_string_sprintfa(str, "botcmd: %s, ", rec->autosendcmd);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2000-06-10 04:34:20 -04:00
|
|
|
if (str->len > 2) g_string_truncate(str, str->len-2);
|
2001-01-07 14:42:59 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_CHANSETUP_LINE,
|
2000-08-26 11:39:44 -04:00
|
|
|
rec->name, rec->chatnet == NULL ? "" : rec->chatnet,
|
2000-05-04 06:32:42 -04:00
|
|
|
rec->password == NULL ? "" : rec->password, str->str);
|
|
|
|
}
|
|
|
|
g_string_free(str, TRUE);
|
2001-01-07 14:42:59 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_CHANSETUP_FOOTER);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
static void cmd_channel(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
|
2000-05-04 06:32:42 -04:00
|
|
|
{
|
2000-06-28 13:15:37 -04:00
|
|
|
if (*data == '\0')
|
|
|
|
cmd_channel_list_joined();
|
|
|
|
else
|
|
|
|
command_runsub("channel", data, server, item);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2000-07-23 19:19:22 -04:00
|
|
|
/* SYNTAX: CHANNEL ADD [-auto | -noauto] [-bots <masks>] [-botcmd <command>]
|
2000-09-02 14:53:58 -04:00
|
|
|
<channel> <chatnet> [<password>] */
|
2000-05-04 06:32:42 -04:00
|
|
|
static void cmd_channel_add(const char *data)
|
|
|
|
{
|
2000-06-17 21:18:12 -04:00
|
|
|
GHashTable *optlist;
|
2001-02-17 14:44:22 -05:00
|
|
|
CHATNET_REC *chatnetrec;
|
2000-08-26 11:39:44 -04:00
|
|
|
CHANNEL_SETUP_REC *rec;
|
2000-09-02 14:53:58 -04:00
|
|
|
char *botarg, *botcmdarg, *chatnet, *channel, *password;
|
2000-06-17 21:18:12 -04:00
|
|
|
void *free_arg;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
|
2000-09-02 14:53:58 -04:00
|
|
|
"channel add", &optlist, &channel, &chatnet, &password))
|
2000-06-17 21:18:12 -04:00
|
|
|
return;
|
|
|
|
|
2001-02-17 14:44:22 -05:00
|
|
|
if (*chatnet == '\0' || *channel == '\0')
|
|
|
|
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
|
|
|
|
|
|
|
chatnetrec = chatnet_find(chatnet);
|
|
|
|
if (chatnetrec == NULL) {
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_UNKNOWN_CHATNET, chatnet);
|
|
|
|
cmd_params_free(free_arg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
botarg = g_hash_table_lookup(optlist, "bots");
|
|
|
|
botcmdarg = g_hash_table_lookup(optlist, "botcmd");
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-02-17 14:44:22 -05:00
|
|
|
rec = channel_setup_find(channel, chatnet);
|
2000-05-04 06:32:42 -04:00
|
|
|
if (rec == NULL) {
|
2001-02-17 14:44:22 -05:00
|
|
|
rec = CHAT_PROTOCOL(chatnetrec)->create_channel_setup();
|
2000-05-04 06:32:42 -04:00
|
|
|
rec->name = g_strdup(channel);
|
2000-09-02 14:53:58 -04:00
|
|
|
rec->chatnet = g_strdup(chatnet);
|
2000-05-04 06:32:42 -04:00
|
|
|
} else {
|
2000-06-17 21:18:12 -04:00
|
|
|
if (g_hash_table_lookup(optlist, "bots")) g_free_and_null(rec->botmasks);
|
|
|
|
if (g_hash_table_lookup(optlist, "botcmd")) g_free_and_null(rec->autosendcmd);
|
2000-06-04 09:24:53 -04:00
|
|
|
if (*password != '\0') g_free_and_null(rec->password);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
2000-06-17 21:18:12 -04:00
|
|
|
if (g_hash_table_lookup(optlist, "auto")) rec->autojoin = TRUE;
|
|
|
|
if (g_hash_table_lookup(optlist, "noauto")) rec->autojoin = FALSE;
|
|
|
|
if (botarg != NULL && *botarg != '\0') rec->botmasks = g_strdup(botarg);
|
|
|
|
if (botcmdarg != NULL && *botcmdarg != '\0') rec->autosendcmd = g_strdup(botcmdarg);
|
2000-06-04 09:24:53 -04:00
|
|
|
if (*password != '\0' && strcmp(password, "-") != 0) rec->password = g_strdup(password);
|
2001-02-17 14:44:22 -05:00
|
|
|
|
|
|
|
signal_emit("channel add fill", 2, rec, optlist);
|
|
|
|
|
|
|
|
channel_setup_create(rec);
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
TXT_CHANSETUP_ADDED, channel, chatnet);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2000-06-17 21:18:12 -04:00
|
|
|
cmd_params_free(free_arg);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
/* SYNTAX: CHANNEL REMOVE <channel> <chatnet> */
|
2000-05-04 06:32:42 -04:00
|
|
|
static void cmd_channel_remove(const char *data)
|
|
|
|
{
|
2000-08-26 11:39:44 -04:00
|
|
|
CHANNEL_SETUP_REC *rec;
|
2000-09-02 14:53:58 -04:00
|
|
|
char *chatnet, *channel;
|
2000-06-17 21:18:12 -04:00
|
|
|
void *free_arg;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2000-09-02 14:53:58 -04:00
|
|
|
if (!cmd_get_params(data, &free_arg, 2, &channel, &chatnet))
|
2000-06-17 21:18:12 -04:00
|
|
|
return;
|
2000-09-02 14:53:58 -04:00
|
|
|
if (*chatnet == '\0' || *channel == '\0')
|
2000-05-04 06:32:42 -04:00
|
|
|
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
|
|
|
|
2001-02-17 14:44:22 -05:00
|
|
|
rec = channel_setup_find(channel, chatnet);
|
2000-05-04 06:32:42 -04:00
|
|
|
if (rec == NULL)
|
2001-01-07 14:42:59 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CHANSETUP_NOT_FOUND, channel, chatnet);
|
2000-05-04 06:32:42 -04:00
|
|
|
else {
|
2001-01-07 14:42:59 -05:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CHANSETUP_REMOVED, channel, chatnet);
|
2001-02-17 14:44:22 -05:00
|
|
|
channel_setup_remove(rec);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
2000-06-17 21:18:12 -04:00
|
|
|
cmd_params_free(free_arg);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2001-01-28 10:46:00 -05:00
|
|
|
static int get_nick_length(void *data)
|
|
|
|
{
|
|
|
|
return strlen(((NICK_REC *) data)->nick);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void display_sorted_nicks(CHANNEL_REC *channel, GSList *nicklist)
|
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
|
|
|
TEXT_DEST_REC dest;
|
|
|
|
GString *str;
|
|
|
|
GSList *tmp;
|
|
|
|
char *format, *stripped;
|
|
|
|
char *linebuf, nickmode[2] = { 0, 0 };
|
|
|
|
int *columns, cols, rows, last_col_rows, col, row, max_width;
|
2001-03-04 04:04:53 -05:00
|
|
|
int item_extra, linebuf_size;
|
2001-01-28 10:46:00 -05:00
|
|
|
|
|
|
|
window = window_find_closest(channel->server, channel->name,
|
|
|
|
MSGLEVEL_CLIENTCRAP);
|
|
|
|
max_width = window->width;
|
|
|
|
|
|
|
|
/* get the length of item extra stuff ("[ ] ") */
|
|
|
|
format = format_get_text(MODULE_NAME, NULL,
|
|
|
|
channel->server, channel->name,
|
|
|
|
TXT_NAMES_NICK, " ", "");
|
|
|
|
stripped = strip_codes(format);
|
|
|
|
item_extra = strlen(stripped);
|
|
|
|
g_free(stripped);
|
|
|
|
g_free(format);
|
|
|
|
|
2001-02-17 14:44:22 -05:00
|
|
|
if (settings_get_int("names_max_width") > 0 &&
|
|
|
|
max_width > settings_get_int("names_max_width"))
|
|
|
|
max_width = settings_get_int("names_max_width");
|
|
|
|
|
2001-01-28 10:46:00 -05:00
|
|
|
/* remove width of timestamp from max_width */
|
|
|
|
format_create_dest(&dest, channel->server, channel->name,
|
|
|
|
MSGLEVEL_CLIENTCRAP, NULL);
|
|
|
|
format = format_get_line_start(current_theme, &dest, time(NULL));
|
|
|
|
if (format != NULL) {
|
|
|
|
stripped = strip_codes(format);
|
|
|
|
max_width -= strlen(stripped);
|
|
|
|
g_free(stripped);
|
|
|
|
g_free(format);
|
|
|
|
}
|
|
|
|
|
2001-02-09 23:54:09 -05:00
|
|
|
/* calculate columns */
|
2001-01-28 10:46:00 -05:00
|
|
|
cols = get_max_column_count(nicklist, get_nick_length, max_width,
|
2001-02-09 23:54:09 -05:00
|
|
|
settings_get_int("names_max_columns"),
|
2001-01-28 10:46:00 -05:00
|
|
|
item_extra, 3, &columns, &rows);
|
|
|
|
nicklist = columns_sort_list(nicklist, rows);
|
|
|
|
|
|
|
|
/* rows in last column */
|
|
|
|
last_col_rows = rows-(cols*rows-g_slist_length(nicklist));
|
|
|
|
if (last_col_rows == 0)
|
|
|
|
last_col_rows = rows;
|
|
|
|
|
|
|
|
str = g_string_new(NULL);
|
2001-03-04 04:04:53 -05:00
|
|
|
linebuf_size = max_width+1; linebuf = g_malloc(linebuf_size);
|
2001-01-28 10:46:00 -05:00
|
|
|
|
|
|
|
col = 0; row = 0;
|
|
|
|
for (tmp = nicklist; tmp != NULL; tmp = tmp->next) {
|
|
|
|
NICK_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
nickmode[0] = rec->op ? '@' : rec->voice ? '+' : ' ';
|
|
|
|
|
2001-03-04 04:04:53 -05:00
|
|
|
if (linebuf_size < columns[col]-item_extra+1) {
|
|
|
|
linebuf_size = (columns[col]-item_extra+1)*2;
|
|
|
|
linebuf = g_realloc(linebuf, linebuf_size);
|
|
|
|
}
|
2001-01-28 10:46:00 -05:00
|
|
|
memset(linebuf, ' ', columns[col]-item_extra);
|
|
|
|
linebuf[columns[col]-item_extra] = '\0';
|
|
|
|
memcpy(linebuf, rec->nick, strlen(rec->nick));
|
|
|
|
|
|
|
|
format = format_get_text(MODULE_NAME, NULL,
|
|
|
|
channel->server, channel->name,
|
|
|
|
TXT_NAMES_NICK, nickmode, linebuf);
|
|
|
|
g_string_append(str, format);
|
|
|
|
g_free(format);
|
|
|
|
|
|
|
|
if (++col == cols) {
|
|
|
|
printtext(channel->server, channel->name,
|
|
|
|
MSGLEVEL_CLIENTCRAP, "%s", str->str);
|
|
|
|
g_string_truncate(str, 0);
|
|
|
|
col = 0; row++;
|
|
|
|
|
|
|
|
if (row == last_col_rows)
|
|
|
|
cols--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str->len != 0) {
|
|
|
|
printtext(channel->server, channel->name,
|
|
|
|
MSGLEVEL_CLIENTCRAP, "%s", str->str);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free(nicklist);
|
|
|
|
g_string_free(str, TRUE);
|
2001-03-03 19:14:00 -05:00
|
|
|
g_free_not_null(columns);
|
2001-01-28 10:46:00 -05:00
|
|
|
g_free(linebuf);
|
|
|
|
}
|
|
|
|
|
2001-03-03 19:14:00 -05:00
|
|
|
void fe_channels_nicklist(CHANNEL_REC *channel, int flags)
|
2001-01-28 10:46:00 -05:00
|
|
|
{
|
|
|
|
NICK_REC *nick;
|
|
|
|
GSList *tmp, *nicklist, *sorted;
|
|
|
|
int nicks, normal, voices, ops;
|
|
|
|
|
|
|
|
nicks = normal = voices = ops = 0;
|
|
|
|
nicklist = nicklist_getnicks(channel);
|
|
|
|
sorted = NULL;
|
|
|
|
|
|
|
|
/* sort the nicklist */
|
|
|
|
for (tmp = nicklist; tmp != NULL; tmp = tmp->next) {
|
|
|
|
nick = tmp->data;
|
|
|
|
|
2001-03-03 19:14:00 -05:00
|
|
|
nicks++;
|
|
|
|
if (nick->op) {
|
2001-01-28 10:46:00 -05:00
|
|
|
ops++;
|
2001-03-03 19:14:00 -05:00
|
|
|
if ((flags & CHANNEL_NICKLIST_FLAG_OPS) == 0)
|
|
|
|
continue;
|
|
|
|
} else if (nick->halfop) {
|
|
|
|
if ((flags & CHANNEL_NICKLIST_FLAG_HALFOPS) == 0)
|
|
|
|
continue;
|
|
|
|
} else if (nick->voice) {
|
2001-01-28 10:46:00 -05:00
|
|
|
voices++;
|
2001-03-03 19:14:00 -05:00
|
|
|
if ((flags & CHANNEL_NICKLIST_FLAG_VOICES) == 0)
|
|
|
|
continue;
|
|
|
|
} else {
|
2001-01-28 10:46:00 -05:00
|
|
|
normal++;
|
2001-03-03 19:14:00 -05:00
|
|
|
if ((flags & CHANNEL_NICKLIST_FLAG_NORMAL) == 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
sorted = g_slist_insert_sorted(sorted, nick, (GCompareFunc)
|
|
|
|
nicklist_compare);
|
2001-01-28 10:46:00 -05:00
|
|
|
}
|
|
|
|
g_slist_free(nicklist);
|
|
|
|
|
|
|
|
/* display the nicks */
|
|
|
|
printformat(channel->server, channel->name,
|
|
|
|
MSGLEVEL_CRAP, TXT_NAMES, channel->name, "");
|
|
|
|
display_sorted_nicks(channel, sorted);
|
|
|
|
g_slist_free(sorted);
|
|
|
|
|
|
|
|
printformat(channel->server, channel->name,
|
|
|
|
MSGLEVEL_CRAP, TXT_ENDOFNAMES,
|
|
|
|
channel->name, nicks, ops, voices, normal);
|
|
|
|
}
|
|
|
|
|
2001-03-03 19:14:00 -05:00
|
|
|
/* SYNTAX: NAMES [-ops -halfops -voices -normal] [<channels> | **] */
|
2001-01-28 10:46:00 -05:00
|
|
|
static void cmd_names(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
|
|
|
|
{
|
2001-03-03 19:14:00 -05:00
|
|
|
CHANNEL_REC *chanrec;
|
|
|
|
GHashTable *optlist;
|
|
|
|
GString *unknowns;
|
|
|
|
char *channel, **channels, **tmp;
|
|
|
|
int flags;
|
|
|
|
void *free_arg;
|
2001-01-28 10:46:00 -05:00
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
2001-03-03 19:14:00 -05:00
|
|
|
if (!IS_SERVER(server) || !server->connected)
|
2001-01-28 10:46:00 -05:00
|
|
|
cmd_return_error(CMDERR_NOT_CONNECTED);
|
|
|
|
|
2001-03-03 19:14:00 -05:00
|
|
|
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
|
|
|
|
PARAM_FLAG_GETREST, "names", &optlist, &channel))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (strcmp(channel, "*") == 0 || *channel == '\0') {
|
2001-01-28 10:46:00 -05:00
|
|
|
if (!IS_CHANNEL(item))
|
2001-03-03 19:14:00 -05:00
|
|
|
cmd_param_error(CMDERR_NOT_JOINED);
|
2001-01-28 10:46:00 -05:00
|
|
|
|
2001-03-03 19:14:00 -05:00
|
|
|
channel = item->name;
|
2001-01-28 10:46:00 -05:00
|
|
|
}
|
|
|
|
|
2001-03-03 19:14:00 -05:00
|
|
|
flags = 0;
|
|
|
|
if (g_hash_table_lookup(optlist, "ops") != NULL)
|
|
|
|
flags |= CHANNEL_NICKLIST_FLAG_OPS;
|
|
|
|
if (g_hash_table_lookup(optlist, "halfops") != NULL)
|
|
|
|
flags |= CHANNEL_NICKLIST_FLAG_HALFOPS;
|
|
|
|
if (g_hash_table_lookup(optlist, "voices") != NULL)
|
|
|
|
flags |= CHANNEL_NICKLIST_FLAG_VOICES;
|
|
|
|
if (g_hash_table_lookup(optlist, "normal") != NULL)
|
|
|
|
flags |= CHANNEL_NICKLIST_FLAG_NORMAL;
|
|
|
|
|
|
|
|
if (flags == 0) flags = CHANNEL_NICKLIST_FLAG_ALL;
|
|
|
|
|
|
|
|
unknowns = g_string_new(NULL);
|
|
|
|
|
|
|
|
channels = g_strsplit(channel, ",", -1);
|
|
|
|
for (tmp = channels; *tmp != NULL; tmp++) {
|
|
|
|
chanrec = channel_find(server, *tmp);
|
2001-03-04 03:10:01 -05:00
|
|
|
if (chanrec == NULL)
|
|
|
|
g_string_sprintfa(unknowns, "%s,", *tmp);
|
|
|
|
else {
|
2001-03-03 19:14:00 -05:00
|
|
|
fe_channels_nicklist(chanrec, flags);
|
2001-03-04 03:10:01 -05:00
|
|
|
signal_stop();
|
|
|
|
}
|
2001-01-28 10:46:00 -05:00
|
|
|
}
|
2001-03-03 19:14:00 -05:00
|
|
|
g_strfreev(channels);
|
|
|
|
|
|
|
|
if (unknowns->len > 1)
|
|
|
|
g_string_truncate(unknowns, unknowns->len-1);
|
|
|
|
|
2001-03-04 03:10:01 -05:00
|
|
|
if (unknowns->len > 0 && strcmp(channel, unknowns->str) != 0)
|
2001-03-03 19:14:00 -05:00
|
|
|
signal_emit("command names", 3, unknowns->str, server, item);
|
|
|
|
g_string_free(unknowns, TRUE);
|
|
|
|
|
|
|
|
cmd_params_free(free_arg);
|
2001-01-28 10:46:00 -05:00
|
|
|
}
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
void fe_channels_init(void)
|
|
|
|
{
|
2000-06-28 18:58:54 -04:00
|
|
|
settings_add_bool("lookandfeel", "autoclose_windows", TRUE);
|
2001-02-09 23:54:09 -05:00
|
|
|
settings_add_int("lookandfeel", "names_max_columns", 6);
|
|
|
|
settings_add_int("lookandfeel", "names_max_width", 0);
|
2000-06-17 08:22:56 -04:00
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_add("channel created", (SIGNAL_FUNC) signal_channel_created);
|
|
|
|
signal_add("channel destroyed", (SIGNAL_FUNC) signal_channel_destroyed);
|
2000-12-02 14:08:21 -05:00
|
|
|
signal_add_last("window item destroy", (SIGNAL_FUNC) signal_window_item_destroy);
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_add_last("window item changed", (SIGNAL_FUNC) signal_window_item_changed);
|
|
|
|
signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected);
|
|
|
|
|
2000-08-11 22:16:52 -04:00
|
|
|
command_bind_first("join", NULL, (SIGNAL_FUNC) cmd_wjoin_pre);
|
2000-12-02 01:08:31 -05:00
|
|
|
command_bind("join", NULL, (SIGNAL_FUNC) cmd_join);
|
2000-08-11 22:16:52 -04:00
|
|
|
command_bind_last("join", NULL, (SIGNAL_FUNC) cmd_wjoin_post);
|
2000-05-04 06:32:42 -04:00
|
|
|
command_bind("channel", NULL, (SIGNAL_FUNC) cmd_channel);
|
|
|
|
command_bind("channel add", NULL, (SIGNAL_FUNC) cmd_channel_add);
|
|
|
|
command_bind("channel remove", NULL, (SIGNAL_FUNC) cmd_channel_remove);
|
|
|
|
command_bind("channel list", NULL, (SIGNAL_FUNC) cmd_channel_list);
|
2001-01-28 10:46:00 -05:00
|
|
|
command_bind("names", NULL, (SIGNAL_FUNC) cmd_names);
|
2000-06-17 21:18:12 -04:00
|
|
|
|
|
|
|
command_set_options("channel add", "auto noauto -bots -botcmd");
|
2001-03-03 19:14:00 -05:00
|
|
|
command_set_options("names", "ops halfops voices normal");
|
2000-08-11 22:16:52 -04:00
|
|
|
command_set_options("join", "window");
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void fe_channels_deinit(void)
|
|
|
|
{
|
|
|
|
signal_remove("channel created", (SIGNAL_FUNC) signal_channel_created);
|
|
|
|
signal_remove("channel destroyed", (SIGNAL_FUNC) signal_channel_destroyed);
|
2000-12-02 14:08:21 -05:00
|
|
|
signal_remove("window item destroy", (SIGNAL_FUNC) signal_window_item_destroy);
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_remove("window item changed", (SIGNAL_FUNC) signal_window_item_changed);
|
|
|
|
signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
|
|
|
|
|
2000-08-11 22:16:52 -04:00
|
|
|
command_unbind("join", (SIGNAL_FUNC) cmd_wjoin_pre);
|
2000-12-02 01:08:31 -05:00
|
|
|
command_unbind("join", (SIGNAL_FUNC) cmd_join);
|
2000-08-11 22:16:52 -04:00
|
|
|
command_unbind("join", (SIGNAL_FUNC) cmd_wjoin_post);
|
2000-05-04 06:32:42 -04:00
|
|
|
command_unbind("channel", (SIGNAL_FUNC) cmd_channel);
|
|
|
|
command_unbind("channel add", (SIGNAL_FUNC) cmd_channel_add);
|
|
|
|
command_unbind("channel remove", (SIGNAL_FUNC) cmd_channel_remove);
|
|
|
|
command_unbind("channel list", (SIGNAL_FUNC) cmd_channel_list);
|
2001-01-28 10:46:00 -05:00
|
|
|
command_unbind("names", (SIGNAL_FUNC) cmd_names);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|