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_ARGC_GE_OR_RETURN_(Client, Req, 1)
73 _IRC_GET_SENDER_OR_RETURN_(origin, Req, Client)
75 /* Channel or user mode? */
76 cl = NULL; chan = NULL;
77 if (Client_IsValidNick(Req->argv[0]))
78 cl = Client_Search(Req->argv[0]);
79 if (Channel_IsValidName(Req->argv[0]))
80 chan = Channel_Search(Req->argv[0]);
83 return Client_Mode(Client, Req, origin, cl);
85 return Channel_Mode(Client, Req, origin, chan);
87 /* No target found! */
88 return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
89 Client_ID(Client), Req->argv[0]);
93 * Check if the "mode limit" for a client has been reached.
95 * This limit doesn't apply for servers or services!
97 * @param Client The client to check.
98 * @param Count The number of modes already handled.
99 * @return true if the limit has been reached.
102 Mode_Limit_Reached(CLIENT *Client, int Count)
104 if (Client_Type(Client) == CLIENT_SERVER
105 || Client_Type(Client) == CLIENT_SERVICE)
107 if (Count < MAX_HNDL_MODES_ARG)
113 * Handle client mode requests
115 * @param Client The client from which this command has been received.
116 * @param Req Request structure with prefix and all parameters.
117 * @param Origin The originator of the MODE command (prefix).
118 * @param Target The target (client) of this MODE command.
119 * @return CONNECTED or DISCONNECTED.
122 Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
124 char the_modes[COMMAND_LEN], x[2], *mode_ptr;
126 bool send_RPL_HOSTHIDDEN_MSG = false;
130 /* Is the client allowed to request or change the modes? */
131 if (Client_Type(Client) == CLIENT_USER) {
132 /* Users are only allowed to manipulate their own modes! */
133 if (Target != Client)
134 return IRC_WriteStrClient(Client,
135 ERR_USERSDONTMATCH_MSG,
139 /* Mode request: let's answer it :-) */
141 return IRC_WriteStrClient(Origin, RPL_UMODEIS_MSG,
143 Client_Modes(Target));
146 mode_ptr = Req->argv[mode_arg];
148 /* Initial state: set or unset modes? */
149 if (*mode_ptr == '+') {
151 strcpy(the_modes, "+");
152 } else if (*mode_ptr == '-') {
154 strcpy(the_modes, "-");
156 return IRC_WriteStrClient(Origin, ERR_UMODEUNKNOWNFLAG_MSG,
164 /* Try next argument if there's any */
166 if (mode_arg < Req->argc)
167 mode_ptr = Req->argv[mode_arg];
175 if ((*mode_ptr == '+' && !set)
176 || (*mode_ptr == '-' && set)) {
177 /* Action modifier ("+"/"-") must be changed */
178 len = strlen(the_modes) - 1;
179 if (the_modes[len] == '+'
180 || the_modes[len] == '-') {
181 /* Last character in the "result
182 * string" was an "action", so just
183 * overwrite it with the new action */
184 the_modes[len] = *mode_ptr;
186 /* Append new modifier character to
187 * the resulting mode string */
189 strlcat(the_modes, x,
192 if (*mode_ptr == '+')
203 case 'b': /* Block private msgs */
204 case 'C': /* Only messages from clients sharing a channel */
205 case 'i': /* Invisible */
206 case 's': /* Server messages */
207 case 'w': /* Wallops messages */
211 if (Client_Type(Client) == CLIENT_SERVER) {
213 Client_SetAway(Origin, DEFAULT_AWAY_MSG);
215 ok = IRC_WriteStrClient(Origin,
216 ERR_NOPRIVILEGES_MSG,
220 if (Client_HasMode(Client, 'r'))
221 ok = IRC_WriteStrClient(Origin,
227 case 'c': /* Receive connect notices
228 * (only settable by IRC operators!) */
229 if (!set || Client_Type(Client) == CLIENT_SERVER
230 || Client_OperByMe(Origin))
233 ok = IRC_WriteStrClient(Origin,
234 ERR_NOPRIVILEGES_MSG,
237 case 'o': /* IRC operator (only unsettable!) */
238 if (!set || Client_Type(Client) == CLIENT_SERVER) {
239 Client_SetOperByMe(Target, false);
242 ok = IRC_WriteStrClient(Origin,
243 ERR_NOPRIVILEGES_MSG,
246 case 'q': /* KICK-protected user */
247 if (!set || Client_Type(Client) == CLIENT_SERVER
248 || Client_OperByMe(Origin))
251 ok = IRC_WriteStrClient(Origin,
252 ERR_NOPRIVILEGES_MSG,
255 case 'r': /* Restricted (only settable) */
256 if (set || Client_Type(Client) == CLIENT_SERVER)
259 ok = IRC_WriteStrClient(Origin,
263 case 'R': /* Registered (not [un]settable by clients) */
264 if (Client_Type(Client) == CLIENT_SERVER)
267 ok = IRC_WriteStrClient(Origin,
268 ERR_NICKREGISTER_MSG,
271 case 'x': /* Cloak hostname */
272 if (Client_HasMode(Client, 'r'))
273 ok = IRC_WriteStrClient(Origin,
276 else if (!set || Conf_CloakHostModeX[0]
277 || Client_Type(Client) == CLIENT_SERVER
278 || Client_OperByMe(Client)) {
280 send_RPL_HOSTHIDDEN_MSG = true;
282 ok = IRC_WriteStrClient(Origin,
283 ERR_NOPRIVILEGES_MSG,
287 if (Client_Type(Client) != CLIENT_SERVER) {
289 "Unknown mode \"%c%c\" from \"%s\"!?",
290 set ? '+' : '-', *mode_ptr,
292 ok = IRC_WriteStrClient(Origin,
293 ERR_UMODEUNKNOWNFLAG2_MSG,
300 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
301 set ? '+' : '-', *mode_ptr,
302 Client_ID(Origin), Client_ID(Target));
310 /* Is there a valid mode change? */
315 if (Client_ModeAdd(Target, x[0]))
316 strlcat(the_modes, x, sizeof(the_modes));
318 if (Client_ModeDel(Target, x[0]))
319 strlcat(the_modes, x, sizeof(the_modes));
323 /* Are there changed modes? */
325 /* Remove needless action modifier characters */
326 len = strlen(the_modes) - 1;
327 if (the_modes[len] == '+' || the_modes[len] == '-')
328 the_modes[len] = '\0';
330 if (Client_Type(Client) == CLIENT_SERVER) {
331 /* Forward modes to other servers */
332 if (Client_Conn(Target) != NONE) {
333 /* Remote server (service?) changed modes
334 * for one of our clients. Inform it! */
335 IRC_WriteStrClientPrefix(Target, Origin,
340 IRC_WriteStrServersPrefix(Client, Origin,
345 /* Send reply to client and inform other servers */
346 ok = IRC_WriteStrClientPrefix(Client, Origin,
350 IRC_WriteStrServersPrefix(Client, Origin,
356 if (send_RPL_HOSTHIDDEN_MSG && Client_Conn(Target) > NONE) {
357 /* A new (cloaked) hostname must be announced */
358 IRC_WriteStrClientPrefix(Target, Origin,
361 Client_HostnameDisplayed(Target));
365 LogDebug("%s \"%s\": Mode change, now \"%s\".",
366 Client_TypeText(Target), Client_Mask(Target),
367 Client_Modes(Target));
370 IRC_SetPenalty(Client, 1);
375 * Reply to a channel mode request.
377 * @param Origin The originator of the MODE command (prefix).
378 * @param Channel The channel of which the modes should be sent.
379 * @return CONNECTED or DISCONNECTED.
382 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
384 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
385 const char *mode_ptr;
387 /* Member or not? -- That's the question! */
388 if (!Channel_IsMemberOf(Channel, Origin))
389 return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
390 Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
392 /* The sender is a member: generate extended reply */
393 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
394 mode_ptr = the_modes;
400 snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
401 strlcat(the_args, argadd, sizeof(the_args));
404 strlcat(the_args, " ", sizeof(the_args));
405 strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
411 strlcat(the_modes, the_args, sizeof(the_modes));
413 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
414 Client_ID(Origin), Channel_Name(Channel),
418 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
419 Client_ID(Origin), Channel_Name(Channel),
420 Channel_CreationTime(Channel)))
427 * Handle channel mode and channel-user mode changes
429 * @param Client The client from which this command has been received.
430 * @param Req Request structure with prefix and all parameters.
431 * @param Origin The originator of the MODE command (prefix).
432 * @param Channel The target channel of this MODE command.
433 * @return CONNECTED or DISCONNECTED.
436 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
438 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
439 argadd[CLIENT_PASS_LEN], *mode_ptr, *o_mode_ptr;
440 bool connected, set, skiponce, retval, use_servermode,
441 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
442 int mode_arg, arg_arg, mode_arg_count = 0;
447 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
449 if (Channel_IsModeless(Channel))
450 return IRC_WriteStrClient(Client, ERR_NOCHANMODES_MSG,
451 Client_ID(Client), Channel_Name(Channel));
453 /* Mode request: let's answer it :-) */
455 return Channel_Mode_Answer_Request(Origin, Channel);
457 /* Check if origin is oper and opers can use mode */
458 use_servermode = Conf_OperServerMode;
459 if(Client_OperByMe(Client) && Conf_OperCanMode) {
463 /* Check if client is a server/service */
464 if(Client_Type(Client) == CLIENT_SERVER ||
465 Client_Type(Client) == CLIENT_SERVICE) {
469 /* Check if client is member of channel or an oper or an server/service */
470 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
471 return IRC_WriteStrClient(Origin, ERR_NOTONCHANNEL_MSG,
473 Channel_Name(Channel));
476 mode_ptr = Req->argv[mode_arg];
477 if (Req->argc > mode_arg + 1)
478 arg_arg = mode_arg + 1;
482 /* Initial state: set or unset modes? */
496 /* Prepare reply string */
497 strcpy(the_modes, set ? "+" : "-");
501 connected = CONNECTED;
506 /* Try next argument if there's any */
509 if (arg_arg > mode_arg)
514 if (mode_arg >= Req->argc)
516 mode_ptr = Req->argv[mode_arg];
518 if (Req->argc > mode_arg + 1)
519 arg_arg = mode_arg + 1;
528 if (((*mode_ptr == '+') && !set)
529 || ((*mode_ptr == '-') && set)) {
530 /* Action modifier ("+"/"-") must be changed ... */
531 len = strlen(the_modes) - 1;
532 if (the_modes[len] == '+' || the_modes[len] == '-') {
533 /* Adjust last action modifier in result */
534 the_modes[len] = *mode_ptr;
536 /* Append modifier character to result string */
538 strlcat(the_modes, x, sizeof(the_modes));
540 set = *mode_ptr == '+';
545 /* Are there arguments left? */
546 if (arg_arg >= Req->argc)
549 if(!is_machine && !is_oper) {
550 o_mode_ptr = Channel_UserModes(Channel, Client);
551 while( *o_mode_ptr ) {
552 if ( *o_mode_ptr == 'q')
554 if ( *o_mode_ptr == 'a')
556 if ( *o_mode_ptr == 'o')
558 if ( *o_mode_ptr == 'h')
569 /* --- Channel modes --- */
570 case 'R': /* Registered users only */
571 case 's': /* Secret channel */
572 case 'z': /* Secure connections only */
573 if(!is_oper && !is_machine && !is_owner &&
574 !is_admin && !is_op) {
575 connected = IRC_WriteStrClient(Origin,
576 ERR_CHANOPRIVSNEEDED_MSG,
577 Client_ID(Origin), Channel_Name(Channel));
580 case 'i': /* Invite only */
581 case 'V': /* Invite disallow */
582 case 'M': /* Only identified nicks can write */
583 case 'm': /* Moderated */
584 case 'n': /* Only members can write */
585 case 'Q': /* No kicks */
586 case 't': /* Topic locked */
587 if(is_oper || is_machine || is_owner ||
588 is_admin || is_op || is_halfop)
591 connected = IRC_WriteStrClient(Origin,
592 ERR_CHANOPRIVSNEEDED_MSG,
593 Client_ID(Origin), Channel_Name(Channel));
595 case 'k': /* Channel key */
596 if (Mode_Limit_Reached(Client, mode_arg_count++))
599 if (is_oper || is_machine || is_owner ||
600 is_admin || is_op || is_halfop)
603 connected = IRC_WriteStrClient(Origin,
604 ERR_CHANOPRIVSNEEDED_MSG,
606 Channel_Name(Channel));
609 if (arg_arg > mode_arg) {
610 if (is_oper || is_machine || is_owner ||
611 is_admin || is_op || is_halfop) {
612 Channel_ModeDel(Channel, 'k');
613 Channel_SetKey(Channel,
615 strlcpy(argadd, Channel_Key(Channel),
619 connected = IRC_WriteStrClient(Origin,
620 ERR_CHANOPRIVSNEEDED_MSG,
622 Channel_Name(Channel));
624 Req->argv[arg_arg][0] = '\0';
628 /* Only send error message in "strict" mode,
629 * this is how ircd2.11 and others behave ... */
630 connected = IRC_WriteStrClient(Origin,
631 ERR_NEEDMOREPARAMS_MSG,
632 Client_ID(Origin), Req->command);
637 case 'l': /* Member limit */
638 if (Mode_Limit_Reached(Client, mode_arg_count++))
641 if (is_oper || is_machine || is_owner ||
642 is_admin || is_op || is_halfop)
645 connected = IRC_WriteStrClient(Origin,
646 ERR_CHANOPRIVSNEEDED_MSG,
648 Channel_Name(Channel));
651 if (arg_arg > mode_arg) {
652 if (is_oper || is_machine || is_owner ||
653 is_admin || is_op || is_halfop) {
654 l = atol(Req->argv[arg_arg]);
655 if (l > 0 && l < 0xFFFF) {
656 Channel_ModeDel(Channel, 'l');
657 Channel_SetMaxUsers(Channel, l);
658 snprintf(argadd, sizeof(argadd),
663 connected = IRC_WriteStrClient(Origin,
664 ERR_CHANOPRIVSNEEDED_MSG,
666 Channel_Name(Channel));
668 Req->argv[arg_arg][0] = '\0';
672 /* Only send error message in "strict" mode,
673 * this is how ircd2.11 and others behave ... */
674 connected = IRC_WriteStrClient(Origin,
675 ERR_NEEDMOREPARAMS_MSG,
676 Client_ID(Origin), Req->command);
681 case 'O': /* IRC operators only */
683 /* Only IRC operators are allowed to
684 * set the 'O' channel mode! */
685 if(is_oper || is_machine)
688 connected = IRC_WriteStrClient(Origin,
689 ERR_NOPRIVILEGES_MSG,
691 } else if(is_oper || is_machine || is_owner ||
695 connected = IRC_WriteStrClient(Origin,
696 ERR_CHANOPRIVSNEEDED_MSG,
698 Channel_Name(Channel));
700 case 'P': /* Persistent channel */
702 /* Only IRC operators are allowed to
703 * set the 'P' channel mode! */
704 if(is_oper || is_machine)
707 connected = IRC_WriteStrClient(Origin,
708 ERR_NOPRIVILEGES_MSG,
710 } else if(is_oper || is_machine || is_owner ||
714 connected = IRC_WriteStrClient(Origin,
715 ERR_CHANOPRIVSNEEDED_MSG,
717 Channel_Name(Channel));
719 /* --- Channel user modes --- */
720 case 'q': /* Owner */
721 case 'a': /* Channel admin */
722 if(!is_oper && !is_machine && !is_owner && !is_admin) {
723 connected = IRC_WriteStrClient(Origin,
724 ERR_CHANOPPRIVTOOLOW_MSG,
726 Channel_Name(Channel));
729 case 'o': /* Channel operator */
730 if(!is_oper && !is_machine && !is_owner &&
731 !is_admin && !is_op) {
732 connected = IRC_WriteStrClient(Origin,
733 ERR_CHANOPRIVSNEEDED_MSG,
735 Channel_Name(Channel));
738 case 'h': /* Half Op */
739 if(!is_oper && !is_machine && !is_owner &&
740 !is_admin && !is_op) {
741 connected = IRC_WriteStrClient(Origin,
742 ERR_CHANOPRIVSNEEDED_MSG,
744 Channel_Name(Channel));
747 case 'v': /* Voice */
748 if (arg_arg > mode_arg) {
749 if (is_oper || is_machine || is_owner ||
750 is_admin || is_op || is_halfop) {
751 client = Client_Search(Req->argv[arg_arg]);
755 connected = IRC_WriteStrClient(Origin,
760 connected = IRC_WriteStrClient(Origin,
761 ERR_CHANOPRIVSNEEDED_MSG,
763 Channel_Name(Channel));
765 Req->argv[arg_arg][0] = '\0';
769 /* Report an error to the client, when a user
770 * mode should be changed but no nickname is
771 * given. But don't do it when not in "strict"
772 * mode, because most other servers don't do
773 * it as well and some clients send "wired"
774 * MODE commands like "MODE #chan -ooo nick". */
775 connected = IRC_WriteStrClient(Origin,
776 ERR_NEEDMOREPARAMS_MSG,
777 Client_ID(Origin), Req->command);
782 /* --- Channel lists --- */
783 case 'I': /* Invite lists */
784 case 'b': /* Ban lists */
785 case 'e': /* Channel exception lists */
786 if (Mode_Limit_Reached(Client, mode_arg_count++))
788 if (arg_arg > mode_arg) {
790 if (is_oper || is_machine || is_owner ||
791 is_admin || is_op || is_halfop) {
793 ? Add_To_List(*mode_ptr, Origin,
796 : Del_From_List(*mode_ptr, Origin,
800 connected = IRC_WriteStrClient(Origin,
801 ERR_CHANOPRIVSNEEDED_MSG,
803 Channel_Name(Channel));
805 Req->argv[arg_arg][0] = '\0';
810 Channel_ShowInvites(Origin, Channel);
813 Channel_ShowBans(Origin, Channel);
816 Channel_ShowExcepts(Origin, Channel);
822 if (Client_Type(Client) != CLIENT_SERVER) {
824 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
825 set ? '+' : '-', *mode_ptr,
826 Client_ID(Origin), Channel_Name(Channel));
827 connected = IRC_WriteStrClient(Origin,
829 Client_ID(Origin), *mode_ptr,
830 Channel_Name(Channel));
834 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
835 set ? '+' : '-', *mode_ptr,
836 Client_ID(Origin), Channel_Name(Channel));
844 /* Is there a valid mode change? */
848 /* Validate target client */
849 if (client && (!Channel_IsMemberOf(Channel, client))) {
850 if (!IRC_WriteStrClient
851 (Origin, ERR_USERNOTINCHANNEL_MSG,
852 Client_ID(Origin), Client_ID(client),
853 Channel_Name(Channel)))
860 /* Channel-User-Mode */
862 ? Channel_UserModeAdd(Channel, client, x[0])
863 : Channel_UserModeDel(Channel, client, x[0]);
865 strlcat(the_args, " ", sizeof(the_args));
866 strlcat(the_args, Client_ID(client),
868 strlcat(the_modes, x, sizeof(the_modes));
870 ("User \"%s\": Mode change on %s, now \"%s\"",
871 Client_Mask(client), Channel_Name(Channel),
872 Channel_UserModes(Channel, client));
877 ? Channel_ModeAdd(Channel, x[0])
878 : Channel_ModeDel(Channel, x[0]);
880 strlcat(the_modes, x, sizeof(the_modes));
881 LogDebug("Channel %s: Mode change, now \"%s\".",
882 Channel_Name(Channel),
883 Channel_Modes(Channel));
887 /* Are there additional arguments to add? */
889 strlcat(the_args, " ", sizeof(the_args));
890 strlcat(the_args, argadd, sizeof(the_args));
895 /* Are there changed modes? */
897 /* Clean up mode string */
898 len = strlen(the_modes) - 1;
899 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
900 the_modes[len] = '\0';
902 if (Client_Type(Client) == CLIENT_SERVER) {
903 /* MODE requests for local channels from other servers
904 * are definitely invalid! */
905 if (Channel_IsLocal(Channel)) {
906 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
910 /* Forward mode changes to channel users and all the
911 * other remote servers: */
912 IRC_WriteStrServersPrefix(Client, Origin,
913 "MODE %s %s%s", Channel_Name(Channel),
914 the_modes, the_args);
915 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
916 false, "MODE %s %s%s", Channel_Name(Channel),
917 the_modes, the_args);
920 Origin = Client_ThisServer();
921 /* Send reply to client and inform other servers and channel users */
922 connected = IRC_WriteStrClientPrefix(Client, Origin,
923 "MODE %s %s%s", Channel_Name(Channel),
924 the_modes, the_args);
925 /* Only forward requests for non-local channels */
926 if (!Channel_IsLocal(Channel))
927 IRC_WriteStrServersPrefix(Client, Origin,
928 "MODE %s %s%s", Channel_Name(Channel),
929 the_modes, the_args);
930 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
931 false, "MODE %s %s%s", Channel_Name(Channel),
932 the_modes, the_args);
936 IRC_SetPenalty(Client, 1);
941 * Handler for the IRC "AWAY" command.
943 * @param Client The client from which this command has been received.
944 * @param Req Request structure with prefix and all parameters.
945 * @return CONNECTED or DISCONNECTED.
948 IRC_AWAY( CLIENT *Client, REQUEST *Req )
950 assert (Client != NULL);
951 assert (Req != NULL);
953 _IRC_ARGC_LE_OR_RETURN_(Client, Req, 1)
955 if (Req->argc == 1 && Req->argv[0][0]) {
956 Client_SetAway(Client, Req->argv[0]);
957 Client_ModeAdd(Client, 'a');
958 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :+a",
960 return IRC_WriteStrClient(Client, RPL_NOWAWAY_MSG,
963 Client_ModeDel(Client, 'a');
964 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :-a",
966 return IRC_WriteStrClient(Client, RPL_UNAWAY_MSG,
972 * Add entries to channel invite, ban and exception lists.
974 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
975 * @param Prefix The originator of the command.
976 * @param Client The sender of the command.
977 * @param Channel The channel of which the list should be modified.
978 * @param Pattern The pattern to add to the list.
979 * @return CONNECTED or DISCONNECTED.
982 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
986 struct list_head *list = NULL;
987 long int current_count;
989 assert(Client != NULL);
990 assert(Channel != NULL);
991 assert(Pattern != NULL);
992 assert(what == 'I' || what == 'b' || what == 'e');
994 Lists_MakeMask(Pattern, mask, sizeof(mask));
995 current_count = Lists_Count(Channel_GetListInvites(Channel))
996 + Lists_Count(Channel_GetListExcepts(Channel))
997 + Lists_Count(Channel_GetListBans(Channel));
1001 list = Channel_GetListInvites(Channel);
1004 list = Channel_GetListBans(Channel);
1007 list = Channel_GetListExcepts(Channel);
1011 if (Lists_CheckDupeMask(list, mask))
1013 if (Client_Type(Client) == CLIENT_USER &&
1014 current_count >= MAX_HNDL_CHANNEL_LISTS)
1015 return IRC_WriteStrClient(Client, ERR_LISTFULL_MSG,
1017 Channel_Name(Channel), mask,
1018 MAX_HNDL_CHANNEL_LISTS);
1022 if (!Channel_AddInvite(Channel, mask, false))
1026 if (!Channel_AddBan(Channel, mask))
1030 if (!Channel_AddExcept(Channel, mask))
1034 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1038 * Delete entries from channel invite, ban and exception lists.
1040 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1041 * @param Prefix The originator of the command.
1042 * @param Client The sender of the command.
1043 * @param Channel The channel of which the list should be modified.
1044 * @param Pattern The pattern to add to the list.
1045 * @return CONNECTED or DISCONNECTED.
1048 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1049 const char *Pattern)
1051 char mask[MASK_LEN];
1052 struct list_head *list = NULL;
1054 assert(Client != NULL);
1055 assert(Channel != NULL);
1056 assert(Pattern != NULL);
1057 assert(what == 'I' || what == 'b' || what == 'e');
1059 Lists_MakeMask(Pattern, mask, sizeof(mask));
1063 list = Channel_GetListInvites(Channel);
1066 list = Channel_GetListBans(Channel);
1069 list = Channel_GetListExcepts(Channel);
1073 if (!Lists_CheckDupeMask(list, mask))
1075 Lists_Del(list, mask);
1077 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1081 * Send information about changed channel invite/ban/exception lists to clients.
1083 * @param IsAdd true if the list item has been added, false otherwise.
1084 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1085 * @param Prefix The originator of the mode list change.
1086 * @param Client The sender of the command.
1087 * @param Channel The channel of which the list has been modified.
1088 * @param Mask The mask which has been added or removed.
1089 * @return CONNECTED or DISCONNECTED.
1092 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1093 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1097 /* Send confirmation to the client */
1098 if (Client_Type(Client) == CLIENT_USER)
1099 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1100 Channel_Name(Channel),
1104 /* to other servers */
1105 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1106 Channel_Name(Channel), IsAdd ? '+' : '-',
1109 /* and local users in channel */
1110 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1111 "MODE %s %c%c %s", Channel_Name(Channel),
1112 IsAdd ? '+' : '-', ModeChar, Mask );
1115 } /* Send_ListChange */