2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
16 * IRC commands for mode changes (like MODE, AWAY, etc.)
28 #include "irc-write.h"
39 static bool Client_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
41 static bool Channel_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
44 static bool Add_To_List PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
45 CHANNEL *Channel, const char *Pattern));
46 static bool Del_From_List PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
47 CHANNEL *Channel, const char *Pattern));
49 static bool Send_ListChange PARAMS((const bool IsAdd, const char ModeChar,
50 CLIENT *Prefix, CLIENT *Client,
51 CHANNEL *Channel, const char *Mask));
55 * Handler for the IRC "MODE" command.
57 * See RFC 2812 section 3.1.5 ("user mode message") and section 3.2.3
58 * ("channel mode message"), and RFC 2811 section 4 ("channel modes").
60 * @param Client The client from which this command has been received.
61 * @param Req Request structure with prefix and all parameters.
62 * @returns CONNECTED or DISCONNECTED.
65 IRC_MODE( CLIENT *Client, REQUEST *Req )
70 assert(Client != NULL);
75 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
76 Client_ID(Client), Req->command);
78 /* Origin for answers */
79 if (Client_Type(Client) == CLIENT_SERVER) {
80 origin = Client_Search(Req->prefix);
82 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
88 /* Channel or user mode? */
89 cl = NULL; chan = NULL;
90 if (Client_IsValidNick(Req->argv[0]))
91 cl = Client_Search(Req->argv[0]);
92 if (Channel_IsValidName(Req->argv[0]))
93 chan = Channel_Search(Req->argv[0]);
96 return Client_Mode(Client, Req, origin, cl);
98 return Channel_Mode(Client, Req, origin, chan);
100 /* No target found! */
101 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
102 Client_ID(Client), Req->argv[0]);
107 * Check if the "mode limit" for a client has been reached.
109 * This limit doesn't apply for servers or services!
111 * @param Client The client to check.
112 * @param Count The number of modes already handled.
113 * @return true if the limit has been reached.
116 Mode_Limit_Reached(CLIENT *Client, int Count)
118 if (Client_Type(Client) == CLIENT_SERVER
119 || Client_Type(Client) == CLIENT_SERVICE)
121 if (Count < MAX_HNDL_MODES_ARG)
128 * Handle client mode requests
130 * @param Client The client from which this command has been received.
131 * @param Req Request structure with prefix and all parameters.
132 * @param Origin The originator of the MODE command (prefix).
133 * @param Target The target (client) of this MODE command.
134 * @returns CONNECTED or DISCONNECTED.
137 Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
139 char the_modes[COMMAND_LEN], x[2], *mode_ptr;
144 /* Is the client allowed to request or change the modes? */
145 if (Client_Type(Client) == CLIENT_USER) {
146 /* Users are only allowed to manipulate their own modes! */
147 if (Target != Client)
148 return IRC_WriteStrClient(Client,
149 ERR_USERSDONTMATCH_MSG,
153 /* Mode request: let's answer it :-) */
155 return IRC_WriteStrClient(Origin, RPL_UMODEIS_MSG,
157 Client_Modes(Target));
160 mode_ptr = Req->argv[mode_arg];
162 /* Initial state: set or unset modes? */
163 if (*mode_ptr == '+') {
165 strcpy(the_modes, "+");
166 } else if (*mode_ptr == '-') {
168 strcpy(the_modes, "-");
170 return IRC_WriteStrClient(Origin, ERR_UMODEUNKNOWNFLAG_MSG,
178 /* Try next argument if there's any */
180 if (mode_arg < Req->argc)
181 mode_ptr = Req->argv[mode_arg];
189 if ((*mode_ptr == '+' && !set)
190 || (*mode_ptr == '-' && set)) {
191 /* Action modifier ("+"/"-") must be changed */
192 len = strlen(the_modes) - 1;
193 if (the_modes[len] == '+'
194 || the_modes[len] == '-') {
195 /* Last character in the "result
196 * string" was an "action", so just
197 * overwrite it with the new action */
198 the_modes[len] = *mode_ptr;
200 /* Append new modifier character to
201 * the resulting mode string */
203 strlcat(the_modes, x,
206 if (*mode_ptr == '+')
217 case 'C': /* Only messages from clients sharing a channel */
218 case 'i': /* Invisible */
219 case 's': /* Server messages */
220 case 'w': /* Wallops messages */
224 if (Client_Type(Client) == CLIENT_SERVER) {
226 Client_SetAway(Origin, DEFAULT_AWAY_MSG);
228 ok = IRC_WriteStrClient(Origin,
229 ERR_NOPRIVILEGES_MSG,
232 case 'c': /* Receive connect notices
233 * (only settable by IRC operators!) */
234 if (!set || Client_Type(Client) == CLIENT_SERVER
235 || Client_OperByMe(Origin))
238 ok = IRC_WriteStrClient(Origin,
239 ERR_NOPRIVILEGES_MSG,
242 case 'o': /* IRC operator (only unsettable!) */
243 if (!set || Client_Type(Client) == CLIENT_SERVER) {
244 Client_SetOperByMe(Target, false);
247 ok = IRC_WriteStrClient(Origin,
248 ERR_NOPRIVILEGES_MSG,
251 case 'r': /* Restricted (only settable) */
252 if (set || Client_Type(Client) == CLIENT_SERVER)
255 ok = IRC_WriteStrClient(Origin,
259 case 'x': /* Cloak hostname */
260 if (Client_HasMode(Client, 'r'))
261 ok = IRC_WriteStrClient(Origin,
268 if (Client_Type(Client) != CLIENT_SERVER) {
270 "Unknown mode \"%c%c\" from \"%s\"!?",
271 set ? '+' : '-', *mode_ptr,
273 ok = IRC_WriteStrClient(Origin,
274 ERR_UMODEUNKNOWNFLAG2_MSG,
281 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
282 set ? '+' : '-', *mode_ptr,
283 Client_ID(Origin), Client_ID(Target));
291 /* Is there a valid mode change? */
296 if (Client_ModeAdd(Target, x[0]))
297 strlcat(the_modes, x, sizeof(the_modes));
299 if (Client_ModeDel(Target, x[0]))
300 strlcat(the_modes, x, sizeof(the_modes));
304 /* Are there changed modes? */
306 /* Remove needless action modifier characters */
307 len = strlen(the_modes) - 1;
308 if (the_modes[len] == '+' || the_modes[len] == '-')
309 the_modes[len] = '\0';
311 if (Client_Type(Client) == CLIENT_SERVER) {
312 /* Forward modes to other servers */
313 if (Client_Conn(Target) != NONE) {
314 /* Remote server (service?) changed modes
315 * for one of our clients. Inform it! */
316 IRC_WriteStrClientPrefix(Target, Origin,
321 IRC_WriteStrServersPrefix(Client, Origin,
326 /* Send reply to client and inform other servers */
327 ok = IRC_WriteStrClientPrefix(Client, Origin,
331 IRC_WriteStrServersPrefix(Client, Origin,
336 LogDebug("%s \"%s\": Mode change, now \"%s\".",
337 Client_TypeText(Target), Client_Mask(Target),
338 Client_Modes(Target));
341 IRC_SetPenalty(Client, 1);
347 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
349 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
350 const char *mode_ptr;
352 /* Member or not? -- That's the question! */
353 if (!Channel_IsMemberOf(Channel, Origin))
354 return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
355 Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
357 /* The sender is a member: generate extended reply */
358 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
359 mode_ptr = the_modes;
365 snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
366 strlcat(the_args, argadd, sizeof(the_args));
369 strlcat(the_args, " ", sizeof(the_args));
370 strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
376 strlcat(the_modes, the_args, sizeof(the_modes));
378 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
379 Client_ID(Origin), Channel_Name(Channel),
383 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
384 Client_ID(Origin), Channel_Name(Channel),
385 Channel_CreationTime(Channel)))
393 * Handle channel mode and channel-user mode changes
396 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
398 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
399 argadd[CLIENT_PASS_LEN], *mode_ptr, *o_mode_ptr;
400 bool connected, set, skiponce, retval, use_servermode,
401 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
402 int mode_arg, arg_arg, mode_arg_count = 0;
407 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
409 if (Channel_IsModeless(Channel))
410 return IRC_WriteStrClient(Client, ERR_NOCHANMODES_MSG,
411 Client_ID(Client), Channel_Name(Channel));
413 /* Mode request: let's answer it :-) */
415 return Channel_Mode_Answer_Request(Origin, Channel);
417 /* Check if origin is oper and opers can use mode */
418 use_servermode = Conf_OperServerMode;
419 if(Client_OperByMe(Client) && Conf_OperCanMode) {
423 /* Check if client is a server/service */
424 if(Client_Type(Client) == CLIENT_SERVER ||
425 Client_Type(Client) == CLIENT_SERVICE) {
429 /* Check if client is member of channel or an oper or an server/service */
430 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
431 return IRC_WriteStrClient(Origin, ERR_NOTONCHANNEL_MSG,
433 Channel_Name(Channel));
436 mode_ptr = Req->argv[mode_arg];
437 if (Req->argc > mode_arg + 1)
438 arg_arg = mode_arg + 1;
442 /* Initial state: set or unset modes? */
456 /* Prepare reply string */
457 strcpy(the_modes, set ? "+" : "-");
461 connected = CONNECTED;
466 /* Try next argument if there's any */
469 if (arg_arg > mode_arg)
474 if (mode_arg >= Req->argc)
476 mode_ptr = Req->argv[mode_arg];
478 if (Req->argc > mode_arg + 1)
479 arg_arg = mode_arg + 1;
488 if (((*mode_ptr == '+') && !set)
489 || ((*mode_ptr == '-') && set)) {
490 /* Action modifier ("+"/"-") must be changed ... */
491 len = strlen(the_modes) - 1;
492 if (the_modes[len] == '+' || the_modes[len] == '-') {
493 /* Adjust last action modifier in result */
494 the_modes[len] = *mode_ptr;
496 /* Append modifier character to result string */
498 strlcat(the_modes, x, sizeof(the_modes));
500 set = *mode_ptr == '+';
505 /* Are there arguments left? */
506 if (arg_arg >= Req->argc)
510 o_mode_ptr = Channel_UserModes(Channel, Client);
511 while( *o_mode_ptr ) {
512 if ( *o_mode_ptr == 'q')
514 if ( *o_mode_ptr == 'a')
516 if ( *o_mode_ptr == 'o')
518 if ( *o_mode_ptr == 'h')
529 /* --- Channel modes --- */
530 case 'R': /* Registered users only */
531 case 's': /* Secret channel */
532 case 'z': /* Secure connections only */
533 if(!is_oper && !is_machine && !is_owner &&
534 !is_admin && !is_op) {
535 connected = IRC_WriteStrClient(Origin,
536 ERR_CHANOPRIVSNEEDED_MSG,
537 Client_ID(Origin), Channel_Name(Channel));
540 case 'i': /* Invite only */
541 case 'm': /* Moderated */
542 case 'n': /* Only members can write */
543 case 't': /* Topic locked */
544 if(is_oper || is_machine || is_owner ||
545 is_admin || is_op || is_halfop)
548 connected = IRC_WriteStrClient(Origin,
549 ERR_CHANOPRIVSNEEDED_MSG,
550 Client_ID(Origin), Channel_Name(Channel));
552 case 'k': /* Channel key */
553 if (Mode_Limit_Reached(Client, mode_arg_count++))
556 if (is_oper || is_machine || is_owner ||
557 is_admin || is_op || is_halfop)
560 connected = IRC_WriteStrClient(Origin,
561 ERR_CHANOPRIVSNEEDED_MSG,
563 Channel_Name(Channel));
566 if (arg_arg > mode_arg) {
567 if (is_oper || is_machine || is_owner ||
568 is_admin || is_op || is_halfop) {
569 Channel_ModeDel(Channel, 'k');
570 Channel_SetKey(Channel,
572 strlcpy(argadd, Channel_Key(Channel),
576 connected = IRC_WriteStrClient(Origin,
577 ERR_CHANOPRIVSNEEDED_MSG,
579 Channel_Name(Channel));
581 Req->argv[arg_arg][0] = '\0';
584 connected = IRC_WriteStrClient(Origin,
585 ERR_NEEDMOREPARAMS_MSG,
586 Client_ID(Origin), Req->command);
590 case 'l': /* Member limit */
591 if (Mode_Limit_Reached(Client, mode_arg_count++))
594 if (is_oper || is_machine || is_owner ||
595 is_admin || is_op || is_halfop)
598 connected = IRC_WriteStrClient(Origin,
599 ERR_CHANOPRIVSNEEDED_MSG,
601 Channel_Name(Channel));
604 if (arg_arg > mode_arg) {
605 if (is_oper || is_machine || is_owner ||
606 is_admin || is_op || is_halfop) {
607 l = atol(Req->argv[arg_arg]);
608 if (l > 0 && l < 0xFFFF) {
609 Channel_ModeDel(Channel, 'l');
610 Channel_SetMaxUsers(Channel, l);
611 snprintf(argadd, sizeof(argadd),
616 connected = IRC_WriteStrClient(Origin,
617 ERR_CHANOPRIVSNEEDED_MSG,
619 Channel_Name(Channel));
621 Req->argv[arg_arg][0] = '\0';
624 connected = IRC_WriteStrClient(Origin,
625 ERR_NEEDMOREPARAMS_MSG,
626 Client_ID(Origin), Req->command);
630 case 'O': /* IRC operators only */
632 /* Only IRC operators are allowed to
633 * set the 'O' channel mode! */
634 if(is_oper || is_machine)
637 connected = IRC_WriteStrClient(Origin,
638 ERR_NOPRIVILEGES_MSG,
640 } else if(is_oper || is_machine || is_owner ||
644 connected = IRC_WriteStrClient(Origin,
645 ERR_CHANOPRIVSNEEDED_MSG,
647 Channel_Name(Channel));
649 case 'P': /* Persistent channel */
651 /* Only IRC operators are allowed to
652 * set the 'P' channel mode! */
653 if(is_oper || is_machine)
656 connected = IRC_WriteStrClient(Origin,
657 ERR_NOPRIVILEGES_MSG,
659 } else if(is_oper || is_machine || is_owner ||
663 connected = IRC_WriteStrClient(Origin,
664 ERR_CHANOPRIVSNEEDED_MSG,
666 Channel_Name(Channel));
668 /* --- Channel user modes --- */
669 case 'q': /* Owner */
670 case 'a': /* Channel admin */
671 if(!is_oper && !is_machine && !is_owner) {
672 connected = IRC_WriteStrClient(Origin,
673 ERR_CHANOPRIVSNEEDED_MSG,
675 Channel_Name(Channel));
678 case 'o': /* Channel operator */
679 if(!is_oper && !is_machine && !is_owner &&
680 !is_admin && !is_op) {
681 connected = IRC_WriteStrClient(Origin,
682 ERR_CHANOPRIVSNEEDED_MSG,
684 Channel_Name(Channel));
687 case 'h': /* Half Op */
688 if(!is_oper && !is_machine && !is_owner &&
689 !is_admin && !is_op) {
690 connected = IRC_WriteStrClient(Origin,
691 ERR_CHANOPRIVSNEEDED_MSG,
693 Channel_Name(Channel));
696 case 'v': /* Voice */
697 if (arg_arg > mode_arg) {
698 if (is_oper || is_machine || is_owner ||
699 is_admin || is_op || is_halfop) {
700 client = Client_Search(Req->argv[arg_arg]);
704 connected = IRC_WriteStrClient(Origin,
709 connected = IRC_WriteStrClient(Origin,
710 ERR_CHANOPRIVSNEEDED_MSG,
712 Channel_Name(Channel));
714 Req->argv[arg_arg][0] = '\0';
717 connected = IRC_WriteStrClient(Origin,
718 ERR_NEEDMOREPARAMS_MSG,
719 Client_ID(Origin), Req->command);
723 /* --- Channel lists --- */
724 case 'I': /* Invite lists */
725 case 'b': /* Ban lists */
726 case 'e': /* Channel exception lists */
727 if (Mode_Limit_Reached(Client, mode_arg_count++))
729 if (arg_arg > mode_arg) {
731 if (is_oper || is_machine || is_owner ||
732 is_admin || is_op || is_halfop) {
734 ? Add_To_List(*mode_ptr, Origin,
737 : Del_From_List(*mode_ptr, Origin,
741 connected = IRC_WriteStrClient(Origin,
742 ERR_CHANOPRIVSNEEDED_MSG,
744 Channel_Name(Channel));
746 Req->argv[arg_arg][0] = '\0';
751 Channel_ShowInvites(Origin, Channel);
754 Channel_ShowBans(Origin, Channel);
757 Channel_ShowExcepts(Origin, Channel);
763 if (Client_Type(Client) != CLIENT_SERVER) {
765 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
766 set ? '+' : '-', *mode_ptr,
767 Client_ID(Origin), Channel_Name(Channel));
768 connected = IRC_WriteStrClient(Origin,
770 Client_ID(Origin), *mode_ptr,
771 Channel_Name(Channel));
775 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
776 set ? '+' : '-', *mode_ptr,
777 Client_ID(Origin), Channel_Name(Channel));
785 /* Is there a valid mode change? */
789 /* Validate target client */
790 if (client && (!Channel_IsMemberOf(Channel, client))) {
791 if (!IRC_WriteStrClient
792 (Origin, ERR_USERNOTINCHANNEL_MSG,
793 Client_ID(Origin), Client_ID(client),
794 Channel_Name(Channel)))
801 /* Channel-User-Mode */
803 ? Channel_UserModeAdd(Channel, client, x[0])
804 : Channel_UserModeDel(Channel, client, x[0]);
806 strlcat(the_args, " ", sizeof(the_args));
807 strlcat(the_args, Client_ID(client),
809 strlcat(the_modes, x, sizeof(the_modes));
811 ("User \"%s\": Mode change on %s, now \"%s\"",
812 Client_Mask(client), Channel_Name(Channel),
813 Channel_UserModes(Channel, client));
818 ? Channel_ModeAdd(Channel, x[0])
819 : Channel_ModeDel(Channel, x[0]);
821 strlcat(the_modes, x, sizeof(the_modes));
822 LogDebug("Channel %s: Mode change, now \"%s\".",
823 Channel_Name(Channel),
824 Channel_Modes(Channel));
828 /* Are there additional arguments to add? */
830 strlcat(the_args, " ", sizeof(the_args));
831 strlcat(the_args, argadd, sizeof(the_args));
836 /* Are there changed modes? */
838 /* Clean up mode string */
839 len = strlen(the_modes) - 1;
840 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
841 the_modes[len] = '\0';
843 if (Client_Type(Client) == CLIENT_SERVER) {
844 /* MODE requests for local channels from other servers
845 * are definitely invalid! */
846 if (Channel_IsLocal(Channel)) {
847 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
851 /* Forward mode changes to channel users and all the
852 * other remote servers: */
853 IRC_WriteStrServersPrefix(Client, Origin,
854 "MODE %s %s%s", Channel_Name(Channel),
855 the_modes, the_args);
856 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
857 false, "MODE %s %s%s", Channel_Name(Channel),
858 the_modes, the_args);
861 Origin = Client_ThisServer();
862 /* Send reply to client and inform other servers and channel users */
863 connected = IRC_WriteStrClientPrefix(Client, Origin,
864 "MODE %s %s%s", Channel_Name(Channel),
865 the_modes, the_args);
866 /* Only forward requests for non-local channels */
867 if (!Channel_IsLocal(Channel))
868 IRC_WriteStrServersPrefix(Client, Origin,
869 "MODE %s %s%s", Channel_Name(Channel),
870 the_modes, the_args);
871 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
872 false, "MODE %s %s%s", Channel_Name(Channel),
873 the_modes, the_args);
877 IRC_SetPenalty(Client, 1);
883 IRC_AWAY( CLIENT *Client, REQUEST *Req )
885 assert( Client != NULL );
886 assert( Req != NULL );
888 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
890 if(( Req->argc == 1 ) && (Req->argv[0][0] ))
892 Client_SetAway( Client, Req->argv[0] );
893 Client_ModeAdd( Client, 'a' );
894 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
895 return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
899 Client_ModeDel( Client, 'a' );
900 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
901 return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
907 * Add entries to channel invite, ban and exception lists.
909 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
910 * @param Prefix The originator of the command.
911 * @param Client The sender of the command.
912 * @param Channel The channel of which the list should be modified.
913 * @param Pattern The pattern to add to the list.
914 * @return CONNECTED or DISCONNECTED.
917 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
921 struct list_head *list = NULL;
922 long int current_count;
924 assert(Client != NULL);
925 assert(Channel != NULL);
926 assert(Pattern != NULL);
927 assert(what == 'I' || what == 'b' || what == 'e');
929 mask = Lists_MakeMask(Pattern);
930 current_count = Lists_Count(Channel_GetListInvites(Channel))
931 + Lists_Count(Channel_GetListExcepts(Channel))
932 + Lists_Count(Channel_GetListBans(Channel));
936 list = Channel_GetListInvites(Channel);
939 list = Channel_GetListBans(Channel);
942 list = Channel_GetListExcepts(Channel);
946 if (Lists_CheckDupeMask(list, mask))
948 if (Client_Type(Client) == CLIENT_USER &&
949 current_count >= MAX_HNDL_CHANNEL_LISTS)
950 return IRC_WriteStrClient(Client, ERR_LISTFULL_MSG,
952 Channel_Name(Channel), mask,
953 MAX_HNDL_CHANNEL_LISTS);
957 if (!Channel_AddInvite(Channel, mask, false))
961 if (!Channel_AddBan(Channel, mask))
965 if (!Channel_AddExcept(Channel, mask))
969 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
974 * Delete entries from channel invite, ban and exeption lists.
976 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
977 * @param Prefix The originator of the command.
978 * @param Client The sender of the command.
979 * @param Channel The channel of which the list should be modified.
980 * @param Pattern The pattern to add to the list.
981 * @return CONNECTED or DISCONNECTED.
984 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
988 struct list_head *list = NULL;
990 assert(Client != NULL);
991 assert(Channel != NULL);
992 assert(Pattern != NULL);
993 assert(what == 'I' || what == 'b' || what == 'e');
995 mask = Lists_MakeMask(Pattern);
999 list = Channel_GetListInvites(Channel);
1002 list = Channel_GetListBans(Channel);
1005 list = Channel_GetListExcepts(Channel);
1009 if (!Lists_CheckDupeMask(list, mask))
1011 Lists_Del(list, mask);
1013 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1018 * Send information about changed channel invite/ban/exception lists to clients.
1020 * @param IsAdd true if the list item has been added, false otherwise.
1021 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1022 * @param Prefix The originator of the mode list change.
1023 * @param Client The sender of the command.
1024 * @param Channel The channel of which the list has been modified.
1025 * @param Mask The mask which has been added or removed.
1026 * @return CONNECTED or DISCONNECTED.
1029 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1030 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1034 /* Send confirmation to the client */
1035 if (Client_Type(Client) == CLIENT_USER)
1036 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1037 Channel_Name(Channel),
1041 /* to other servers */
1042 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1043 Channel_Name(Channel), IsAdd ? '+' : '-',
1046 /* and local users in channel */
1047 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1048 "MODE %s %c%c %s", Channel_Name(Channel),
1049 IsAdd ? '+' : '-', ModeChar, Mask );
1052 } /* Send_ListChange */