2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2013 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-macros.h"
29 #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));
54 * Handler for the IRC "MODE" command.
56 * This function detects whether user or channel modes should be modified
57 * and calls the appropriate sub-functions.
59 * @param Client The client from which this command has been received.
60 * @param Req Request structure with prefix and all parameters.
61 * @return CONNECTED or DISCONNECTED.
64 IRC_MODE( CLIENT *Client, REQUEST *Req )
69 assert(Client != NULL);
72 _IRC_GET_SENDER_OR_RETURN_(origin, Req, Client)
74 /* Channel or user mode? */
75 cl = NULL; chan = NULL;
76 if (Client_IsValidNick(Req->argv[0]))
77 cl = Client_Search(Req->argv[0]);
78 if (Channel_IsValidName(Req->argv[0]))
79 chan = Channel_Search(Req->argv[0]);
82 return Client_Mode(Client, Req, origin, cl);
84 return Channel_Mode(Client, Req, origin, chan);
86 /* No target found! */
87 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
88 Client_ID(Client), Req->argv[0]);
92 * Check if the "mode limit" for a client has been reached.
94 * This limit doesn't apply for servers or services!
96 * @param Client The client to check.
97 * @param Count The number of modes already handled.
98 * @return true if the limit has been reached.
101 Mode_Limit_Reached(CLIENT *Client, int Count)
103 if (Client_Type(Client) == CLIENT_SERVER
104 || Client_Type(Client) == CLIENT_SERVICE)
106 if (Count < MAX_HNDL_MODES_ARG)
112 * Handle client mode requests
114 * @param Client The client from which this command has been received.
115 * @param Req Request structure with prefix and all parameters.
116 * @param Origin The originator of the MODE command (prefix).
117 * @param Target The target (client) of this MODE command.
118 * @return CONNECTED or DISCONNECTED.
121 Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
123 char the_modes[COMMAND_LEN], x[2], *mode_ptr;
125 bool send_RPL_HOSTHIDDEN_MSG = false;
129 /* Is the client allowed to request or change the modes? */
130 if (Client_Type(Client) == CLIENT_USER) {
131 /* Users are only allowed to manipulate their own modes! */
132 if (Target != Client)
133 return IRC_WriteErrClient(Client,
134 ERR_USERSDONTMATCH_MSG,
138 /* Mode request: let's answer it :-) */
140 return IRC_WriteStrClient(Origin, RPL_UMODEIS_MSG,
142 Client_Modes(Target));
145 mode_ptr = Req->argv[mode_arg];
147 /* Initial state: set or unset modes? */
148 if (*mode_ptr == '+') {
150 strcpy(the_modes, "+");
151 } else if (*mode_ptr == '-') {
153 strcpy(the_modes, "-");
155 return IRC_WriteErrClient(Origin, ERR_UMODEUNKNOWNFLAG_MSG,
163 /* Try next argument if there's any */
165 if (mode_arg < Req->argc)
166 mode_ptr = Req->argv[mode_arg];
174 if ((*mode_ptr == '+' && !set)
175 || (*mode_ptr == '-' && set)) {
176 /* Action modifier ("+"/"-") must be changed */
177 len = strlen(the_modes) - 1;
178 if (the_modes[len] == '+'
179 || the_modes[len] == '-') {
180 /* Last character in the "result
181 * string" was an "action", so just
182 * overwrite it with the new action */
183 the_modes[len] = *mode_ptr;
185 /* Append new modifier character to
186 * the resulting mode string */
188 strlcat(the_modes, x,
191 if (*mode_ptr == '+')
202 case 'b': /* Block private msgs */
203 case 'C': /* Only messages from clients sharing a channel */
204 case 'i': /* Invisible */
205 case 's': /* Server messages */
206 case 'w': /* Wallops messages */
210 if (Client_Type(Client) == CLIENT_SERVER) {
212 Client_SetAway(Origin, DEFAULT_AWAY_MSG);
214 ok = IRC_WriteErrClient(Origin,
215 ERR_NOPRIVILEGES_MSG,
219 if (Client_HasMode(Client, 'r'))
220 ok = IRC_WriteErrClient(Origin,
226 case 'c': /* Receive connect notices
227 * (only settable by IRC operators!) */
228 if (!set || Client_Type(Client) == CLIENT_SERVER
229 || Client_OperByMe(Origin))
232 ok = IRC_WriteErrClient(Origin,
233 ERR_NOPRIVILEGES_MSG,
236 case 'o': /* IRC operator (only unsettable!) */
237 if (!set || Client_Type(Client) == CLIENT_SERVER) {
238 Client_SetOperByMe(Target, false);
241 ok = IRC_WriteErrClient(Origin,
242 ERR_NOPRIVILEGES_MSG,
245 case 'q': /* KICK-protected user */
246 if (!set || Client_Type(Client) == CLIENT_SERVER
247 || Client_OperByMe(Origin))
250 ok = IRC_WriteErrClient(Origin,
251 ERR_NOPRIVILEGES_MSG,
254 case 'r': /* Restricted (only settable) */
255 if (set || Client_Type(Client) == CLIENT_SERVER)
258 ok = IRC_WriteErrClient(Origin,
262 case 'R': /* Registered (not [un]settable by clients) */
263 if (Client_Type(Client) == CLIENT_SERVER)
266 ok = IRC_WriteErrClient(Origin,
267 ERR_NICKREGISTER_MSG,
270 case 'x': /* Cloak hostname */
271 if (Client_HasMode(Client, 'r'))
272 ok = IRC_WriteErrClient(Origin,
275 else if (!set || Conf_CloakHostModeX[0]
276 || Client_Type(Client) == CLIENT_SERVER
277 || Client_OperByMe(Client)) {
279 send_RPL_HOSTHIDDEN_MSG = true;
281 ok = IRC_WriteErrClient(Origin,
282 ERR_NOPRIVILEGES_MSG,
286 if (Client_Type(Client) != CLIENT_SERVER) {
288 "Unknown mode \"%c%c\" from \"%s\"!?",
289 set ? '+' : '-', *mode_ptr,
291 ok = IRC_WriteErrClient(Origin,
292 ERR_UMODEUNKNOWNFLAG2_MSG,
299 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
300 set ? '+' : '-', *mode_ptr,
301 Client_ID(Origin), Client_ID(Target));
309 /* Is there a valid mode change? */
314 if (Client_ModeAdd(Target, x[0]))
315 strlcat(the_modes, x, sizeof(the_modes));
317 if (Client_ModeDel(Target, x[0]))
318 strlcat(the_modes, x, sizeof(the_modes));
322 /* Are there changed modes? */
324 /* Remove needless action modifier characters */
325 len = strlen(the_modes) - 1;
326 if (the_modes[len] == '+' || the_modes[len] == '-')
327 the_modes[len] = '\0';
329 if (Client_Type(Client) == CLIENT_SERVER) {
330 /* Forward modes to other servers */
331 if (Client_Conn(Target) != NONE) {
332 /* Remote server (service?) changed modes
333 * for one of our clients. Inform it! */
334 IRC_WriteStrClientPrefix(Target, Origin,
339 IRC_WriteStrServersPrefix(Client, Origin,
344 /* Send reply to client and inform other servers */
345 ok = IRC_WriteStrClientPrefix(Client, Origin,
349 IRC_WriteStrServersPrefix(Client, Origin,
355 if (send_RPL_HOSTHIDDEN_MSG && Client_Conn(Target) > NONE) {
356 /* A new (cloaked) hostname must be announced */
357 IRC_WriteStrClientPrefix(Target, Origin,
360 Client_HostnameDisplayed(Target));
364 LogDebug("%s \"%s\": Mode change, now \"%s\".",
365 Client_TypeText(Target), Client_Mask(Target),
366 Client_Modes(Target));
369 IRC_SetPenalty(Client, 1);
374 * Reply to a channel mode request.
376 * @param Origin The originator of the MODE command (prefix).
377 * @param Channel The channel of which the modes should be sent.
378 * @return CONNECTED or DISCONNECTED.
381 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
383 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
384 const char *mode_ptr;
386 /* Member or not? -- That's the question! */
387 if (!Channel_IsMemberOf(Channel, Origin))
388 return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
389 Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
391 /* The sender is a member: generate extended reply */
392 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
393 mode_ptr = the_modes;
399 snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
400 strlcat(the_args, argadd, sizeof(the_args));
403 strlcat(the_args, " ", sizeof(the_args));
404 strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
410 strlcat(the_modes, the_args, sizeof(the_modes));
412 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
413 Client_ID(Origin), Channel_Name(Channel),
417 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
418 Client_ID(Origin), Channel_Name(Channel),
419 Channel_CreationTime(Channel)))
426 * Handle channel mode and channel-user mode changes
428 * @param Client The client from which this command has been received.
429 * @param Req Request structure with prefix and all parameters.
430 * @param Origin The originator of the MODE command (prefix).
431 * @param Channel The target channel of this MODE command.
432 * @return CONNECTED or DISCONNECTED.
435 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
437 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
438 argadd[CLIENT_PASS_LEN], *mode_ptr;
439 bool connected, set, skiponce, retval, use_servermode,
440 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
441 int mode_arg, arg_arg, mode_arg_count = 0;
446 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
448 if (Channel_IsModeless(Channel))
449 return IRC_WriteErrClient(Client, ERR_NOCHANMODES_MSG,
450 Client_ID(Client), Channel_Name(Channel));
452 /* Mode request: let's answer it :-) */
454 return Channel_Mode_Answer_Request(Origin, Channel);
456 /* Check if origin is oper and opers can use mode */
457 use_servermode = Conf_OperServerMode;
458 if(Client_OperByMe(Client) && Conf_OperCanMode) {
462 /* Check if client is a server/service */
463 if(Client_Type(Client) == CLIENT_SERVER ||
464 Client_Type(Client) == CLIENT_SERVICE) {
468 /* Check if client is member of channel or an oper or an server/service */
469 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
470 return IRC_WriteErrClient(Origin, ERR_NOTONCHANNEL_MSG,
472 Channel_Name(Channel));
475 mode_ptr = Req->argv[mode_arg];
476 if (Req->argc > mode_arg + 1)
477 arg_arg = mode_arg + 1;
481 /* Initial state: set or unset modes? */
495 /* Prepare reply string */
496 strcpy(the_modes, set ? "+" : "-");
500 connected = CONNECTED;
505 /* Try next argument if there's any */
508 if (arg_arg > mode_arg)
513 if (mode_arg >= Req->argc)
515 mode_ptr = Req->argv[mode_arg];
517 if (Req->argc > mode_arg + 1)
518 arg_arg = mode_arg + 1;
527 if (((*mode_ptr == '+') && !set)
528 || ((*mode_ptr == '-') && set)) {
529 /* Action modifier ("+"/"-") must be changed ... */
530 len = strlen(the_modes) - 1;
531 if (the_modes[len] == '+' || the_modes[len] == '-') {
532 /* Adjust last action modifier in result */
533 the_modes[len] = *mode_ptr;
535 /* Append modifier character to result string */
537 strlcat(the_modes, x, sizeof(the_modes));
539 set = *mode_ptr == '+';
544 /* Are there arguments left? */
545 if (arg_arg >= Req->argc)
548 if(!is_machine && !is_oper) {
549 if (Channel_UserHasMode(Channel, Client, 'q'))
551 if (Channel_UserHasMode(Channel, Client, 'a'))
553 if (Channel_UserHasMode(Channel, Client, 'o'))
555 if (Channel_UserHasMode(Channel, Client, 'h'))
564 /* --- Channel modes --- */
565 case 'R': /* Registered users only */
566 case 's': /* Secret channel */
567 case 'z': /* Secure connections only */
568 if(!is_oper && !is_machine && !is_owner &&
569 !is_admin && !is_op) {
570 connected = IRC_WriteErrClient(Origin,
571 ERR_CHANOPRIVSNEEDED_MSG,
572 Client_ID(Origin), Channel_Name(Channel));
575 case 'i': /* Invite only */
576 case 'V': /* Invite disallow */
577 case 'M': /* Only identified nicks can write */
578 case 'm': /* Moderated */
579 case 'n': /* Only members can write */
580 case 'Q': /* No kicks */
581 case 't': /* Topic locked */
582 if(is_oper || is_machine || is_owner ||
583 is_admin || is_op || is_halfop)
586 connected = IRC_WriteErrClient(Origin,
587 ERR_CHANOPRIVSNEEDED_MSG,
588 Client_ID(Origin), Channel_Name(Channel));
590 case 'k': /* Channel key */
591 if (Mode_Limit_Reached(Client, mode_arg_count++))
594 if (is_oper || is_machine || is_owner ||
595 is_admin || is_op || is_halfop)
598 connected = IRC_WriteErrClient(Origin,
599 ERR_CHANOPRIVSNEEDED_MSG,
601 Channel_Name(Channel));
604 if (arg_arg > mode_arg) {
605 if (is_oper || is_machine || is_owner ||
606 is_admin || is_op || is_halfop) {
607 Channel_ModeDel(Channel, 'k');
608 Channel_SetKey(Channel,
610 strlcpy(argadd, Channel_Key(Channel),
614 connected = IRC_WriteErrClient(Origin,
615 ERR_CHANOPRIVSNEEDED_MSG,
617 Channel_Name(Channel));
619 Req->argv[arg_arg][0] = '\0';
623 /* Only send error message in "strict" mode,
624 * this is how ircd2.11 and others behave ... */
625 connected = IRC_WriteErrClient(Origin,
626 ERR_NEEDMOREPARAMS_MSG,
627 Client_ID(Origin), Req->command);
632 case 'l': /* Member limit */
633 if (Mode_Limit_Reached(Client, mode_arg_count++))
636 if (is_oper || is_machine || is_owner ||
637 is_admin || is_op || is_halfop)
640 connected = IRC_WriteErrClient(Origin,
641 ERR_CHANOPRIVSNEEDED_MSG,
643 Channel_Name(Channel));
646 if (arg_arg > mode_arg) {
647 if (is_oper || is_machine || is_owner ||
648 is_admin || is_op || is_halfop) {
649 l = atol(Req->argv[arg_arg]);
650 if (l > 0 && l < 0xFFFF) {
651 Channel_ModeDel(Channel, 'l');
652 Channel_SetMaxUsers(Channel, l);
653 snprintf(argadd, sizeof(argadd),
658 connected = IRC_WriteErrClient(Origin,
659 ERR_CHANOPRIVSNEEDED_MSG,
661 Channel_Name(Channel));
663 Req->argv[arg_arg][0] = '\0';
667 /* Only send error message in "strict" mode,
668 * this is how ircd2.11 and others behave ... */
669 connected = IRC_WriteErrClient(Origin,
670 ERR_NEEDMOREPARAMS_MSG,
671 Client_ID(Origin), Req->command);
676 case 'O': /* IRC operators only */
678 /* Only IRC operators are allowed to
679 * set the 'O' channel mode! */
680 if(is_oper || is_machine)
683 connected = IRC_WriteErrClient(Origin,
684 ERR_NOPRIVILEGES_MSG,
686 } else if(is_oper || is_machine || is_owner ||
690 connected = IRC_WriteErrClient(Origin,
691 ERR_CHANOPRIVSNEEDED_MSG,
693 Channel_Name(Channel));
695 case 'P': /* Persistent channel */
697 /* Only IRC operators are allowed to
698 * set the 'P' channel mode! */
699 if(is_oper || is_machine)
702 connected = IRC_WriteErrClient(Origin,
703 ERR_NOPRIVILEGES_MSG,
705 } else if(is_oper || is_machine || is_owner ||
709 connected = IRC_WriteErrClient(Origin,
710 ERR_CHANOPRIVSNEEDED_MSG,
712 Channel_Name(Channel));
714 /* --- Channel user modes --- */
715 case 'q': /* Owner */
716 case 'a': /* Channel admin */
717 if(!is_oper && !is_machine && !is_owner && !is_admin) {
718 connected = IRC_WriteErrClient(Origin,
719 ERR_CHANOPPRIVTOOLOW_MSG,
721 Channel_Name(Channel));
724 case 'o': /* Channel operator */
725 if(!is_oper && !is_machine && !is_owner &&
726 !is_admin && !is_op) {
727 connected = IRC_WriteErrClient(Origin,
728 ERR_CHANOPRIVSNEEDED_MSG,
730 Channel_Name(Channel));
733 case 'h': /* Half Op */
734 if(!is_oper && !is_machine && !is_owner &&
735 !is_admin && !is_op) {
736 connected = IRC_WriteErrClient(Origin,
737 ERR_CHANOPRIVSNEEDED_MSG,
739 Channel_Name(Channel));
742 case 'v': /* Voice */
743 if (arg_arg > mode_arg) {
744 if (is_oper || is_machine || is_owner ||
745 is_admin || is_op || is_halfop) {
746 client = Client_Search(Req->argv[arg_arg]);
750 connected = IRC_WriteErrClient(Origin,
755 connected = IRC_WriteErrClient(Origin,
756 ERR_CHANOPRIVSNEEDED_MSG,
758 Channel_Name(Channel));
760 Req->argv[arg_arg][0] = '\0';
764 /* Report an error to the client, when a user
765 * mode should be changed but no nickname is
766 * given. But don't do it when not in "strict"
767 * mode, because most other servers don't do
768 * it as well and some clients send "wired"
769 * MODE commands like "MODE #chan -ooo nick". */
770 connected = IRC_WriteErrClient(Origin,
771 ERR_NEEDMOREPARAMS_MSG,
772 Client_ID(Origin), Req->command);
777 /* --- Channel lists --- */
778 case 'I': /* Invite lists */
779 case 'b': /* Ban lists */
780 case 'e': /* Channel exception lists */
781 if (Mode_Limit_Reached(Client, mode_arg_count++))
783 if (arg_arg > mode_arg) {
785 if (is_oper || is_machine || is_owner ||
786 is_admin || is_op || is_halfop) {
788 ? Add_To_List(*mode_ptr, Origin,
791 : Del_From_List(*mode_ptr, Origin,
795 connected = IRC_WriteErrClient(Origin,
796 ERR_CHANOPRIVSNEEDED_MSG,
798 Channel_Name(Channel));
800 Req->argv[arg_arg][0] = '\0';
805 Channel_ShowInvites(Origin, Channel);
808 Channel_ShowBans(Origin, Channel);
811 Channel_ShowExcepts(Origin, Channel);
817 if (Client_Type(Client) != CLIENT_SERVER) {
819 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
820 set ? '+' : '-', *mode_ptr,
821 Client_ID(Origin), Channel_Name(Channel));
822 connected = IRC_WriteErrClient(Origin,
824 Client_ID(Origin), *mode_ptr,
825 Channel_Name(Channel));
829 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
830 set ? '+' : '-', *mode_ptr,
831 Client_ID(Origin), Channel_Name(Channel));
839 /* Is there a valid mode change? */
843 /* Validate target client */
844 if (client && (!Channel_IsMemberOf(Channel, client))) {
845 if (!IRC_WriteErrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
848 Channel_Name(Channel)))
854 /* Channel-User-Mode */
856 ? Channel_UserModeAdd(Channel, client, x[0])
857 : Channel_UserModeDel(Channel, client, x[0]);
859 strlcat(the_args, " ", sizeof(the_args));
860 strlcat(the_args, Client_ID(client),
862 strlcat(the_modes, x, sizeof(the_modes));
864 ("User \"%s\": Mode change on %s, now \"%s\"",
865 Client_Mask(client), Channel_Name(Channel),
866 Channel_UserModes(Channel, client));
871 ? Channel_ModeAdd(Channel, x[0])
872 : Channel_ModeDel(Channel, x[0]);
874 strlcat(the_modes, x, sizeof(the_modes));
875 LogDebug("Channel %s: Mode change, now \"%s\".",
876 Channel_Name(Channel),
877 Channel_Modes(Channel));
881 /* Are there additional arguments to add? */
883 strlcat(the_args, " ", sizeof(the_args));
884 strlcat(the_args, argadd, sizeof(the_args));
889 /* Are there changed modes? */
891 /* Clean up mode string */
892 len = strlen(the_modes) - 1;
893 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
894 the_modes[len] = '\0';
896 if (Client_Type(Client) == CLIENT_SERVER) {
897 /* MODE requests for local channels from other servers
898 * are definitely invalid! */
899 if (Channel_IsLocal(Channel)) {
900 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
904 /* Forward mode changes to channel users and all the
905 * other remote servers: */
906 IRC_WriteStrServersPrefix(Client, Origin,
907 "MODE %s %s%s", Channel_Name(Channel),
908 the_modes, the_args);
909 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
910 false, "MODE %s %s%s", Channel_Name(Channel),
911 the_modes, the_args);
914 Origin = Client_ThisServer();
915 /* Send reply to client and inform other servers and channel users */
916 connected = IRC_WriteStrClientPrefix(Client, Origin,
917 "MODE %s %s%s", Channel_Name(Channel),
918 the_modes, the_args);
919 /* Only forward requests for non-local channels */
920 if (!Channel_IsLocal(Channel))
921 IRC_WriteStrServersPrefix(Client, Origin,
922 "MODE %s %s%s", Channel_Name(Channel),
923 the_modes, the_args);
924 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
925 false, "MODE %s %s%s", Channel_Name(Channel),
926 the_modes, the_args);
930 IRC_SetPenalty(Client, 1);
935 * Handler for the IRC "AWAY" command.
937 * @param Client The client from which this command has been received.
938 * @param Req Request structure with prefix and all parameters.
939 * @return CONNECTED or DISCONNECTED.
942 IRC_AWAY( CLIENT *Client, REQUEST *Req )
944 assert (Client != NULL);
945 assert (Req != NULL);
947 if (Req->argc == 1 && Req->argv[0][0]) {
948 Client_SetAway(Client, Req->argv[0]);
949 Client_ModeAdd(Client, 'a');
950 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :+a",
952 return IRC_WriteStrClient(Client, RPL_NOWAWAY_MSG,
955 Client_ModeDel(Client, 'a');
956 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :-a",
958 return IRC_WriteStrClient(Client, RPL_UNAWAY_MSG,
964 * Add entries to channel invite, ban and exception lists.
966 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
967 * @param Prefix The originator of the command.
968 * @param Client The sender of the command.
969 * @param Channel The channel of which the list should be modified.
970 * @param Pattern The pattern to add to the list.
971 * @return CONNECTED or DISCONNECTED.
974 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
978 struct list_head *list = NULL;
979 long int current_count;
981 assert(Client != NULL);
982 assert(Channel != NULL);
983 assert(Pattern != NULL);
984 assert(what == 'I' || what == 'b' || what == 'e');
986 Lists_MakeMask(Pattern, mask, sizeof(mask));
987 current_count = Lists_Count(Channel_GetListInvites(Channel))
988 + Lists_Count(Channel_GetListExcepts(Channel))
989 + Lists_Count(Channel_GetListBans(Channel));
993 list = Channel_GetListInvites(Channel);
996 list = Channel_GetListBans(Channel);
999 list = Channel_GetListExcepts(Channel);
1003 if (Lists_CheckDupeMask(list, mask))
1005 if (Client_Type(Client) == CLIENT_USER &&
1006 current_count >= MAX_HNDL_CHANNEL_LISTS)
1007 return IRC_WriteErrClient(Client, ERR_LISTFULL_MSG,
1009 Channel_Name(Channel), mask,
1010 MAX_HNDL_CHANNEL_LISTS);
1014 if (!Channel_AddInvite(Channel, mask, false))
1018 if (!Channel_AddBan(Channel, mask))
1022 if (!Channel_AddExcept(Channel, mask))
1026 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1030 * Delete entries from channel invite, ban and exception lists.
1032 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1033 * @param Prefix The originator of the command.
1034 * @param Client The sender of the command.
1035 * @param Channel The channel of which the list should be modified.
1036 * @param Pattern The pattern to add to the list.
1037 * @return CONNECTED or DISCONNECTED.
1040 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1041 const char *Pattern)
1043 char mask[MASK_LEN];
1044 struct list_head *list = NULL;
1046 assert(Client != NULL);
1047 assert(Channel != NULL);
1048 assert(Pattern != NULL);
1049 assert(what == 'I' || what == 'b' || what == 'e');
1051 Lists_MakeMask(Pattern, mask, sizeof(mask));
1055 list = Channel_GetListInvites(Channel);
1058 list = Channel_GetListBans(Channel);
1061 list = Channel_GetListExcepts(Channel);
1065 if (!Lists_CheckDupeMask(list, mask))
1067 Lists_Del(list, mask);
1069 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1073 * Send information about changed channel invite/ban/exception lists to clients.
1075 * @param IsAdd true if the list item has been added, false otherwise.
1076 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1077 * @param Prefix The originator of the mode list change.
1078 * @param Client The sender of the command.
1079 * @param Channel The channel of which the list has been modified.
1080 * @param Mask The mask which has been added or removed.
1081 * @return CONNECTED or DISCONNECTED.
1084 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1085 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1089 /* Send confirmation to the client */
1090 if (Client_Type(Client) == CLIENT_USER)
1091 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1092 Channel_Name(Channel),
1096 /* to other servers */
1097 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1098 Channel_Name(Channel), IsAdd ? '+' : '-',
1101 /* and local users in channel */
1102 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1103 "MODE %s %c%c %s", Channel_Name(Channel),
1104 IsAdd ? '+' : '-', ModeChar, Mask );
1107 } /* Send_ListChange */