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 'q': /* KICK-protected user */
261 if (!set || Client_Type(Client) == CLIENT_SERVER
262 || Client_OperByMe(Origin))
265 ok = IRC_WriteStrClient(Origin,
266 ERR_NOPRIVILEGES_MSG,
269 case 'r': /* Restricted (only settable) */
270 if (set || Client_Type(Client) == CLIENT_SERVER)
273 ok = IRC_WriteStrClient(Origin,
277 case 'R': /* Registered (not [un]settable by clients) */
278 if (Client_Type(Client) == CLIENT_SERVER)
281 ok = IRC_WriteStrClient(Origin,
282 ERR_NICKREGISTER_MSG,
285 case 'x': /* Cloak hostname */
286 if (Client_HasMode(Client, 'r'))
287 ok = IRC_WriteStrClient(Origin,
290 else if (!set || Conf_CloakHostModeX[0]
291 || Client_Type(Client) == CLIENT_SERVER
292 || Client_OperByMe(Client)) {
294 send_RPL_HOSTHIDDEN_MSG = true;
296 ok = IRC_WriteStrClient(Origin,
297 ERR_NOPRIVILEGES_MSG,
301 if (Client_Type(Client) != CLIENT_SERVER) {
303 "Unknown mode \"%c%c\" from \"%s\"!?",
304 set ? '+' : '-', *mode_ptr,
306 ok = IRC_WriteStrClient(Origin,
307 ERR_UMODEUNKNOWNFLAG2_MSG,
314 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
315 set ? '+' : '-', *mode_ptr,
316 Client_ID(Origin), Client_ID(Target));
324 /* Is there a valid mode change? */
329 if (Client_ModeAdd(Target, x[0]))
330 strlcat(the_modes, x, sizeof(the_modes));
332 if (Client_ModeDel(Target, x[0]))
333 strlcat(the_modes, x, sizeof(the_modes));
337 /* Are there changed modes? */
339 /* Remove needless action modifier characters */
340 len = strlen(the_modes) - 1;
341 if (the_modes[len] == '+' || the_modes[len] == '-')
342 the_modes[len] = '\0';
344 if (Client_Type(Client) == CLIENT_SERVER) {
345 /* Forward modes to other servers */
346 if (Client_Conn(Target) != NONE) {
347 /* Remote server (service?) changed modes
348 * for one of our clients. Inform it! */
349 IRC_WriteStrClientPrefix(Target, Origin,
354 IRC_WriteStrServersPrefix(Client, Origin,
359 /* Send reply to client and inform other servers */
360 ok = IRC_WriteStrClientPrefix(Client, Origin,
364 IRC_WriteStrServersPrefix(Client, Origin,
368 if (send_RPL_HOSTHIDDEN_MSG)
369 IRC_WriteStrClient(Client, RPL_HOSTHIDDEN_MSG,
371 Client_HostnameCloaked(Client));
373 LogDebug("%s \"%s\": Mode change, now \"%s\".",
374 Client_TypeText(Target), Client_Mask(Target),
375 Client_Modes(Target));
378 IRC_SetPenalty(Client, 1);
384 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
386 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
387 const char *mode_ptr;
389 /* Member or not? -- That's the question! */
390 if (!Channel_IsMemberOf(Channel, Origin))
391 return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
392 Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
394 /* The sender is a member: generate extended reply */
395 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
396 mode_ptr = the_modes;
402 snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
403 strlcat(the_args, argadd, sizeof(the_args));
406 strlcat(the_args, " ", sizeof(the_args));
407 strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
413 strlcat(the_modes, the_args, sizeof(the_modes));
415 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
416 Client_ID(Origin), Channel_Name(Channel),
420 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
421 Client_ID(Origin), Channel_Name(Channel),
422 Channel_CreationTime(Channel)))
430 * Handle channel mode and channel-user mode changes
433 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
435 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
436 argadd[CLIENT_PASS_LEN], *mode_ptr, *o_mode_ptr;
437 bool connected, set, skiponce, retval, use_servermode,
438 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
439 int mode_arg, arg_arg, mode_arg_count = 0;
444 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
446 if (Channel_IsModeless(Channel))
447 return IRC_WriteStrClient(Client, ERR_NOCHANMODES_MSG,
448 Client_ID(Client), Channel_Name(Channel));
450 /* Mode request: let's answer it :-) */
452 return Channel_Mode_Answer_Request(Origin, Channel);
454 /* Check if origin is oper and opers can use mode */
455 use_servermode = Conf_OperServerMode;
456 if(Client_OperByMe(Client) && Conf_OperCanMode) {
460 /* Check if client is a server/service */
461 if(Client_Type(Client) == CLIENT_SERVER ||
462 Client_Type(Client) == CLIENT_SERVICE) {
466 /* Check if client is member of channel or an oper or an server/service */
467 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
468 return IRC_WriteStrClient(Origin, ERR_NOTONCHANNEL_MSG,
470 Channel_Name(Channel));
473 mode_ptr = Req->argv[mode_arg];
474 if (Req->argc > mode_arg + 1)
475 arg_arg = mode_arg + 1;
479 /* Initial state: set or unset modes? */
493 /* Prepare reply string */
494 strcpy(the_modes, set ? "+" : "-");
498 connected = CONNECTED;
503 /* Try next argument if there's any */
506 if (arg_arg > mode_arg)
511 if (mode_arg >= Req->argc)
513 mode_ptr = Req->argv[mode_arg];
515 if (Req->argc > mode_arg + 1)
516 arg_arg = mode_arg + 1;
525 if (((*mode_ptr == '+') && !set)
526 || ((*mode_ptr == '-') && set)) {
527 /* Action modifier ("+"/"-") must be changed ... */
528 len = strlen(the_modes) - 1;
529 if (the_modes[len] == '+' || the_modes[len] == '-') {
530 /* Adjust last action modifier in result */
531 the_modes[len] = *mode_ptr;
533 /* Append modifier character to result string */
535 strlcat(the_modes, x, sizeof(the_modes));
537 set = *mode_ptr == '+';
542 /* Are there arguments left? */
543 if (arg_arg >= Req->argc)
547 o_mode_ptr = Channel_UserModes(Channel, Client);
548 while( *o_mode_ptr ) {
549 if ( *o_mode_ptr == 'q')
551 if ( *o_mode_ptr == 'a')
553 if ( *o_mode_ptr == 'o')
555 if ( *o_mode_ptr == 'h')
566 /* --- Channel modes --- */
567 case 'R': /* Registered users only */
568 case 's': /* Secret channel */
569 case 'z': /* Secure connections only */
570 if(!is_oper && !is_machine && !is_owner &&
571 !is_admin && !is_op) {
572 connected = IRC_WriteStrClient(Origin,
573 ERR_CHANOPRIVSNEEDED_MSG,
574 Client_ID(Origin), Channel_Name(Channel));
577 case 'i': /* Invite only */
578 case 'V': /* Invite disallow */
579 case 'M': /* Only identified nicks can write */
580 case 'm': /* Moderated */
581 case 'n': /* Only members can write */
582 case 'Q': /* No kicks */
583 case 't': /* Topic locked */
584 if(is_oper || is_machine || is_owner ||
585 is_admin || is_op || is_halfop)
588 connected = IRC_WriteStrClient(Origin,
589 ERR_CHANOPRIVSNEEDED_MSG,
590 Client_ID(Origin), Channel_Name(Channel));
592 case 'k': /* Channel key */
593 if (Mode_Limit_Reached(Client, mode_arg_count++))
596 if (is_oper || is_machine || is_owner ||
597 is_admin || is_op || is_halfop)
600 connected = IRC_WriteStrClient(Origin,
601 ERR_CHANOPRIVSNEEDED_MSG,
603 Channel_Name(Channel));
606 if (arg_arg > mode_arg) {
607 if (is_oper || is_machine || is_owner ||
608 is_admin || is_op || is_halfop) {
609 Channel_ModeDel(Channel, 'k');
610 Channel_SetKey(Channel,
612 strlcpy(argadd, Channel_Key(Channel),
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 'l': /* Member limit */
631 if (Mode_Limit_Reached(Client, mode_arg_count++))
634 if (is_oper || is_machine || is_owner ||
635 is_admin || is_op || is_halfop)
638 connected = IRC_WriteStrClient(Origin,
639 ERR_CHANOPRIVSNEEDED_MSG,
641 Channel_Name(Channel));
644 if (arg_arg > mode_arg) {
645 if (is_oper || is_machine || is_owner ||
646 is_admin || is_op || is_halfop) {
647 l = atol(Req->argv[arg_arg]);
648 if (l > 0 && l < 0xFFFF) {
649 Channel_ModeDel(Channel, 'l');
650 Channel_SetMaxUsers(Channel, l);
651 snprintf(argadd, sizeof(argadd),
656 connected = IRC_WriteStrClient(Origin,
657 ERR_CHANOPRIVSNEEDED_MSG,
659 Channel_Name(Channel));
661 Req->argv[arg_arg][0] = '\0';
664 connected = IRC_WriteStrClient(Origin,
665 ERR_NEEDMOREPARAMS_MSG,
666 Client_ID(Origin), Req->command);
670 case 'O': /* IRC operators only */
672 /* Only IRC operators are allowed to
673 * set the 'O' channel mode! */
674 if(is_oper || is_machine)
677 connected = IRC_WriteStrClient(Origin,
678 ERR_NOPRIVILEGES_MSG,
680 } else if(is_oper || is_machine || is_owner ||
684 connected = IRC_WriteStrClient(Origin,
685 ERR_CHANOPRIVSNEEDED_MSG,
687 Channel_Name(Channel));
689 case 'P': /* Persistent channel */
691 /* Only IRC operators are allowed to
692 * set the 'P' channel mode! */
693 if(is_oper || is_machine)
696 connected = IRC_WriteStrClient(Origin,
697 ERR_NOPRIVILEGES_MSG,
699 } else if(is_oper || is_machine || is_owner ||
703 connected = IRC_WriteStrClient(Origin,
704 ERR_CHANOPRIVSNEEDED_MSG,
706 Channel_Name(Channel));
708 /* --- Channel user modes --- */
709 case 'q': /* Owner */
710 case 'a': /* Channel admin */
711 if(!is_oper && !is_machine && !is_owner && !is_admin) {
712 connected = IRC_WriteStrClient(Origin,
713 ERR_CHANOPPRIVTOOLOW_MSG,
715 Channel_Name(Channel));
718 case 'o': /* Channel operator */
719 if(!is_oper && !is_machine && !is_owner &&
720 !is_admin && !is_op) {
721 connected = IRC_WriteStrClient(Origin,
722 ERR_CHANOPRIVSNEEDED_MSG,
724 Channel_Name(Channel));
727 case 'h': /* Half Op */
728 if(!is_oper && !is_machine && !is_owner &&
729 !is_admin && !is_op) {
730 connected = IRC_WriteStrClient(Origin,
731 ERR_CHANOPRIVSNEEDED_MSG,
733 Channel_Name(Channel));
736 case 'v': /* Voice */
737 if (arg_arg > mode_arg) {
738 if (is_oper || is_machine || is_owner ||
739 is_admin || is_op || is_halfop) {
740 client = Client_Search(Req->argv[arg_arg]);
744 connected = IRC_WriteStrClient(Origin,
749 connected = IRC_WriteStrClient(Origin,
750 ERR_CHANOPRIVSNEEDED_MSG,
752 Channel_Name(Channel));
754 Req->argv[arg_arg][0] = '\0';
757 connected = IRC_WriteStrClient(Origin,
758 ERR_NEEDMOREPARAMS_MSG,
759 Client_ID(Origin), Req->command);
763 /* --- Channel lists --- */
764 case 'I': /* Invite lists */
765 case 'b': /* Ban lists */
766 case 'e': /* Channel exception lists */
767 if (Mode_Limit_Reached(Client, mode_arg_count++))
769 if (arg_arg > mode_arg) {
771 if (is_oper || is_machine || is_owner ||
772 is_admin || is_op || is_halfop) {
774 ? Add_To_List(*mode_ptr, Origin,
777 : Del_From_List(*mode_ptr, Origin,
781 connected = IRC_WriteStrClient(Origin,
782 ERR_CHANOPRIVSNEEDED_MSG,
784 Channel_Name(Channel));
786 Req->argv[arg_arg][0] = '\0';
791 Channel_ShowInvites(Origin, Channel);
794 Channel_ShowBans(Origin, Channel);
797 Channel_ShowExcepts(Origin, Channel);
803 if (Client_Type(Client) != CLIENT_SERVER) {
805 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
806 set ? '+' : '-', *mode_ptr,
807 Client_ID(Origin), Channel_Name(Channel));
808 connected = IRC_WriteStrClient(Origin,
810 Client_ID(Origin), *mode_ptr,
811 Channel_Name(Channel));
815 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
816 set ? '+' : '-', *mode_ptr,
817 Client_ID(Origin), Channel_Name(Channel));
825 /* Is there a valid mode change? */
829 /* Validate target client */
830 if (client && (!Channel_IsMemberOf(Channel, client))) {
831 if (!IRC_WriteStrClient
832 (Origin, ERR_USERNOTINCHANNEL_MSG,
833 Client_ID(Origin), Client_ID(client),
834 Channel_Name(Channel)))
841 /* Channel-User-Mode */
843 ? Channel_UserModeAdd(Channel, client, x[0])
844 : Channel_UserModeDel(Channel, client, x[0]);
846 strlcat(the_args, " ", sizeof(the_args));
847 strlcat(the_args, Client_ID(client),
849 strlcat(the_modes, x, sizeof(the_modes));
851 ("User \"%s\": Mode change on %s, now \"%s\"",
852 Client_Mask(client), Channel_Name(Channel),
853 Channel_UserModes(Channel, client));
858 ? Channel_ModeAdd(Channel, x[0])
859 : Channel_ModeDel(Channel, x[0]);
861 strlcat(the_modes, x, sizeof(the_modes));
862 LogDebug("Channel %s: Mode change, now \"%s\".",
863 Channel_Name(Channel),
864 Channel_Modes(Channel));
868 /* Are there additional arguments to add? */
870 strlcat(the_args, " ", sizeof(the_args));
871 strlcat(the_args, argadd, sizeof(the_args));
876 /* Are there changed modes? */
878 /* Clean up mode string */
879 len = strlen(the_modes) - 1;
880 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
881 the_modes[len] = '\0';
883 if (Client_Type(Client) == CLIENT_SERVER) {
884 /* MODE requests for local channels from other servers
885 * are definitely invalid! */
886 if (Channel_IsLocal(Channel)) {
887 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
891 /* Forward mode changes to channel users and all the
892 * other remote servers: */
893 IRC_WriteStrServersPrefix(Client, Origin,
894 "MODE %s %s%s", Channel_Name(Channel),
895 the_modes, the_args);
896 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
897 false, "MODE %s %s%s", Channel_Name(Channel),
898 the_modes, the_args);
901 Origin = Client_ThisServer();
902 /* Send reply to client and inform other servers and channel users */
903 connected = IRC_WriteStrClientPrefix(Client, Origin,
904 "MODE %s %s%s", Channel_Name(Channel),
905 the_modes, the_args);
906 /* Only forward requests for non-local channels */
907 if (!Channel_IsLocal(Channel))
908 IRC_WriteStrServersPrefix(Client, Origin,
909 "MODE %s %s%s", Channel_Name(Channel),
910 the_modes, the_args);
911 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
912 false, "MODE %s %s%s", Channel_Name(Channel),
913 the_modes, the_args);
917 IRC_SetPenalty(Client, 1);
923 IRC_AWAY( CLIENT *Client, REQUEST *Req )
925 assert( Client != NULL );
926 assert( Req != NULL );
928 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
930 if(( Req->argc == 1 ) && (Req->argv[0][0] ))
932 Client_SetAway( Client, Req->argv[0] );
933 Client_ModeAdd( Client, 'a' );
934 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
935 return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
939 Client_ModeDel( Client, 'a' );
940 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
941 return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
947 * Add entries to channel invite, ban and exception lists.
949 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
950 * @param Prefix The originator of the command.
951 * @param Client The sender of the command.
952 * @param Channel The channel of which the list should be modified.
953 * @param Pattern The pattern to add to the list.
954 * @return CONNECTED or DISCONNECTED.
957 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
961 struct list_head *list = NULL;
962 long int current_count;
964 assert(Client != NULL);
965 assert(Channel != NULL);
966 assert(Pattern != NULL);
967 assert(what == 'I' || what == 'b' || what == 'e');
969 mask = Lists_MakeMask(Pattern);
970 current_count = Lists_Count(Channel_GetListInvites(Channel))
971 + Lists_Count(Channel_GetListExcepts(Channel))
972 + Lists_Count(Channel_GetListBans(Channel));
976 list = Channel_GetListInvites(Channel);
979 list = Channel_GetListBans(Channel);
982 list = Channel_GetListExcepts(Channel);
986 if (Lists_CheckDupeMask(list, mask))
988 if (Client_Type(Client) == CLIENT_USER &&
989 current_count >= MAX_HNDL_CHANNEL_LISTS)
990 return IRC_WriteStrClient(Client, ERR_LISTFULL_MSG,
992 Channel_Name(Channel), mask,
993 MAX_HNDL_CHANNEL_LISTS);
997 if (!Channel_AddInvite(Channel, mask, false))
1001 if (!Channel_AddBan(Channel, mask))
1005 if (!Channel_AddExcept(Channel, mask))
1009 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1014 * Delete entries from channel invite, ban and exeption lists.
1016 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1017 * @param Prefix The originator of the command.
1018 * @param Client The sender of the command.
1019 * @param Channel The channel of which the list should be modified.
1020 * @param Pattern The pattern to add to the list.
1021 * @return CONNECTED or DISCONNECTED.
1024 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1025 const char *Pattern)
1028 struct list_head *list = NULL;
1030 assert(Client != NULL);
1031 assert(Channel != NULL);
1032 assert(Pattern != NULL);
1033 assert(what == 'I' || what == 'b' || what == 'e');
1035 mask = Lists_MakeMask(Pattern);
1039 list = Channel_GetListInvites(Channel);
1042 list = Channel_GetListBans(Channel);
1045 list = Channel_GetListExcepts(Channel);
1049 if (!Lists_CheckDupeMask(list, mask))
1051 Lists_Del(list, mask);
1053 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1058 * Send information about changed channel invite/ban/exception lists to clients.
1060 * @param IsAdd true if the list item has been added, false otherwise.
1061 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1062 * @param Prefix The originator of the mode list change.
1063 * @param Client The sender of the command.
1064 * @param Channel The channel of which the list has been modified.
1065 * @param Mask The mask which has been added or removed.
1066 * @return CONNECTED or DISCONNECTED.
1069 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1070 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1074 /* Send confirmation to the client */
1075 if (Client_Type(Client) == CLIENT_USER)
1076 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1077 Channel_Name(Channel),
1081 /* to other servers */
1082 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1083 Channel_Name(Channel), IsAdd ? '+' : '-',
1086 /* and local users in channel */
1087 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1088 "MODE %s %c%c %s", Channel_Name(Channel),
1089 IsAdd ? '+' : '-', ModeChar, Mask );
1092 } /* Send_ListChange */