2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
16 * IRC commands for mode changes (like MODE, AWAY, etc.)
28 #include "irc-macros.h"
29 #include "irc-write.h"
39 static bool Client_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
41 static bool Channel_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
44 static bool Add_To_List PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
45 CHANNEL *Channel, const char *Pattern));
46 static bool Del_From_List PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
47 CHANNEL *Channel, const char *Pattern));
49 static bool Send_ListChange PARAMS((const bool IsAdd, const char ModeChar,
50 CLIENT *Prefix, CLIENT *Client,
51 CHANNEL *Channel, const char *Mask));
54 * Handler for the IRC "MODE" command.
56 * This function detects whether user or channel modes should be modified
57 * and calls the appropriate sub-functions.
59 * @param Client The client from which this command has been received.
60 * @param Req Request structure with prefix and all parameters.
61 * @return CONNECTED or DISCONNECTED.
64 IRC_MODE( CLIENT *Client, REQUEST *Req )
69 assert(Client != NULL);
72 _IRC_GET_SENDER_OR_RETURN_(origin, Req, Client)
74 /* Channel or user mode? */
75 cl = NULL; chan = NULL;
76 if (Client_IsValidNick(Req->argv[0]))
77 cl = Client_Search(Req->argv[0]);
78 if (Channel_IsValidName(Req->argv[0]))
79 chan = Channel_Search(Req->argv[0]);
82 return Client_Mode(Client, Req, origin, cl);
84 return Channel_Mode(Client, Req, origin, chan);
86 /* No target found! */
87 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
88 Client_ID(Client), Req->argv[0]);
92 * Check if the "mode limit" for a client has been reached.
94 * This limit doesn't apply for servers or services!
96 * @param Client The client to check.
97 * @param Count The number of modes already handled.
98 * @return true if the limit has been reached.
101 Mode_Limit_Reached(CLIENT *Client, int Count)
103 if (Client_Type(Client) == CLIENT_SERVER
104 || Client_Type(Client) == CLIENT_SERVICE)
106 if (Count < MAX_HNDL_MODES_ARG)
112 * Handle client mode requests
114 * @param Client The client from which this command has been received.
115 * @param Req Request structure with prefix and all parameters.
116 * @param Origin The originator of the MODE command (prefix).
117 * @param Target The target (client) of this MODE command.
118 * @return CONNECTED or DISCONNECTED.
121 Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
123 char the_modes[COMMAND_LEN], x[2], *mode_ptr;
125 bool send_RPL_HOSTHIDDEN_MSG = false;
129 /* Is the client allowed to request or change the modes? */
130 if (Client_Type(Client) == CLIENT_USER) {
131 /* Users are only allowed to manipulate their own modes! */
132 if (Target != Client)
133 return IRC_WriteErrClient(Client,
134 ERR_USERSDONTMATCH_MSG,
138 /* Mode request: let's answer it :-) */
140 return IRC_WriteStrClient(Origin, RPL_UMODEIS_MSG,
142 Client_Modes(Target));
145 mode_ptr = Req->argv[mode_arg];
147 /* Initial state: set or unset modes? */
148 if (*mode_ptr == '+') {
150 strcpy(the_modes, "+");
151 } else if (*mode_ptr == '-') {
153 strcpy(the_modes, "-");
155 return IRC_WriteErrClient(Origin, ERR_UMODEUNKNOWNFLAG_MSG,
163 /* Try next argument if there's any */
165 if (mode_arg < Req->argc)
166 mode_ptr = Req->argv[mode_arg];
174 if ((*mode_ptr == '+' && !set)
175 || (*mode_ptr == '-' && set)) {
176 /* Action modifier ("+"/"-") must be changed */
177 len = strlen(the_modes) - 1;
178 if (the_modes[len] == '+'
179 || the_modes[len] == '-') {
180 /* Last character in the "result
181 * string" was an "action", so just
182 * overwrite it with the new action */
183 the_modes[len] = *mode_ptr;
185 /* Append new modifier character to
186 * the resulting mode string */
188 strlcat(the_modes, x,
191 if (*mode_ptr == '+')
202 case 'b': /* Block private msgs */
203 case 'C': /* Only messages from clients sharing a channel */
204 case 'i': /* Invisible */
205 case 's': /* Server messages */
206 case 'w': /* Wallops messages */
210 if (Client_Type(Client) == CLIENT_SERVER) {
212 Client_SetAway(Origin, DEFAULT_AWAY_MSG);
214 ok = IRC_WriteErrClient(Origin,
215 ERR_NOPRIVILEGES_MSG,
219 if (Client_HasMode(Client, 'r'))
220 ok = IRC_WriteErrClient(Origin,
226 case 'c': /* Receive connect notices
227 * (only settable by IRC operators!) */
228 if (!set || Client_Type(Client) == CLIENT_SERVER
229 || Client_OperByMe(Origin))
232 ok = IRC_WriteErrClient(Origin,
233 ERR_NOPRIVILEGES_MSG,
236 case 'o': /* IRC operator (only unsettable!) */
237 if (!set || Client_Type(Client) == CLIENT_SERVER) {
238 Client_SetOperByMe(Target, false);
241 ok = IRC_WriteErrClient(Origin,
242 ERR_NOPRIVILEGES_MSG,
245 case 'q': /* KICK-protected user */
246 if (!set || Client_Type(Client) == CLIENT_SERVER
247 || Client_OperByMe(Origin))
250 ok = IRC_WriteErrClient(Origin,
251 ERR_NOPRIVILEGES_MSG,
254 case 'r': /* Restricted (only settable) */
255 if (set || Client_Type(Client) == CLIENT_SERVER)
258 ok = IRC_WriteErrClient(Origin,
262 case 'R': /* Registered (not [un]settable by clients) */
263 if (Client_Type(Client) == CLIENT_SERVER)
266 ok = IRC_WriteErrClient(Origin,
267 ERR_NICKREGISTER_MSG,
270 case 'x': /* Cloak hostname */
271 if (Client_HasMode(Client, 'r'))
272 ok = IRC_WriteErrClient(Origin,
275 else if (!set || Conf_CloakHostModeX[0]
276 || Client_Type(Client) == CLIENT_SERVER
277 || Client_OperByMe(Client)) {
279 send_RPL_HOSTHIDDEN_MSG = true;
281 ok = IRC_WriteErrClient(Origin,
282 ERR_NOPRIVILEGES_MSG,
286 if (Client_Type(Client) != CLIENT_SERVER) {
288 "Unknown mode \"%c%c\" from \"%s\"!?",
289 set ? '+' : '-', *mode_ptr,
291 ok = IRC_WriteErrClient(Origin,
292 ERR_UMODEUNKNOWNFLAG2_MSG,
299 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
300 set ? '+' : '-', *mode_ptr,
301 Client_ID(Origin), Client_ID(Target));
309 /* Is there a valid mode change? */
314 if (Client_ModeAdd(Target, x[0]))
315 strlcat(the_modes, x, sizeof(the_modes));
317 if (Client_ModeDel(Target, x[0]))
318 strlcat(the_modes, x, sizeof(the_modes));
322 /* Are there changed modes? */
324 /* Remove needless action modifier characters */
325 len = strlen(the_modes) - 1;
326 if (the_modes[len] == '+' || the_modes[len] == '-')
327 the_modes[len] = '\0';
329 if (Client_Type(Client) == CLIENT_SERVER) {
330 /* Forward modes to other servers */
331 if (Client_Conn(Target) != NONE) {
332 /* Remote server (service?) changed modes
333 * for one of our clients. Inform it! */
334 IRC_WriteStrClientPrefix(Target, Origin,
339 IRC_WriteStrServersPrefix(Client, Origin,
344 /* Send reply to client and inform other servers */
345 ok = IRC_WriteStrClientPrefix(Client, Origin,
349 IRC_WriteStrServersPrefix(Client, Origin,
355 if (send_RPL_HOSTHIDDEN_MSG && Client_Conn(Target) > NONE) {
356 /* A new (cloaked) hostname must be announced */
357 IRC_WriteStrClientPrefix(Target, Origin,
360 Client_HostnameDisplayed(Target));
364 LogDebug("%s \"%s\": Mode change, now \"%s\".",
365 Client_TypeText(Target), Client_Mask(Target),
366 Client_Modes(Target));
369 IRC_SetPenalty(Client, 1);
374 * Reply to a channel mode request.
376 * @param Origin The originator of the MODE command (prefix).
377 * @param Channel The channel of which the modes should be sent.
378 * @return CONNECTED or DISCONNECTED.
381 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
383 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
384 const char *mode_ptr;
386 /* Member or not? -- That's the question! */
387 if (!Channel_IsMemberOf(Channel, Origin))
388 return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
389 Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
391 /* The sender is a member: generate extended reply */
392 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
393 mode_ptr = the_modes;
399 snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
400 strlcat(the_args, argadd, sizeof(the_args));
403 strlcat(the_args, " ", sizeof(the_args));
404 strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
410 strlcat(the_modes, the_args, sizeof(the_modes));
412 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
413 Client_ID(Origin), Channel_Name(Channel),
417 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
418 Client_ID(Origin), Channel_Name(Channel),
419 Channel_CreationTime(Channel)))
426 * Handle channel mode and channel-user mode changes
428 * @param Client The client from which this command has been received.
429 * @param Req Request structure with prefix and all parameters.
430 * @param Origin The originator of the MODE command (prefix).
431 * @param Channel The target channel of this MODE command.
432 * @return CONNECTED or DISCONNECTED.
435 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
437 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
438 argadd[CLIENT_PASS_LEN], *mode_ptr;
439 bool connected, set, skiponce, retval, use_servermode,
440 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
441 int mode_arg, arg_arg, mode_arg_count = 0;
446 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
448 if (Channel_IsModeless(Channel))
449 return IRC_WriteErrClient(Client, ERR_NOCHANMODES_MSG,
450 Client_ID(Client), Channel_Name(Channel));
452 /* Mode request: let's answer it :-) */
454 return Channel_Mode_Answer_Request(Origin, Channel);
456 /* Check if origin is oper and opers can use mode */
457 use_servermode = Conf_OperServerMode;
458 if(Client_OperByMe(Client) && Conf_OperCanMode) {
462 /* Check if client is a server/service */
463 if(Client_Type(Client) == CLIENT_SERVER ||
464 Client_Type(Client) == CLIENT_SERVICE) {
468 /* Check if client is member of channel or an oper or an server/service */
469 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
470 return IRC_WriteErrClient(Origin, ERR_NOTONCHANNEL_MSG,
472 Channel_Name(Channel));
475 mode_ptr = Req->argv[mode_arg];
476 if (Req->argc > mode_arg + 1)
477 arg_arg = mode_arg + 1;
481 /* Initial state: set or unset modes? */
495 /* Prepare reply string */
496 strcpy(the_modes, set ? "+" : "-");
500 connected = CONNECTED;
505 /* Try next argument if there's any */
508 if (arg_arg > mode_arg)
513 if (mode_arg >= Req->argc)
515 mode_ptr = Req->argv[mode_arg];
517 if (Req->argc > mode_arg + 1)
518 arg_arg = mode_arg + 1;
527 if (((*mode_ptr == '+') && !set)
528 || ((*mode_ptr == '-') && set)) {
529 /* Action modifier ("+"/"-") must be changed ... */
530 len = strlen(the_modes) - 1;
531 if (the_modes[len] == '+' || the_modes[len] == '-') {
532 /* Adjust last action modifier in result */
533 the_modes[len] = *mode_ptr;
535 /* Append modifier character to result string */
537 strlcat(the_modes, x, sizeof(the_modes));
539 set = *mode_ptr == '+';
544 /* Are there arguments left? */
545 if (arg_arg >= Req->argc)
548 if(!is_machine && !is_oper) {
549 if (Channel_UserHasMode(Channel, Client, 'q'))
551 if (Channel_UserHasMode(Channel, Client, 'a'))
553 if (Channel_UserHasMode(Channel, Client, 'o'))
555 if (Channel_UserHasMode(Channel, Client, 'h'))
564 /* --- Channel modes --- */
565 case 'R': /* Registered users only */
566 case 's': /* Secret channel */
567 case 'z': /* Secure connections only */
568 if(!is_oper && !is_machine && !is_owner &&
569 !is_admin && !is_op) {
570 connected = IRC_WriteErrClient(Origin,
571 ERR_CHANOPRIVSNEEDED_MSG,
572 Client_ID(Origin), Channel_Name(Channel));
575 case 'i': /* Invite only */
576 case 'V': /* Invite disallow */
577 case 'M': /* Only identified nicks can write */
578 case 'm': /* Moderated */
579 case 'n': /* Only members can write */
580 case 'Q': /* No kicks */
581 case 't': /* Topic locked */
582 if(is_oper || is_machine || is_owner ||
583 is_admin || is_op || is_halfop)
586 connected = IRC_WriteErrClient(Origin,
587 ERR_CHANOPRIVSNEEDED_MSG,
588 Client_ID(Origin), Channel_Name(Channel));
590 case 'k': /* Channel key */
591 if (Mode_Limit_Reached(Client, mode_arg_count++))
594 if (is_oper || is_machine || is_owner ||
595 is_admin || is_op || is_halfop)
598 connected = IRC_WriteErrClient(Origin,
599 ERR_CHANOPRIVSNEEDED_MSG,
601 Channel_Name(Channel));
604 if (arg_arg > mode_arg) {
605 if (is_oper || is_machine || is_owner ||
606 is_admin || is_op || is_halfop) {
607 Channel_ModeDel(Channel, 'k');
608 Channel_SetKey(Channel,
610 strlcpy(argadd, Channel_Key(Channel),
614 connected = IRC_WriteErrClient(Origin,
615 ERR_CHANOPRIVSNEEDED_MSG,
617 Channel_Name(Channel));
619 Req->argv[arg_arg][0] = '\0';
623 /* Only send error message in "strict" mode,
624 * this is how ircd2.11 and others behave ... */
625 IRC_SetPenalty(Origin, 2);
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 IRC_SetPenalty(Origin, 2);
671 connected = IRC_WriteErrClient(Origin,
672 ERR_NEEDMOREPARAMS_MSG,
673 Client_ID(Origin), Req->command);
678 case 'O': /* IRC operators only */
680 /* Only IRC operators are allowed to
681 * set the 'O' channel mode! */
682 if(is_oper || is_machine)
685 connected = IRC_WriteErrClient(Origin,
686 ERR_NOPRIVILEGES_MSG,
688 } else if(is_oper || is_machine || is_owner ||
692 connected = IRC_WriteErrClient(Origin,
693 ERR_CHANOPRIVSNEEDED_MSG,
695 Channel_Name(Channel));
697 case 'P': /* Persistent channel */
699 /* Only IRC operators are allowed to
700 * set the 'P' channel mode! */
701 if(is_oper || is_machine)
704 connected = IRC_WriteErrClient(Origin,
705 ERR_NOPRIVILEGES_MSG,
707 } else if(is_oper || is_machine || is_owner ||
711 connected = IRC_WriteErrClient(Origin,
712 ERR_CHANOPRIVSNEEDED_MSG,
714 Channel_Name(Channel));
716 /* --- Channel user modes --- */
717 case 'q': /* Owner */
718 case 'a': /* Channel admin */
719 if(!is_oper && !is_machine && !is_owner && !is_admin) {
720 connected = IRC_WriteErrClient(Origin,
721 ERR_CHANOPPRIVTOOLOW_MSG,
723 Channel_Name(Channel));
726 case 'o': /* Channel operator */
727 if(!is_oper && !is_machine && !is_owner &&
728 !is_admin && !is_op) {
729 connected = IRC_WriteErrClient(Origin,
730 ERR_CHANOPRIVSNEEDED_MSG,
732 Channel_Name(Channel));
735 case 'h': /* Half Op */
736 if(!is_oper && !is_machine && !is_owner &&
737 !is_admin && !is_op) {
738 connected = IRC_WriteErrClient(Origin,
739 ERR_CHANOPRIVSNEEDED_MSG,
741 Channel_Name(Channel));
744 case 'v': /* Voice */
745 if (arg_arg > mode_arg) {
746 if (is_oper || is_machine || is_owner ||
747 is_admin || is_op || is_halfop) {
748 client = Client_Search(Req->argv[arg_arg]);
752 connected = IRC_WriteErrClient(Origin,
757 connected = IRC_WriteErrClient(Origin,
758 ERR_CHANOPRIVSNEEDED_MSG,
760 Channel_Name(Channel));
762 Req->argv[arg_arg][0] = '\0';
766 /* Report an error to the client, when a user
767 * mode should be changed but no nickname is
768 * given. But don't do it when not in "strict"
769 * mode, because most other servers don't do
770 * it as well and some clients send "wired"
771 * MODE commands like "MODE #chan -ooo nick". */
772 IRC_SetPenalty(Origin, 2);
773 connected = IRC_WriteErrClient(Origin,
774 ERR_NEEDMOREPARAMS_MSG,
775 Client_ID(Origin), Req->command);
780 /* --- Channel lists --- */
781 case 'I': /* Invite lists */
782 case 'b': /* Ban lists */
783 case 'e': /* Channel exception lists */
784 if (Mode_Limit_Reached(Client, mode_arg_count++))
786 if (arg_arg > mode_arg) {
788 if (is_oper || is_machine || is_owner ||
789 is_admin || is_op || is_halfop) {
791 ? Add_To_List(*mode_ptr, Origin,
794 : Del_From_List(*mode_ptr, Origin,
798 connected = IRC_WriteErrClient(Origin,
799 ERR_CHANOPRIVSNEEDED_MSG,
801 Channel_Name(Channel));
803 Req->argv[arg_arg][0] = '\0';
808 Channel_ShowInvites(Origin, Channel);
811 Channel_ShowBans(Origin, Channel);
814 Channel_ShowExcepts(Origin, Channel);
820 if (Client_Type(Client) != CLIENT_SERVER) {
822 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
823 set ? '+' : '-', *mode_ptr,
824 Client_ID(Origin), Channel_Name(Channel));
825 connected = IRC_WriteErrClient(Origin,
827 Client_ID(Origin), *mode_ptr,
828 Channel_Name(Channel));
832 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
833 set ? '+' : '-', *mode_ptr,
834 Client_ID(Origin), Channel_Name(Channel));
842 /* Is there a valid mode change? */
846 /* Validate target client */
847 if (client && (!Channel_IsMemberOf(Channel, client))) {
848 if (!IRC_WriteErrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
851 Channel_Name(Channel)))
857 /* Channel-User-Mode */
859 ? Channel_UserModeAdd(Channel, client, x[0])
860 : Channel_UserModeDel(Channel, client, x[0]);
862 strlcat(the_args, " ", sizeof(the_args));
863 strlcat(the_args, Client_ID(client),
865 strlcat(the_modes, x, sizeof(the_modes));
867 ("User \"%s\": Mode change on %s, now \"%s\"",
868 Client_Mask(client), Channel_Name(Channel),
869 Channel_UserModes(Channel, client));
874 ? Channel_ModeAdd(Channel, x[0])
875 : Channel_ModeDel(Channel, x[0]);
877 strlcat(the_modes, x, sizeof(the_modes));
878 LogDebug("Channel %s: Mode change, now \"%s\".",
879 Channel_Name(Channel),
880 Channel_Modes(Channel));
884 /* Are there additional arguments to add? */
886 strlcat(the_args, " ", sizeof(the_args));
887 strlcat(the_args, argadd, sizeof(the_args));
892 /* Are there changed modes? */
894 /* Clean up mode string */
895 len = strlen(the_modes) - 1;
896 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
897 the_modes[len] = '\0';
899 if (Client_Type(Client) == CLIENT_SERVER) {
900 /* MODE requests for local channels from other servers
901 * are definitely invalid! */
902 if (Channel_IsLocal(Channel)) {
903 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
907 /* Forward mode changes to channel users and all the
908 * other remote servers: */
909 IRC_WriteStrServersPrefix(Client, Origin,
910 "MODE %s %s%s", Channel_Name(Channel),
911 the_modes, the_args);
912 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
913 false, "MODE %s %s%s", Channel_Name(Channel),
914 the_modes, the_args);
917 Origin = Client_ThisServer();
918 /* Send reply to client and inform other servers and channel users */
919 connected = IRC_WriteStrClientPrefix(Client, Origin,
920 "MODE %s %s%s", Channel_Name(Channel),
921 the_modes, the_args);
922 /* Only forward requests for non-local channels */
923 if (!Channel_IsLocal(Channel))
924 IRC_WriteStrServersPrefix(Client, Origin,
925 "MODE %s %s%s", Channel_Name(Channel),
926 the_modes, the_args);
927 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
928 false, "MODE %s %s%s", Channel_Name(Channel),
929 the_modes, the_args);
933 IRC_SetPenalty(Client, 1);
938 * Handler for the IRC "AWAY" command.
940 * @param Client The client from which this command has been received.
941 * @param Req Request structure with prefix and all parameters.
942 * @return CONNECTED or DISCONNECTED.
945 IRC_AWAY( CLIENT *Client, REQUEST *Req )
947 assert (Client != NULL);
948 assert (Req != NULL);
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 */