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 case 'q': /* KICK-protected user */
228 /* (only settable by IRC operators!) */
229 if (!set || Client_Type(Client) == CLIENT_SERVER
230 || Client_HasMode(Origin, 'o'))
233 ok = IRC_WriteErrClient(Origin,
234 ERR_NOPRIVILEGES_MSG,
237 case 'o': /* IRC operator (only unsettable!) */
238 if (!set || Client_Type(Client) == CLIENT_SERVER) {
241 ok = IRC_WriteErrClient(Origin,
242 ERR_NOPRIVILEGES_MSG,
245 case 'r': /* Restricted (only settable) */
246 if (set || Client_Type(Client) == CLIENT_SERVER)
249 ok = IRC_WriteErrClient(Origin,
253 case 'R': /* Registered (not [un]settable by clients) */
254 if (Client_Type(Client) == CLIENT_SERVER)
257 ok = IRC_WriteErrClient(Origin,
258 ERR_NICKREGISTER_MSG,
261 case 'x': /* Cloak hostname */
262 if (Client_HasMode(Client, 'r'))
263 ok = IRC_WriteErrClient(Origin,
266 else if (!set || Conf_CloakHostModeX[0]
267 || Client_Type(Client) == CLIENT_SERVER
268 || Client_HasMode(Origin, 'o')) {
270 send_RPL_HOSTHIDDEN_MSG = true;
272 ok = IRC_WriteErrClient(Origin,
273 ERR_NOPRIVILEGES_MSG,
277 if (Client_Type(Client) != CLIENT_SERVER) {
279 "Unknown mode \"%c%c\" from \"%s\"!?",
280 set ? '+' : '-', *mode_ptr,
282 ok = IRC_WriteErrClient(Origin,
283 ERR_UMODEUNKNOWNFLAG2_MSG,
290 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
291 set ? '+' : '-', *mode_ptr,
292 Client_ID(Origin), Client_ID(Target));
300 /* Is there a valid mode change? */
305 if (Client_ModeAdd(Target, x[0]))
306 strlcat(the_modes, x, sizeof(the_modes));
308 if (Client_ModeDel(Target, x[0]))
309 strlcat(the_modes, x, sizeof(the_modes));
313 /* Are there changed modes? */
315 /* Remove needless action modifier characters */
316 len = strlen(the_modes) - 1;
317 if (the_modes[len] == '+' || the_modes[len] == '-')
318 the_modes[len] = '\0';
320 if (Client_Type(Client) == CLIENT_SERVER) {
321 /* Forward modes to other servers */
322 if (Client_Conn(Target) != NONE) {
323 /* Remote server (service?) changed modes
324 * for one of our clients. Inform it! */
325 IRC_WriteStrClientPrefix(Target, Origin,
330 IRC_WriteStrServersPrefix(Client, Origin,
335 /* Send reply to client and inform other servers */
336 ok = IRC_WriteStrClientPrefix(Client, Origin,
340 IRC_WriteStrServersPrefix(Client, Origin,
346 if (send_RPL_HOSTHIDDEN_MSG && Client_Conn(Target) > NONE) {
347 /* A new (cloaked) hostname must be announced */
348 IRC_WriteStrClientPrefix(Target, Origin,
351 Client_HostnameDisplayed(Target));
355 LogDebug("%s \"%s\": Mode change, now \"%s\".",
356 Client_TypeText(Target), Client_Mask(Target),
357 Client_Modes(Target));
360 IRC_SetPenalty(Client, 1);
365 * Reply to a channel mode request.
367 * @param Origin The originator of the MODE command (prefix).
368 * @param Channel The channel of which the modes should be sent.
369 * @return CONNECTED or DISCONNECTED.
372 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
374 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
375 const char *mode_ptr;
377 /* Member or not? -- That's the question! */
378 if (!Channel_IsMemberOf(Channel, Origin))
379 return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
380 Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
382 /* The sender is a member: generate extended reply */
383 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
384 mode_ptr = the_modes;
390 snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
391 strlcat(the_args, argadd, sizeof(the_args));
394 strlcat(the_args, " ", sizeof(the_args));
395 strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
401 strlcat(the_modes, the_args, sizeof(the_modes));
403 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
404 Client_ID(Origin), Channel_Name(Channel),
408 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
409 Client_ID(Origin), Channel_Name(Channel),
410 Channel_CreationTime(Channel)))
417 * Handle channel mode and channel-user mode changes
419 * @param Client The client from which this command has been received.
420 * @param Req Request structure with prefix and all parameters.
421 * @param Origin The originator of the MODE command (prefix).
422 * @param Channel The target channel of this MODE command.
423 * @return CONNECTED or DISCONNECTED.
426 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
428 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
429 argadd[CLIENT_PASS_LEN], *mode_ptr;
430 bool connected, set, skiponce, retval, use_servermode,
431 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
432 int mode_arg, arg_arg, mode_arg_count = 0;
437 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
439 if (Channel_IsModeless(Channel))
440 return IRC_WriteErrClient(Client, ERR_NOCHANMODES_MSG,
441 Client_ID(Client), Channel_Name(Channel));
443 /* Mode request: let's answer it :-) */
445 return Channel_Mode_Answer_Request(Origin, Channel);
447 /* Check if origin is oper and opers can use mode */
448 use_servermode = Conf_OperServerMode;
449 if(Client_HasMode(Client, 'o') && Conf_OperCanMode) {
453 /* Check if client is a server/service */
454 if(Client_Type(Client) == CLIENT_SERVER ||
455 Client_Type(Client) == CLIENT_SERVICE) {
459 /* Check if client is member of channel or an oper or an server/service */
460 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
461 return IRC_WriteErrClient(Origin, ERR_NOTONCHANNEL_MSG,
463 Channel_Name(Channel));
466 mode_ptr = Req->argv[mode_arg];
467 if (Req->argc > mode_arg + 1)
468 arg_arg = mode_arg + 1;
472 /* Initial state: set or unset modes? */
486 /* Prepare reply string */
487 strcpy(the_modes, set ? "+" : "-");
491 connected = CONNECTED;
496 /* Try next argument if there's any */
499 if (arg_arg > mode_arg)
504 if (mode_arg >= Req->argc)
506 mode_ptr = Req->argv[mode_arg];
508 if (Req->argc > mode_arg + 1)
509 arg_arg = mode_arg + 1;
518 if (((*mode_ptr == '+') && !set)
519 || ((*mode_ptr == '-') && set)) {
520 /* Action modifier ("+"/"-") must be changed ... */
521 len = strlen(the_modes) - 1;
522 if (the_modes[len] == '+' || the_modes[len] == '-') {
523 /* Adjust last action modifier in result */
524 the_modes[len] = *mode_ptr;
526 /* Append modifier character to result string */
528 strlcat(the_modes, x, sizeof(the_modes));
530 set = *mode_ptr == '+';
535 /* Are there arguments left? */
536 if (arg_arg >= Req->argc)
539 if(!is_machine && !is_oper) {
540 if (Channel_UserHasMode(Channel, Client, 'q'))
542 if (Channel_UserHasMode(Channel, Client, 'a'))
544 if (Channel_UserHasMode(Channel, Client, 'o'))
546 if (Channel_UserHasMode(Channel, Client, 'h'))
555 /* --- Channel modes --- */
556 case 'R': /* Registered users only */
557 case 's': /* Secret channel */
558 case 'z': /* Secure connections only */
559 if(!is_oper && !is_machine && !is_owner &&
560 !is_admin && !is_op) {
561 connected = IRC_WriteErrClient(Origin,
562 ERR_CHANOPRIVSNEEDED_MSG,
563 Client_ID(Origin), Channel_Name(Channel));
566 case 'i': /* Invite only */
567 case 'V': /* Invite disallow */
568 case 'M': /* Only identified nicks can write */
569 case 'm': /* Moderated */
570 case 'n': /* Only members can write */
571 case 'Q': /* No kicks */
572 case 't': /* Topic locked */
573 if(is_oper || is_machine || is_owner ||
574 is_admin || is_op || is_halfop)
577 connected = IRC_WriteErrClient(Origin,
578 ERR_CHANOPRIVSNEEDED_MSG,
579 Client_ID(Origin), Channel_Name(Channel));
581 case 'k': /* Channel key */
582 if (Mode_Limit_Reached(Client, mode_arg_count++))
585 if (is_oper || is_machine || is_owner ||
586 is_admin || is_op || is_halfop)
589 connected = IRC_WriteErrClient(Origin,
590 ERR_CHANOPRIVSNEEDED_MSG,
592 Channel_Name(Channel));
595 if (arg_arg > mode_arg) {
596 if (is_oper || is_machine || is_owner ||
597 is_admin || is_op || is_halfop) {
598 Channel_ModeDel(Channel, 'k');
599 Channel_SetKey(Channel,
601 strlcpy(argadd, Channel_Key(Channel),
605 connected = IRC_WriteErrClient(Origin,
606 ERR_CHANOPRIVSNEEDED_MSG,
608 Channel_Name(Channel));
610 Req->argv[arg_arg][0] = '\0';
614 /* Only send error message in "strict" mode,
615 * this is how ircd2.11 and others behave ... */
616 IRC_SetPenalty(Origin, 2);
617 connected = IRC_WriteErrClient(Origin,
618 ERR_NEEDMOREPARAMS_MSG,
619 Client_ID(Origin), Req->command);
624 case 'l': /* Member limit */
625 if (Mode_Limit_Reached(Client, mode_arg_count++))
628 if (is_oper || is_machine || is_owner ||
629 is_admin || is_op || is_halfop)
632 connected = IRC_WriteErrClient(Origin,
633 ERR_CHANOPRIVSNEEDED_MSG,
635 Channel_Name(Channel));
638 if (arg_arg > mode_arg) {
639 if (is_oper || is_machine || is_owner ||
640 is_admin || is_op || is_halfop) {
641 l = atol(Req->argv[arg_arg]);
642 if (l > 0 && l < 0xFFFF) {
643 Channel_ModeDel(Channel, 'l');
644 Channel_SetMaxUsers(Channel, l);
645 snprintf(argadd, sizeof(argadd),
650 connected = IRC_WriteErrClient(Origin,
651 ERR_CHANOPRIVSNEEDED_MSG,
653 Channel_Name(Channel));
655 Req->argv[arg_arg][0] = '\0';
659 /* Only send error message in "strict" mode,
660 * this is how ircd2.11 and others behave ... */
661 IRC_SetPenalty(Origin, 2);
662 connected = IRC_WriteErrClient(Origin,
663 ERR_NEEDMOREPARAMS_MSG,
664 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_WriteErrClient(Origin,
677 ERR_NOPRIVILEGES_MSG,
679 } else if(is_oper || is_machine || is_owner ||
683 connected = IRC_WriteErrClient(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_WriteErrClient(Origin,
696 ERR_NOPRIVILEGES_MSG,
698 } else if(is_oper || is_machine || is_owner ||
702 connected = IRC_WriteErrClient(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 && !is_admin) {
711 connected = IRC_WriteErrClient(Origin,
712 ERR_CHANOPPRIVTOOLOW_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_WriteErrClient(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_WriteErrClient(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_WriteErrClient(Origin,
748 connected = IRC_WriteErrClient(Origin,
749 ERR_CHANOPRIVSNEEDED_MSG,
751 Channel_Name(Channel));
753 Req->argv[arg_arg][0] = '\0';
757 /* Report an error to the client, when a user
758 * mode should be changed but no nickname is
759 * given. But don't do it when not in "strict"
760 * mode, because most other servers don't do
761 * it as well and some clients send "wired"
762 * MODE commands like "MODE #chan -ooo nick". */
763 IRC_SetPenalty(Origin, 2);
764 connected = IRC_WriteErrClient(Origin,
765 ERR_NEEDMOREPARAMS_MSG,
766 Client_ID(Origin), Req->command);
771 /* --- Channel lists --- */
772 case 'I': /* Invite lists */
773 case 'b': /* Ban lists */
774 case 'e': /* Channel exception lists */
775 if (Mode_Limit_Reached(Client, mode_arg_count++))
777 if (arg_arg > mode_arg) {
779 if (is_oper || is_machine || is_owner ||
780 is_admin || is_op || is_halfop) {
782 ? Add_To_List(*mode_ptr, Origin,
785 : Del_From_List(*mode_ptr, Origin,
789 connected = IRC_WriteErrClient(Origin,
790 ERR_CHANOPRIVSNEEDED_MSG,
792 Channel_Name(Channel));
794 Req->argv[arg_arg][0] = '\0';
799 Channel_ShowInvites(Origin, Channel);
802 Channel_ShowBans(Origin, Channel);
805 Channel_ShowExcepts(Origin, Channel);
811 if (Client_Type(Client) != CLIENT_SERVER) {
813 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
814 set ? '+' : '-', *mode_ptr,
815 Client_ID(Origin), Channel_Name(Channel));
816 connected = IRC_WriteErrClient(Origin,
818 Client_ID(Origin), *mode_ptr,
819 Channel_Name(Channel));
823 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
824 set ? '+' : '-', *mode_ptr,
825 Client_ID(Origin), Channel_Name(Channel));
833 /* Is there a valid mode change? */
837 /* Validate target client */
838 if (client && (!Channel_IsMemberOf(Channel, client))) {
839 if (!IRC_WriteErrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
842 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);
929 * Handler for the IRC "AWAY" command.
931 * @param Client The client from which this command has been received.
932 * @param Req Request structure with prefix and all parameters.
933 * @return CONNECTED or DISCONNECTED.
936 IRC_AWAY( CLIENT *Client, REQUEST *Req )
938 assert (Client != NULL);
939 assert (Req != NULL);
941 if (Req->argc == 1 && Req->argv[0][0]) {
942 Client_SetAway(Client, Req->argv[0]);
943 Client_ModeAdd(Client, 'a');
944 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :+a",
946 return IRC_WriteStrClient(Client, RPL_NOWAWAY_MSG,
949 Client_ModeDel(Client, 'a');
950 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :-a",
952 return IRC_WriteStrClient(Client, RPL_UNAWAY_MSG,
958 * Add entries to channel invite, ban and exception lists.
960 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
961 * @param Prefix The originator of the command.
962 * @param Client The sender of the command.
963 * @param Channel The channel of which the list should be modified.
964 * @param Pattern The pattern to add to the list.
965 * @return CONNECTED or DISCONNECTED.
968 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
972 struct list_head *list = NULL;
973 long int current_count;
975 assert(Client != NULL);
976 assert(Channel != NULL);
977 assert(Pattern != NULL);
978 assert(what == 'I' || what == 'b' || what == 'e');
980 Lists_MakeMask(Pattern, mask, sizeof(mask));
981 current_count = Lists_Count(Channel_GetListInvites(Channel))
982 + Lists_Count(Channel_GetListExcepts(Channel))
983 + Lists_Count(Channel_GetListBans(Channel));
987 list = Channel_GetListInvites(Channel);
990 list = Channel_GetListBans(Channel);
993 list = Channel_GetListExcepts(Channel);
997 if (Lists_CheckDupeMask(list, mask))
999 if (Client_Type(Client) == CLIENT_USER &&
1000 current_count >= MAX_HNDL_CHANNEL_LISTS)
1001 return IRC_WriteErrClient(Client, ERR_LISTFULL_MSG,
1003 Channel_Name(Channel), mask,
1004 MAX_HNDL_CHANNEL_LISTS);
1008 if (!Channel_AddInvite(Channel, mask, false))
1012 if (!Channel_AddBan(Channel, mask))
1016 if (!Channel_AddExcept(Channel, mask))
1020 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1024 * Delete entries from channel invite, ban and exception lists.
1026 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1027 * @param Prefix The originator of the command.
1028 * @param Client The sender of the command.
1029 * @param Channel The channel of which the list should be modified.
1030 * @param Pattern The pattern to add to the list.
1031 * @return CONNECTED or DISCONNECTED.
1034 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1035 const char *Pattern)
1037 char mask[MASK_LEN];
1038 struct list_head *list = NULL;
1040 assert(Client != NULL);
1041 assert(Channel != NULL);
1042 assert(Pattern != NULL);
1043 assert(what == 'I' || what == 'b' || what == 'e');
1045 Lists_MakeMask(Pattern, mask, sizeof(mask));
1049 list = Channel_GetListInvites(Channel);
1052 list = Channel_GetListBans(Channel);
1055 list = Channel_GetListExcepts(Channel);
1059 if (!Lists_CheckDupeMask(list, mask))
1061 Lists_Del(list, mask);
1063 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1067 * Send information about changed channel invite/ban/exception lists to clients.
1069 * @param IsAdd true if the list item has been added, false otherwise.
1070 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1071 * @param Prefix The originator of the mode list change.
1072 * @param Client The sender of the command.
1073 * @param Channel The channel of which the list has been modified.
1074 * @param Mask The mask which has been added or removed.
1075 * @return CONNECTED or DISCONNECTED.
1078 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1079 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1083 /* Send confirmation to the client */
1084 if (Client_Type(Client) == CLIENT_USER)
1085 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1086 Channel_Name(Channel),
1090 /* to other servers */
1091 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1092 Channel_Name(Channel), IsAdd ? '+' : '-',
1095 /* and local users in channel */
1096 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1097 "MODE %s %c%c %s", Channel_Name(Channel),
1098 IsAdd ? '+' : '-', ModeChar, Mask );
1101 } /* Send_ListChange */