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.)
27 #include "irc-macros.h"
28 #include "irc-write.h"
37 static bool Client_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
39 static bool Channel_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
42 static bool Add_To_List PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
43 CHANNEL *Channel, const char *Pattern));
44 static bool Del_From_List PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
45 CHANNEL *Channel, const char *Pattern));
47 static bool Send_ListChange PARAMS((const bool IsAdd, const char ModeChar,
48 CLIENT *Prefix, CLIENT *Client,
49 CHANNEL *Channel, const char *Mask));
52 * Handler for the IRC "MODE" command.
54 * This function detects whether user or channel modes should be modified
55 * and calls the appropriate sub-functions.
57 * @param Client The client from which this command has been received.
58 * @param Req Request structure with prefix and all parameters.
59 * @return CONNECTED or DISCONNECTED.
62 IRC_MODE( CLIENT *Client, REQUEST *Req )
67 assert(Client != NULL);
70 _IRC_GET_SENDER_OR_RETURN_(origin, Req, Client)
72 /* Channel or user mode? */
73 cl = NULL; chan = NULL;
74 if (Client_IsValidNick(Req->argv[0]))
75 cl = Client_Search(Req->argv[0]);
76 if (Channel_IsValidName(Req->argv[0]))
77 chan = Channel_Search(Req->argv[0]);
80 return Client_Mode(Client, Req, origin, cl);
82 return Channel_Mode(Client, Req, origin, chan);
84 /* No target found! */
85 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
86 Client_ID(Client), Req->argv[0]);
90 * Check if the "mode limit" for a client has been reached.
92 * This limit doesn't apply for servers or services!
94 * @param Client The client to check.
95 * @param Count The number of modes already handled.
96 * @return true if the limit has been reached.
99 Mode_Limit_Reached(CLIENT *Client, int Count)
101 if (Client_Type(Client) == CLIENT_SERVER
102 || Client_Type(Client) == CLIENT_SERVICE)
104 if (Count < MAX_HNDL_MODES_ARG)
110 * Handle client mode requests
112 * @param Client The client from which this command has been received.
113 * @param Req Request structure with prefix and all parameters.
114 * @param Origin The originator of the MODE command (prefix).
115 * @param Target The target (client) of this MODE command.
116 * @return CONNECTED or DISCONNECTED.
119 Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
121 char the_modes[COMMAND_LEN], x[2], *mode_ptr;
123 bool send_RPL_HOSTHIDDEN_MSG = false;
127 /* Is the client allowed to request or change the modes? */
128 if (Client_Type(Client) == CLIENT_USER) {
129 /* Users are only allowed to manipulate their own modes! */
130 if (Target != Client)
131 return IRC_WriteErrClient(Client,
132 ERR_USERSDONTMATCH_MSG,
136 /* Mode request: let's answer it :-) */
138 return IRC_WriteStrClient(Origin, RPL_UMODEIS_MSG,
140 Client_Modes(Target));
143 mode_ptr = Req->argv[mode_arg];
145 /* Initial state: set or unset modes? */
146 if (*mode_ptr == '+') {
148 strcpy(the_modes, "+");
149 } else if (*mode_ptr == '-') {
151 strcpy(the_modes, "-");
153 return IRC_WriteErrClient(Origin, ERR_UMODEUNKNOWNFLAG_MSG,
161 /* Try next argument if there's any */
163 if (mode_arg < Req->argc)
164 mode_ptr = Req->argv[mode_arg];
172 if ((*mode_ptr == '+' && !set)
173 || (*mode_ptr == '-' && set)) {
174 /* Action modifier ("+"/"-") must be changed */
175 len = strlen(the_modes) - 1;
176 if (the_modes[len] == '+'
177 || the_modes[len] == '-') {
178 /* Last character in the "result
179 * string" was an "action", so just
180 * overwrite it with the new action */
181 the_modes[len] = *mode_ptr;
183 /* Append new modifier character to
184 * the resulting mode string */
186 strlcat(the_modes, x,
189 if (*mode_ptr == '+')
200 case 'b': /* Block private msgs */
201 case 'C': /* Only messages from clients sharing a channel */
202 case 'i': /* Invisible */
203 case 's': /* Server messages */
204 case 'w': /* Wallops messages */
208 if (Client_Type(Client) == CLIENT_SERVER) {
210 Client_SetAway(Origin, DEFAULT_AWAY_MSG);
212 ok = IRC_WriteErrClient(Origin,
213 ERR_NOPRIVILEGES_MSG,
217 if (Client_HasMode(Client, 'r'))
218 ok = IRC_WriteErrClient(Origin,
224 case 'c': /* Receive connect notices */
225 case 'q': /* KICK-protected user */
226 /* (only settable by IRC operators!) */
227 if (!set || Client_Type(Client) == CLIENT_SERVER
228 || Client_HasMode(Origin, 'o'))
231 ok = IRC_WriteErrClient(Origin,
232 ERR_NOPRIVILEGES_MSG,
235 case 'o': /* IRC operator (only unsettable!) */
236 if (!set || Client_Type(Client) == CLIENT_SERVER) {
239 ok = IRC_WriteErrClient(Origin,
240 ERR_NOPRIVILEGES_MSG,
243 case 'r': /* Restricted (only settable) */
244 if (set || Client_Type(Client) == CLIENT_SERVER)
247 ok = IRC_WriteErrClient(Origin,
251 case 'R': /* Registered (not [un]settable by clients) */
252 if (Client_Type(Client) == CLIENT_SERVER)
255 ok = IRC_WriteErrClient(Origin,
256 ERR_NICKREGISTER_MSG,
259 case 'x': /* Cloak hostname */
260 if (Client_HasMode(Client, 'r'))
261 ok = IRC_WriteErrClient(Origin,
264 else if (!set || Conf_CloakHostModeX[0]
265 || Client_Type(Client) == CLIENT_SERVER
266 || Client_HasMode(Origin, 'o')) {
268 send_RPL_HOSTHIDDEN_MSG = true;
270 ok = IRC_WriteErrClient(Origin,
271 ERR_NOPRIVILEGES_MSG,
275 if (Client_Type(Client) != CLIENT_SERVER) {
277 "Unknown mode \"%c%c\" from \"%s\"!?",
278 set ? '+' : '-', *mode_ptr,
280 ok = IRC_WriteErrClient(Origin,
281 ERR_UMODEUNKNOWNFLAG2_MSG,
288 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
289 set ? '+' : '-', *mode_ptr,
290 Client_ID(Origin), Client_ID(Target));
298 /* Is there a valid mode change? */
303 if (Client_ModeAdd(Target, x[0]))
304 strlcat(the_modes, x, sizeof(the_modes));
306 if (Client_ModeDel(Target, x[0]))
307 strlcat(the_modes, x, sizeof(the_modes));
311 /* Are there changed modes? */
313 /* Remove needless action modifier characters */
314 len = strlen(the_modes) - 1;
315 if (the_modes[len] == '+' || the_modes[len] == '-')
316 the_modes[len] = '\0';
318 if (Client_Type(Client) == CLIENT_SERVER) {
319 /* Forward modes to other servers */
320 if (Client_Conn(Target) != NONE) {
321 /* Remote server (service?) changed modes
322 * for one of our clients. Inform it! */
323 IRC_WriteStrClientPrefix(Target, Origin,
328 IRC_WriteStrServersPrefix(Client, Origin,
333 /* Send reply to client and inform other servers */
334 ok = IRC_WriteStrClientPrefix(Client, Origin,
338 IRC_WriteStrServersPrefix(Client, Origin,
344 if (send_RPL_HOSTHIDDEN_MSG && Client_Conn(Target) > NONE) {
345 /* A new (cloaked) hostname must be announced */
346 IRC_WriteStrClientPrefix(Target, Origin,
349 Client_HostnameDisplayed(Target));
353 LogDebug("%s \"%s\": Mode change, now \"%s\".",
354 Client_TypeText(Target), Client_Mask(Target),
355 Client_Modes(Target));
362 * Reply to a channel mode request.
364 * @param Origin The originator of the MODE command (prefix).
365 * @param Channel The channel of which the modes should be sent.
366 * @return CONNECTED or DISCONNECTED.
369 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
371 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
372 const char *mode_ptr;
374 /* Member or not? -- That's the question! */
375 if (!Channel_IsMemberOf(Channel, Origin))
376 return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
377 Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
379 /* The sender is a member: generate extended reply */
380 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
381 mode_ptr = the_modes;
387 snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
388 strlcat(the_args, argadd, sizeof(the_args));
391 strlcat(the_args, " ", sizeof(the_args));
392 strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
398 strlcat(the_modes, the_args, sizeof(the_modes));
400 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
401 Client_ID(Origin), Channel_Name(Channel),
405 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
406 Client_ID(Origin), Channel_Name(Channel),
407 Channel_CreationTime(Channel)))
414 * Handle channel mode and channel-user mode changes
416 * @param Client The client from which this command has been received.
417 * @param Req Request structure with prefix and all parameters.
418 * @param Origin The originator of the MODE command (prefix).
419 * @param Channel The target channel of this MODE command.
420 * @return CONNECTED or DISCONNECTED.
423 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
425 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
426 argadd[CLIENT_PASS_LEN], *mode_ptr;
427 bool connected, set, skiponce, retval, use_servermode,
428 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
429 int mode_arg, arg_arg, mode_arg_count = 0;
434 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
436 if (Channel_IsModeless(Channel))
437 return IRC_WriteErrClient(Client, ERR_NOCHANMODES_MSG,
438 Client_ID(Client), Channel_Name(Channel));
440 /* Mode request: let's answer it :-) */
442 return Channel_Mode_Answer_Request(Origin, Channel);
444 /* Check if origin is oper and opers can use mode */
445 use_servermode = Conf_OperServerMode;
446 if(Client_HasMode(Client, 'o') && Conf_OperCanMode) {
450 /* Check if client is a server/service */
451 if(Client_Type(Client) == CLIENT_SERVER ||
452 Client_Type(Client) == CLIENT_SERVICE) {
456 /* Check if client is member of channel or an oper or an server/service */
457 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
458 return IRC_WriteErrClient(Origin, ERR_NOTONCHANNEL_MSG,
460 Channel_Name(Channel));
463 mode_ptr = Req->argv[mode_arg];
464 if (Req->argc > mode_arg + 1)
465 arg_arg = mode_arg + 1;
469 /* Initial state: set or unset modes? */
483 /* Prepare reply string */
484 strcpy(the_modes, set ? "+" : "-");
488 connected = CONNECTED;
493 /* Try next argument if there's any */
496 if (arg_arg > mode_arg)
501 if (mode_arg >= Req->argc)
503 mode_ptr = Req->argv[mode_arg];
505 if (Req->argc > mode_arg + 1)
506 arg_arg = mode_arg + 1;
515 if (((*mode_ptr == '+') && !set)
516 || ((*mode_ptr == '-') && set)) {
517 /* Action modifier ("+"/"-") must be changed ... */
518 len = strlen(the_modes) - 1;
519 if (the_modes[len] == '+' || the_modes[len] == '-') {
520 /* Adjust last action modifier in result */
521 the_modes[len] = *mode_ptr;
523 /* Append modifier character to result string */
525 strlcat(the_modes, x, sizeof(the_modes));
527 set = *mode_ptr == '+';
532 /* Are there arguments left? */
533 if (arg_arg >= Req->argc)
536 if(!is_machine && !is_oper) {
537 if (Channel_UserHasMode(Channel, Client, 'q'))
539 if (Channel_UserHasMode(Channel, Client, 'a'))
541 if (Channel_UserHasMode(Channel, Client, 'o'))
543 if (Channel_UserHasMode(Channel, Client, 'h'))
552 /* --- Channel modes --- */
553 case 'R': /* Registered users only */
554 case 's': /* Secret channel */
555 case 'z': /* Secure connections only */
556 if(!is_oper && !is_machine && !is_owner &&
557 !is_admin && !is_op) {
558 connected = IRC_WriteErrClient(Origin,
559 ERR_CHANOPRIVSNEEDED_MSG,
560 Client_ID(Origin), Channel_Name(Channel));
563 case 'i': /* Invite only */
564 case 'V': /* Invite disallow */
565 case 'M': /* Only identified nicks can write */
566 case 'm': /* Moderated */
567 case 'n': /* Only members can write */
568 case 'Q': /* No kicks */
569 case 't': /* Topic locked */
570 if(is_oper || is_machine || is_owner ||
571 is_admin || is_op || is_halfop)
574 connected = IRC_WriteErrClient(Origin,
575 ERR_CHANOPRIVSNEEDED_MSG,
576 Client_ID(Origin), Channel_Name(Channel));
578 case 'k': /* Channel key */
579 if (Mode_Limit_Reached(Client, mode_arg_count++))
582 if (is_oper || is_machine || is_owner ||
583 is_admin || is_op || is_halfop) {
585 if (Channel_HasMode(Channel, 'k'))
586 strlcpy(argadd, "*", sizeof(argadd));
587 if (arg_arg > mode_arg)
590 connected = IRC_WriteErrClient(Origin,
591 ERR_CHANOPRIVSNEEDED_MSG,
593 Channel_Name(Channel));
596 if (arg_arg > mode_arg) {
597 if (is_oper || is_machine || is_owner ||
598 is_admin || is_op || is_halfop) {
599 Channel_ModeDel(Channel, 'k');
600 Channel_SetKey(Channel,
602 strlcpy(argadd, Channel_Key(Channel),
606 connected = IRC_WriteErrClient(Origin,
607 ERR_CHANOPRIVSNEEDED_MSG,
609 Channel_Name(Channel));
611 Req->argv[arg_arg][0] = '\0';
615 /* Only send error message in "strict" mode,
616 * this is how ircd2.11 and others behave ... */
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 connected = IRC_WriteErrClient(Origin,
662 ERR_NEEDMOREPARAMS_MSG,
663 Client_ID(Origin), Req->command);
668 case 'O': /* IRC operators only */
670 /* Only IRC operators are allowed to
671 * set the 'O' channel mode! */
672 if(is_oper || is_machine)
675 connected = IRC_WriteErrClient(Origin,
676 ERR_NOPRIVILEGES_MSG,
678 } else if(is_oper || is_machine || is_owner ||
682 connected = IRC_WriteErrClient(Origin,
683 ERR_CHANOPRIVSNEEDED_MSG,
685 Channel_Name(Channel));
687 case 'P': /* Persistent channel */
689 /* Only IRC operators are allowed to
690 * set the 'P' channel mode! */
691 if(is_oper || is_machine)
694 connected = IRC_WriteErrClient(Origin,
695 ERR_NOPRIVILEGES_MSG,
697 } else if(is_oper || is_machine || is_owner ||
701 connected = IRC_WriteErrClient(Origin,
702 ERR_CHANOPRIVSNEEDED_MSG,
704 Channel_Name(Channel));
706 /* --- Channel user modes --- */
707 case 'q': /* Owner */
708 case 'a': /* Channel admin */
709 if(!is_oper && !is_machine && !is_owner && !is_admin) {
710 connected = IRC_WriteErrClient(Origin,
711 ERR_CHANOPPRIVTOOLOW_MSG,
713 Channel_Name(Channel));
716 case 'o': /* Channel operator */
717 if(!is_oper && !is_machine && !is_owner &&
718 !is_admin && !is_op) {
719 connected = IRC_WriteErrClient(Origin,
720 ERR_CHANOPRIVSNEEDED_MSG,
722 Channel_Name(Channel));
725 case 'h': /* Half Op */
726 if(!is_oper && !is_machine && !is_owner &&
727 !is_admin && !is_op) {
728 connected = IRC_WriteErrClient(Origin,
729 ERR_CHANOPRIVSNEEDED_MSG,
731 Channel_Name(Channel));
734 case 'v': /* Voice */
735 if (arg_arg > mode_arg) {
736 if (is_oper || is_machine || is_owner ||
737 is_admin || is_op || is_halfop) {
738 client = Client_Search(Req->argv[arg_arg]);
742 connected = IRC_WriteErrClient(Origin,
747 connected = IRC_WriteErrClient(Origin,
748 ERR_CHANOPRIVSNEEDED_MSG,
750 Channel_Name(Channel));
752 Req->argv[arg_arg][0] = '\0';
756 /* Report an error to the client, when a user
757 * mode should be changed but no nickname is
758 * given. But don't do it when not in "strict"
759 * mode, because most other servers don't do
760 * it as well and some clients send "wired"
761 * MODE commands like "MODE #chan -ooo nick". */
762 connected = IRC_WriteErrClient(Origin,
763 ERR_NEEDMOREPARAMS_MSG,
764 Client_ID(Origin), Req->command);
769 /* --- Channel lists --- */
770 case 'I': /* Invite lists */
771 case 'b': /* Ban lists */
772 case 'e': /* Channel exception lists */
773 if (Mode_Limit_Reached(Client, mode_arg_count++))
775 if (arg_arg > mode_arg) {
777 if (is_oper || is_machine || is_owner ||
778 is_admin || is_op || is_halfop) {
780 ? Add_To_List(*mode_ptr, Origin,
783 : Del_From_List(*mode_ptr, Origin,
787 connected = IRC_WriteErrClient(Origin,
788 ERR_CHANOPRIVSNEEDED_MSG,
790 Channel_Name(Channel));
792 Req->argv[arg_arg][0] = '\0';
797 Channel_ShowInvites(Origin, Channel);
800 Channel_ShowBans(Origin, Channel);
803 Channel_ShowExcepts(Origin, Channel);
809 if (Client_Type(Client) != CLIENT_SERVER) {
811 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
812 set ? '+' : '-', *mode_ptr,
813 Client_ID(Origin), Channel_Name(Channel));
814 connected = IRC_WriteErrClient(Origin,
816 Client_ID(Origin), *mode_ptr,
817 Channel_Name(Channel));
821 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
822 set ? '+' : '-', *mode_ptr,
823 Client_ID(Origin), Channel_Name(Channel));
831 /* Is there a valid mode change? */
835 /* Validate target client */
836 if (client && (!Channel_IsMemberOf(Channel, client))) {
837 if (!IRC_WriteErrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
840 Channel_Name(Channel)))
846 /* Channel-User-Mode */
848 ? Channel_UserModeAdd(Channel, client, x[0])
849 : Channel_UserModeDel(Channel, client, x[0]);
851 strlcat(the_args, " ", sizeof(the_args));
852 strlcat(the_args, Client_ID(client),
854 strlcat(the_modes, x, sizeof(the_modes));
856 ("User \"%s\": Mode change on %s, now \"%s\"",
857 Client_Mask(client), Channel_Name(Channel),
858 Channel_UserModes(Channel, client));
863 ? Channel_ModeAdd(Channel, x[0])
864 : Channel_ModeDel(Channel, x[0]);
866 strlcat(the_modes, x, sizeof(the_modes));
867 LogDebug("Channel %s: Mode change, now \"%s\".",
868 Channel_Name(Channel),
869 Channel_Modes(Channel));
873 /* Are there additional arguments to add? */
875 strlcat(the_args, " ", sizeof(the_args));
876 strlcat(the_args, argadd, sizeof(the_args));
881 /* Are there changed modes? */
883 /* Clean up mode string */
884 len = strlen(the_modes) - 1;
885 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
886 the_modes[len] = '\0';
888 if (Client_Type(Client) == CLIENT_SERVER) {
889 /* MODE requests for local channels from other servers
890 * are definitely invalid! */
891 if (Channel_IsLocal(Channel)) {
892 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
896 /* Forward mode changes to channel users and all the
897 * other remote servers: */
898 IRC_WriteStrServersPrefix(Client, Origin,
899 "MODE %s %s%s", Channel_Name(Channel),
900 the_modes, the_args);
901 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
902 false, "MODE %s %s%s", Channel_Name(Channel),
903 the_modes, the_args);
906 Origin = Client_ThisServer();
907 /* Send reply to client and inform other servers and channel users */
908 connected = IRC_WriteStrClientPrefix(Client, Origin,
909 "MODE %s %s%s", Channel_Name(Channel),
910 the_modes, the_args);
911 /* Only forward requests for non-local channels */
912 if (!Channel_IsLocal(Channel))
913 IRC_WriteStrServersPrefix(Client, Origin,
914 "MODE %s %s%s", Channel_Name(Channel),
915 the_modes, the_args);
916 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
917 false, "MODE %s %s%s", Channel_Name(Channel),
918 the_modes, the_args);
926 * Handler for the IRC "AWAY" command.
928 * @param Client The client from which this command has been received.
929 * @param Req Request structure with prefix and all parameters.
930 * @return CONNECTED or DISCONNECTED.
933 IRC_AWAY( CLIENT *Client, REQUEST *Req )
935 assert (Client != NULL);
936 assert (Req != NULL);
938 if (Req->argc == 1 && Req->argv[0][0]) {
939 Client_SetAway(Client, Req->argv[0]);
940 Client_ModeAdd(Client, 'a');
941 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :+a",
943 return IRC_WriteStrClient(Client, RPL_NOWAWAY_MSG,
946 Client_ModeDel(Client, 'a');
947 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :-a",
949 return IRC_WriteStrClient(Client, RPL_UNAWAY_MSG,
955 * Add entries to channel invite, ban and exception lists.
957 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
958 * @param Prefix The originator of the command.
959 * @param Client The sender of the command.
960 * @param Channel The channel of which the list should be modified.
961 * @param Pattern The pattern to add to the list.
962 * @return CONNECTED or DISCONNECTED.
965 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
969 struct list_head *list = NULL;
970 long int current_count;
972 assert(Client != NULL);
973 assert(Channel != NULL);
974 assert(Pattern != NULL);
975 assert(what == 'I' || what == 'b' || what == 'e');
977 Lists_MakeMask(Pattern, mask, sizeof(mask));
978 current_count = Lists_Count(Channel_GetListInvites(Channel))
979 + Lists_Count(Channel_GetListExcepts(Channel))
980 + Lists_Count(Channel_GetListBans(Channel));
984 list = Channel_GetListInvites(Channel);
987 list = Channel_GetListBans(Channel);
990 list = Channel_GetListExcepts(Channel);
994 if (Lists_CheckDupeMask(list, mask))
996 if (Client_Type(Client) == CLIENT_USER &&
997 current_count >= MAX_HNDL_CHANNEL_LISTS)
998 return IRC_WriteErrClient(Client, ERR_LISTFULL_MSG,
1000 Channel_Name(Channel), mask,
1001 MAX_HNDL_CHANNEL_LISTS);
1005 if (!Channel_AddInvite(Channel, mask, false))
1009 if (!Channel_AddBan(Channel, mask))
1013 if (!Channel_AddExcept(Channel, mask))
1017 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1021 * Delete entries from channel invite, ban and exception lists.
1023 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1024 * @param Prefix The originator of the command.
1025 * @param Client The sender of the command.
1026 * @param Channel The channel of which the list should be modified.
1027 * @param Pattern The pattern to add to the list.
1028 * @return CONNECTED or DISCONNECTED.
1031 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1032 const char *Pattern)
1034 char mask[MASK_LEN];
1035 struct list_head *list = NULL;
1037 assert(Client != NULL);
1038 assert(Channel != NULL);
1039 assert(Pattern != NULL);
1040 assert(what == 'I' || what == 'b' || what == 'e');
1042 Lists_MakeMask(Pattern, mask, sizeof(mask));
1046 list = Channel_GetListInvites(Channel);
1049 list = Channel_GetListBans(Channel);
1052 list = Channel_GetListExcepts(Channel);
1056 if (!Lists_CheckDupeMask(list, mask))
1058 Lists_Del(list, mask);
1060 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1064 * Send information about changed channel invite/ban/exception lists to clients.
1066 * @param IsAdd true if the list item has been added, false otherwise.
1067 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1068 * @param Prefix The originator of the mode list change.
1069 * @param Client The sender of the command.
1070 * @param Channel The channel of which the list has been modified.
1071 * @param Mask The mask which has been added or removed.
1072 * @return CONNECTED or DISCONNECTED.
1075 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1076 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1080 /* Send confirmation to the client */
1081 if (Client_Type(Client) == CLIENT_USER)
1082 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1083 Channel_Name(Channel),
1087 /* to other servers */
1088 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1089 Channel_Name(Channel), IsAdd ? '+' : '-',
1092 /* and local users in channel */
1093 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1094 "MODE %s %c%c %s", Channel_Name(Channel),
1095 IsAdd ? '+' : '-', ModeChar, Mask );
1098 } /* Send_ListChange */