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 void Announce_Client_Hostname PARAMS((CLIENT *Origin, CLIENT *Client));
41 static bool Client_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
43 static bool Channel_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
46 static bool Add_To_List PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
47 CHANNEL *Channel, const char *Pattern));
48 static bool Del_From_List PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
49 CHANNEL *Channel, const char *Pattern));
51 static bool Send_ListChange PARAMS((const bool IsAdd, const char ModeChar,
52 CLIENT *Prefix, CLIENT *Client,
53 CHANNEL *Channel, const char *Mask));
57 * Handler for the IRC "MODE" command.
59 * See RFC 2812 section 3.1.5 ("user mode message") and section 3.2.3
60 * ("channel mode message"), and RFC 2811 section 4 ("channel modes").
62 * @param Client The client from which this command has been received.
63 * @param Req Request structure with prefix and all parameters.
64 * @returns CONNECTED or DISCONNECTED.
67 IRC_MODE( CLIENT *Client, REQUEST *Req )
72 assert(Client != NULL);
77 return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
78 Client_ID(Client), Req->command);
80 /* Origin for answers */
81 if (Client_Type(Client) == CLIENT_SERVER) {
82 origin = Client_Search(Req->prefix);
84 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
90 /* Channel or user mode? */
91 cl = NULL; chan = NULL;
92 if (Client_IsValidNick(Req->argv[0]))
93 cl = Client_Search(Req->argv[0]);
94 if (Channel_IsValidName(Req->argv[0]))
95 chan = Channel_Search(Req->argv[0]);
98 return Client_Mode(Client, Req, origin, cl);
100 return Channel_Mode(Client, Req, origin, chan);
102 /* No target found! */
103 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
104 Client_ID(Client), Req->argv[0]);
109 * Check if the "mode limit" for a client has been reached.
111 * This limit doesn't apply for servers or services!
113 * @param Client The client to check.
114 * @param Count The number of modes already handled.
115 * @return true if the limit has been reached.
118 Mode_Limit_Reached(CLIENT *Client, int Count)
120 if (Client_Type(Client) == CLIENT_SERVER
121 || Client_Type(Client) == CLIENT_SERVICE)
123 if (Count < MAX_HNDL_MODES_ARG)
130 * Handle client mode requests
132 * @param Client The client from which this command has been received.
133 * @param Req Request structure with prefix and all parameters.
134 * @param Origin The originator of the MODE command (prefix).
135 * @param Target The target (client) of this MODE command.
136 * @returns CONNECTED or DISCONNECTED.
139 Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
141 char the_modes[COMMAND_LEN], x[2], *mode_ptr;
143 bool send_RPL_HOSTHIDDEN_MSG = false;
147 /* Is the client allowed to request or change the modes? */
148 if (Client_Type(Client) == CLIENT_USER) {
149 /* Users are only allowed to manipulate their own modes! */
150 if (Target != Client)
151 return IRC_WriteStrClient(Client,
152 ERR_USERSDONTMATCH_MSG,
156 /* Mode request: let's answer it :-) */
158 return IRC_WriteStrClient(Origin, RPL_UMODEIS_MSG,
160 Client_Modes(Target));
163 mode_ptr = Req->argv[mode_arg];
165 /* Initial state: set or unset modes? */
166 if (*mode_ptr == '+') {
168 strcpy(the_modes, "+");
169 } else if (*mode_ptr == '-') {
171 strcpy(the_modes, "-");
173 return IRC_WriteStrClient(Origin, ERR_UMODEUNKNOWNFLAG_MSG,
181 /* Try next argument if there's any */
183 if (mode_arg < Req->argc)
184 mode_ptr = Req->argv[mode_arg];
192 if ((*mode_ptr == '+' && !set)
193 || (*mode_ptr == '-' && set)) {
194 /* Action modifier ("+"/"-") must be changed */
195 len = strlen(the_modes) - 1;
196 if (the_modes[len] == '+'
197 || the_modes[len] == '-') {
198 /* Last character in the "result
199 * string" was an "action", so just
200 * overwrite it with the new action */
201 the_modes[len] = *mode_ptr;
203 /* Append new modifier character to
204 * the resulting mode string */
206 strlcat(the_modes, x,
209 if (*mode_ptr == '+')
220 case 'b': /* Block private msgs */
221 case 'C': /* Only messages from clients sharing a channel */
222 case 'i': /* Invisible */
223 case 's': /* Server messages */
224 case 'w': /* Wallops messages */
228 if (Client_Type(Client) == CLIENT_SERVER) {
230 Client_SetAway(Origin, DEFAULT_AWAY_MSG);
232 ok = IRC_WriteStrClient(Origin,
233 ERR_NOPRIVILEGES_MSG,
237 if (Client_HasMode(Client, 'r'))
238 ok = IRC_WriteStrClient(Origin,
244 case 'c': /* Receive connect notices
245 * (only settable by IRC operators!) */
246 if (!set || Client_Type(Client) == CLIENT_SERVER
247 || Client_OperByMe(Origin))
250 ok = IRC_WriteStrClient(Origin,
251 ERR_NOPRIVILEGES_MSG,
254 case 'o': /* IRC operator (only unsettable!) */
255 if (!set || Client_Type(Client) == CLIENT_SERVER) {
256 Client_SetOperByMe(Target, false);
259 ok = IRC_WriteStrClient(Origin,
260 ERR_NOPRIVILEGES_MSG,
263 case 'q': /* KICK-protected user */
264 if (!set || Client_Type(Client) == CLIENT_SERVER
265 || Client_OperByMe(Origin))
268 ok = IRC_WriteStrClient(Origin,
269 ERR_NOPRIVILEGES_MSG,
272 case 'r': /* Restricted (only settable) */
273 if (set || Client_Type(Client) == CLIENT_SERVER)
276 ok = IRC_WriteStrClient(Origin,
280 case 'R': /* Registered (not [un]settable by clients) */
281 if (Client_Type(Client) == CLIENT_SERVER)
284 ok = IRC_WriteStrClient(Origin,
285 ERR_NICKREGISTER_MSG,
288 case 'x': /* Cloak hostname */
289 if (Client_HasMode(Client, 'r'))
290 ok = IRC_WriteStrClient(Origin,
293 else if (!set || Conf_CloakHostModeX[0]
294 || Client_Type(Client) == CLIENT_SERVER
295 || Client_OperByMe(Client)) {
297 send_RPL_HOSTHIDDEN_MSG = true;
299 ok = IRC_WriteStrClient(Origin,
300 ERR_NOPRIVILEGES_MSG,
304 if (Client_Type(Client) != CLIENT_SERVER) {
306 "Unknown mode \"%c%c\" from \"%s\"!?",
307 set ? '+' : '-', *mode_ptr,
309 ok = IRC_WriteStrClient(Origin,
310 ERR_UMODEUNKNOWNFLAG2_MSG,
317 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
318 set ? '+' : '-', *mode_ptr,
319 Client_ID(Origin), Client_ID(Target));
327 /* Is there a valid mode change? */
332 if (Client_ModeAdd(Target, x[0]))
333 strlcat(the_modes, x, sizeof(the_modes));
335 if (Client_ModeDel(Target, x[0]))
336 strlcat(the_modes, x, sizeof(the_modes));
340 /* Are there changed modes? */
342 /* Remove needless action modifier characters */
343 len = strlen(the_modes) - 1;
344 if (the_modes[len] == '+' || the_modes[len] == '-')
345 the_modes[len] = '\0';
347 if (Client_Type(Client) == CLIENT_SERVER) {
348 /* Forward modes to other servers */
349 if (Client_Conn(Target) != NONE) {
350 /* Remote server (service?) changed modes
351 * for one of our clients. Inform it! */
352 IRC_WriteStrClientPrefix(Target, Origin,
357 IRC_WriteStrServersPrefix(Client, Origin,
362 /* Send reply to client and inform other servers */
363 ok = IRC_WriteStrClientPrefix(Client, Origin,
367 IRC_WriteStrServersPrefix(Client, Origin,
371 if (send_RPL_HOSTHIDDEN_MSG)
372 Announce_Client_Hostname(Origin, Client);
374 LogDebug("%s \"%s\": Mode change, now \"%s\".",
375 Client_TypeText(Target), Client_Mask(Target),
376 Client_Modes(Target));
379 IRC_SetPenalty(Client, 1);
385 * Announce changed client hostname in the network.
387 * @param Client The client of which the hostname changed.
390 Announce_Client_Hostname(CLIENT *Origin, CLIENT *Client)
392 assert(Client != NULL);
394 /* Inform the client itself */
395 IRC_WriteStrClient(Client, RPL_HOSTHIDDEN_MSG, Client_ID(Client),
396 Client_HostnameDisplayed(Client));
398 /* Inform other servers in the network */
399 IRC_WriteStrServersPrefixFlag(Origin, Client_ThisServer(), 'M',
400 "METADATA %s host :%s", Client_ID(Client),
401 Client_HostnameDisplayed(Client));
406 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
408 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
409 const char *mode_ptr;
411 /* Member or not? -- That's the question! */
412 if (!Channel_IsMemberOf(Channel, Origin))
413 return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
414 Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
416 /* The sender is a member: generate extended reply */
417 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
418 mode_ptr = the_modes;
424 snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
425 strlcat(the_args, argadd, sizeof(the_args));
428 strlcat(the_args, " ", sizeof(the_args));
429 strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
435 strlcat(the_modes, the_args, sizeof(the_modes));
437 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
438 Client_ID(Origin), Channel_Name(Channel),
442 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
443 Client_ID(Origin), Channel_Name(Channel),
444 Channel_CreationTime(Channel)))
452 * Handle channel mode and channel-user mode changes
455 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
457 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
458 argadd[CLIENT_PASS_LEN], *mode_ptr, *o_mode_ptr;
459 bool connected, set, skiponce, retval, use_servermode,
460 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
461 int mode_arg, arg_arg, mode_arg_count = 0;
466 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
468 if (Channel_IsModeless(Channel))
469 return IRC_WriteStrClient(Client, ERR_NOCHANMODES_MSG,
470 Client_ID(Client), Channel_Name(Channel));
472 /* Mode request: let's answer it :-) */
474 return Channel_Mode_Answer_Request(Origin, Channel);
476 /* Check if origin is oper and opers can use mode */
477 use_servermode = Conf_OperServerMode;
478 if(Client_OperByMe(Client) && Conf_OperCanMode) {
482 /* Check if client is a server/service */
483 if(Client_Type(Client) == CLIENT_SERVER ||
484 Client_Type(Client) == CLIENT_SERVICE) {
488 /* Check if client is member of channel or an oper or an server/service */
489 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
490 return IRC_WriteStrClient(Origin, ERR_NOTONCHANNEL_MSG,
492 Channel_Name(Channel));
495 mode_ptr = Req->argv[mode_arg];
496 if (Req->argc > mode_arg + 1)
497 arg_arg = mode_arg + 1;
501 /* Initial state: set or unset modes? */
515 /* Prepare reply string */
516 strcpy(the_modes, set ? "+" : "-");
520 connected = CONNECTED;
525 /* Try next argument if there's any */
528 if (arg_arg > mode_arg)
533 if (mode_arg >= Req->argc)
535 mode_ptr = Req->argv[mode_arg];
537 if (Req->argc > mode_arg + 1)
538 arg_arg = mode_arg + 1;
547 if (((*mode_ptr == '+') && !set)
548 || ((*mode_ptr == '-') && set)) {
549 /* Action modifier ("+"/"-") must be changed ... */
550 len = strlen(the_modes) - 1;
551 if (the_modes[len] == '+' || the_modes[len] == '-') {
552 /* Adjust last action modifier in result */
553 the_modes[len] = *mode_ptr;
555 /* Append modifier character to result string */
557 strlcat(the_modes, x, sizeof(the_modes));
559 set = *mode_ptr == '+';
564 /* Are there arguments left? */
565 if (arg_arg >= Req->argc)
569 o_mode_ptr = Channel_UserModes(Channel, Client);
570 while( *o_mode_ptr ) {
571 if ( *o_mode_ptr == 'q')
573 if ( *o_mode_ptr == 'a')
575 if ( *o_mode_ptr == 'o')
577 if ( *o_mode_ptr == 'h')
588 /* --- Channel modes --- */
589 case 'R': /* Registered users only */
590 case 's': /* Secret channel */
591 case 'z': /* Secure connections only */
592 if(!is_oper && !is_machine && !is_owner &&
593 !is_admin && !is_op) {
594 connected = IRC_WriteStrClient(Origin,
595 ERR_CHANOPRIVSNEEDED_MSG,
596 Client_ID(Origin), Channel_Name(Channel));
599 case 'i': /* Invite only */
600 case 'V': /* Invite disallow */
601 case 'M': /* Only identified nicks can write */
602 case 'm': /* Moderated */
603 case 'n': /* Only members can write */
604 case 'Q': /* No kicks */
605 case 't': /* Topic locked */
606 if(is_oper || is_machine || is_owner ||
607 is_admin || is_op || is_halfop)
610 connected = IRC_WriteStrClient(Origin,
611 ERR_CHANOPRIVSNEEDED_MSG,
612 Client_ID(Origin), Channel_Name(Channel));
614 case 'k': /* Channel key */
615 if (Mode_Limit_Reached(Client, mode_arg_count++))
618 if (is_oper || is_machine || is_owner ||
619 is_admin || is_op || is_halfop)
622 connected = IRC_WriteStrClient(Origin,
623 ERR_CHANOPRIVSNEEDED_MSG,
625 Channel_Name(Channel));
628 if (arg_arg > mode_arg) {
629 if (is_oper || is_machine || is_owner ||
630 is_admin || is_op || is_halfop) {
631 Channel_ModeDel(Channel, 'k');
632 Channel_SetKey(Channel,
634 strlcpy(argadd, Channel_Key(Channel),
638 connected = IRC_WriteStrClient(Origin,
639 ERR_CHANOPRIVSNEEDED_MSG,
641 Channel_Name(Channel));
643 Req->argv[arg_arg][0] = '\0';
646 connected = IRC_WriteStrClient(Origin,
647 ERR_NEEDMOREPARAMS_MSG,
648 Client_ID(Origin), Req->command);
652 case 'l': /* Member limit */
653 if (Mode_Limit_Reached(Client, mode_arg_count++))
656 if (is_oper || is_machine || is_owner ||
657 is_admin || is_op || is_halfop)
660 connected = IRC_WriteStrClient(Origin,
661 ERR_CHANOPRIVSNEEDED_MSG,
663 Channel_Name(Channel));
666 if (arg_arg > mode_arg) {
667 if (is_oper || is_machine || is_owner ||
668 is_admin || is_op || is_halfop) {
669 l = atol(Req->argv[arg_arg]);
670 if (l > 0 && l < 0xFFFF) {
671 Channel_ModeDel(Channel, 'l');
672 Channel_SetMaxUsers(Channel, l);
673 snprintf(argadd, sizeof(argadd),
678 connected = IRC_WriteStrClient(Origin,
679 ERR_CHANOPRIVSNEEDED_MSG,
681 Channel_Name(Channel));
683 Req->argv[arg_arg][0] = '\0';
686 connected = IRC_WriteStrClient(Origin,
687 ERR_NEEDMOREPARAMS_MSG,
688 Client_ID(Origin), Req->command);
692 case 'O': /* IRC operators only */
694 /* Only IRC operators are allowed to
695 * set the 'O' channel mode! */
696 if(is_oper || is_machine)
699 connected = IRC_WriteStrClient(Origin,
700 ERR_NOPRIVILEGES_MSG,
702 } else if(is_oper || is_machine || is_owner ||
706 connected = IRC_WriteStrClient(Origin,
707 ERR_CHANOPRIVSNEEDED_MSG,
709 Channel_Name(Channel));
711 case 'P': /* Persistent channel */
713 /* Only IRC operators are allowed to
714 * set the 'P' channel mode! */
715 if(is_oper || is_machine)
718 connected = IRC_WriteStrClient(Origin,
719 ERR_NOPRIVILEGES_MSG,
721 } else if(is_oper || is_machine || is_owner ||
725 connected = IRC_WriteStrClient(Origin,
726 ERR_CHANOPRIVSNEEDED_MSG,
728 Channel_Name(Channel));
730 /* --- Channel user modes --- */
731 case 'q': /* Owner */
732 case 'a': /* Channel admin */
733 if(!is_oper && !is_machine && !is_owner && !is_admin) {
734 connected = IRC_WriteStrClient(Origin,
735 ERR_CHANOPPRIVTOOLOW_MSG,
737 Channel_Name(Channel));
740 case 'o': /* Channel operator */
741 if(!is_oper && !is_machine && !is_owner &&
742 !is_admin && !is_op) {
743 connected = IRC_WriteStrClient(Origin,
744 ERR_CHANOPRIVSNEEDED_MSG,
746 Channel_Name(Channel));
749 case 'h': /* Half Op */
750 if(!is_oper && !is_machine && !is_owner &&
751 !is_admin && !is_op) {
752 connected = IRC_WriteStrClient(Origin,
753 ERR_CHANOPRIVSNEEDED_MSG,
755 Channel_Name(Channel));
758 case 'v': /* Voice */
759 if (arg_arg > mode_arg) {
760 if (is_oper || is_machine || is_owner ||
761 is_admin || is_op || is_halfop) {
762 client = Client_Search(Req->argv[arg_arg]);
766 connected = IRC_WriteStrClient(Origin,
771 connected = IRC_WriteStrClient(Origin,
772 ERR_CHANOPRIVSNEEDED_MSG,
774 Channel_Name(Channel));
776 Req->argv[arg_arg][0] = '\0';
779 connected = IRC_WriteStrClient(Origin,
780 ERR_NEEDMOREPARAMS_MSG,
781 Client_ID(Origin), Req->command);
785 /* --- Channel lists --- */
786 case 'I': /* Invite lists */
787 case 'b': /* Ban lists */
788 case 'e': /* Channel exception lists */
789 if (Mode_Limit_Reached(Client, mode_arg_count++))
791 if (arg_arg > mode_arg) {
793 if (is_oper || is_machine || is_owner ||
794 is_admin || is_op || is_halfop) {
796 ? Add_To_List(*mode_ptr, Origin,
799 : Del_From_List(*mode_ptr, Origin,
803 connected = IRC_WriteStrClient(Origin,
804 ERR_CHANOPRIVSNEEDED_MSG,
806 Channel_Name(Channel));
808 Req->argv[arg_arg][0] = '\0';
813 Channel_ShowInvites(Origin, Channel);
816 Channel_ShowBans(Origin, Channel);
819 Channel_ShowExcepts(Origin, Channel);
825 if (Client_Type(Client) != CLIENT_SERVER) {
827 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
828 set ? '+' : '-', *mode_ptr,
829 Client_ID(Origin), Channel_Name(Channel));
830 connected = IRC_WriteStrClient(Origin,
832 Client_ID(Origin), *mode_ptr,
833 Channel_Name(Channel));
837 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
838 set ? '+' : '-', *mode_ptr,
839 Client_ID(Origin), Channel_Name(Channel));
847 /* Is there a valid mode change? */
851 /* Validate target client */
852 if (client && (!Channel_IsMemberOf(Channel, client))) {
853 if (!IRC_WriteStrClient
854 (Origin, ERR_USERNOTINCHANNEL_MSG,
855 Client_ID(Origin), Client_ID(client),
856 Channel_Name(Channel)))
863 /* Channel-User-Mode */
865 ? Channel_UserModeAdd(Channel, client, x[0])
866 : Channel_UserModeDel(Channel, client, x[0]);
868 strlcat(the_args, " ", sizeof(the_args));
869 strlcat(the_args, Client_ID(client),
871 strlcat(the_modes, x, sizeof(the_modes));
873 ("User \"%s\": Mode change on %s, now \"%s\"",
874 Client_Mask(client), Channel_Name(Channel),
875 Channel_UserModes(Channel, client));
880 ? Channel_ModeAdd(Channel, x[0])
881 : Channel_ModeDel(Channel, x[0]);
883 strlcat(the_modes, x, sizeof(the_modes));
884 LogDebug("Channel %s: Mode change, now \"%s\".",
885 Channel_Name(Channel),
886 Channel_Modes(Channel));
890 /* Are there additional arguments to add? */
892 strlcat(the_args, " ", sizeof(the_args));
893 strlcat(the_args, argadd, sizeof(the_args));
898 /* Are there changed modes? */
900 /* Clean up mode string */
901 len = strlen(the_modes) - 1;
902 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
903 the_modes[len] = '\0';
905 if (Client_Type(Client) == CLIENT_SERVER) {
906 /* MODE requests for local channels from other servers
907 * are definitely invalid! */
908 if (Channel_IsLocal(Channel)) {
909 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
913 /* Forward mode changes to channel users and all the
914 * other remote servers: */
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);
923 Origin = Client_ThisServer();
924 /* Send reply to client and inform other servers and channel users */
925 connected = IRC_WriteStrClientPrefix(Client, Origin,
926 "MODE %s %s%s", Channel_Name(Channel),
927 the_modes, the_args);
928 /* Only forward requests for non-local channels */
929 if (!Channel_IsLocal(Channel))
930 IRC_WriteStrServersPrefix(Client, Origin,
931 "MODE %s %s%s", Channel_Name(Channel),
932 the_modes, the_args);
933 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
934 false, "MODE %s %s%s", Channel_Name(Channel),
935 the_modes, the_args);
939 IRC_SetPenalty(Client, 1);
945 IRC_AWAY( CLIENT *Client, REQUEST *Req )
947 assert( Client != NULL );
948 assert( Req != NULL );
950 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
952 if(( Req->argc == 1 ) && (Req->argv[0][0] ))
954 Client_SetAway( Client, Req->argv[0] );
955 Client_ModeAdd( Client, 'a' );
956 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
957 return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
961 Client_ModeDel( Client, 'a' );
962 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
963 return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
969 * Add entries to channel invite, ban and exception lists.
971 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
972 * @param Prefix The originator of the command.
973 * @param Client The sender of the command.
974 * @param Channel The channel of which the list should be modified.
975 * @param Pattern The pattern to add to the list.
976 * @return CONNECTED or DISCONNECTED.
979 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
983 struct list_head *list = NULL;
984 long int current_count;
986 assert(Client != NULL);
987 assert(Channel != NULL);
988 assert(Pattern != NULL);
989 assert(what == 'I' || what == 'b' || what == 'e');
991 mask = Lists_MakeMask(Pattern);
992 current_count = Lists_Count(Channel_GetListInvites(Channel))
993 + Lists_Count(Channel_GetListExcepts(Channel))
994 + Lists_Count(Channel_GetListBans(Channel));
998 list = Channel_GetListInvites(Channel);
1001 list = Channel_GetListBans(Channel);
1004 list = Channel_GetListExcepts(Channel);
1008 if (Lists_CheckDupeMask(list, mask))
1010 if (Client_Type(Client) == CLIENT_USER &&
1011 current_count >= MAX_HNDL_CHANNEL_LISTS)
1012 return IRC_WriteStrClient(Client, ERR_LISTFULL_MSG,
1014 Channel_Name(Channel), mask,
1015 MAX_HNDL_CHANNEL_LISTS);
1019 if (!Channel_AddInvite(Channel, mask, false))
1023 if (!Channel_AddBan(Channel, mask))
1027 if (!Channel_AddExcept(Channel, mask))
1031 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1036 * Delete entries from channel invite, ban and exeption lists.
1038 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1039 * @param Prefix The originator of the command.
1040 * @param Client The sender of the command.
1041 * @param Channel The channel of which the list should be modified.
1042 * @param Pattern The pattern to add to the list.
1043 * @return CONNECTED or DISCONNECTED.
1046 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1047 const char *Pattern)
1050 struct list_head *list = NULL;
1052 assert(Client != NULL);
1053 assert(Channel != NULL);
1054 assert(Pattern != NULL);
1055 assert(what == 'I' || what == 'b' || what == 'e');
1057 mask = Lists_MakeMask(Pattern);
1061 list = Channel_GetListInvites(Channel);
1064 list = Channel_GetListBans(Channel);
1067 list = Channel_GetListExcepts(Channel);
1071 if (!Lists_CheckDupeMask(list, mask))
1073 Lists_Del(list, mask);
1075 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1080 * Send information about changed channel invite/ban/exception lists to clients.
1082 * @param IsAdd true if the list item has been added, false otherwise.
1083 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1084 * @param Prefix The originator of the mode list change.
1085 * @param Client The sender of the command.
1086 * @param Channel The channel of which the list has been modified.
1087 * @param Mask The mask which has been added or removed.
1088 * @return CONNECTED or DISCONNECTED.
1091 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1092 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1096 /* Send confirmation to the client */
1097 if (Client_Type(Client) == CLIENT_USER)
1098 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1099 Channel_Name(Channel),
1103 /* to other servers */
1104 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1105 Channel_Name(Channel), IsAdd ? '+' : '-',
1108 /* and local users in channel */
1109 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1110 "MODE %s %c%c %s", Channel_Name(Channel),
1111 IsAdd ? '+' : '-', ModeChar, Mask );
1114 } /* Send_ListChange */