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 'M': /* Only identified nicks can write */
579 case 'm': /* Moderated */
580 case 'n': /* Only members can write */
581 case 'Q': /* No kicks */
582 case 't': /* Topic locked */
583 if(is_oper || is_machine || is_owner ||
584 is_admin || is_op || is_halfop)
587 connected = IRC_WriteStrClient(Origin,
588 ERR_CHANOPRIVSNEEDED_MSG,
589 Client_ID(Origin), Channel_Name(Channel));
591 case 'k': /* Channel key */
592 if (Mode_Limit_Reached(Client, mode_arg_count++))
595 if (is_oper || is_machine || is_owner ||
596 is_admin || is_op || is_halfop)
599 connected = IRC_WriteStrClient(Origin,
600 ERR_CHANOPRIVSNEEDED_MSG,
602 Channel_Name(Channel));
605 if (arg_arg > mode_arg) {
606 if (is_oper || is_machine || is_owner ||
607 is_admin || is_op || is_halfop) {
608 Channel_ModeDel(Channel, 'k');
609 Channel_SetKey(Channel,
611 strlcpy(argadd, Channel_Key(Channel),
615 connected = IRC_WriteStrClient(Origin,
616 ERR_CHANOPRIVSNEEDED_MSG,
618 Channel_Name(Channel));
620 Req->argv[arg_arg][0] = '\0';
623 connected = IRC_WriteStrClient(Origin,
624 ERR_NEEDMOREPARAMS_MSG,
625 Client_ID(Origin), Req->command);
629 case 'l': /* Member limit */
630 if (Mode_Limit_Reached(Client, mode_arg_count++))
633 if (is_oper || is_machine || is_owner ||
634 is_admin || is_op || is_halfop)
637 connected = IRC_WriteStrClient(Origin,
638 ERR_CHANOPRIVSNEEDED_MSG,
640 Channel_Name(Channel));
643 if (arg_arg > mode_arg) {
644 if (is_oper || is_machine || is_owner ||
645 is_admin || is_op || is_halfop) {
646 l = atol(Req->argv[arg_arg]);
647 if (l > 0 && l < 0xFFFF) {
648 Channel_ModeDel(Channel, 'l');
649 Channel_SetMaxUsers(Channel, l);
650 snprintf(argadd, sizeof(argadd),
655 connected = IRC_WriteStrClient(Origin,
656 ERR_CHANOPRIVSNEEDED_MSG,
658 Channel_Name(Channel));
660 Req->argv[arg_arg][0] = '\0';
663 connected = IRC_WriteStrClient(Origin,
664 ERR_NEEDMOREPARAMS_MSG,
665 Client_ID(Origin), Req->command);
669 case 'O': /* IRC operators only */
671 /* Only IRC operators are allowed to
672 * set the 'O' channel mode! */
673 if(is_oper || is_machine)
676 connected = IRC_WriteStrClient(Origin,
677 ERR_NOPRIVILEGES_MSG,
679 } else if(is_oper || is_machine || is_owner ||
683 connected = IRC_WriteStrClient(Origin,
684 ERR_CHANOPRIVSNEEDED_MSG,
686 Channel_Name(Channel));
688 case 'P': /* Persistent channel */
690 /* Only IRC operators are allowed to
691 * set the 'P' channel mode! */
692 if(is_oper || is_machine)
695 connected = IRC_WriteStrClient(Origin,
696 ERR_NOPRIVILEGES_MSG,
698 } else if(is_oper || is_machine || is_owner ||
702 connected = IRC_WriteStrClient(Origin,
703 ERR_CHANOPRIVSNEEDED_MSG,
705 Channel_Name(Channel));
707 /* --- Channel user modes --- */
708 case 'q': /* Owner */
709 case 'a': /* Channel admin */
710 if(!is_oper && !is_machine && !is_owner) {
711 connected = IRC_WriteStrClient(Origin,
712 ERR_CHANOPRIVSNEEDED_MSG,
714 Channel_Name(Channel));
717 case 'o': /* Channel operator */
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 'h': /* Half Op */
727 if(!is_oper && !is_machine && !is_owner &&
728 !is_admin && !is_op) {
729 connected = IRC_WriteStrClient(Origin,
730 ERR_CHANOPRIVSNEEDED_MSG,
732 Channel_Name(Channel));
735 case 'v': /* Voice */
736 if (arg_arg > mode_arg) {
737 if (is_oper || is_machine || is_owner ||
738 is_admin || is_op || is_halfop) {
739 client = Client_Search(Req->argv[arg_arg]);
743 connected = IRC_WriteStrClient(Origin,
748 connected = IRC_WriteStrClient(Origin,
749 ERR_CHANOPRIVSNEEDED_MSG,
751 Channel_Name(Channel));
753 Req->argv[arg_arg][0] = '\0';
756 connected = IRC_WriteStrClient(Origin,
757 ERR_NEEDMOREPARAMS_MSG,
758 Client_ID(Origin), Req->command);
762 /* --- Channel lists --- */
763 case 'I': /* Invite lists */
764 case 'b': /* Ban lists */
765 case 'e': /* Channel exception lists */
766 if (Mode_Limit_Reached(Client, mode_arg_count++))
768 if (arg_arg > mode_arg) {
770 if (is_oper || is_machine || is_owner ||
771 is_admin || is_op || is_halfop) {
773 ? Add_To_List(*mode_ptr, Origin,
776 : Del_From_List(*mode_ptr, Origin,
780 connected = IRC_WriteStrClient(Origin,
781 ERR_CHANOPRIVSNEEDED_MSG,
783 Channel_Name(Channel));
785 Req->argv[arg_arg][0] = '\0';
790 Channel_ShowInvites(Origin, Channel);
793 Channel_ShowBans(Origin, Channel);
796 Channel_ShowExcepts(Origin, Channel);
802 if (Client_Type(Client) != CLIENT_SERVER) {
804 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
805 set ? '+' : '-', *mode_ptr,
806 Client_ID(Origin), Channel_Name(Channel));
807 connected = IRC_WriteStrClient(Origin,
809 Client_ID(Origin), *mode_ptr,
810 Channel_Name(Channel));
814 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
815 set ? '+' : '-', *mode_ptr,
816 Client_ID(Origin), Channel_Name(Channel));
824 /* Is there a valid mode change? */
828 /* Validate target client */
829 if (client && (!Channel_IsMemberOf(Channel, client))) {
830 if (!IRC_WriteStrClient
831 (Origin, ERR_USERNOTINCHANNEL_MSG,
832 Client_ID(Origin), Client_ID(client),
833 Channel_Name(Channel)))
840 /* Channel-User-Mode */
842 ? Channel_UserModeAdd(Channel, client, x[0])
843 : Channel_UserModeDel(Channel, client, x[0]);
845 strlcat(the_args, " ", sizeof(the_args));
846 strlcat(the_args, Client_ID(client),
848 strlcat(the_modes, x, sizeof(the_modes));
850 ("User \"%s\": Mode change on %s, now \"%s\"",
851 Client_Mask(client), Channel_Name(Channel),
852 Channel_UserModes(Channel, client));
857 ? Channel_ModeAdd(Channel, x[0])
858 : Channel_ModeDel(Channel, x[0]);
860 strlcat(the_modes, x, sizeof(the_modes));
861 LogDebug("Channel %s: Mode change, now \"%s\".",
862 Channel_Name(Channel),
863 Channel_Modes(Channel));
867 /* Are there additional arguments to add? */
869 strlcat(the_args, " ", sizeof(the_args));
870 strlcat(the_args, argadd, sizeof(the_args));
875 /* Are there changed modes? */
877 /* Clean up mode string */
878 len = strlen(the_modes) - 1;
879 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
880 the_modes[len] = '\0';
882 if (Client_Type(Client) == CLIENT_SERVER) {
883 /* MODE requests for local channels from other servers
884 * are definitely invalid! */
885 if (Channel_IsLocal(Channel)) {
886 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
890 /* Forward mode changes to channel users and all the
891 * other remote servers: */
892 IRC_WriteStrServersPrefix(Client, Origin,
893 "MODE %s %s%s", Channel_Name(Channel),
894 the_modes, the_args);
895 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
896 false, "MODE %s %s%s", Channel_Name(Channel),
897 the_modes, the_args);
900 Origin = Client_ThisServer();
901 /* Send reply to client and inform other servers and channel users */
902 connected = IRC_WriteStrClientPrefix(Client, Origin,
903 "MODE %s %s%s", Channel_Name(Channel),
904 the_modes, the_args);
905 /* Only forward requests for non-local channels */
906 if (!Channel_IsLocal(Channel))
907 IRC_WriteStrServersPrefix(Client, Origin,
908 "MODE %s %s%s", Channel_Name(Channel),
909 the_modes, the_args);
910 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
911 false, "MODE %s %s%s", Channel_Name(Channel),
912 the_modes, the_args);
916 IRC_SetPenalty(Client, 1);
922 IRC_AWAY( CLIENT *Client, REQUEST *Req )
924 assert( Client != NULL );
925 assert( Req != NULL );
927 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
929 if(( Req->argc == 1 ) && (Req->argv[0][0] ))
931 Client_SetAway( Client, Req->argv[0] );
932 Client_ModeAdd( Client, 'a' );
933 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
934 return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
938 Client_ModeDel( Client, 'a' );
939 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
940 return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
946 * Add entries to channel invite, ban and exception lists.
948 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
949 * @param Prefix The originator of the command.
950 * @param Client The sender of the command.
951 * @param Channel The channel of which the list should be modified.
952 * @param Pattern The pattern to add to the list.
953 * @return CONNECTED or DISCONNECTED.
956 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
960 struct list_head *list = NULL;
961 long int current_count;
963 assert(Client != NULL);
964 assert(Channel != NULL);
965 assert(Pattern != NULL);
966 assert(what == 'I' || what == 'b' || what == 'e');
968 mask = Lists_MakeMask(Pattern);
969 current_count = Lists_Count(Channel_GetListInvites(Channel))
970 + Lists_Count(Channel_GetListExcepts(Channel))
971 + Lists_Count(Channel_GetListBans(Channel));
975 list = Channel_GetListInvites(Channel);
978 list = Channel_GetListBans(Channel);
981 list = Channel_GetListExcepts(Channel);
985 if (Lists_CheckDupeMask(list, mask))
987 if (Client_Type(Client) == CLIENT_USER &&
988 current_count >= MAX_HNDL_CHANNEL_LISTS)
989 return IRC_WriteStrClient(Client, ERR_LISTFULL_MSG,
991 Channel_Name(Channel), mask,
992 MAX_HNDL_CHANNEL_LISTS);
996 if (!Channel_AddInvite(Channel, mask, false))
1000 if (!Channel_AddBan(Channel, mask))
1004 if (!Channel_AddExcept(Channel, mask))
1008 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1013 * Delete entries from channel invite, ban and exeption lists.
1015 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1016 * @param Prefix The originator of the command.
1017 * @param Client The sender of the command.
1018 * @param Channel The channel of which the list should be modified.
1019 * @param Pattern The pattern to add to the list.
1020 * @return CONNECTED or DISCONNECTED.
1023 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1024 const char *Pattern)
1027 struct list_head *list = NULL;
1029 assert(Client != NULL);
1030 assert(Channel != NULL);
1031 assert(Pattern != NULL);
1032 assert(what == 'I' || what == 'b' || what == 'e');
1034 mask = Lists_MakeMask(Pattern);
1038 list = Channel_GetListInvites(Channel);
1041 list = Channel_GetListBans(Channel);
1044 list = Channel_GetListExcepts(Channel);
1048 if (!Lists_CheckDupeMask(list, mask))
1050 Lists_Del(list, mask);
1052 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1057 * Send information about changed channel invite/ban/exception lists to clients.
1059 * @param IsAdd true if the list item has been added, false otherwise.
1060 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1061 * @param Prefix The originator of the mode list change.
1062 * @param Client The sender of the command.
1063 * @param Channel The channel of which the list has been modified.
1064 * @param Mask The mask which has been added or removed.
1065 * @return CONNECTED or DISCONNECTED.
1068 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1069 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1073 /* Send confirmation to the client */
1074 if (Client_Type(Client) == CLIENT_USER)
1075 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1076 Channel_Name(Channel),
1080 /* to other servers */
1081 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1082 Channel_Name(Channel), IsAdd ? '+' : '-',
1085 /* and local users in channel */
1086 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1087 "MODE %s %c%c %s", Channel_Name(Channel),
1088 IsAdd ? '+' : '-', ModeChar, Mask );
1091 } /* Send_ListChange */