+/**
+ * Add entries to channel invite, ban and exception lists.
+ *
+ * @param what Can be 'I' for invite or 'b' for ban list.
+ * @param Prefix The originator of the command.
+ * @param Client The sender of the command.
+ * @param Channel The channel of which the list should be modified.
+ * @param Pattern The pattern to add to the list.
+ * @return CONNECTED or DISCONNECTED.
+ */
+static bool
+Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
+ const char *Pattern)
+{
+ const char *mask;
+ struct list_head *list;
+
+ assert(Client != NULL);
+ assert(Channel != NULL);
+ assert(Pattern != NULL);
+ assert(what == 'I' || what == 'b');
+
+ mask = Lists_MakeMask(Pattern);
+
+ switch(what) {
+ case 'I':
+ list = Channel_GetListInvites(Channel);
+ break;
+ case 'b':
+ list = Channel_GetListBans(Channel);
+ break;
+ }
+
+ if (Lists_CheckDupeMask(list, mask))
+ return CONNECTED;
+ if (Client_Type(Client) == CLIENT_USER &&
+ Lists_Count(list) >= MAX_HNDL_CHANNEL_LISTS)
+ return IRC_WriteStrClient(Client, ERR_LISTFULL_MSG,
+ Client_ID(Client),
+ Channel_Name(Channel), mask,
+ MAX_HNDL_CHANNEL_LISTS);
+
+ switch (what) {
+ case 'I':
+ if (!Channel_AddInvite(Channel, mask, false))
+ return CONNECTED;
+ break;
+ case 'b':
+ if (!Channel_AddBan(Channel, mask))
+ return CONNECTED;
+ break;
+ }
+ return Send_ListChange(true, what, Prefix, Client, Channel, mask);
+}
+
+
+/**
+ * Delete entries from channel invite, ban and exeption lists.
+ *
+ * @param what Can be 'I' for invite or 'b' for ban list.
+ * @param Prefix The originator of the command.
+ * @param Client The sender of the command.
+ * @param Channel The channel of which the list should be modified.
+ * @param Pattern The pattern to add to the list.
+ * @return CONNECTED or DISCONNECTED.
+ */
+static bool
+Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
+ const char *Pattern)
+{
+ const char *mask;
+ struct list_head *list;
+
+ assert(Client != NULL);
+ assert(Channel != NULL);
+ assert(Pattern != NULL);
+ assert(what == 'I' || what == 'b');
+
+ mask = Lists_MakeMask(Pattern);
+
+ switch (what) {
+ case 'I':
+ list = Channel_GetListInvites(Channel);
+ break;
+ case 'b':
+ list = Channel_GetListBans(Channel);
+ break;
+ }
+
+ if (!Lists_CheckDupeMask(list, mask))
+ return CONNECTED;
+ Lists_Del(list, mask);
+
+ return Send_ListChange(false, what, Prefix, Client, Channel, mask);
+}
+
+
+/**
+ * Send information about changed channel ban/invite lists to clients.
+ *
+ * @param IsAdd true if the list item has been added, false otherwise.
+ * @param ModeChar The mode to use (e. g. 'b' or 'I')
+ * @param Prefix The originator of the mode list change.
+ * @param Client The sender of the command.
+ * @param Channel The channel of which the list has been modified.
+ * @param Mask The mask which has been added or removed.
+ * @return CONNECTED or DISCONNECTED.
+ */
+static bool
+Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
+ CLIENT *Client, CHANNEL *Channel, const char *Mask)
+{
+ bool ok = true;
+
+ /* Send confirmation to the client */
+ if (Client_Type(Client) == CLIENT_USER)
+ ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
+ Channel_Name(Channel),
+ IsAdd ? '+' : '-',
+ ModeChar, Mask);
+
+ /* to other servers */
+ IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
+ Channel_Name(Channel), IsAdd ? '+' : '-',
+ ModeChar, Mask);
+
+ /* and local users in channel */
+ IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
+ "MODE %s %c%c %s", Channel_Name(Channel),
+ IsAdd ? '+' : '-', ModeChar, Mask );
+
+ return ok;
+} /* Send_ListChange */
+
+