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.)
26 #include "irc-macros.h"
27 #include "irc-write.h"
34 static bool Client_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
36 static bool Channel_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
39 static bool Add_To_List PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
40 CHANNEL *Channel, const char *Pattern));
41 static bool Del_From_List PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
42 CHANNEL *Channel, const char *Pattern));
44 static bool Send_ListChange PARAMS((const bool IsAdd, const char ModeChar,
45 CLIENT *Prefix, CLIENT *Client,
46 CHANNEL *Channel, const char *Mask));
49 * Handler for the IRC "MODE" command.
51 * This function detects whether user or channel modes should be modified
52 * and calls the appropriate sub-functions.
54 * @param Client The client from which this command has been received.
55 * @param Req Request structure with prefix and all parameters.
56 * @return CONNECTED or DISCONNECTED.
59 IRC_MODE( CLIENT *Client, REQUEST *Req )
64 assert(Client != NULL);
67 _IRC_GET_SENDER_OR_RETURN_(origin, Req, Client)
69 /* Channel or user mode? */
70 cl = NULL; chan = NULL;
71 if (Client_IsValidNick(Req->argv[0]))
72 cl = Client_Search(Req->argv[0]);
73 if (Channel_IsValidName(Req->argv[0]))
74 chan = Channel_Search(Req->argv[0]);
77 return Client_Mode(Client, Req, origin, cl);
79 return Channel_Mode(Client, Req, origin, chan);
81 /* No target found! */
82 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
83 Client_ID(Client), Req->argv[0]);
87 * Check if the "mode limit" for a client has been reached.
89 * This limit doesn't apply for servers or services!
91 * @param Client The client to check.
92 * @param Count The number of modes already handled.
93 * @return true if the limit has been reached.
96 Mode_Limit_Reached(CLIENT *Client, int Count)
98 if (Client_Type(Client) == CLIENT_SERVER
99 || Client_Type(Client) == CLIENT_SERVICE)
101 if (Count < MAX_HNDL_MODES_ARG)
107 * Handle client mode requests
109 * @param Client The client from which this command has been received.
110 * @param Req Request structure with prefix and all parameters.
111 * @param Origin The originator of the MODE command (prefix).
112 * @param Target The target (client) of this MODE command.
113 * @return CONNECTED or DISCONNECTED.
116 Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
118 char the_modes[COMMAND_LEN], x[2], *mode_ptr;
120 bool send_RPL_HOSTHIDDEN_MSG = false;
124 /* Is the client allowed to request or change the modes? */
125 if (Client_Type(Client) == CLIENT_USER) {
126 /* Users are only allowed to manipulate their own modes! */
127 if (Target != Client)
128 return IRC_WriteErrClient(Client,
129 ERR_USERSDONTMATCH_MSG,
133 /* Mode request: let's answer it :-) */
135 return IRC_WriteStrClient(Origin, RPL_UMODEIS_MSG,
137 Client_Modes(Target));
140 mode_ptr = Req->argv[mode_arg];
142 /* Initial state: set or unset modes? */
143 if (*mode_ptr == '+') {
145 strcpy(the_modes, "+");
146 } else if (*mode_ptr == '-') {
148 strcpy(the_modes, "-");
150 return IRC_WriteErrClient(Origin, ERR_UMODEUNKNOWNFLAG_MSG,
158 /* Try next argument if there's any */
160 if (mode_arg < Req->argc)
161 mode_ptr = Req->argv[mode_arg];
169 if ((*mode_ptr == '+' && !set)
170 || (*mode_ptr == '-' && set)) {
171 /* Action modifier ("+"/"-") must be changed */
172 len = strlen(the_modes) - 1;
173 if (the_modes[len] == '+'
174 || the_modes[len] == '-') {
175 /* Last character in the "result
176 * string" was an "action", so just
177 * overwrite it with the new action */
178 the_modes[len] = *mode_ptr;
180 /* Append new modifier character to
181 * the resulting mode string */
183 strlcat(the_modes, x,
186 if (*mode_ptr == '+')
197 case 'b': /* Block private msgs */
198 case 'C': /* Only messages from clients sharing a channel */
199 case 'i': /* Invisible */
200 case 's': /* Server messages */
201 case 'w': /* Wallops messages */
205 if (Client_Type(Client) == CLIENT_SERVER) {
207 Client_SetAway(Origin, DEFAULT_AWAY_MSG);
209 ok = IRC_WriteErrClient(Origin,
210 ERR_NOPRIVILEGES_MSG,
214 if (Client_HasMode(Client, 'r'))
215 ok = IRC_WriteErrClient(Origin,
221 case 'c': /* Receive connect notices */
222 case 'q': /* KICK-protected user */
223 /* (only settable by IRC operators!) */
224 if (!set || Client_Type(Client) == CLIENT_SERVER
225 || Client_HasMode(Origin, 'o'))
228 ok = IRC_WriteErrClient(Origin,
229 ERR_NOPRIVILEGES_MSG,
232 case 'o': /* IRC operator (only unsettable!) */
233 if (!set || Client_Type(Client) == CLIENT_SERVER) {
236 ok = IRC_WriteErrClient(Origin,
237 ERR_NOPRIVILEGES_MSG,
240 case 'r': /* Restricted (only settable) */
241 if (set || Client_Type(Client) == CLIENT_SERVER)
244 ok = IRC_WriteErrClient(Origin,
248 case 'R': /* Registered (not [un]settable by clients) */
249 if (Client_Type(Client) == CLIENT_SERVER)
252 ok = IRC_WriteErrClient(Origin,
253 ERR_NICKREGISTER_MSG,
256 case 'x': /* Cloak hostname */
257 if (Client_HasMode(Client, 'r'))
258 ok = IRC_WriteErrClient(Origin,
261 else if (!set || Conf_CloakHostModeX[0]
262 || Client_Type(Client) == CLIENT_SERVER
263 || Client_HasMode(Origin, 'o')) {
265 send_RPL_HOSTHIDDEN_MSG = true;
267 ok = IRC_WriteErrClient(Origin,
268 ERR_NOPRIVILEGES_MSG,
272 if (Client_Type(Client) != CLIENT_SERVER) {
274 "Unknown mode \"%c%c\" from \"%s\"!?",
275 set ? '+' : '-', *mode_ptr,
277 ok = IRC_WriteErrClient(Origin,
278 ERR_UMODEUNKNOWNFLAG2_MSG,
285 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
286 set ? '+' : '-', *mode_ptr,
287 Client_ID(Origin), Client_ID(Target));
295 /* Is there a valid mode change? */
300 if (Client_ModeAdd(Target, x[0]))
301 strlcat(the_modes, x, sizeof(the_modes));
303 if (Client_ModeDel(Target, x[0]))
304 strlcat(the_modes, x, sizeof(the_modes));
308 /* Are there changed modes? */
310 /* Remove needless action modifier characters */
311 len = strlen(the_modes) - 1;
312 if (the_modes[len] == '+' || the_modes[len] == '-')
313 the_modes[len] = '\0';
315 if (Client_Type(Client) == CLIENT_SERVER) {
316 /* Forward modes to other servers */
317 if (Client_Conn(Target) != NONE) {
318 /* Remote server (service?) changed modes
319 * for one of our clients. Inform it! */
320 IRC_WriteStrClientPrefix(Target, Origin,
325 IRC_WriteStrServersPrefix(Client, Origin,
330 /* Send reply to client and inform other servers */
331 ok = IRC_WriteStrClientPrefix(Client, Origin,
335 IRC_WriteStrServersPrefix(Client, Origin,
341 if (send_RPL_HOSTHIDDEN_MSG && Client_Conn(Target) > NONE) {
342 /* A new (cloaked) hostname must be announced */
343 IRC_WriteStrClientPrefix(Target, Origin,
346 Client_HostnameDisplayed(Target));
350 LogDebug("%s \"%s\": Mode change, now \"%s\".",
351 Client_TypeText(Target), Client_Mask(Target),
352 Client_Modes(Target));
359 * Reply to a channel mode request.
361 * @param Origin The originator of the MODE command (prefix).
362 * @param Channel The channel of which the modes should be sent.
363 * @return CONNECTED or DISCONNECTED.
366 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
368 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
369 const char *mode_ptr;
371 /* Member or not? -- That's the question! */
372 if (!Channel_IsMemberOf(Channel, Origin))
373 return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
374 Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
376 /* The sender is a member: generate extended reply */
377 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
378 mode_ptr = the_modes;
384 snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
385 strlcat(the_args, argadd, sizeof(the_args));
388 strlcat(the_args, " ", sizeof(the_args));
389 strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
395 strlcat(the_modes, the_args, sizeof(the_modes));
397 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
398 Client_ID(Origin), Channel_Name(Channel),
402 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
403 Client_ID(Origin), Channel_Name(Channel),
404 Channel_CreationTime(Channel)))
411 * Handle channel mode and channel-user mode changes
413 * @param Client The client from which this command has been received.
414 * @param Req Request structure with prefix and all parameters.
415 * @param Origin The originator of the MODE command (prefix).
416 * @param Channel The target channel of this MODE command.
417 * @return CONNECTED or DISCONNECTED.
420 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
422 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
423 argadd[CLIENT_PASS_LEN], *mode_ptr;
424 bool connected, set, skiponce, retval, use_servermode,
425 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
426 int mode_arg, arg_arg, mode_arg_count = 0;
431 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
433 if (Channel_IsModeless(Channel))
434 return IRC_WriteErrClient(Client, ERR_NOCHANMODES_MSG,
435 Client_ID(Client), Channel_Name(Channel));
437 /* Mode request: let's answer it :-) */
439 return Channel_Mode_Answer_Request(Origin, Channel);
441 /* Check if origin is oper and opers can use mode */
442 use_servermode = Conf_OperServerMode;
443 if(Client_HasMode(Client, 'o') && Conf_OperCanMode) {
447 /* Check if client is a server/service */
448 if(Client_Type(Client) == CLIENT_SERVER ||
449 Client_Type(Client) == CLIENT_SERVICE) {
453 /* Check if client is member of channel or an oper or an server/service */
454 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
455 return IRC_WriteErrClient(Origin, ERR_NOTONCHANNEL_MSG,
457 Channel_Name(Channel));
460 mode_ptr = Req->argv[mode_arg];
461 if (Req->argc > mode_arg + 1)
462 arg_arg = mode_arg + 1;
466 /* Initial state: set or unset modes? */
480 /* Prepare reply string */
481 strcpy(the_modes, set ? "+" : "-");
485 connected = CONNECTED;
490 /* Try next argument if there's any */
493 if (arg_arg > mode_arg)
498 if (mode_arg >= Req->argc)
500 mode_ptr = Req->argv[mode_arg];
502 if (Req->argc > mode_arg + 1)
503 arg_arg = mode_arg + 1;
512 if (((*mode_ptr == '+') && !set)
513 || ((*mode_ptr == '-') && set)) {
514 /* Action modifier ("+"/"-") must be changed ... */
515 len = strlen(the_modes) - 1;
516 if (the_modes[len] == '+' || the_modes[len] == '-') {
517 /* Adjust last action modifier in result */
518 the_modes[len] = *mode_ptr;
520 /* Append modifier character to result string */
522 strlcat(the_modes, x, sizeof(the_modes));
524 set = *mode_ptr == '+';
529 /* Are there arguments left? */
530 if (arg_arg >= Req->argc)
533 if(!is_machine && !is_oper) {
534 if (Channel_UserHasMode(Channel, Client, 'q'))
536 if (Channel_UserHasMode(Channel, Client, 'a'))
538 if (Channel_UserHasMode(Channel, Client, 'o'))
540 if (Channel_UserHasMode(Channel, Client, 'h'))
549 /* --- Channel modes --- */
550 case 'R': /* Registered users only */
551 case 's': /* Secret channel */
552 case 'z': /* Secure connections only */
553 if(!is_oper && !is_machine && !is_owner &&
554 !is_admin && !is_op) {
555 connected = IRC_WriteErrClient(Origin,
556 ERR_CHANOPRIVSNEEDED_MSG,
557 Client_ID(Origin), Channel_Name(Channel));
560 case 'i': /* Invite only */
561 case 'V': /* Invite disallow */
562 case 'M': /* Only identified nicks can write */
563 case 'm': /* Moderated */
564 case 'n': /* Only members can write */
565 case 'Q': /* No kicks */
566 case 't': /* Topic locked */
567 if(is_oper || is_machine || is_owner ||
568 is_admin || is_op || is_halfop)
571 connected = IRC_WriteErrClient(Origin,
572 ERR_CHANOPRIVSNEEDED_MSG,
573 Client_ID(Origin), Channel_Name(Channel));
575 case 'k': /* Channel key */
576 if (Mode_Limit_Reached(Client, mode_arg_count++))
579 if (is_oper || is_machine || is_owner ||
580 is_admin || is_op || is_halfop) {
582 if (Channel_HasMode(Channel, 'k'))
583 strlcpy(argadd, "*", sizeof(argadd));
584 if (arg_arg > mode_arg)
587 connected = IRC_WriteErrClient(Origin,
588 ERR_CHANOPRIVSNEEDED_MSG,
590 Channel_Name(Channel));
593 if (arg_arg > mode_arg) {
594 if (is_oper || is_machine || is_owner ||
595 is_admin || is_op || is_halfop) {
596 Channel_ModeDel(Channel, 'k');
597 Channel_SetKey(Channel,
599 strlcpy(argadd, Channel_Key(Channel),
603 connected = IRC_WriteErrClient(Origin,
604 ERR_CHANOPRIVSNEEDED_MSG,
606 Channel_Name(Channel));
608 Req->argv[arg_arg][0] = '\0';
612 /* Only send error message in "strict" mode,
613 * this is how ircd2.11 and others behave ... */
614 connected = IRC_WriteErrClient(Origin,
615 ERR_NEEDMOREPARAMS_MSG,
616 Client_ID(Origin), Req->command);
621 case 'l': /* Member limit */
622 if (Mode_Limit_Reached(Client, mode_arg_count++))
625 if (is_oper || is_machine || is_owner ||
626 is_admin || is_op || is_halfop)
629 connected = IRC_WriteErrClient(Origin,
630 ERR_CHANOPRIVSNEEDED_MSG,
632 Channel_Name(Channel));
635 if (arg_arg > mode_arg) {
636 if (is_oper || is_machine || is_owner ||
637 is_admin || is_op || is_halfop) {
638 l = atol(Req->argv[arg_arg]);
639 if (l > 0 && l < 0xFFFF) {
640 Channel_ModeDel(Channel, 'l');
641 Channel_SetMaxUsers(Channel, l);
642 snprintf(argadd, sizeof(argadd),
647 connected = IRC_WriteErrClient(Origin,
648 ERR_CHANOPRIVSNEEDED_MSG,
650 Channel_Name(Channel));
652 Req->argv[arg_arg][0] = '\0';
656 /* Only send error message in "strict" mode,
657 * this is how ircd2.11 and others behave ... */
658 connected = IRC_WriteErrClient(Origin,
659 ERR_NEEDMOREPARAMS_MSG,
660 Client_ID(Origin), Req->command);
665 case 'O': /* IRC operators only */
667 /* Only IRC operators are allowed to
668 * set the 'O' channel mode! */
669 if(is_oper || is_machine)
672 connected = IRC_WriteErrClient(Origin,
673 ERR_NOPRIVILEGES_MSG,
675 } else if(is_oper || is_machine || is_owner ||
679 connected = IRC_WriteErrClient(Origin,
680 ERR_CHANOPRIVSNEEDED_MSG,
682 Channel_Name(Channel));
684 case 'P': /* Persistent channel */
686 /* Only IRC operators are allowed to
687 * set the 'P' channel mode! */
688 if(is_oper || is_machine)
691 connected = IRC_WriteErrClient(Origin,
692 ERR_NOPRIVILEGES_MSG,
694 } else if(is_oper || is_machine || is_owner ||
698 connected = IRC_WriteErrClient(Origin,
699 ERR_CHANOPRIVSNEEDED_MSG,
701 Channel_Name(Channel));
703 /* --- Channel user modes --- */
704 case 'q': /* Owner */
705 case 'a': /* Channel admin */
706 if(!is_oper && !is_machine && !is_owner && !is_admin) {
707 connected = IRC_WriteErrClient(Origin,
708 ERR_CHANOPPRIVTOOLOW_MSG,
710 Channel_Name(Channel));
713 case 'o': /* Channel operator */
714 if(!is_oper && !is_machine && !is_owner &&
715 !is_admin && !is_op) {
716 connected = IRC_WriteErrClient(Origin,
717 ERR_CHANOPRIVSNEEDED_MSG,
719 Channel_Name(Channel));
722 case 'h': /* Half Op */
723 if(!is_oper && !is_machine && !is_owner &&
724 !is_admin && !is_op) {
725 connected = IRC_WriteErrClient(Origin,
726 ERR_CHANOPRIVSNEEDED_MSG,
728 Channel_Name(Channel));
731 case 'v': /* Voice */
732 if (arg_arg > mode_arg) {
733 if (is_oper || is_machine || is_owner ||
734 is_admin || is_op || is_halfop) {
735 client = Client_Search(Req->argv[arg_arg]);
739 connected = IRC_WriteErrClient(Origin,
744 connected = IRC_WriteErrClient(Origin,
745 ERR_CHANOPRIVSNEEDED_MSG,
747 Channel_Name(Channel));
749 Req->argv[arg_arg][0] = '\0';
753 /* Report an error to the client, when a user
754 * mode should be changed but no nickname is
755 * given. But don't do it when not in "strict"
756 * mode, because most other servers don't do
757 * it as well and some clients send "wired"
758 * MODE commands like "MODE #chan -ooo nick". */
759 connected = IRC_WriteErrClient(Origin,
760 ERR_NEEDMOREPARAMS_MSG,
761 Client_ID(Origin), Req->command);
766 /* --- Channel lists --- */
767 case 'I': /* Invite lists */
768 case 'b': /* Ban lists */
769 case 'e': /* Channel exception lists */
770 if (Mode_Limit_Reached(Client, mode_arg_count++))
772 if (arg_arg > mode_arg) {
774 if (is_oper || is_machine || is_owner ||
775 is_admin || is_op || is_halfop) {
777 ? Add_To_List(*mode_ptr, Origin,
780 : Del_From_List(*mode_ptr, Origin,
784 connected = IRC_WriteErrClient(Origin,
785 ERR_CHANOPRIVSNEEDED_MSG,
787 Channel_Name(Channel));
789 Req->argv[arg_arg][0] = '\0';
794 Channel_ShowInvites(Origin, Channel);
797 Channel_ShowBans(Origin, Channel);
800 Channel_ShowExcepts(Origin, Channel);
806 if (Client_Type(Client) != CLIENT_SERVER) {
808 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
809 set ? '+' : '-', *mode_ptr,
810 Client_ID(Origin), Channel_Name(Channel));
811 connected = IRC_WriteErrClient(Origin,
813 Client_ID(Origin), *mode_ptr,
814 Channel_Name(Channel));
818 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
819 set ? '+' : '-', *mode_ptr,
820 Client_ID(Origin), Channel_Name(Channel));
828 /* Is there a valid mode change? */
832 /* Validate target client */
833 if (client && (!Channel_IsMemberOf(Channel, client))) {
834 if (!IRC_WriteErrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
837 Channel_Name(Channel)))
843 /* Channel-User-Mode */
845 ? Channel_UserModeAdd(Channel, client, x[0])
846 : Channel_UserModeDel(Channel, client, x[0]);
848 strlcat(the_args, " ", sizeof(the_args));
849 strlcat(the_args, Client_ID(client),
851 strlcat(the_modes, x, sizeof(the_modes));
853 ("User \"%s\": Mode change on %s, now \"%s\"",
854 Client_Mask(client), Channel_Name(Channel),
855 Channel_UserModes(Channel, client));
860 ? Channel_ModeAdd(Channel, x[0])
861 : Channel_ModeDel(Channel, x[0]);
863 strlcat(the_modes, x, sizeof(the_modes));
864 LogDebug("Channel %s: Mode change, now \"%s\".",
865 Channel_Name(Channel),
866 Channel_Modes(Channel));
870 /* Are there additional arguments to add? */
872 strlcat(the_args, " ", sizeof(the_args));
873 strlcat(the_args, argadd, sizeof(the_args));
878 /* Are there changed modes? */
880 /* Clean up mode string */
881 len = strlen(the_modes) - 1;
882 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
883 the_modes[len] = '\0';
885 if (Client_Type(Client) == CLIENT_SERVER) {
886 /* MODE requests for local channels from other servers
887 * are definitely invalid! */
888 if (Channel_IsLocal(Channel)) {
889 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
893 /* Forward mode changes to channel users and all the
894 * other remote servers: */
895 IRC_WriteStrServersPrefix(Client, Origin,
896 "MODE %s %s%s", Channel_Name(Channel),
897 the_modes, the_args);
898 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
899 false, "MODE %s %s%s", Channel_Name(Channel),
900 the_modes, the_args);
903 Origin = Client_ThisServer();
904 /* Send reply to client and inform other servers and channel users */
905 connected = IRC_WriteStrClientPrefix(Client, Origin,
906 "MODE %s %s%s", Channel_Name(Channel),
907 the_modes, the_args);
908 /* Only forward requests for non-local channels */
909 if (!Channel_IsLocal(Channel))
910 IRC_WriteStrServersPrefix(Client, Origin,
911 "MODE %s %s%s", Channel_Name(Channel),
912 the_modes, the_args);
913 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
914 false, "MODE %s %s%s", Channel_Name(Channel),
915 the_modes, the_args);
923 * Handler for the IRC "AWAY" command.
925 * @param Client The client from which this command has been received.
926 * @param Req Request structure with prefix and all parameters.
927 * @return CONNECTED or DISCONNECTED.
930 IRC_AWAY( CLIENT *Client, REQUEST *Req )
932 assert (Client != NULL);
933 assert (Req != NULL);
935 if (Req->argc == 1 && Req->argv[0][0]) {
936 Client_SetAway(Client, Req->argv[0]);
937 Client_ModeAdd(Client, 'a');
938 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :+a",
940 return IRC_WriteStrClient(Client, RPL_NOWAWAY_MSG,
943 Client_ModeDel(Client, 'a');
944 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :-a",
946 return IRC_WriteStrClient(Client, RPL_UNAWAY_MSG,
952 * Add entries to channel invite, ban and exception lists.
954 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
955 * @param Prefix The originator of the command.
956 * @param Client The sender of the command.
957 * @param Channel The channel of which the list should be modified.
958 * @param Pattern The pattern to add to the list.
959 * @return CONNECTED or DISCONNECTED.
962 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
966 struct list_head *list = NULL;
967 long int current_count;
969 assert(Client != NULL);
970 assert(Channel != NULL);
971 assert(Pattern != NULL);
972 assert(what == 'I' || what == 'b' || what == 'e');
974 Lists_MakeMask(Pattern, mask, sizeof(mask));
975 current_count = Lists_Count(Channel_GetListInvites(Channel))
976 + Lists_Count(Channel_GetListExcepts(Channel))
977 + Lists_Count(Channel_GetListBans(Channel));
981 list = Channel_GetListInvites(Channel);
984 list = Channel_GetListBans(Channel);
987 list = Channel_GetListExcepts(Channel);
991 if (Lists_CheckDupeMask(list, mask))
993 if (Client_Type(Client) == CLIENT_USER &&
994 current_count >= MAX_HNDL_CHANNEL_LISTS)
995 return IRC_WriteErrClient(Client, ERR_LISTFULL_MSG,
997 Channel_Name(Channel), mask,
998 MAX_HNDL_CHANNEL_LISTS);
1002 if (!Channel_AddInvite(Channel, mask, false))
1006 if (!Channel_AddBan(Channel, mask))
1010 if (!Channel_AddExcept(Channel, mask))
1014 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1018 * Delete entries from channel invite, ban and exception lists.
1020 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1021 * @param Prefix The originator of the command.
1022 * @param Client The sender of the command.
1023 * @param Channel The channel of which the list should be modified.
1024 * @param Pattern The pattern to add to the list.
1025 * @return CONNECTED or DISCONNECTED.
1028 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1029 const char *Pattern)
1031 char mask[MASK_LEN];
1032 struct list_head *list = NULL;
1034 assert(Client != NULL);
1035 assert(Channel != NULL);
1036 assert(Pattern != NULL);
1037 assert(what == 'I' || what == 'b' || what == 'e');
1039 Lists_MakeMask(Pattern, mask, sizeof(mask));
1043 list = Channel_GetListInvites(Channel);
1046 list = Channel_GetListBans(Channel);
1049 list = Channel_GetListExcepts(Channel);
1053 if (!Lists_CheckDupeMask(list, mask))
1055 Lists_Del(list, mask);
1057 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1061 * Send information about changed channel invite/ban/exception lists to clients.
1063 * @param IsAdd true if the list item has been added, false otherwise.
1064 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1065 * @param Prefix The originator of the mode list change.
1066 * @param Client The sender of the command.
1067 * @param Channel The channel of which the list has been modified.
1068 * @param Mask The mask which has been added or removed.
1069 * @return CONNECTED or DISCONNECTED.
1072 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1073 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1077 /* Send confirmation to the client */
1078 if (Client_Type(Client) == CLIENT_USER)
1079 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1080 Channel_Name(Channel),
1084 /* to other servers */
1085 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1086 Channel_Name(Channel), IsAdd ? '+' : '-',
1089 /* and local users in channel */
1090 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1091 "MODE %s %c%c %s", Channel_Name(Channel),
1092 IsAdd ? '+' : '-', ModeChar, Mask );
1095 } /* Send_ListChange */