+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 */
+
+
+/**
+ * Check wether a client is allowed to administer a channel or not.
+ *
+ * @param Chan The channel to test.
+ * @param Client The client from which the command has been received.
+ * @param Origin The originator of the command (or NULL).
+ * @param OnChannel Set to true if the originator is member of the channel.
+ * @param AdminOk Set to true if the client is allowed to do
+ * administrative tasks on this channel.
+ * @param UseServerMode Set to true if ngIRCd should emulate "server mode",
+ * that is send commands as if originating from a server
+ * and not the originator of the command.
+ */
+GLOBAL void
+Channel_CheckAdminRights(CHANNEL *Chan, CLIENT *Client, CLIENT *Origin,
+ bool *OnChannel, bool *AdminOk, bool *UseServerMode)
+{
+ assert (Chan != NULL);
+ assert (Client != NULL);
+ assert (OnChannel != NULL);
+ assert (AdminOk != NULL);
+ assert (UseServerMode != NULL);
+
+ /* Use the client as origin, if no origin has been given (no prefix?) */
+ if (!Origin)
+ Origin = Client;
+
+ *OnChannel = false;
+ *AdminOk = false;
+ *UseServerMode = false;
+
+ if (Client_Type(Client) != CLIENT_USER
+ && Client_Type(Client) != CLIENT_SERVER
+ && Client_Type(Client) != CLIENT_SERVICE)
+ return;
+
+ /* Allow channel administration if the client is a server or service */
+ if (Client_Type(Client) != CLIENT_USER) {
+ *AdminOk = true;
+ return;
+ }
+
+ *OnChannel = Channel_IsMemberOf(Chan, Origin);
+
+ if (*OnChannel && strchr(Channel_UserModes(Chan, Origin), 'o')) {
+ /* User is a channel operator */
+ *AdminOk = true;
+ } else if (Conf_OperCanMode) {
+ /* IRC operators are allowed to administer channels as well */
+ if (Client_OperByMe(Origin)) {
+ *AdminOk = true;
+ if (Conf_OperServerMode)
+ *UseServerMode = true;
+ }
+ }
+} /* Channel_CheckAdminRights */
+
+
+static CL2CHAN *