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,
283 send_RPL_HOSTHIDDEN_MSG = true;
286 if (Client_Type(Client) != CLIENT_SERVER) {
288 "Unknown mode \"%c%c\" from \"%s\"!?",
289 set ? '+' : '-', *mode_ptr,
291 ok = IRC_WriteStrClient(Origin,
292 ERR_UMODEUNKNOWNFLAG2_MSG,
299 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
300 set ? '+' : '-', *mode_ptr,
301 Client_ID(Origin), Client_ID(Target));
309 /* Is there a valid mode change? */
314 if (Client_ModeAdd(Target, x[0]))
315 strlcat(the_modes, x, sizeof(the_modes));
317 if (Client_ModeDel(Target, x[0]))
318 strlcat(the_modes, x, sizeof(the_modes));
322 /* Are there changed modes? */
324 /* Remove needless action modifier characters */
325 len = strlen(the_modes) - 1;
326 if (the_modes[len] == '+' || the_modes[len] == '-')
327 the_modes[len] = '\0';
329 if (Client_Type(Client) == CLIENT_SERVER) {
330 /* Forward modes to other servers */
331 if (Client_Conn(Target) != NONE) {
332 /* Remote server (service?) changed modes
333 * for one of our clients. Inform it! */
334 IRC_WriteStrClientPrefix(Target, Origin,
339 IRC_WriteStrServersPrefix(Client, Origin,
344 /* Send reply to client and inform other servers */
345 ok = IRC_WriteStrClientPrefix(Client, Origin,
349 IRC_WriteStrServersPrefix(Client, Origin,
353 if (send_RPL_HOSTHIDDEN_MSG)
354 IRC_WriteStrClient(Client, RPL_HOSTHIDDEN_MSG,
356 Client_HostnameCloaked(Client));
358 LogDebug("%s \"%s\": Mode change, now \"%s\".",
359 Client_TypeText(Target), Client_Mask(Target),
360 Client_Modes(Target));
363 IRC_SetPenalty(Client, 1);
369 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
371 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
372 const char *mode_ptr;
374 /* Member or not? -- That's the question! */
375 if (!Channel_IsMemberOf(Channel, Origin))
376 return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
377 Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
379 /* The sender is a member: generate extended reply */
380 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
381 mode_ptr = the_modes;
387 snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
388 strlcat(the_args, argadd, sizeof(the_args));
391 strlcat(the_args, " ", sizeof(the_args));
392 strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
398 strlcat(the_modes, the_args, sizeof(the_modes));
400 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
401 Client_ID(Origin), Channel_Name(Channel),
405 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
406 Client_ID(Origin), Channel_Name(Channel),
407 Channel_CreationTime(Channel)))
415 * Handle channel mode and channel-user mode changes
418 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
420 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
421 argadd[CLIENT_PASS_LEN], *mode_ptr, *o_mode_ptr;
422 bool connected, set, skiponce, retval, use_servermode,
423 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
424 int mode_arg, arg_arg, mode_arg_count = 0;
429 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
431 if (Channel_IsModeless(Channel))
432 return IRC_WriteStrClient(Client, ERR_NOCHANMODES_MSG,
433 Client_ID(Client), Channel_Name(Channel));
435 /* Mode request: let's answer it :-) */
437 return Channel_Mode_Answer_Request(Origin, Channel);
439 /* Check if origin is oper and opers can use mode */
440 use_servermode = Conf_OperServerMode;
441 if(Client_OperByMe(Client) && Conf_OperCanMode) {
445 /* Check if client is a server/service */
446 if(Client_Type(Client) == CLIENT_SERVER ||
447 Client_Type(Client) == CLIENT_SERVICE) {
451 /* Check if client is member of channel or an oper or an server/service */
452 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
453 return IRC_WriteStrClient(Origin, ERR_NOTONCHANNEL_MSG,
455 Channel_Name(Channel));
458 mode_ptr = Req->argv[mode_arg];
459 if (Req->argc > mode_arg + 1)
460 arg_arg = mode_arg + 1;
464 /* Initial state: set or unset modes? */
478 /* Prepare reply string */
479 strcpy(the_modes, set ? "+" : "-");
483 connected = CONNECTED;
488 /* Try next argument if there's any */
491 if (arg_arg > mode_arg)
496 if (mode_arg >= Req->argc)
498 mode_ptr = Req->argv[mode_arg];
500 if (Req->argc > mode_arg + 1)
501 arg_arg = mode_arg + 1;
510 if (((*mode_ptr == '+') && !set)
511 || ((*mode_ptr == '-') && set)) {
512 /* Action modifier ("+"/"-") must be changed ... */
513 len = strlen(the_modes) - 1;
514 if (the_modes[len] == '+' || the_modes[len] == '-') {
515 /* Adjust last action modifier in result */
516 the_modes[len] = *mode_ptr;
518 /* Append modifier character to result string */
520 strlcat(the_modes, x, sizeof(the_modes));
522 set = *mode_ptr == '+';
527 /* Are there arguments left? */
528 if (arg_arg >= Req->argc)
532 o_mode_ptr = Channel_UserModes(Channel, Client);
533 while( *o_mode_ptr ) {
534 if ( *o_mode_ptr == 'q')
536 if ( *o_mode_ptr == 'a')
538 if ( *o_mode_ptr == 'o')
540 if ( *o_mode_ptr == 'h')
551 /* --- Channel modes --- */
552 case 'R': /* Registered users only */
553 case 's': /* Secret channel */
554 case 'z': /* Secure connections only */
555 if(!is_oper && !is_machine && !is_owner &&
556 !is_admin && !is_op) {
557 connected = IRC_WriteStrClient(Origin,
558 ERR_CHANOPRIVSNEEDED_MSG,
559 Client_ID(Origin), Channel_Name(Channel));
562 case 'i': /* Invite only */
563 case 'M': /* Only identified nicks can write */
564 case 'm': /* Moderated */
565 case 'n': /* Only members can write */
566 case 't': /* Topic locked */
567 if(is_oper || is_machine || is_owner ||
568 is_admin || is_op || is_halfop)
571 connected = IRC_WriteStrClient(Origin,
572 ERR_CHANOPRIVSNEEDED_MSG,
573 Client_ID(Origin), Channel_Name(Channel));
575 case 'k': /* Channel key */
576 if (Mode_Limit_Reached(Client, mode_arg_count++))
579 if (is_oper || is_machine || is_owner ||
580 is_admin || is_op || is_halfop)
583 connected = IRC_WriteStrClient(Origin,
584 ERR_CHANOPRIVSNEEDED_MSG,
586 Channel_Name(Channel));
589 if (arg_arg > mode_arg) {
590 if (is_oper || is_machine || is_owner ||
591 is_admin || is_op || is_halfop) {
592 Channel_ModeDel(Channel, 'k');
593 Channel_SetKey(Channel,
595 strlcpy(argadd, Channel_Key(Channel),
599 connected = IRC_WriteStrClient(Origin,
600 ERR_CHANOPRIVSNEEDED_MSG,
602 Channel_Name(Channel));
604 Req->argv[arg_arg][0] = '\0';
607 connected = IRC_WriteStrClient(Origin,
608 ERR_NEEDMOREPARAMS_MSG,
609 Client_ID(Origin), Req->command);
613 case 'l': /* Member limit */
614 if (Mode_Limit_Reached(Client, mode_arg_count++))
617 if (is_oper || is_machine || is_owner ||
618 is_admin || is_op || is_halfop)
621 connected = IRC_WriteStrClient(Origin,
622 ERR_CHANOPRIVSNEEDED_MSG,
624 Channel_Name(Channel));
627 if (arg_arg > mode_arg) {
628 if (is_oper || is_machine || is_owner ||
629 is_admin || is_op || is_halfop) {
630 l = atol(Req->argv[arg_arg]);
631 if (l > 0 && l < 0xFFFF) {
632 Channel_ModeDel(Channel, 'l');
633 Channel_SetMaxUsers(Channel, l);
634 snprintf(argadd, sizeof(argadd),
639 connected = IRC_WriteStrClient(Origin,
640 ERR_CHANOPRIVSNEEDED_MSG,
642 Channel_Name(Channel));
644 Req->argv[arg_arg][0] = '\0';
647 connected = IRC_WriteStrClient(Origin,
648 ERR_NEEDMOREPARAMS_MSG,
649 Client_ID(Origin), Req->command);
653 case 'O': /* IRC operators only */
655 /* Only IRC operators are allowed to
656 * set the 'O' channel mode! */
657 if(is_oper || is_machine)
660 connected = IRC_WriteStrClient(Origin,
661 ERR_NOPRIVILEGES_MSG,
663 } else if(is_oper || is_machine || is_owner ||
667 connected = IRC_WriteStrClient(Origin,
668 ERR_CHANOPRIVSNEEDED_MSG,
670 Channel_Name(Channel));
672 case 'P': /* Persistent channel */
674 /* Only IRC operators are allowed to
675 * set the 'P' channel mode! */
676 if(is_oper || is_machine)
679 connected = IRC_WriteStrClient(Origin,
680 ERR_NOPRIVILEGES_MSG,
682 } else if(is_oper || is_machine || is_owner ||
686 connected = IRC_WriteStrClient(Origin,
687 ERR_CHANOPRIVSNEEDED_MSG,
689 Channel_Name(Channel));
691 /* --- Channel user modes --- */
692 case 'q': /* Owner */
693 case 'a': /* Channel admin */
694 if(!is_oper && !is_machine && !is_owner) {
695 connected = IRC_WriteStrClient(Origin,
696 ERR_CHANOPRIVSNEEDED_MSG,
698 Channel_Name(Channel));
701 case 'o': /* Channel operator */
702 if(!is_oper && !is_machine && !is_owner &&
703 !is_admin && !is_op) {
704 connected = IRC_WriteStrClient(Origin,
705 ERR_CHANOPRIVSNEEDED_MSG,
707 Channel_Name(Channel));
710 case 'h': /* Half Op */
711 if(!is_oper && !is_machine && !is_owner &&
712 !is_admin && !is_op) {
713 connected = IRC_WriteStrClient(Origin,
714 ERR_CHANOPRIVSNEEDED_MSG,
716 Channel_Name(Channel));
719 case 'v': /* Voice */
720 if (arg_arg > mode_arg) {
721 if (is_oper || is_machine || is_owner ||
722 is_admin || is_op || is_halfop) {
723 client = Client_Search(Req->argv[arg_arg]);
727 connected = IRC_WriteStrClient(Origin,
732 connected = IRC_WriteStrClient(Origin,
733 ERR_CHANOPRIVSNEEDED_MSG,
735 Channel_Name(Channel));
737 Req->argv[arg_arg][0] = '\0';
740 connected = IRC_WriteStrClient(Origin,
741 ERR_NEEDMOREPARAMS_MSG,
742 Client_ID(Origin), Req->command);
746 /* --- Channel lists --- */
747 case 'I': /* Invite lists */
748 case 'b': /* Ban lists */
749 case 'e': /* Channel exception lists */
750 if (Mode_Limit_Reached(Client, mode_arg_count++))
752 if (arg_arg > mode_arg) {
754 if (is_oper || is_machine || is_owner ||
755 is_admin || is_op || is_halfop) {
757 ? Add_To_List(*mode_ptr, Origin,
760 : Del_From_List(*mode_ptr, Origin,
764 connected = IRC_WriteStrClient(Origin,
765 ERR_CHANOPRIVSNEEDED_MSG,
767 Channel_Name(Channel));
769 Req->argv[arg_arg][0] = '\0';
774 Channel_ShowInvites(Origin, Channel);
777 Channel_ShowBans(Origin, Channel);
780 Channel_ShowExcepts(Origin, Channel);
786 if (Client_Type(Client) != CLIENT_SERVER) {
788 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
789 set ? '+' : '-', *mode_ptr,
790 Client_ID(Origin), Channel_Name(Channel));
791 connected = IRC_WriteStrClient(Origin,
793 Client_ID(Origin), *mode_ptr,
794 Channel_Name(Channel));
798 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
799 set ? '+' : '-', *mode_ptr,
800 Client_ID(Origin), Channel_Name(Channel));
808 /* Is there a valid mode change? */
812 /* Validate target client */
813 if (client && (!Channel_IsMemberOf(Channel, client))) {
814 if (!IRC_WriteStrClient
815 (Origin, ERR_USERNOTINCHANNEL_MSG,
816 Client_ID(Origin), Client_ID(client),
817 Channel_Name(Channel)))
824 /* Channel-User-Mode */
826 ? Channel_UserModeAdd(Channel, client, x[0])
827 : Channel_UserModeDel(Channel, client, x[0]);
829 strlcat(the_args, " ", sizeof(the_args));
830 strlcat(the_args, Client_ID(client),
832 strlcat(the_modes, x, sizeof(the_modes));
834 ("User \"%s\": Mode change on %s, now \"%s\"",
835 Client_Mask(client), Channel_Name(Channel),
836 Channel_UserModes(Channel, client));
841 ? Channel_ModeAdd(Channel, x[0])
842 : Channel_ModeDel(Channel, x[0]);
844 strlcat(the_modes, x, sizeof(the_modes));
845 LogDebug("Channel %s: Mode change, now \"%s\".",
846 Channel_Name(Channel),
847 Channel_Modes(Channel));
851 /* Are there additional arguments to add? */
853 strlcat(the_args, " ", sizeof(the_args));
854 strlcat(the_args, argadd, sizeof(the_args));
859 /* Are there changed modes? */
861 /* Clean up mode string */
862 len = strlen(the_modes) - 1;
863 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
864 the_modes[len] = '\0';
866 if (Client_Type(Client) == CLIENT_SERVER) {
867 /* MODE requests for local channels from other servers
868 * are definitely invalid! */
869 if (Channel_IsLocal(Channel)) {
870 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
874 /* Forward mode changes to channel users and all the
875 * other remote servers: */
876 IRC_WriteStrServersPrefix(Client, Origin,
877 "MODE %s %s%s", Channel_Name(Channel),
878 the_modes, the_args);
879 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
880 false, "MODE %s %s%s", Channel_Name(Channel),
881 the_modes, the_args);
884 Origin = Client_ThisServer();
885 /* Send reply to client and inform other servers and channel users */
886 connected = IRC_WriteStrClientPrefix(Client, Origin,
887 "MODE %s %s%s", Channel_Name(Channel),
888 the_modes, the_args);
889 /* Only forward requests for non-local channels */
890 if (!Channel_IsLocal(Channel))
891 IRC_WriteStrServersPrefix(Client, Origin,
892 "MODE %s %s%s", Channel_Name(Channel),
893 the_modes, the_args);
894 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
895 false, "MODE %s %s%s", Channel_Name(Channel),
896 the_modes, the_args);
900 IRC_SetPenalty(Client, 1);
906 IRC_AWAY( CLIENT *Client, REQUEST *Req )
908 assert( Client != NULL );
909 assert( Req != NULL );
911 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
913 if(( Req->argc == 1 ) && (Req->argv[0][0] ))
915 Client_SetAway( Client, Req->argv[0] );
916 Client_ModeAdd( Client, 'a' );
917 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
918 return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
922 Client_ModeDel( Client, 'a' );
923 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
924 return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
930 * Add entries to channel invite, ban and exception lists.
932 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
933 * @param Prefix The originator of the command.
934 * @param Client The sender of the command.
935 * @param Channel The channel of which the list should be modified.
936 * @param Pattern The pattern to add to the list.
937 * @return CONNECTED or DISCONNECTED.
940 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
944 struct list_head *list = NULL;
945 long int current_count;
947 assert(Client != NULL);
948 assert(Channel != NULL);
949 assert(Pattern != NULL);
950 assert(what == 'I' || what == 'b' || what == 'e');
952 mask = Lists_MakeMask(Pattern);
953 current_count = Lists_Count(Channel_GetListInvites(Channel))
954 + Lists_Count(Channel_GetListExcepts(Channel))
955 + Lists_Count(Channel_GetListBans(Channel));
959 list = Channel_GetListInvites(Channel);
962 list = Channel_GetListBans(Channel);
965 list = Channel_GetListExcepts(Channel);
969 if (Lists_CheckDupeMask(list, mask))
971 if (Client_Type(Client) == CLIENT_USER &&
972 current_count >= MAX_HNDL_CHANNEL_LISTS)
973 return IRC_WriteStrClient(Client, ERR_LISTFULL_MSG,
975 Channel_Name(Channel), mask,
976 MAX_HNDL_CHANNEL_LISTS);
980 if (!Channel_AddInvite(Channel, mask, false))
984 if (!Channel_AddBan(Channel, mask))
988 if (!Channel_AddExcept(Channel, mask))
992 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
997 * Delete entries from channel invite, ban and exeption lists.
999 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1000 * @param Prefix The originator of the command.
1001 * @param Client The sender of the command.
1002 * @param Channel The channel of which the list should be modified.
1003 * @param Pattern The pattern to add to the list.
1004 * @return CONNECTED or DISCONNECTED.
1007 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1008 const char *Pattern)
1011 struct list_head *list = NULL;
1013 assert(Client != NULL);
1014 assert(Channel != NULL);
1015 assert(Pattern != NULL);
1016 assert(what == 'I' || what == 'b' || what == 'e');
1018 mask = Lists_MakeMask(Pattern);
1022 list = Channel_GetListInvites(Channel);
1025 list = Channel_GetListBans(Channel);
1028 list = Channel_GetListExcepts(Channel);
1032 if (!Lists_CheckDupeMask(list, mask))
1034 Lists_Del(list, mask);
1036 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1041 * Send information about changed channel invite/ban/exception lists to clients.
1043 * @param IsAdd true if the list item has been added, false otherwise.
1044 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1045 * @param Prefix The originator of the mode list change.
1046 * @param Client The sender of the command.
1047 * @param Channel The channel of which the list has been modified.
1048 * @param Mask The mask which has been added or removed.
1049 * @return CONNECTED or DISCONNECTED.
1052 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1053 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1057 /* Send confirmation to the client */
1058 if (Client_Type(Client) == CLIENT_USER)
1059 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1060 Channel_Name(Channel),
1064 /* to other servers */
1065 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1066 Channel_Name(Channel), IsAdd ? '+' : '-',
1069 /* and local users in channel */
1070 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1071 "MODE %s %c%c %s", Channel_Name(Channel),
1072 IsAdd ? '+' : '-', ModeChar, Mask );
1075 } /* Send_ListChange */