Merged Irssi 0.8.2 from irssi.org cvs.
[silc.git] / apps / irssi / src / fe-common / core / fe-channels.c
1 /*
2  fe-channels.c : irssi
3
4     Copyright (C) 1999-2000 Timo Sirainen
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "module.h"
22 #include "module-formats.h"
23 #include "modules.h"
24 #include "signals.h"
25 #include "commands.h"
26 #include "levels.h"
27 #include "misc.h"
28 #include "settings.h"
29
30 #include "chat-protocols.h"
31 #include "chatnets.h"
32 #include "servers.h"
33 #include "channels.h"
34 #include "channels-setup.h"
35 #include "nicklist.h"
36
37 #include "fe-windows.h"
38 #include "fe-channels.h"
39 #include "window-items.h"
40 #include "printtext.h"
41
42 static void signal_channel_created(CHANNEL_REC *channel, void *automatic)
43 {
44         if (window_item_window(channel) == NULL) {
45                 window_item_create((WI_ITEM_REC *) channel,
46                                    GPOINTER_TO_INT(automatic));
47         }
48 }
49
50 static void signal_channel_created_curwin(CHANNEL_REC *channel)
51 {
52         g_return_if_fail(channel != NULL);
53
54         window_item_add(active_win, (WI_ITEM_REC *) channel, FALSE);
55 }
56
57 static void signal_channel_destroyed(CHANNEL_REC *channel)
58 {
59         WINDOW_REC *window;
60
61         g_return_if_fail(channel != NULL);
62
63         window = window_item_window((WI_ITEM_REC *) channel);
64         if (window == NULL)
65                 return;
66
67         window_item_destroy((WI_ITEM_REC *) channel);
68
69         if (channel->joined && !channel->left &&
70             channel->server != NULL) {
71                 /* kicked out from channel */
72                 window_bind_add(window, channel->server->tag,
73                                 channel->name);
74         } else if (!channel->joined || channel->left)
75                 window_auto_destroy(window);
76 }
77
78 static void sig_disconnected(SERVER_REC *server)
79 {
80         WINDOW_REC *window;
81         GSList *tmp;
82
83         g_return_if_fail(IS_SERVER(server));
84
85         for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
86                 CHANNEL_REC *channel = tmp->data;
87
88                 window = window_item_window((WI_ITEM_REC *) channel);
89                 window_bind_add(window, server->tag, channel->name);
90         }
91 }
92
93 static void signal_window_item_changed(WINDOW_REC *window, WI_ITEM_REC *item)
94 {
95         g_return_if_fail(window != NULL);
96         if (item == NULL) return;
97
98         if (g_slist_length(window->items) > 1 && IS_CHANNEL(item)) {
99                 printformat(item->server, item->name, MSGLEVEL_CLIENTNOTICE,
100                             TXT_TALKING_IN, item->name);
101                 signal_stop();
102         }
103 }
104
105 static void cmd_wjoin_pre(const char *data)
106 {
107         GHashTable *optlist;
108         char *nick;
109         void *free_arg;
110
111         if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
112                             PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
113                             "join", &optlist, &nick))
114                 return;
115
116         if (g_hash_table_lookup(optlist, "window") != NULL) {
117                 signal_add("channel created",
118                            (SIGNAL_FUNC) signal_channel_created_curwin);
119         }
120         cmd_params_free(free_arg);
121 }
122
123 static void cmd_join(const char *data, SERVER_REC *server)
124 {
125         WINDOW_REC *window;
126         CHANNEL_REC *channel;
127
128         if (strchr(data, ' ') != NULL || strchr(data, ',') != NULL)
129                 return;
130
131         channel = channel_find(server, data);
132         if (channel == NULL)
133                 return;
134
135         window = window_item_window(channel);
136
137         if (window == active_win) {
138                 /* channel is in active window, set it active */
139                 window_item_set_active(active_win,
140                                        (WI_ITEM_REC *) channel);
141         } else {
142                 /* notify user how to move the channel to active
143                    window. this was used to be done automatically
144                    but it just confused everyone who did it
145                    accidentally */
146                 printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
147                                    TXT_CHANNEL_MOVE_NOTIFY, channel->name,
148                                    window->refnum);
149         }
150 }
151
152 static void cmd_wjoin_post(const char *data)
153 {
154         GHashTable *optlist;
155         char *nick;
156         void *free_arg;
157
158         if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
159                             PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
160                             "join", &optlist, &nick))
161                 return;
162
163         if (g_hash_table_lookup(optlist, "window") != NULL) {
164                 signal_remove("channel created",
165                            (SIGNAL_FUNC) signal_channel_created_curwin);
166         }
167         cmd_params_free(free_arg);
168 }
169
170 static void cmd_channel_list_joined(void)
171 {
172         CHANNEL_REC *channel;
173         GString *nicks;
174         GSList *nicklist, *tmp, *ntmp;
175
176         if (channels == NULL) {
177                 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_NOT_IN_CHANNELS);
178                 return;
179         }
180
181         /* print active channel */
182         channel = CHANNEL(active_win->active);
183         if (channel != NULL)
184                 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CURRENT_CHANNEL, channel->name);
185
186         /* print list of all channels, their modes, server tags and nicks */
187         printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_CHANLIST_HEADER);
188         for (tmp = channels; tmp != NULL; tmp = tmp->next) {
189                 channel = tmp->data;
190
191                 nicklist = nicklist_getnicks(channel);
192                 nicks = g_string_new(NULL);
193                 for (ntmp = nicklist; ntmp != NULL; ntmp = ntmp->next) {
194                         NICK_REC *rec = ntmp->data;
195
196                         g_string_sprintfa(nicks, "%s ", rec->nick);
197                 }
198
199                 if (nicks->len > 1) g_string_truncate(nicks, nicks->len-1);
200                 printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_CHANLIST_LINE,
201                             channel->name, channel->mode, channel->server->tag, nicks->str);
202
203                 g_slist_free(nicklist);
204                 g_string_free(nicks, TRUE);
205         }
206 }
207
208 /* SYNTAX: CHANNEL LIST */
209 static void cmd_channel_list(void)
210 {
211         GString *str;
212         GSList *tmp;
213
214         str = g_string_new(NULL);
215         printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_CHANSETUP_HEADER);
216         for (tmp = setupchannels; tmp != NULL; tmp = tmp->next) {
217                 CHANNEL_SETUP_REC *rec = tmp->data;
218
219                 g_string_truncate(str, 0);
220                 if (rec->autojoin)
221                         g_string_append(str, "autojoin, ");
222                 if (rec->botmasks != NULL && *rec->botmasks != '\0')
223                         g_string_sprintfa(str, "bots: %s, ", rec->botmasks);
224                 if (rec->autosendcmd != NULL && *rec->autosendcmd != '\0')
225                         g_string_sprintfa(str, "botcmd: %s, ", rec->autosendcmd);
226
227                 if (str->len > 2) g_string_truncate(str, str->len-2);
228                 printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_CHANSETUP_LINE,
229                             rec->name, rec->chatnet == NULL ? "" : rec->chatnet,
230                             rec->password == NULL ? "" : rec->password, str->str);
231         }
232         g_string_free(str, TRUE);
233         printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_CHANSETUP_FOOTER);
234 }
235
236 static void cmd_channel(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
237 {
238         if (*data == '\0')
239                 cmd_channel_list_joined();
240         else if (server != NULL && server_ischannel(server, data)) {
241                 signal_emit("command join", 3, data, server, item);
242         } else {
243                 command_runsub("channel", data, server, item);
244         }
245 }
246
247 /* SYNTAX: CHANNEL ADD [-auto | -noauto] [-bots <masks>] [-botcmd <command>]
248                        <channel> <chatnet> [<password>] */
249 static void cmd_channel_add(const char *data)
250 {
251         GHashTable *optlist;
252         CHATNET_REC *chatnetrec;
253         CHANNEL_SETUP_REC *rec;
254         char *botarg, *botcmdarg, *chatnet, *channel, *password;
255         void *free_arg;
256
257         if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
258                             "channel add", &optlist, &channel, &chatnet, &password))
259                 return;
260
261         if (*chatnet == '\0' || *channel == '\0')
262                 cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
263
264         chatnetrec = chatnet_find(chatnet);
265         if (chatnetrec == NULL) {
266                 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
267                             TXT_UNKNOWN_CHATNET, chatnet);
268                 cmd_params_free(free_arg);
269                 return;
270         }
271
272         botarg = g_hash_table_lookup(optlist, "bots");
273         botcmdarg = g_hash_table_lookup(optlist, "botcmd");
274
275         rec = channel_setup_find(channel, chatnet);
276         if (rec == NULL) {
277                 rec = CHAT_PROTOCOL(chatnetrec)->create_channel_setup();
278                 rec->name = g_strdup(channel);
279                 rec->chatnet = g_strdup(chatnet);
280         } else {
281                 if (g_hash_table_lookup(optlist, "bots")) g_free_and_null(rec->botmasks);
282                 if (g_hash_table_lookup(optlist, "botcmd")) g_free_and_null(rec->autosendcmd);
283                 if (*password != '\0') g_free_and_null(rec->password);
284         }
285         if (g_hash_table_lookup(optlist, "auto")) rec->autojoin = TRUE;
286         if (g_hash_table_lookup(optlist, "noauto")) rec->autojoin = FALSE;
287         if (botarg != NULL && *botarg != '\0') rec->botmasks = g_strdup(botarg);
288         if (botcmdarg != NULL && *botcmdarg != '\0') rec->autosendcmd = g_strdup(botcmdarg);
289         if (*password != '\0' && strcmp(password, "-") != 0) rec->password = g_strdup(password);
290
291         signal_emit("channel add fill", 2, rec, optlist);
292
293         channel_setup_create(rec);
294         printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
295                     TXT_CHANSETUP_ADDED, channel, chatnet);
296
297         cmd_params_free(free_arg);
298 }
299
300 /* SYNTAX: CHANNEL REMOVE <channel> <chatnet> */
301 static void cmd_channel_remove(const char *data)
302 {
303         CHANNEL_SETUP_REC *rec;
304         char *chatnet, *channel;
305         void *free_arg;
306
307         if (!cmd_get_params(data, &free_arg, 2, &channel, &chatnet))
308                 return;
309         if (*chatnet == '\0' || *channel == '\0')
310                 cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
311
312         rec = channel_setup_find(channel, chatnet);
313         if (rec == NULL)
314                 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CHANSETUP_NOT_FOUND, channel, chatnet);
315         else {
316                 printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_CHANSETUP_REMOVED, channel, chatnet);
317                 channel_setup_remove(rec);
318         }
319         cmd_params_free(free_arg);
320 }
321
322 static int get_nick_length(void *data)
323 {
324         return strlen(((NICK_REC *) data)->nick);
325 }
326
327 static void display_sorted_nicks(CHANNEL_REC *channel, GSList *nicklist)
328 {
329         WINDOW_REC *window;
330         TEXT_DEST_REC dest;
331         GString *str;
332         GSList *tmp;
333         char *format, *stripped, *prefix_format;
334         char *linebuf, nickmode[2] = { 0, 0 };
335         int *columns, cols, rows, last_col_rows, col, row, max_width;
336         int item_extra, linebuf_size, formatnum;
337
338         window = window_find_closest(channel->server, channel->name,
339                                      MSGLEVEL_CLIENTCRAP);
340         max_width = window->width;
341
342         /* get the length of item extra stuff ("[ ] ") */
343         format = format_get_text(MODULE_NAME, NULL,
344                                  channel->server, channel->name,
345                                  TXT_NAMES_NICK, " ", "");
346         stripped = strip_codes(format);
347         item_extra = strlen(stripped);
348         g_free(stripped);
349         g_free(format);
350
351         if (settings_get_int("names_max_width") > 0 &&
352             settings_get_int("names_max_width") < max_width)
353                 max_width = settings_get_int("names_max_width");
354
355         /* remove width of the timestamp from max_width */
356         format_create_dest(&dest, channel->server, channel->name,
357                            MSGLEVEL_CLIENTCRAP, NULL);
358         format = format_get_line_start(current_theme, &dest, time(NULL));
359         if (format != NULL) {
360                 stripped = strip_codes(format);
361                 max_width -= strlen(stripped);
362                 g_free(stripped);
363                 g_free(format);
364         }
365
366         /* remove width of the prefix from max_width */
367         prefix_format = format_get_text(MODULE_NAME, NULL,
368                                         channel->server, channel->name,
369                                         TXT_NAMES_PREFIX, channel->name);
370         if (prefix_format != NULL) {
371                 stripped = strip_codes(prefix_format);
372                 max_width -= strlen(stripped);
373                 g_free(stripped);
374         }
375
376         if (max_width <= 0) {
377                 /* we should always have at least some space .. if we
378                    really don't, it won't show properly anyway. */
379                 max_width = 10;
380         }
381
382         /* calculate columns */
383         cols = get_max_column_count(nicklist, get_nick_length, max_width,
384                                     settings_get_int("names_max_columns"),
385                                     item_extra, 3, &columns, &rows);
386         nicklist = columns_sort_list(nicklist, rows);
387
388         /* rows in last column */
389         last_col_rows = rows-(cols*rows-g_slist_length(nicklist));
390         if (last_col_rows == 0)
391                 last_col_rows = rows;
392
393         str = g_string_new(prefix_format);
394         linebuf_size = max_width+1; linebuf = g_malloc(linebuf_size);
395
396         col = 0; row = 0;
397         for (tmp = nicklist; tmp != NULL; tmp = tmp->next) {
398                 NICK_REC *rec = tmp->data;
399
400                 if (rec->op)
401                         nickmode[0] = '@';
402                 else if (rec->halfop)
403                         nickmode[0] = '%';
404                 else if (rec->voice)
405                         nickmode[0] = '+';
406                 else
407                         nickmode[0] = ' ';
408                 
409                 if (linebuf_size < columns[col]-item_extra+1) {
410                         linebuf_size = (columns[col]-item_extra+1)*2;
411                         linebuf = g_realloc(linebuf, linebuf_size);
412                 }
413                 memset(linebuf, ' ', columns[col]-item_extra);
414                 linebuf[columns[col]-item_extra] = '\0';
415                 memcpy(linebuf, rec->nick, strlen(rec->nick));
416
417                 formatnum = rec->op ? TXT_NAMES_NICK_OP :
418                         rec->halfop ? TXT_NAMES_NICK_HALFOP :
419                         rec->voice ? TXT_NAMES_NICK_VOICE :
420                         TXT_NAMES_NICK;
421                 format = format_get_text(MODULE_NAME, NULL,
422                                          channel->server, channel->name,
423                                          formatnum, nickmode, linebuf);
424                 g_string_append(str, format);
425                 g_free(format);
426
427                 if (++col == cols) {
428                         printtext(channel->server, channel->name,
429                                   MSGLEVEL_CLIENTCRAP, "%s", str->str);
430                         g_string_truncate(str, 0);
431                         if (prefix_format != NULL)
432                                 g_string_assign(str, prefix_format);
433                         col = 0; row++;
434
435                         if (row == last_col_rows)
436                                 cols--;
437                 }
438         }
439
440         if (str->len > strlen(prefix_format)) {
441                 printtext(channel->server, channel->name,
442                           MSGLEVEL_CLIENTCRAP, "%s", str->str);
443         }
444
445         g_slist_free(nicklist);
446         g_string_free(str, TRUE);
447         g_free_not_null(columns);
448         g_free_not_null(prefix_format);
449         g_free(linebuf);
450 }
451
452 void fe_channels_nicklist(CHANNEL_REC *channel, int flags)
453 {
454         NICK_REC *nick;
455         GSList *tmp, *nicklist, *sorted;
456         int nicks, normal, voices, halfops, ops;
457
458         nicks = normal = voices = halfops = ops = 0;
459         nicklist = nicklist_getnicks(channel);
460         sorted = NULL;
461
462         /* sort the nicklist */
463         for (tmp = nicklist; tmp != NULL; tmp = tmp->next) {
464                 nick = tmp->data;
465
466                 nicks++;
467                 if (nick->op) {
468                         ops++;
469                         if ((flags & CHANNEL_NICKLIST_FLAG_OPS) == 0)
470                                 continue;
471                 } else if (nick->halfop) {
472                         halfops++;
473                         if ((flags & CHANNEL_NICKLIST_FLAG_HALFOPS) == 0)
474                                 continue;
475                 } else if (nick->voice) {
476                         voices++;
477                         if ((flags & CHANNEL_NICKLIST_FLAG_VOICES) == 0)
478                                 continue;
479                 } else {
480                         normal++;
481                         if ((flags & CHANNEL_NICKLIST_FLAG_NORMAL) == 0)
482                                 continue;
483                 }
484
485                 sorted = g_slist_insert_sorted(sorted, nick, (GCompareFunc)
486                                                nicklist_compare);
487         }
488         g_slist_free(nicklist);
489
490         /* display the nicks */
491         if ((flags & CHANNEL_NICKLIST_FLAG_COUNT) == 0) {
492                 printformat(channel->server, channel->name,
493                             MSGLEVEL_CLIENTCRAP, TXT_NAMES, channel->name, nicks, ops, halfops, voices, normal);
494                 display_sorted_nicks(channel, sorted);
495         }
496         g_slist_free(sorted);
497
498         printformat(channel->server, channel->name,
499                     MSGLEVEL_CLIENTNOTICE, TXT_ENDOFNAMES,
500                     channel->name, nicks, ops, halfops, voices, normal);
501 }
502
503 /* SYNTAX: NAMES [-count | -ops -halfops -voices -normal] [<channels> | **] */
504 static void cmd_names(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
505 {
506         CHANNEL_REC *chanrec;
507         GHashTable *optlist;
508         GString *unknowns;
509         char *channel, **channels, **tmp;
510         int flags;
511         void *free_arg;
512
513         g_return_if_fail(data != NULL);
514         if (!IS_SERVER(server) || !server->connected)
515                 cmd_return_error(CMDERR_NOT_CONNECTED);
516
517         if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
518                             "names", &optlist, &channel))
519                 return;
520
521         if (strcmp(channel, "*") == 0 || *channel == '\0') {
522                 if (!IS_CHANNEL(item))
523                         cmd_param_error(CMDERR_NOT_JOINED);
524
525                 channel = item->name;
526         }
527
528         flags = 0;
529         if (g_hash_table_lookup(optlist, "ops") != NULL)
530                 flags |= CHANNEL_NICKLIST_FLAG_OPS;
531         if (g_hash_table_lookup(optlist, "halfops") != NULL)
532                 flags |= CHANNEL_NICKLIST_FLAG_HALFOPS;
533         if (g_hash_table_lookup(optlist, "voices") != NULL)
534                 flags |= CHANNEL_NICKLIST_FLAG_VOICES;
535         if (g_hash_table_lookup(optlist, "normal") != NULL)
536                 flags |= CHANNEL_NICKLIST_FLAG_NORMAL;
537         if (g_hash_table_lookup(optlist, "count") != NULL)
538                 flags |= CHANNEL_NICKLIST_FLAG_COUNT;
539
540         if (flags == 0) flags = CHANNEL_NICKLIST_FLAG_ALL;
541
542         unknowns = g_string_new(NULL);
543
544         channels = g_strsplit(channel, ",", -1);
545         for (tmp = channels; *tmp != NULL; tmp++) {
546                 chanrec = channel_find(server, *tmp);
547                 if (chanrec == NULL)
548                         g_string_sprintfa(unknowns, "%s,", *tmp);
549                 else {
550                         fe_channels_nicklist(chanrec, flags);
551                         signal_stop();
552                 }
553         }
554         g_strfreev(channels);
555
556         if (unknowns->len > 1)
557                 g_string_truncate(unknowns, unknowns->len-1);
558
559         if (unknowns->len > 0 && strcmp(channel, unknowns->str) != 0)
560                 signal_emit("command names", 3, unknowns->str, server, item);
561         g_string_free(unknowns, TRUE);
562
563         cmd_params_free(free_arg);
564 }
565
566 /* SYNTAX: CYCLE [<channel>] [<message>] */
567 static void cmd_cycle(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
568 {
569         CHANNEL_REC *chanrec;
570         char *channame, *msg, *joindata;
571         void *free_arg;
572
573         g_return_if_fail(data != NULL);
574         if (!IS_SERVER(server) || !server->connected)
575                 cmd_return_error(CMDERR_NOT_CONNECTED);
576
577         if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTCHAN,
578                             item, &channame, &msg))
579                 return;
580         if (*channame == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
581
582         chanrec = channel_find(server, channame);
583         if (chanrec == NULL) cmd_param_error(CMDERR_CHAN_NOT_FOUND);
584
585         joindata = chanrec->get_join_data(chanrec);
586         window_bind_add(window_item_window(chanrec),
587                         chanrec->server->tag, chanrec->name);
588
589         /* FIXME: kludgy kludgy... and it relies on channel not
590            being destroyed immediately.. */
591         signal_emit("command part", 3, data, server, item);
592         chanrec->left = TRUE;
593         channel_destroy(chanrec);
594
595         server->channels_join(server, joindata, FALSE);
596         g_free(joindata);
597
598         cmd_params_free(free_arg);
599 }
600
601 void fe_channels_init(void)
602 {
603         settings_add_bool("lookandfeel", "autoclose_windows", TRUE);
604         settings_add_int("lookandfeel", "names_max_columns", 6);
605         settings_add_int("lookandfeel", "names_max_width", 0);
606
607         signal_add("channel created", (SIGNAL_FUNC) signal_channel_created);
608         signal_add("channel destroyed", (SIGNAL_FUNC) signal_channel_destroyed);
609         signal_add_last("window item changed", (SIGNAL_FUNC) signal_window_item_changed);
610         signal_add_last("server disconnected", (SIGNAL_FUNC) sig_disconnected);
611
612         command_bind_first("join", NULL, (SIGNAL_FUNC) cmd_wjoin_pre);
613         command_bind("join", NULL, (SIGNAL_FUNC) cmd_join);
614         command_bind_last("join", NULL, (SIGNAL_FUNC) cmd_wjoin_post);
615         command_bind("channel", NULL, (SIGNAL_FUNC) cmd_channel);
616         command_bind("channel add", NULL, (SIGNAL_FUNC) cmd_channel_add);
617         command_bind("channel remove", NULL, (SIGNAL_FUNC) cmd_channel_remove);
618         command_bind("channel list", NULL, (SIGNAL_FUNC) cmd_channel_list);
619         command_bind("names", NULL, (SIGNAL_FUNC) cmd_names);
620         command_bind("cycle", NULL, (SIGNAL_FUNC) cmd_cycle);
621
622         command_set_options("channel add", "auto noauto -bots -botcmd");
623         command_set_options("names", "count ops halfops voices normal");
624         command_set_options("join", "window");
625 }
626
627 void fe_channels_deinit(void)
628 {
629         signal_remove("channel created", (SIGNAL_FUNC) signal_channel_created);
630         signal_remove("channel destroyed", (SIGNAL_FUNC) signal_channel_destroyed);
631         signal_remove("window item changed", (SIGNAL_FUNC) signal_window_item_changed);
632         signal_remove("server disconnected", (SIGNAL_FUNC) sig_disconnected);
633
634         command_unbind("join", (SIGNAL_FUNC) cmd_wjoin_pre);
635         command_unbind("join", (SIGNAL_FUNC) cmd_join);
636         command_unbind("join", (SIGNAL_FUNC) cmd_wjoin_post);
637         command_unbind("channel", (SIGNAL_FUNC) cmd_channel);
638         command_unbind("channel add", (SIGNAL_FUNC) cmd_channel_add);
639         command_unbind("channel remove", (SIGNAL_FUNC) cmd_channel_remove);
640         command_unbind("channel list", (SIGNAL_FUNC) cmd_channel_list);
641         command_unbind("names", (SIGNAL_FUNC) cmd_names);
642         command_unbind("cycle", (SIGNAL_FUNC) cmd_cycle);
643 }