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;
141 bool send_RPL_HOSTHIDDEN_MSG = false;
145 /* Is the client allowed to request or change the modes? */
146 if (Client_Type(Client) == CLIENT_USER) {
147 /* Users are only allowed to manipulate their own modes! */
148 if (Target != Client)
149 return IRC_WriteStrClient(Client,
150 ERR_USERSDONTMATCH_MSG,
154 /* Mode request: let's answer it :-) */
156 return IRC_WriteStrClient(Origin, RPL_UMODEIS_MSG,
158 Client_Modes(Target));
161 mode_ptr = Req->argv[mode_arg];
163 /* Initial state: set or unset modes? */
164 if (*mode_ptr == '+') {
166 strcpy(the_modes, "+");
167 } else if (*mode_ptr == '-') {
169 strcpy(the_modes, "-");
171 return IRC_WriteStrClient(Origin, ERR_UMODEUNKNOWNFLAG_MSG,
179 /* Try next argument if there's any */
181 if (mode_arg < Req->argc)
182 mode_ptr = Req->argv[mode_arg];
190 if ((*mode_ptr == '+' && !set)
191 || (*mode_ptr == '-' && set)) {
192 /* Action modifier ("+"/"-") must be changed */
193 len = strlen(the_modes) - 1;
194 if (the_modes[len] == '+'
195 || the_modes[len] == '-') {
196 /* Last character in the "result
197 * string" was an "action", so just
198 * overwrite it with the new action */
199 the_modes[len] = *mode_ptr;
201 /* Append new modifier character to
202 * the resulting mode string */
204 strlcat(the_modes, x,
207 if (*mode_ptr == '+')
218 case 'C': /* Only messages from clients sharing a channel */
219 case 'i': /* Invisible */
220 case 's': /* Server messages */
221 case 'w': /* Wallops messages */
225 if (Client_Type(Client) == CLIENT_SERVER) {
227 Client_SetAway(Origin, DEFAULT_AWAY_MSG);
229 ok = IRC_WriteStrClient(Origin,
230 ERR_NOPRIVILEGES_MSG,
234 if (Client_HasMode(Client, 'r'))
235 ok = IRC_WriteStrClient(Origin,
241 case 'c': /* Receive connect notices
242 * (only settable by IRC operators!) */
243 if (!set || Client_Type(Client) == CLIENT_SERVER
244 || Client_OperByMe(Origin))
247 ok = IRC_WriteStrClient(Origin,
248 ERR_NOPRIVILEGES_MSG,
251 case 'o': /* IRC operator (only unsettable!) */
252 if (!set || Client_Type(Client) == CLIENT_SERVER) {
253 Client_SetOperByMe(Target, false);
256 ok = IRC_WriteStrClient(Origin,
257 ERR_NOPRIVILEGES_MSG,
260 case 'r': /* Restricted (only settable) */
261 if (set || Client_Type(Client) == CLIENT_SERVER)
264 ok = IRC_WriteStrClient(Origin,
268 case 'R': /* Registered (not [un]settable by clients) */
269 if (Client_Type(Client) == CLIENT_SERVER)
272 ok = IRC_WriteStrClient(Origin,
273 ERR_NICKREGISTER_MSG,
276 case 'x': /* Cloak hostname */
277 if (Client_HasMode(Client, 'r'))
278 ok = IRC_WriteStrClient(Origin,
281 else if (!set || Conf_CloakHostModeX[0]
282 || Client_Type(Client) == CLIENT_SERVER
283 || Client_OperByMe(Client)) {
285 send_RPL_HOSTHIDDEN_MSG = true;
287 ok = IRC_WriteStrClient(Origin,
288 ERR_NOPRIVILEGES_MSG,
292 if (Client_Type(Client) != CLIENT_SERVER) {
294 "Unknown mode \"%c%c\" from \"%s\"!?",
295 set ? '+' : '-', *mode_ptr,
297 ok = IRC_WriteStrClient(Origin,
298 ERR_UMODEUNKNOWNFLAG2_MSG,
305 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
306 set ? '+' : '-', *mode_ptr,
307 Client_ID(Origin), Client_ID(Target));
315 /* Is there a valid mode change? */
320 if (Client_ModeAdd(Target, x[0]))
321 strlcat(the_modes, x, sizeof(the_modes));
323 if (Client_ModeDel(Target, x[0]))
324 strlcat(the_modes, x, sizeof(the_modes));
328 /* Are there changed modes? */
330 /* Remove needless action modifier characters */
331 len = strlen(the_modes) - 1;
332 if (the_modes[len] == '+' || the_modes[len] == '-')
333 the_modes[len] = '\0';
335 if (Client_Type(Client) == CLIENT_SERVER) {
336 /* Forward modes to other servers */
337 if (Client_Conn(Target) != NONE) {
338 /* Remote server (service?) changed modes
339 * for one of our clients. Inform it! */
340 IRC_WriteStrClientPrefix(Target, Origin,
345 IRC_WriteStrServersPrefix(Client, Origin,
350 /* Send reply to client and inform other servers */
351 ok = IRC_WriteStrClientPrefix(Client, Origin,
355 IRC_WriteStrServersPrefix(Client, Origin,
359 if (send_RPL_HOSTHIDDEN_MSG)
360 IRC_WriteStrClient(Client, RPL_HOSTHIDDEN_MSG,
362 Client_HostnameCloaked(Client));
364 LogDebug("%s \"%s\": Mode change, now \"%s\".",
365 Client_TypeText(Target), Client_Mask(Target),
366 Client_Modes(Target));
369 IRC_SetPenalty(Client, 1);
375 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
377 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
378 const char *mode_ptr;
380 /* Member or not? -- That's the question! */
381 if (!Channel_IsMemberOf(Channel, Origin))
382 return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
383 Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
385 /* The sender is a member: generate extended reply */
386 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
387 mode_ptr = the_modes;
393 snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
394 strlcat(the_args, argadd, sizeof(the_args));
397 strlcat(the_args, " ", sizeof(the_args));
398 strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
404 strlcat(the_modes, the_args, sizeof(the_modes));
406 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
407 Client_ID(Origin), Channel_Name(Channel),
411 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
412 Client_ID(Origin), Channel_Name(Channel),
413 Channel_CreationTime(Channel)))
421 * Handle channel mode and channel-user mode changes
424 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
426 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
427 argadd[CLIENT_PASS_LEN], *mode_ptr, *o_mode_ptr;
428 bool connected, set, skiponce, retval, use_servermode,
429 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
430 int mode_arg, arg_arg, mode_arg_count = 0;
435 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
437 if (Channel_IsModeless(Channel))
438 return IRC_WriteStrClient(Client, ERR_NOCHANMODES_MSG,
439 Client_ID(Client), Channel_Name(Channel));
441 /* Mode request: let's answer it :-) */
443 return Channel_Mode_Answer_Request(Origin, Channel);
445 /* Check if origin is oper and opers can use mode */
446 use_servermode = Conf_OperServerMode;
447 if(Client_OperByMe(Client) && Conf_OperCanMode) {
451 /* Check if client is a server/service */
452 if(Client_Type(Client) == CLIENT_SERVER ||
453 Client_Type(Client) == CLIENT_SERVICE) {
457 /* Check if client is member of channel or an oper or an server/service */
458 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
459 return IRC_WriteStrClient(Origin, ERR_NOTONCHANNEL_MSG,
461 Channel_Name(Channel));
464 mode_ptr = Req->argv[mode_arg];
465 if (Req->argc > mode_arg + 1)
466 arg_arg = mode_arg + 1;
470 /* Initial state: set or unset modes? */
484 /* Prepare reply string */
485 strcpy(the_modes, set ? "+" : "-");
489 connected = CONNECTED;
494 /* Try next argument if there's any */
497 if (arg_arg > mode_arg)
502 if (mode_arg >= Req->argc)
504 mode_ptr = Req->argv[mode_arg];
506 if (Req->argc > mode_arg + 1)
507 arg_arg = mode_arg + 1;
516 if (((*mode_ptr == '+') && !set)
517 || ((*mode_ptr == '-') && set)) {
518 /* Action modifier ("+"/"-") must be changed ... */
519 len = strlen(the_modes) - 1;
520 if (the_modes[len] == '+' || the_modes[len] == '-') {
521 /* Adjust last action modifier in result */
522 the_modes[len] = *mode_ptr;
524 /* Append modifier character to result string */
526 strlcat(the_modes, x, sizeof(the_modes));
528 set = *mode_ptr == '+';
533 /* Are there arguments left? */
534 if (arg_arg >= Req->argc)
538 o_mode_ptr = Channel_UserModes(Channel, Client);
539 while( *o_mode_ptr ) {
540 if ( *o_mode_ptr == 'q')
542 if ( *o_mode_ptr == 'a')
544 if ( *o_mode_ptr == 'o')
546 if ( *o_mode_ptr == 'h')
557 /* --- Channel modes --- */
558 case 'R': /* Registered users only */
559 case 's': /* Secret channel */
560 case 'z': /* Secure connections only */
561 if(!is_oper && !is_machine && !is_owner &&
562 !is_admin && !is_op) {
563 connected = IRC_WriteStrClient(Origin,
564 ERR_CHANOPRIVSNEEDED_MSG,
565 Client_ID(Origin), Channel_Name(Channel));
568 case 'i': /* Invite only */
569 case 'M': /* Only identified nicks can write */
570 case 'm': /* Moderated */
571 case 'n': /* Only members can write */
572 case 't': /* Topic locked */
573 if(is_oper || is_machine || is_owner ||
574 is_admin || is_op || is_halfop)
577 connected = IRC_WriteStrClient(Origin,
578 ERR_CHANOPRIVSNEEDED_MSG,
579 Client_ID(Origin), Channel_Name(Channel));
581 case 'k': /* Channel key */
582 if (Mode_Limit_Reached(Client, mode_arg_count++))
585 if (is_oper || is_machine || is_owner ||
586 is_admin || is_op || is_halfop)
589 connected = IRC_WriteStrClient(Origin,
590 ERR_CHANOPRIVSNEEDED_MSG,
592 Channel_Name(Channel));
595 if (arg_arg > mode_arg) {
596 if (is_oper || is_machine || is_owner ||
597 is_admin || is_op || is_halfop) {
598 Channel_ModeDel(Channel, 'k');
599 Channel_SetKey(Channel,
601 strlcpy(argadd, Channel_Key(Channel),
605 connected = IRC_WriteStrClient(Origin,
606 ERR_CHANOPRIVSNEEDED_MSG,
608 Channel_Name(Channel));
610 Req->argv[arg_arg][0] = '\0';
613 connected = IRC_WriteStrClient(Origin,
614 ERR_NEEDMOREPARAMS_MSG,
615 Client_ID(Origin), Req->command);
619 case 'l': /* Member limit */
620 if (Mode_Limit_Reached(Client, mode_arg_count++))
623 if (is_oper || is_machine || is_owner ||
624 is_admin || is_op || is_halfop)
627 connected = IRC_WriteStrClient(Origin,
628 ERR_CHANOPRIVSNEEDED_MSG,
630 Channel_Name(Channel));
633 if (arg_arg > mode_arg) {
634 if (is_oper || is_machine || is_owner ||
635 is_admin || is_op || is_halfop) {
636 l = atol(Req->argv[arg_arg]);
637 if (l > 0 && l < 0xFFFF) {
638 Channel_ModeDel(Channel, 'l');
639 Channel_SetMaxUsers(Channel, l);
640 snprintf(argadd, sizeof(argadd),
645 connected = IRC_WriteStrClient(Origin,
646 ERR_CHANOPRIVSNEEDED_MSG,
648 Channel_Name(Channel));
650 Req->argv[arg_arg][0] = '\0';
653 connected = IRC_WriteStrClient(Origin,
654 ERR_NEEDMOREPARAMS_MSG,
655 Client_ID(Origin), Req->command);
659 case 'O': /* IRC operators only */
661 /* Only IRC operators are allowed to
662 * set the 'O' channel mode! */
663 if(is_oper || is_machine)
666 connected = IRC_WriteStrClient(Origin,
667 ERR_NOPRIVILEGES_MSG,
669 } else if(is_oper || is_machine || is_owner ||
673 connected = IRC_WriteStrClient(Origin,
674 ERR_CHANOPRIVSNEEDED_MSG,
676 Channel_Name(Channel));
678 case 'P': /* Persistent channel */
680 /* Only IRC operators are allowed to
681 * set the 'P' channel mode! */
682 if(is_oper || is_machine)
685 connected = IRC_WriteStrClient(Origin,
686 ERR_NOPRIVILEGES_MSG,
688 } else if(is_oper || is_machine || is_owner ||
692 connected = IRC_WriteStrClient(Origin,
693 ERR_CHANOPRIVSNEEDED_MSG,
695 Channel_Name(Channel));
697 /* --- Channel user modes --- */
698 case 'q': /* Owner */
699 case 'a': /* Channel admin */
700 if(!is_oper && !is_machine && !is_owner) {
701 connected = IRC_WriteStrClient(Origin,
702 ERR_CHANOPRIVSNEEDED_MSG,
704 Channel_Name(Channel));
707 case 'o': /* Channel operator */
708 if(!is_oper && !is_machine && !is_owner &&
709 !is_admin && !is_op) {
710 connected = IRC_WriteStrClient(Origin,
711 ERR_CHANOPRIVSNEEDED_MSG,
713 Channel_Name(Channel));
716 case 'h': /* Half Op */
717 if(!is_oper && !is_machine && !is_owner &&
718 !is_admin && !is_op) {
719 connected = IRC_WriteStrClient(Origin,
720 ERR_CHANOPRIVSNEEDED_MSG,
722 Channel_Name(Channel));
725 case 'v': /* Voice */
726 if (arg_arg > mode_arg) {
727 if (is_oper || is_machine || is_owner ||
728 is_admin || is_op || is_halfop) {
729 client = Client_Search(Req->argv[arg_arg]);
733 connected = IRC_WriteStrClient(Origin,
738 connected = IRC_WriteStrClient(Origin,
739 ERR_CHANOPRIVSNEEDED_MSG,
741 Channel_Name(Channel));
743 Req->argv[arg_arg][0] = '\0';
746 connected = IRC_WriteStrClient(Origin,
747 ERR_NEEDMOREPARAMS_MSG,
748 Client_ID(Origin), Req->command);
752 /* --- Channel lists --- */
753 case 'I': /* Invite lists */
754 case 'b': /* Ban lists */
755 case 'e': /* Channel exception lists */
756 if (Mode_Limit_Reached(Client, mode_arg_count++))
758 if (arg_arg > mode_arg) {
760 if (is_oper || is_machine || is_owner ||
761 is_admin || is_op || is_halfop) {
763 ? Add_To_List(*mode_ptr, Origin,
766 : Del_From_List(*mode_ptr, Origin,
770 connected = IRC_WriteStrClient(Origin,
771 ERR_CHANOPRIVSNEEDED_MSG,
773 Channel_Name(Channel));
775 Req->argv[arg_arg][0] = '\0';
780 Channel_ShowInvites(Origin, Channel);
783 Channel_ShowBans(Origin, Channel);
786 Channel_ShowExcepts(Origin, Channel);
792 if (Client_Type(Client) != CLIENT_SERVER) {
794 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
795 set ? '+' : '-', *mode_ptr,
796 Client_ID(Origin), Channel_Name(Channel));
797 connected = IRC_WriteStrClient(Origin,
799 Client_ID(Origin), *mode_ptr,
800 Channel_Name(Channel));
804 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
805 set ? '+' : '-', *mode_ptr,
806 Client_ID(Origin), Channel_Name(Channel));
814 /* Is there a valid mode change? */
818 /* Validate target client */
819 if (client && (!Channel_IsMemberOf(Channel, client))) {
820 if (!IRC_WriteStrClient
821 (Origin, ERR_USERNOTINCHANNEL_MSG,
822 Client_ID(Origin), Client_ID(client),
823 Channel_Name(Channel)))
830 /* Channel-User-Mode */
832 ? Channel_UserModeAdd(Channel, client, x[0])
833 : Channel_UserModeDel(Channel, client, x[0]);
835 strlcat(the_args, " ", sizeof(the_args));
836 strlcat(the_args, Client_ID(client),
838 strlcat(the_modes, x, sizeof(the_modes));
840 ("User \"%s\": Mode change on %s, now \"%s\"",
841 Client_Mask(client), Channel_Name(Channel),
842 Channel_UserModes(Channel, client));
847 ? Channel_ModeAdd(Channel, x[0])
848 : Channel_ModeDel(Channel, x[0]);
850 strlcat(the_modes, x, sizeof(the_modes));
851 LogDebug("Channel %s: Mode change, now \"%s\".",
852 Channel_Name(Channel),
853 Channel_Modes(Channel));
857 /* Are there additional arguments to add? */
859 strlcat(the_args, " ", sizeof(the_args));
860 strlcat(the_args, argadd, sizeof(the_args));
865 /* Are there changed modes? */
867 /* Clean up mode string */
868 len = strlen(the_modes) - 1;
869 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
870 the_modes[len] = '\0';
872 if (Client_Type(Client) == CLIENT_SERVER) {
873 /* MODE requests for local channels from other servers
874 * are definitely invalid! */
875 if (Channel_IsLocal(Channel)) {
876 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
880 /* Forward mode changes to channel users and all the
881 * other remote servers: */
882 IRC_WriteStrServersPrefix(Client, Origin,
883 "MODE %s %s%s", Channel_Name(Channel),
884 the_modes, the_args);
885 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
886 false, "MODE %s %s%s", Channel_Name(Channel),
887 the_modes, the_args);
890 Origin = Client_ThisServer();
891 /* Send reply to client and inform other servers and channel users */
892 connected = IRC_WriteStrClientPrefix(Client, Origin,
893 "MODE %s %s%s", Channel_Name(Channel),
894 the_modes, the_args);
895 /* Only forward requests for non-local channels */
896 if (!Channel_IsLocal(Channel))
897 IRC_WriteStrServersPrefix(Client, Origin,
898 "MODE %s %s%s", Channel_Name(Channel),
899 the_modes, the_args);
900 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
901 false, "MODE %s %s%s", Channel_Name(Channel),
902 the_modes, the_args);
906 IRC_SetPenalty(Client, 1);
912 IRC_AWAY( CLIENT *Client, REQUEST *Req )
914 assert( Client != NULL );
915 assert( Req != NULL );
917 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
919 if(( Req->argc == 1 ) && (Req->argv[0][0] ))
921 Client_SetAway( Client, Req->argv[0] );
922 Client_ModeAdd( Client, 'a' );
923 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
924 return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
928 Client_ModeDel( Client, 'a' );
929 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
930 return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
936 * Add entries to channel invite, ban and exception lists.
938 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
939 * @param Prefix The originator of the command.
940 * @param Client The sender of the command.
941 * @param Channel The channel of which the list should be modified.
942 * @param Pattern The pattern to add to the list.
943 * @return CONNECTED or DISCONNECTED.
946 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
950 struct list_head *list = NULL;
951 long int current_count;
953 assert(Client != NULL);
954 assert(Channel != NULL);
955 assert(Pattern != NULL);
956 assert(what == 'I' || what == 'b' || what == 'e');
958 mask = Lists_MakeMask(Pattern);
959 current_count = Lists_Count(Channel_GetListInvites(Channel))
960 + Lists_Count(Channel_GetListExcepts(Channel))
961 + Lists_Count(Channel_GetListBans(Channel));
965 list = Channel_GetListInvites(Channel);
968 list = Channel_GetListBans(Channel);
971 list = Channel_GetListExcepts(Channel);
975 if (Lists_CheckDupeMask(list, mask))
977 if (Client_Type(Client) == CLIENT_USER &&
978 current_count >= MAX_HNDL_CHANNEL_LISTS)
979 return IRC_WriteStrClient(Client, ERR_LISTFULL_MSG,
981 Channel_Name(Channel), mask,
982 MAX_HNDL_CHANNEL_LISTS);
986 if (!Channel_AddInvite(Channel, mask, false))
990 if (!Channel_AddBan(Channel, mask))
994 if (!Channel_AddExcept(Channel, mask))
998 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1003 * Delete entries from channel invite, ban and exeption lists.
1005 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1006 * @param Prefix The originator of the command.
1007 * @param Client The sender of the command.
1008 * @param Channel The channel of which the list should be modified.
1009 * @param Pattern The pattern to add to the list.
1010 * @return CONNECTED or DISCONNECTED.
1013 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1014 const char *Pattern)
1017 struct list_head *list = NULL;
1019 assert(Client != NULL);
1020 assert(Channel != NULL);
1021 assert(Pattern != NULL);
1022 assert(what == 'I' || what == 'b' || what == 'e');
1024 mask = Lists_MakeMask(Pattern);
1028 list = Channel_GetListInvites(Channel);
1031 list = Channel_GetListBans(Channel);
1034 list = Channel_GetListExcepts(Channel);
1038 if (!Lists_CheckDupeMask(list, mask))
1040 Lists_Del(list, mask);
1042 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1047 * Send information about changed channel invite/ban/exception lists to clients.
1049 * @param IsAdd true if the list item has been added, false otherwise.
1050 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1051 * @param Prefix The originator of the mode list change.
1052 * @param Client The sender of the command.
1053 * @param Channel The channel of which the list has been modified.
1054 * @param Mask The mask which has been added or removed.
1055 * @return CONNECTED or DISCONNECTED.
1058 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1059 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1063 /* Send confirmation to the client */
1064 if (Client_Type(Client) == CLIENT_USER)
1065 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1066 Channel_Name(Channel),
1070 /* to other servers */
1071 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1072 Channel_Name(Channel), IsAdd ? '+' : '-',
1075 /* and local users in channel */
1076 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1077 "MODE %s %c%c %s", Channel_Name(Channel),
1078 IsAdd ? '+' : '-', ModeChar, Mask );
1081 } /* Send_ListChange */