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_WriteErrClient(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_WriteErrClient(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_WriteErrClient(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_WriteErrClient(Origin,
216 ERR_NOPRIVILEGES_MSG,
220 if (Client_HasMode(Client, 'r'))
221 ok = IRC_WriteErrClient(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_WriteErrClient(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_WriteErrClient(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_WriteErrClient(Origin,
252 ERR_NOPRIVILEGES_MSG,
255 case 'r': /* Restricted (only settable) */
256 if (set || Client_Type(Client) == CLIENT_SERVER)
259 ok = IRC_WriteErrClient(Origin,
263 case 'R': /* Registered (not [un]settable by clients) */
264 if (Client_Type(Client) == CLIENT_SERVER)
267 ok = IRC_WriteErrClient(Origin,
268 ERR_NICKREGISTER_MSG,
271 case 'x': /* Cloak hostname */
272 if (Client_HasMode(Client, 'r'))
273 ok = IRC_WriteErrClient(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_WriteErrClient(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_WriteErrClient(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;
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_WriteErrClient(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_WriteErrClient(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 if (Channel_UserHasMode(Channel, Client, 'q'))
552 if (Channel_UserHasMode(Channel, Client, 'a'))
554 if (Channel_UserHasMode(Channel, Client, 'o'))
556 if (Channel_UserHasMode(Channel, Client, 'h'))
565 /* --- Channel modes --- */
566 case 'R': /* Registered users only */
567 case 's': /* Secret channel */
568 case 'z': /* Secure connections only */
569 if(!is_oper && !is_machine && !is_owner &&
570 !is_admin && !is_op) {
571 connected = IRC_WriteErrClient(Origin,
572 ERR_CHANOPRIVSNEEDED_MSG,
573 Client_ID(Origin), Channel_Name(Channel));
576 case 'i': /* Invite only */
577 case 'V': /* Invite disallow */
578 case 'M': /* Only identified nicks can write */
579 case 'm': /* Moderated */
580 case 'n': /* Only members can write */
581 case 'Q': /* No kicks */
582 case 't': /* Topic locked */
583 if(is_oper || is_machine || is_owner ||
584 is_admin || is_op || is_halfop)
587 connected = IRC_WriteErrClient(Origin,
588 ERR_CHANOPRIVSNEEDED_MSG,
589 Client_ID(Origin), Channel_Name(Channel));
591 case 'k': /* Channel key */
592 if (Mode_Limit_Reached(Client, mode_arg_count++))
595 if (is_oper || is_machine || is_owner ||
596 is_admin || is_op || is_halfop)
599 connected = IRC_WriteErrClient(Origin,
600 ERR_CHANOPRIVSNEEDED_MSG,
602 Channel_Name(Channel));
605 if (arg_arg > mode_arg) {
606 if (is_oper || is_machine || is_owner ||
607 is_admin || is_op || is_halfop) {
608 Channel_ModeDel(Channel, 'k');
609 Channel_SetKey(Channel,
611 strlcpy(argadd, Channel_Key(Channel),
615 connected = IRC_WriteErrClient(Origin,
616 ERR_CHANOPRIVSNEEDED_MSG,
618 Channel_Name(Channel));
620 Req->argv[arg_arg][0] = '\0';
624 /* Only send error message in "strict" mode,
625 * this is how ircd2.11 and others behave ... */
626 connected = IRC_WriteErrClient(Origin,
627 ERR_NEEDMOREPARAMS_MSG,
628 Client_ID(Origin), Req->command);
633 case 'l': /* Member limit */
634 if (Mode_Limit_Reached(Client, mode_arg_count++))
637 if (is_oper || is_machine || is_owner ||
638 is_admin || is_op || is_halfop)
641 connected = IRC_WriteErrClient(Origin,
642 ERR_CHANOPRIVSNEEDED_MSG,
644 Channel_Name(Channel));
647 if (arg_arg > mode_arg) {
648 if (is_oper || is_machine || is_owner ||
649 is_admin || is_op || is_halfop) {
650 l = atol(Req->argv[arg_arg]);
651 if (l > 0 && l < 0xFFFF) {
652 Channel_ModeDel(Channel, 'l');
653 Channel_SetMaxUsers(Channel, l);
654 snprintf(argadd, sizeof(argadd),
659 connected = IRC_WriteErrClient(Origin,
660 ERR_CHANOPRIVSNEEDED_MSG,
662 Channel_Name(Channel));
664 Req->argv[arg_arg][0] = '\0';
668 /* Only send error message in "strict" mode,
669 * this is how ircd2.11 and others behave ... */
670 connected = IRC_WriteErrClient(Origin,
671 ERR_NEEDMOREPARAMS_MSG,
672 Client_ID(Origin), Req->command);
677 case 'O': /* IRC operators only */
679 /* Only IRC operators are allowed to
680 * set the 'O' channel mode! */
681 if(is_oper || is_machine)
684 connected = IRC_WriteErrClient(Origin,
685 ERR_NOPRIVILEGES_MSG,
687 } else if(is_oper || is_machine || is_owner ||
691 connected = IRC_WriteErrClient(Origin,
692 ERR_CHANOPRIVSNEEDED_MSG,
694 Channel_Name(Channel));
696 case 'P': /* Persistent channel */
698 /* Only IRC operators are allowed to
699 * set the 'P' channel mode! */
700 if(is_oper || is_machine)
703 connected = IRC_WriteErrClient(Origin,
704 ERR_NOPRIVILEGES_MSG,
706 } else if(is_oper || is_machine || is_owner ||
710 connected = IRC_WriteErrClient(Origin,
711 ERR_CHANOPRIVSNEEDED_MSG,
713 Channel_Name(Channel));
715 /* --- Channel user modes --- */
716 case 'q': /* Owner */
717 case 'a': /* Channel admin */
718 if(!is_oper && !is_machine && !is_owner && !is_admin) {
719 connected = IRC_WriteErrClient(Origin,
720 ERR_CHANOPPRIVTOOLOW_MSG,
722 Channel_Name(Channel));
725 case 'o': /* Channel operator */
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 'h': /* Half Op */
735 if(!is_oper && !is_machine && !is_owner &&
736 !is_admin && !is_op) {
737 connected = IRC_WriteErrClient(Origin,
738 ERR_CHANOPRIVSNEEDED_MSG,
740 Channel_Name(Channel));
743 case 'v': /* Voice */
744 if (arg_arg > mode_arg) {
745 if (is_oper || is_machine || is_owner ||
746 is_admin || is_op || is_halfop) {
747 client = Client_Search(Req->argv[arg_arg]);
751 connected = IRC_WriteErrClient(Origin,
756 connected = IRC_WriteErrClient(Origin,
757 ERR_CHANOPRIVSNEEDED_MSG,
759 Channel_Name(Channel));
761 Req->argv[arg_arg][0] = '\0';
765 /* Report an error to the client, when a user
766 * mode should be changed but no nickname is
767 * given. But don't do it when not in "strict"
768 * mode, because most other servers don't do
769 * it as well and some clients send "wired"
770 * MODE commands like "MODE #chan -ooo nick". */
771 connected = IRC_WriteErrClient(Origin,
772 ERR_NEEDMOREPARAMS_MSG,
773 Client_ID(Origin), Req->command);
778 /* --- Channel lists --- */
779 case 'I': /* Invite lists */
780 case 'b': /* Ban lists */
781 case 'e': /* Channel exception lists */
782 if (Mode_Limit_Reached(Client, mode_arg_count++))
784 if (arg_arg > mode_arg) {
786 if (is_oper || is_machine || is_owner ||
787 is_admin || is_op || is_halfop) {
789 ? Add_To_List(*mode_ptr, Origin,
792 : Del_From_List(*mode_ptr, Origin,
796 connected = IRC_WriteErrClient(Origin,
797 ERR_CHANOPRIVSNEEDED_MSG,
799 Channel_Name(Channel));
801 Req->argv[arg_arg][0] = '\0';
806 Channel_ShowInvites(Origin, Channel);
809 Channel_ShowBans(Origin, Channel);
812 Channel_ShowExcepts(Origin, Channel);
818 if (Client_Type(Client) != CLIENT_SERVER) {
820 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
821 set ? '+' : '-', *mode_ptr,
822 Client_ID(Origin), Channel_Name(Channel));
823 connected = IRC_WriteErrClient(Origin,
825 Client_ID(Origin), *mode_ptr,
826 Channel_Name(Channel));
830 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
831 set ? '+' : '-', *mode_ptr,
832 Client_ID(Origin), Channel_Name(Channel));
840 /* Is there a valid mode change? */
844 /* Validate target client */
845 if (client && (!Channel_IsMemberOf(Channel, client))) {
846 if (!IRC_WriteErrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
849 Channel_Name(Channel)))
855 /* Channel-User-Mode */
857 ? Channel_UserModeAdd(Channel, client, x[0])
858 : Channel_UserModeDel(Channel, client, x[0]);
860 strlcat(the_args, " ", sizeof(the_args));
861 strlcat(the_args, Client_ID(client),
863 strlcat(the_modes, x, sizeof(the_modes));
865 ("User \"%s\": Mode change on %s, now \"%s\"",
866 Client_Mask(client), Channel_Name(Channel),
867 Channel_UserModes(Channel, client));
872 ? Channel_ModeAdd(Channel, x[0])
873 : Channel_ModeDel(Channel, x[0]);
875 strlcat(the_modes, x, sizeof(the_modes));
876 LogDebug("Channel %s: Mode change, now \"%s\".",
877 Channel_Name(Channel),
878 Channel_Modes(Channel));
882 /* Are there additional arguments to add? */
884 strlcat(the_args, " ", sizeof(the_args));
885 strlcat(the_args, argadd, sizeof(the_args));
890 /* Are there changed modes? */
892 /* Clean up mode string */
893 len = strlen(the_modes) - 1;
894 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
895 the_modes[len] = '\0';
897 if (Client_Type(Client) == CLIENT_SERVER) {
898 /* MODE requests for local channels from other servers
899 * are definitely invalid! */
900 if (Channel_IsLocal(Channel)) {
901 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
905 /* Forward mode changes to channel users and all the
906 * other remote servers: */
907 IRC_WriteStrServersPrefix(Client, Origin,
908 "MODE %s %s%s", Channel_Name(Channel),
909 the_modes, the_args);
910 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
911 false, "MODE %s %s%s", Channel_Name(Channel),
912 the_modes, the_args);
915 Origin = Client_ThisServer();
916 /* Send reply to client and inform other servers and channel users */
917 connected = IRC_WriteStrClientPrefix(Client, Origin,
918 "MODE %s %s%s", Channel_Name(Channel),
919 the_modes, the_args);
920 /* Only forward requests for non-local channels */
921 if (!Channel_IsLocal(Channel))
922 IRC_WriteStrServersPrefix(Client, Origin,
923 "MODE %s %s%s", Channel_Name(Channel),
924 the_modes, the_args);
925 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
926 false, "MODE %s %s%s", Channel_Name(Channel),
927 the_modes, the_args);
931 IRC_SetPenalty(Client, 1);
936 * Handler for the IRC "AWAY" command.
938 * @param Client The client from which this command has been received.
939 * @param Req Request structure with prefix and all parameters.
940 * @return CONNECTED or DISCONNECTED.
943 IRC_AWAY( CLIENT *Client, REQUEST *Req )
945 assert (Client != NULL);
946 assert (Req != NULL);
948 _IRC_ARGC_LE_OR_RETURN_(Client, Req, 1)
950 if (Req->argc == 1 && Req->argv[0][0]) {
951 Client_SetAway(Client, Req->argv[0]);
952 Client_ModeAdd(Client, 'a');
953 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :+a",
955 return IRC_WriteStrClient(Client, RPL_NOWAWAY_MSG,
958 Client_ModeDel(Client, 'a');
959 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :-a",
961 return IRC_WriteStrClient(Client, RPL_UNAWAY_MSG,
967 * Add entries to channel invite, ban and exception lists.
969 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
970 * @param Prefix The originator of the command.
971 * @param Client The sender of the command.
972 * @param Channel The channel of which the list should be modified.
973 * @param Pattern The pattern to add to the list.
974 * @return CONNECTED or DISCONNECTED.
977 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
981 struct list_head *list = NULL;
982 long int current_count;
984 assert(Client != NULL);
985 assert(Channel != NULL);
986 assert(Pattern != NULL);
987 assert(what == 'I' || what == 'b' || what == 'e');
989 Lists_MakeMask(Pattern, mask, sizeof(mask));
990 current_count = Lists_Count(Channel_GetListInvites(Channel))
991 + Lists_Count(Channel_GetListExcepts(Channel))
992 + Lists_Count(Channel_GetListBans(Channel));
996 list = Channel_GetListInvites(Channel);
999 list = Channel_GetListBans(Channel);
1002 list = Channel_GetListExcepts(Channel);
1006 if (Lists_CheckDupeMask(list, mask))
1008 if (Client_Type(Client) == CLIENT_USER &&
1009 current_count >= MAX_HNDL_CHANNEL_LISTS)
1010 return IRC_WriteErrClient(Client, ERR_LISTFULL_MSG,
1012 Channel_Name(Channel), mask,
1013 MAX_HNDL_CHANNEL_LISTS);
1017 if (!Channel_AddInvite(Channel, mask, false))
1021 if (!Channel_AddBan(Channel, mask))
1025 if (!Channel_AddExcept(Channel, mask))
1029 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1033 * Delete entries from channel invite, ban and exception lists.
1035 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1036 * @param Prefix The originator of the command.
1037 * @param Client The sender of the command.
1038 * @param Channel The channel of which the list should be modified.
1039 * @param Pattern The pattern to add to the list.
1040 * @return CONNECTED or DISCONNECTED.
1043 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1044 const char *Pattern)
1046 char mask[MASK_LEN];
1047 struct list_head *list = NULL;
1049 assert(Client != NULL);
1050 assert(Channel != NULL);
1051 assert(Pattern != NULL);
1052 assert(what == 'I' || what == 'b' || what == 'e');
1054 Lists_MakeMask(Pattern, mask, sizeof(mask));
1058 list = Channel_GetListInvites(Channel);
1061 list = Channel_GetListBans(Channel);
1064 list = Channel_GetListExcepts(Channel);
1068 if (!Lists_CheckDupeMask(list, mask))
1070 Lists_Del(list, mask);
1072 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1076 * Send information about changed channel invite/ban/exception lists to clients.
1078 * @param IsAdd true if the list item has been added, false otherwise.
1079 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1080 * @param Prefix The originator of the mode list change.
1081 * @param Client The sender of the command.
1082 * @param Channel The channel of which the list has been modified.
1083 * @param Mask The mask which has been added or removed.
1084 * @return CONNECTED or DISCONNECTED.
1087 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1088 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1092 /* Send confirmation to the client */
1093 if (Client_Type(Client) == CLIENT_USER)
1094 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1095 Channel_Name(Channel),
1099 /* to other servers */
1100 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1101 Channel_Name(Channel), IsAdd ? '+' : '-',
1104 /* and local users in channel */
1105 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1106 "MODE %s %c%c %s", Channel_Name(Channel),
1107 IsAdd ? '+' : '-', ModeChar, Mask );
1110 } /* Send_ListChange */