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 'b': /* Block private msgs */
219 case 'C': /* Only messages from clients sharing a channel */
220 case 'i': /* Invisible */
221 case 's': /* Server messages */
222 case 'w': /* Wallops messages */
226 if (Client_Type(Client) == CLIENT_SERVER) {
228 Client_SetAway(Origin, DEFAULT_AWAY_MSG);
230 ok = IRC_WriteStrClient(Origin,
231 ERR_NOPRIVILEGES_MSG,
235 if (Client_HasMode(Client, 'r'))
236 ok = IRC_WriteStrClient(Origin,
242 case 'c': /* Receive connect notices
243 * (only settable by IRC operators!) */
244 if (!set || Client_Type(Client) == CLIENT_SERVER
245 || Client_OperByMe(Origin))
248 ok = IRC_WriteStrClient(Origin,
249 ERR_NOPRIVILEGES_MSG,
252 case 'o': /* IRC operator (only unsettable!) */
253 if (!set || Client_Type(Client) == CLIENT_SERVER) {
254 Client_SetOperByMe(Target, false);
257 ok = IRC_WriteStrClient(Origin,
258 ERR_NOPRIVILEGES_MSG,
261 case 'q': /* KICK-protected user */
262 if (!set || Client_Type(Client) == CLIENT_SERVER
263 || Client_OperByMe(Origin))
266 ok = IRC_WriteStrClient(Origin,
267 ERR_NOPRIVILEGES_MSG,
270 case 'r': /* Restricted (only settable) */
271 if (set || Client_Type(Client) == CLIENT_SERVER)
274 ok = IRC_WriteStrClient(Origin,
278 case 'R': /* Registered (not [un]settable by clients) */
279 if (Client_Type(Client) == CLIENT_SERVER)
282 ok = IRC_WriteStrClient(Origin,
283 ERR_NICKREGISTER_MSG,
286 case 'x': /* Cloak hostname */
287 if (Client_HasMode(Client, 'r'))
288 ok = IRC_WriteStrClient(Origin,
291 else if (!set || Conf_CloakHostModeX[0]
292 || Client_Type(Client) == CLIENT_SERVER
293 || Client_OperByMe(Client)) {
295 send_RPL_HOSTHIDDEN_MSG = true;
297 ok = IRC_WriteStrClient(Origin,
298 ERR_NOPRIVILEGES_MSG,
302 if (Client_Type(Client) != CLIENT_SERVER) {
304 "Unknown mode \"%c%c\" from \"%s\"!?",
305 set ? '+' : '-', *mode_ptr,
307 ok = IRC_WriteStrClient(Origin,
308 ERR_UMODEUNKNOWNFLAG2_MSG,
315 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
316 set ? '+' : '-', *mode_ptr,
317 Client_ID(Origin), Client_ID(Target));
325 /* Is there a valid mode change? */
330 if (Client_ModeAdd(Target, x[0]))
331 strlcat(the_modes, x, sizeof(the_modes));
333 if (Client_ModeDel(Target, x[0]))
334 strlcat(the_modes, x, sizeof(the_modes));
338 /* Are there changed modes? */
340 /* Remove needless action modifier characters */
341 len = strlen(the_modes) - 1;
342 if (the_modes[len] == '+' || the_modes[len] == '-')
343 the_modes[len] = '\0';
345 if (Client_Type(Client) == CLIENT_SERVER) {
346 /* Forward modes to other servers */
347 if (Client_Conn(Target) != NONE) {
348 /* Remote server (service?) changed modes
349 * for one of our clients. Inform it! */
350 IRC_WriteStrClientPrefix(Target, Origin,
355 IRC_WriteStrServersPrefix(Client, Origin,
360 /* Send reply to client and inform other servers */
361 ok = IRC_WriteStrClientPrefix(Client, Origin,
365 IRC_WriteStrServersPrefix(Client, Origin,
371 if (send_RPL_HOSTHIDDEN_MSG && Client_Conn(Target) > NONE) {
372 /* A new (cloaked) hostname must be annoucned */
373 IRC_WriteStrClientPrefix(Target, Origin,
376 Client_HostnameDisplayed(Target));
380 LogDebug("%s \"%s\": Mode change, now \"%s\".",
381 Client_TypeText(Target), Client_Mask(Target),
382 Client_Modes(Target));
385 IRC_SetPenalty(Client, 1);
391 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
393 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
394 const char *mode_ptr;
396 /* Member or not? -- That's the question! */
397 if (!Channel_IsMemberOf(Channel, Origin))
398 return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
399 Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
401 /* The sender is a member: generate extended reply */
402 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
403 mode_ptr = the_modes;
409 snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
410 strlcat(the_args, argadd, sizeof(the_args));
413 strlcat(the_args, " ", sizeof(the_args));
414 strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
420 strlcat(the_modes, the_args, sizeof(the_modes));
422 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
423 Client_ID(Origin), Channel_Name(Channel),
427 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
428 Client_ID(Origin), Channel_Name(Channel),
429 Channel_CreationTime(Channel)))
437 * Handle channel mode and channel-user mode changes
440 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
442 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
443 argadd[CLIENT_PASS_LEN], *mode_ptr, *o_mode_ptr;
444 bool connected, set, skiponce, retval, use_servermode,
445 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
446 int mode_arg, arg_arg, mode_arg_count = 0;
451 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
453 if (Channel_IsModeless(Channel))
454 return IRC_WriteStrClient(Client, ERR_NOCHANMODES_MSG,
455 Client_ID(Client), Channel_Name(Channel));
457 /* Mode request: let's answer it :-) */
459 return Channel_Mode_Answer_Request(Origin, Channel);
461 /* Check if origin is oper and opers can use mode */
462 use_servermode = Conf_OperServerMode;
463 if(Client_OperByMe(Client) && Conf_OperCanMode) {
467 /* Check if client is a server/service */
468 if(Client_Type(Client) == CLIENT_SERVER ||
469 Client_Type(Client) == CLIENT_SERVICE) {
473 /* Check if client is member of channel or an oper or an server/service */
474 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
475 return IRC_WriteStrClient(Origin, ERR_NOTONCHANNEL_MSG,
477 Channel_Name(Channel));
480 mode_ptr = Req->argv[mode_arg];
481 if (Req->argc > mode_arg + 1)
482 arg_arg = mode_arg + 1;
486 /* Initial state: set or unset modes? */
500 /* Prepare reply string */
501 strcpy(the_modes, set ? "+" : "-");
505 connected = CONNECTED;
510 /* Try next argument if there's any */
513 if (arg_arg > mode_arg)
518 if (mode_arg >= Req->argc)
520 mode_ptr = Req->argv[mode_arg];
522 if (Req->argc > mode_arg + 1)
523 arg_arg = mode_arg + 1;
532 if (((*mode_ptr == '+') && !set)
533 || ((*mode_ptr == '-') && set)) {
534 /* Action modifier ("+"/"-") must be changed ... */
535 len = strlen(the_modes) - 1;
536 if (the_modes[len] == '+' || the_modes[len] == '-') {
537 /* Adjust last action modifier in result */
538 the_modes[len] = *mode_ptr;
540 /* Append modifier character to result string */
542 strlcat(the_modes, x, sizeof(the_modes));
544 set = *mode_ptr == '+';
549 /* Are there arguments left? */
550 if (arg_arg >= Req->argc)
553 if(!is_machine && !is_oper) {
554 o_mode_ptr = Channel_UserModes(Channel, Client);
555 while( *o_mode_ptr ) {
556 if ( *o_mode_ptr == 'q')
558 if ( *o_mode_ptr == 'a')
560 if ( *o_mode_ptr == 'o')
562 if ( *o_mode_ptr == 'h')
573 /* --- Channel modes --- */
574 case 'R': /* Registered users only */
575 case 's': /* Secret channel */
576 case 'z': /* Secure connections only */
577 if(!is_oper && !is_machine && !is_owner &&
578 !is_admin && !is_op) {
579 connected = IRC_WriteStrClient(Origin,
580 ERR_CHANOPRIVSNEEDED_MSG,
581 Client_ID(Origin), Channel_Name(Channel));
584 case 'i': /* Invite only */
585 case 'V': /* Invite disallow */
586 case 'M': /* Only identified nicks can write */
587 case 'm': /* Moderated */
588 case 'n': /* Only members can write */
589 case 'Q': /* No kicks */
590 case 't': /* Topic locked */
591 if(is_oper || is_machine || is_owner ||
592 is_admin || is_op || is_halfop)
595 connected = IRC_WriteStrClient(Origin,
596 ERR_CHANOPRIVSNEEDED_MSG,
597 Client_ID(Origin), Channel_Name(Channel));
599 case 'k': /* Channel key */
600 if (Mode_Limit_Reached(Client, mode_arg_count++))
603 if (is_oper || is_machine || is_owner ||
604 is_admin || is_op || is_halfop)
607 connected = IRC_WriteStrClient(Origin,
608 ERR_CHANOPRIVSNEEDED_MSG,
610 Channel_Name(Channel));
613 if (arg_arg > mode_arg) {
614 if (is_oper || is_machine || is_owner ||
615 is_admin || is_op || is_halfop) {
616 Channel_ModeDel(Channel, 'k');
617 Channel_SetKey(Channel,
619 strlcpy(argadd, Channel_Key(Channel),
623 connected = IRC_WriteStrClient(Origin,
624 ERR_CHANOPRIVSNEEDED_MSG,
626 Channel_Name(Channel));
628 Req->argv[arg_arg][0] = '\0';
631 connected = IRC_WriteStrClient(Origin,
632 ERR_NEEDMOREPARAMS_MSG,
633 Client_ID(Origin), Req->command);
637 case 'l': /* Member limit */
638 if (Mode_Limit_Reached(Client, mode_arg_count++))
641 if (is_oper || is_machine || is_owner ||
642 is_admin || is_op || is_halfop)
645 connected = IRC_WriteStrClient(Origin,
646 ERR_CHANOPRIVSNEEDED_MSG,
648 Channel_Name(Channel));
651 if (arg_arg > mode_arg) {
652 if (is_oper || is_machine || is_owner ||
653 is_admin || is_op || is_halfop) {
654 l = atol(Req->argv[arg_arg]);
655 if (l > 0 && l < 0xFFFF) {
656 Channel_ModeDel(Channel, 'l');
657 Channel_SetMaxUsers(Channel, l);
658 snprintf(argadd, sizeof(argadd),
663 connected = IRC_WriteStrClient(Origin,
664 ERR_CHANOPRIVSNEEDED_MSG,
666 Channel_Name(Channel));
668 Req->argv[arg_arg][0] = '\0';
671 connected = IRC_WriteStrClient(Origin,
672 ERR_NEEDMOREPARAMS_MSG,
673 Client_ID(Origin), Req->command);
677 case 'O': /* IRC operators only */
679 /* Only IRC operators are allowed to
680 * set the 'O' channel mode! */
681 if(is_oper || is_machine)
684 connected = IRC_WriteStrClient(Origin,
685 ERR_NOPRIVILEGES_MSG,
687 } else if(is_oper || is_machine || is_owner ||
691 connected = IRC_WriteStrClient(Origin,
692 ERR_CHANOPRIVSNEEDED_MSG,
694 Channel_Name(Channel));
696 case 'P': /* Persistent channel */
698 /* Only IRC operators are allowed to
699 * set the 'P' channel mode! */
700 if(is_oper || is_machine)
703 connected = IRC_WriteStrClient(Origin,
704 ERR_NOPRIVILEGES_MSG,
706 } else if(is_oper || is_machine || is_owner ||
710 connected = IRC_WriteStrClient(Origin,
711 ERR_CHANOPRIVSNEEDED_MSG,
713 Channel_Name(Channel));
715 /* --- Channel user modes --- */
716 case 'q': /* Owner */
717 case 'a': /* Channel admin */
718 if(!is_oper && !is_machine && !is_owner && !is_admin) {
719 connected = IRC_WriteStrClient(Origin,
720 ERR_CHANOPPRIVTOOLOW_MSG,
722 Channel_Name(Channel));
725 case 'o': /* Channel operator */
726 if(!is_oper && !is_machine && !is_owner &&
727 !is_admin && !is_op) {
728 connected = IRC_WriteStrClient(Origin,
729 ERR_CHANOPRIVSNEEDED_MSG,
731 Channel_Name(Channel));
734 case 'h': /* Half Op */
735 if(!is_oper && !is_machine && !is_owner &&
736 !is_admin && !is_op) {
737 connected = IRC_WriteStrClient(Origin,
738 ERR_CHANOPRIVSNEEDED_MSG,
740 Channel_Name(Channel));
743 case 'v': /* Voice */
744 if (arg_arg > mode_arg) {
745 if (is_oper || is_machine || is_owner ||
746 is_admin || is_op || is_halfop) {
747 client = Client_Search(Req->argv[arg_arg]);
751 connected = IRC_WriteStrClient(Origin,
756 connected = IRC_WriteStrClient(Origin,
757 ERR_CHANOPRIVSNEEDED_MSG,
759 Channel_Name(Channel));
761 Req->argv[arg_arg][0] = '\0';
764 connected = IRC_WriteStrClient(Origin,
765 ERR_NEEDMOREPARAMS_MSG,
766 Client_ID(Origin), Req->command);
770 /* --- Channel lists --- */
771 case 'I': /* Invite lists */
772 case 'b': /* Ban lists */
773 case 'e': /* Channel exception lists */
774 if (Mode_Limit_Reached(Client, mode_arg_count++))
776 if (arg_arg > mode_arg) {
778 if (is_oper || is_machine || is_owner ||
779 is_admin || is_op || is_halfop) {
781 ? Add_To_List(*mode_ptr, Origin,
784 : Del_From_List(*mode_ptr, Origin,
788 connected = IRC_WriteStrClient(Origin,
789 ERR_CHANOPRIVSNEEDED_MSG,
791 Channel_Name(Channel));
793 Req->argv[arg_arg][0] = '\0';
798 Channel_ShowInvites(Origin, Channel);
801 Channel_ShowBans(Origin, Channel);
804 Channel_ShowExcepts(Origin, Channel);
810 if (Client_Type(Client) != CLIENT_SERVER) {
812 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
813 set ? '+' : '-', *mode_ptr,
814 Client_ID(Origin), Channel_Name(Channel));
815 connected = IRC_WriteStrClient(Origin,
817 Client_ID(Origin), *mode_ptr,
818 Channel_Name(Channel));
822 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
823 set ? '+' : '-', *mode_ptr,
824 Client_ID(Origin), Channel_Name(Channel));
832 /* Is there a valid mode change? */
836 /* Validate target client */
837 if (client && (!Channel_IsMemberOf(Channel, client))) {
838 if (!IRC_WriteStrClient
839 (Origin, ERR_USERNOTINCHANNEL_MSG,
840 Client_ID(Origin), Client_ID(client),
841 Channel_Name(Channel)))
848 /* Channel-User-Mode */
850 ? Channel_UserModeAdd(Channel, client, x[0])
851 : Channel_UserModeDel(Channel, client, x[0]);
853 strlcat(the_args, " ", sizeof(the_args));
854 strlcat(the_args, Client_ID(client),
856 strlcat(the_modes, x, sizeof(the_modes));
858 ("User \"%s\": Mode change on %s, now \"%s\"",
859 Client_Mask(client), Channel_Name(Channel),
860 Channel_UserModes(Channel, client));
865 ? Channel_ModeAdd(Channel, x[0])
866 : Channel_ModeDel(Channel, x[0]);
868 strlcat(the_modes, x, sizeof(the_modes));
869 LogDebug("Channel %s: Mode change, now \"%s\".",
870 Channel_Name(Channel),
871 Channel_Modes(Channel));
875 /* Are there additional arguments to add? */
877 strlcat(the_args, " ", sizeof(the_args));
878 strlcat(the_args, argadd, sizeof(the_args));
883 /* Are there changed modes? */
885 /* Clean up mode string */
886 len = strlen(the_modes) - 1;
887 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
888 the_modes[len] = '\0';
890 if (Client_Type(Client) == CLIENT_SERVER) {
891 /* MODE requests for local channels from other servers
892 * are definitely invalid! */
893 if (Channel_IsLocal(Channel)) {
894 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
898 /* Forward mode changes to channel users and all the
899 * other remote servers: */
900 IRC_WriteStrServersPrefix(Client, Origin,
901 "MODE %s %s%s", Channel_Name(Channel),
902 the_modes, the_args);
903 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
904 false, "MODE %s %s%s", Channel_Name(Channel),
905 the_modes, the_args);
908 Origin = Client_ThisServer();
909 /* Send reply to client and inform other servers and channel users */
910 connected = IRC_WriteStrClientPrefix(Client, Origin,
911 "MODE %s %s%s", Channel_Name(Channel),
912 the_modes, the_args);
913 /* Only forward requests for non-local channels */
914 if (!Channel_IsLocal(Channel))
915 IRC_WriteStrServersPrefix(Client, Origin,
916 "MODE %s %s%s", Channel_Name(Channel),
917 the_modes, the_args);
918 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
919 false, "MODE %s %s%s", Channel_Name(Channel),
920 the_modes, the_args);
924 IRC_SetPenalty(Client, 1);
930 IRC_AWAY( CLIENT *Client, REQUEST *Req )
932 assert( Client != NULL );
933 assert( Req != NULL );
935 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
937 if(( Req->argc == 1 ) && (Req->argv[0][0] ))
939 Client_SetAway( Client, Req->argv[0] );
940 Client_ModeAdd( Client, 'a' );
941 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
942 return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
946 Client_ModeDel( Client, 'a' );
947 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
948 return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
954 * Add entries to channel invite, ban and exception lists.
956 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
957 * @param Prefix The originator of the command.
958 * @param Client The sender of the command.
959 * @param Channel The channel of which the list should be modified.
960 * @param Pattern The pattern to add to the list.
961 * @return CONNECTED or DISCONNECTED.
964 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
968 struct list_head *list = NULL;
969 long int current_count;
971 assert(Client != NULL);
972 assert(Channel != NULL);
973 assert(Pattern != NULL);
974 assert(what == 'I' || what == 'b' || what == 'e');
976 mask = Lists_MakeMask(Pattern);
977 current_count = Lists_Count(Channel_GetListInvites(Channel))
978 + Lists_Count(Channel_GetListExcepts(Channel))
979 + Lists_Count(Channel_GetListBans(Channel));
983 list = Channel_GetListInvites(Channel);
986 list = Channel_GetListBans(Channel);
989 list = Channel_GetListExcepts(Channel);
993 if (Lists_CheckDupeMask(list, mask))
995 if (Client_Type(Client) == CLIENT_USER &&
996 current_count >= MAX_HNDL_CHANNEL_LISTS)
997 return IRC_WriteStrClient(Client, ERR_LISTFULL_MSG,
999 Channel_Name(Channel), mask,
1000 MAX_HNDL_CHANNEL_LISTS);
1004 if (!Channel_AddInvite(Channel, mask, false))
1008 if (!Channel_AddBan(Channel, mask))
1012 if (!Channel_AddExcept(Channel, mask))
1016 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1021 * Delete entries from channel invite, ban and exeption lists.
1023 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1024 * @param Prefix The originator of the command.
1025 * @param Client The sender of the command.
1026 * @param Channel The channel of which the list should be modified.
1027 * @param Pattern The pattern to add to the list.
1028 * @return CONNECTED or DISCONNECTED.
1031 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1032 const char *Pattern)
1035 struct list_head *list = NULL;
1037 assert(Client != NULL);
1038 assert(Channel != NULL);
1039 assert(Pattern != NULL);
1040 assert(what == 'I' || what == 'b' || what == 'e');
1042 mask = Lists_MakeMask(Pattern);
1046 list = Channel_GetListInvites(Channel);
1049 list = Channel_GetListBans(Channel);
1052 list = Channel_GetListExcepts(Channel);
1056 if (!Lists_CheckDupeMask(list, mask))
1058 Lists_Del(list, mask);
1060 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1065 * Send information about changed channel invite/ban/exception lists to clients.
1067 * @param IsAdd true if the list item has been added, false otherwise.
1068 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1069 * @param Prefix The originator of the mode list change.
1070 * @param Client The sender of the command.
1071 * @param Channel The channel of which the list has been modified.
1072 * @param Mask The mask which has been added or removed.
1073 * @return CONNECTED or DISCONNECTED.
1076 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1077 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1081 /* Send confirmation to the client */
1082 if (Client_Type(Client) == CLIENT_USER)
1083 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1084 Channel_Name(Channel),
1088 /* to other servers */
1089 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1090 Channel_Name(Channel), IsAdd ? '+' : '-',
1093 /* and local users in channel */
1094 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1095 "MODE %s %c%c %s", Channel_Name(Channel),
1096 IsAdd ? '+' : '-', ModeChar, Mask );
1099 } /* Send_ListChange */