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 'V': /* Invite disallow */
570 case 'M': /* Only identified nicks can write */
571 case 'm': /* Moderated */
572 case 'n': /* Only members can write */
573 case 't': /* Topic locked */
574 if(is_oper || is_machine || is_owner ||
575 is_admin || is_op || is_halfop)
578 connected = IRC_WriteStrClient(Origin,
579 ERR_CHANOPRIVSNEEDED_MSG,
580 Client_ID(Origin), Channel_Name(Channel));
582 case 'k': /* Channel key */
583 if (Mode_Limit_Reached(Client, mode_arg_count++))
586 if (is_oper || is_machine || is_owner ||
587 is_admin || is_op || is_halfop)
590 connected = IRC_WriteStrClient(Origin,
591 ERR_CHANOPRIVSNEEDED_MSG,
593 Channel_Name(Channel));
596 if (arg_arg > mode_arg) {
597 if (is_oper || is_machine || is_owner ||
598 is_admin || is_op || is_halfop) {
599 Channel_ModeDel(Channel, 'k');
600 Channel_SetKey(Channel,
602 strlcpy(argadd, Channel_Key(Channel),
606 connected = IRC_WriteStrClient(Origin,
607 ERR_CHANOPRIVSNEEDED_MSG,
609 Channel_Name(Channel));
611 Req->argv[arg_arg][0] = '\0';
614 connected = IRC_WriteStrClient(Origin,
615 ERR_NEEDMOREPARAMS_MSG,
616 Client_ID(Origin), Req->command);
620 case 'l': /* Member limit */
621 if (Mode_Limit_Reached(Client, mode_arg_count++))
624 if (is_oper || is_machine || is_owner ||
625 is_admin || is_op || is_halfop)
628 connected = IRC_WriteStrClient(Origin,
629 ERR_CHANOPRIVSNEEDED_MSG,
631 Channel_Name(Channel));
634 if (arg_arg > mode_arg) {
635 if (is_oper || is_machine || is_owner ||
636 is_admin || is_op || is_halfop) {
637 l = atol(Req->argv[arg_arg]);
638 if (l > 0 && l < 0xFFFF) {
639 Channel_ModeDel(Channel, 'l');
640 Channel_SetMaxUsers(Channel, l);
641 snprintf(argadd, sizeof(argadd),
646 connected = IRC_WriteStrClient(Origin,
647 ERR_CHANOPRIVSNEEDED_MSG,
649 Channel_Name(Channel));
651 Req->argv[arg_arg][0] = '\0';
654 connected = IRC_WriteStrClient(Origin,
655 ERR_NEEDMOREPARAMS_MSG,
656 Client_ID(Origin), Req->command);
660 case 'O': /* IRC operators only */
662 /* Only IRC operators are allowed to
663 * set the 'O' channel mode! */
664 if(is_oper || is_machine)
667 connected = IRC_WriteStrClient(Origin,
668 ERR_NOPRIVILEGES_MSG,
670 } else if(is_oper || is_machine || is_owner ||
674 connected = IRC_WriteStrClient(Origin,
675 ERR_CHANOPRIVSNEEDED_MSG,
677 Channel_Name(Channel));
679 case 'P': /* Persistent channel */
681 /* Only IRC operators are allowed to
682 * set the 'P' channel mode! */
683 if(is_oper || is_machine)
686 connected = IRC_WriteStrClient(Origin,
687 ERR_NOPRIVILEGES_MSG,
689 } else if(is_oper || is_machine || is_owner ||
693 connected = IRC_WriteStrClient(Origin,
694 ERR_CHANOPRIVSNEEDED_MSG,
696 Channel_Name(Channel));
698 /* --- Channel user modes --- */
699 case 'q': /* Owner */
700 case 'a': /* Channel admin */
701 if(!is_oper && !is_machine && !is_owner && !is_admin) {
702 connected = IRC_WriteStrClient(Origin,
703 ERR_CHANOPPRIVTOOLOW_MSG,
705 Channel_Name(Channel));
708 case 'o': /* Channel operator */
709 if(!is_oper && !is_machine && !is_owner &&
710 !is_admin && !is_op) {
711 connected = IRC_WriteStrClient(Origin,
712 ERR_CHANOPRIVSNEEDED_MSG,
714 Channel_Name(Channel));
717 case 'h': /* Half Op */
718 if(!is_oper && !is_machine && !is_owner &&
719 !is_admin && !is_op) {
720 connected = IRC_WriteStrClient(Origin,
721 ERR_CHANOPRIVSNEEDED_MSG,
723 Channel_Name(Channel));
726 case 'v': /* Voice */
727 if (arg_arg > mode_arg) {
728 if (is_oper || is_machine || is_owner ||
729 is_admin || is_op || is_halfop) {
730 client = Client_Search(Req->argv[arg_arg]);
734 connected = IRC_WriteStrClient(Origin,
739 connected = IRC_WriteStrClient(Origin,
740 ERR_CHANOPRIVSNEEDED_MSG,
742 Channel_Name(Channel));
744 Req->argv[arg_arg][0] = '\0';
747 connected = IRC_WriteStrClient(Origin,
748 ERR_NEEDMOREPARAMS_MSG,
749 Client_ID(Origin), Req->command);
753 /* --- Channel lists --- */
754 case 'I': /* Invite lists */
755 case 'b': /* Ban lists */
756 case 'e': /* Channel exception lists */
757 if (Mode_Limit_Reached(Client, mode_arg_count++))
759 if (arg_arg > mode_arg) {
761 if (is_oper || is_machine || is_owner ||
762 is_admin || is_op || is_halfop) {
764 ? Add_To_List(*mode_ptr, Origin,
767 : Del_From_List(*mode_ptr, Origin,
771 connected = IRC_WriteStrClient(Origin,
772 ERR_CHANOPRIVSNEEDED_MSG,
774 Channel_Name(Channel));
776 Req->argv[arg_arg][0] = '\0';
781 Channel_ShowInvites(Origin, Channel);
784 Channel_ShowBans(Origin, Channel);
787 Channel_ShowExcepts(Origin, Channel);
793 if (Client_Type(Client) != CLIENT_SERVER) {
795 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
796 set ? '+' : '-', *mode_ptr,
797 Client_ID(Origin), Channel_Name(Channel));
798 connected = IRC_WriteStrClient(Origin,
800 Client_ID(Origin), *mode_ptr,
801 Channel_Name(Channel));
805 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
806 set ? '+' : '-', *mode_ptr,
807 Client_ID(Origin), Channel_Name(Channel));
815 /* Is there a valid mode change? */
819 /* Validate target client */
820 if (client && (!Channel_IsMemberOf(Channel, client))) {
821 if (!IRC_WriteStrClient
822 (Origin, ERR_USERNOTINCHANNEL_MSG,
823 Client_ID(Origin), Client_ID(client),
824 Channel_Name(Channel)))
831 /* Channel-User-Mode */
833 ? Channel_UserModeAdd(Channel, client, x[0])
834 : Channel_UserModeDel(Channel, client, x[0]);
836 strlcat(the_args, " ", sizeof(the_args));
837 strlcat(the_args, Client_ID(client),
839 strlcat(the_modes, x, sizeof(the_modes));
841 ("User \"%s\": Mode change on %s, now \"%s\"",
842 Client_Mask(client), Channel_Name(Channel),
843 Channel_UserModes(Channel, client));
848 ? Channel_ModeAdd(Channel, x[0])
849 : Channel_ModeDel(Channel, x[0]);
851 strlcat(the_modes, x, sizeof(the_modes));
852 LogDebug("Channel %s: Mode change, now \"%s\".",
853 Channel_Name(Channel),
854 Channel_Modes(Channel));
858 /* Are there additional arguments to add? */
860 strlcat(the_args, " ", sizeof(the_args));
861 strlcat(the_args, argadd, sizeof(the_args));
866 /* Are there changed modes? */
868 /* Clean up mode string */
869 len = strlen(the_modes) - 1;
870 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
871 the_modes[len] = '\0';
873 if (Client_Type(Client) == CLIENT_SERVER) {
874 /* MODE requests for local channels from other servers
875 * are definitely invalid! */
876 if (Channel_IsLocal(Channel)) {
877 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
881 /* Forward mode changes to channel users and all the
882 * other remote servers: */
883 IRC_WriteStrServersPrefix(Client, Origin,
884 "MODE %s %s%s", Channel_Name(Channel),
885 the_modes, the_args);
886 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
887 false, "MODE %s %s%s", Channel_Name(Channel),
888 the_modes, the_args);
891 Origin = Client_ThisServer();
892 /* Send reply to client and inform other servers and channel users */
893 connected = IRC_WriteStrClientPrefix(Client, Origin,
894 "MODE %s %s%s", Channel_Name(Channel),
895 the_modes, the_args);
896 /* Only forward requests for non-local channels */
897 if (!Channel_IsLocal(Channel))
898 IRC_WriteStrServersPrefix(Client, Origin,
899 "MODE %s %s%s", Channel_Name(Channel),
900 the_modes, the_args);
901 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
902 false, "MODE %s %s%s", Channel_Name(Channel),
903 the_modes, the_args);
907 IRC_SetPenalty(Client, 1);
913 IRC_AWAY( CLIENT *Client, REQUEST *Req )
915 assert( Client != NULL );
916 assert( Req != NULL );
918 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
920 if(( Req->argc == 1 ) && (Req->argv[0][0] ))
922 Client_SetAway( Client, Req->argv[0] );
923 Client_ModeAdd( Client, 'a' );
924 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
925 return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
929 Client_ModeDel( Client, 'a' );
930 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
931 return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
937 * Add entries to channel invite, ban and exception lists.
939 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
940 * @param Prefix The originator of the command.
941 * @param Client The sender of the command.
942 * @param Channel The channel of which the list should be modified.
943 * @param Pattern The pattern to add to the list.
944 * @return CONNECTED or DISCONNECTED.
947 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
951 struct list_head *list = NULL;
952 long int current_count;
954 assert(Client != NULL);
955 assert(Channel != NULL);
956 assert(Pattern != NULL);
957 assert(what == 'I' || what == 'b' || what == 'e');
959 mask = Lists_MakeMask(Pattern);
960 current_count = Lists_Count(Channel_GetListInvites(Channel))
961 + Lists_Count(Channel_GetListExcepts(Channel))
962 + Lists_Count(Channel_GetListBans(Channel));
966 list = Channel_GetListInvites(Channel);
969 list = Channel_GetListBans(Channel);
972 list = Channel_GetListExcepts(Channel);
976 if (Lists_CheckDupeMask(list, mask))
978 if (Client_Type(Client) == CLIENT_USER &&
979 current_count >= MAX_HNDL_CHANNEL_LISTS)
980 return IRC_WriteStrClient(Client, ERR_LISTFULL_MSG,
982 Channel_Name(Channel), mask,
983 MAX_HNDL_CHANNEL_LISTS);
987 if (!Channel_AddInvite(Channel, mask, false))
991 if (!Channel_AddBan(Channel, mask))
995 if (!Channel_AddExcept(Channel, mask))
999 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1004 * Delete entries from channel invite, ban and exeption lists.
1006 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1007 * @param Prefix The originator of the command.
1008 * @param Client The sender of the command.
1009 * @param Channel The channel of which the list should be modified.
1010 * @param Pattern The pattern to add to the list.
1011 * @return CONNECTED or DISCONNECTED.
1014 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1015 const char *Pattern)
1018 struct list_head *list = NULL;
1020 assert(Client != NULL);
1021 assert(Channel != NULL);
1022 assert(Pattern != NULL);
1023 assert(what == 'I' || what == 'b' || what == 'e');
1025 mask = Lists_MakeMask(Pattern);
1029 list = Channel_GetListInvites(Channel);
1032 list = Channel_GetListBans(Channel);
1035 list = Channel_GetListExcepts(Channel);
1039 if (!Lists_CheckDupeMask(list, mask))
1041 Lists_Del(list, mask);
1043 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1048 * Send information about changed channel invite/ban/exception lists to clients.
1050 * @param IsAdd true if the list item has been added, false otherwise.
1051 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1052 * @param Prefix The originator of the mode list change.
1053 * @param Client The sender of the command.
1054 * @param Channel The channel of which the list has been modified.
1055 * @param Mask The mask which has been added or removed.
1056 * @return CONNECTED or DISCONNECTED.
1059 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1060 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1064 /* Send confirmation to the client */
1065 if (Client_Type(Client) == CLIENT_USER)
1066 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1067 Channel_Name(Channel),
1071 /* to other servers */
1072 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1073 Channel_Name(Channel), IsAdd ? '+' : '-',
1076 /* and local users in channel */
1077 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1078 "MODE %s %c%c %s", Channel_Name(Channel),
1079 IsAdd ? '+' : '-', ModeChar, Mask );
1082 } /* Send_ListChange */