+GLOBAL bool
+Channel_AddBan(CHANNEL *c, const char *mask )
+{
+ struct list_head *h = Channel_GetListBans(c);
+ LogDebug("Adding \"%s\" to \"%s\" ban list", mask, Channel_Name(c));
+ return Lists_Add(h, mask, false, NULL);
+}
+
+
+GLOBAL bool
+Channel_AddExcept(CHANNEL *c, const char *mask )
+{
+ struct list_head *h = Channel_GetListExcepts(c);
+ LogDebug("Adding \"%s\" to \"%s\" exception list", mask, Channel_Name(c));
+ return Lists_Add(h, mask, false, NULL);
+}
+
+
+GLOBAL bool
+Channel_AddInvite(CHANNEL *c, const char *mask, bool onlyonce)
+{
+ struct list_head *h = Channel_GetListInvites(c);
+ LogDebug("Adding \"%s\" to \"%s\" invite list", mask, Channel_Name(c));
+ return Lists_Add(h, mask, onlyonce, NULL);
+}
+
+
+static bool
+ShowChannelList(struct list_head *head, CLIENT *Client, CHANNEL *Channel,
+ char *msg, char *msg_end)
+{
+ struct list_elem *e;
+
+ assert (Client != NULL);
+ assert (Channel != NULL);
+
+ e = Lists_GetFirst(head);
+ while (e) {
+ if (!IRC_WriteStrClient(Client, msg, Client_ID(Client),
+ Channel_Name(Channel),
+ Lists_GetMask(e)))
+ return DISCONNECTED;
+ e = Lists_GetNext(e);
+ }
+
+ return IRC_WriteStrClient(Client, msg_end, Client_ID(Client),
+ Channel_Name(Channel));
+}
+
+
+GLOBAL bool
+Channel_ShowBans( CLIENT *Client, CHANNEL *Channel )
+{
+ struct list_head *h;
+
+ assert( Channel != NULL );
+
+ h = Channel_GetListBans(Channel);
+ return ShowChannelList(h, Client, Channel, RPL_BANLIST_MSG,
+ RPL_ENDOFBANLIST_MSG);
+}
+
+
+GLOBAL bool
+Channel_ShowExcepts( CLIENT *Client, CHANNEL *Channel )
+{
+ struct list_head *h;
+
+ assert( Channel != NULL );
+
+ h = Channel_GetListExcepts(Channel);
+ return ShowChannelList(h, Client, Channel, RPL_EXCEPTLIST_MSG,
+ RPL_ENDOFEXCEPTLIST_MSG);
+}
+
+
+GLOBAL bool
+Channel_ShowInvites( CLIENT *Client, CHANNEL *Channel )
+{
+ struct list_head *h;
+
+ assert( Channel != NULL );
+
+ h = Channel_GetListInvites(Channel);
+ return ShowChannelList(h, Client, Channel, RPL_INVITELIST_MSG,
+ RPL_ENDOFINVITELIST_MSG);
+}
+
+
+/**
+ * Log a message to the local &SERVER channel, if it exists.
+ */
+GLOBAL void
+Channel_LogServer(const char *msg)
+{
+ CHANNEL *sc;
+ CLIENT *c;
+
+ assert(msg != NULL);
+
+ sc = Channel_Search("&SERVER");
+ if (!sc)
+ return;
+
+ c = Client_ThisServer();
+ Channel_Write(sc, c, c, "PRIVMSG", false, msg);
+} /* Channel_LogServer */
+
+
+GLOBAL bool
+Channel_CheckKey(CHANNEL *Chan, CLIENT *Client, const char *Key)
+{
+ char *file_name, line[COMMAND_LEN], *nick, *pass;
+ FILE *fd;
+
+ assert(Chan != NULL);
+ assert(Client != NULL);
+ assert(Key != NULL);
+
+ if (!strchr(Chan->modes, 'k'))
+ return true;
+ if (*Key == '\0')
+ return false;
+ if (strcmp(Chan->key, Key) == 0)
+ return true;
+
+ file_name = array_start(&Chan->keyfile);
+ if (!file_name)
+ return false;
+ fd = fopen(file_name, "r");
+ if (!fd) {
+ Log(LOG_ERR, "Can't open channel key file \"%s\" for %s: %s",
+ file_name, Chan->name, strerror(errno));
+ return false;
+ }
+
+ while (fgets(line, (int)sizeof(line), fd) != NULL) {
+ ngt_TrimStr(line);
+ if (! (nick = strchr(line, ':')))
+ continue;
+ *nick++ = '\0';
+ if (!Match(line, Client_User(Client)))
+ continue;
+ if (! (pass = strchr(nick, ':')))
+ continue;
+ *pass++ = '\0';
+ if (!Match(nick, Client_ID(Client)))
+ continue;
+ if (strcmp(Key, pass) != 0)
+ continue;
+
+ fclose(fd);
+ return true;
+ }
+ fclose(fd);
+ return false;
+} /* Channel_CheckKey */
+
+
+static CL2CHAN *