2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2014 Alexander Barton (alex@barton.de) and Contributors.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
16 * IRC commands for mode changes (like MODE, AWAY, etc.)
26 #include "irc-macros.h"
27 #include "irc-write.h"
36 static bool Client_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
38 static bool Channel_Mode PARAMS((CLIENT *Client, REQUEST *Req, CLIENT *Origin,
41 static bool Add_To_List PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
42 CHANNEL *Channel, const char *Pattern));
43 static bool Del_From_List PARAMS((char what, CLIENT *Prefix, CLIENT *Client,
44 CHANNEL *Channel, const char *Pattern));
46 static bool Send_ListChange PARAMS((const bool IsAdd, const char ModeChar,
47 CLIENT *Prefix, CLIENT *Client,
48 CHANNEL *Channel, const char *Mask));
51 * Handler for the IRC "MODE" command.
53 * This function detects whether user or channel modes should be modified
54 * and calls the appropriate sub-functions.
56 * @param Client The client from which this command has been received.
57 * @param Req Request structure with prefix and all parameters.
58 * @return CONNECTED or DISCONNECTED.
61 IRC_MODE( CLIENT *Client, REQUEST *Req )
66 assert(Client != NULL);
69 _IRC_GET_SENDER_OR_RETURN_(origin, Req, Client)
71 /* Test for "fake" MODE commands injected by this local instance,
72 * for example when handling the "DefaultUserModes" settings.
73 * This doesn't harm real commands, because prefixes of regular
74 * clients are checked in Validate_Prefix() and can't be faked. */
75 if (Req->prefix && Client_Search(Req->prefix) == Client_ThisServer())
76 Client = Client_Search(Req->prefix);
78 /* Channel or user mode? */
79 cl = NULL; chan = NULL;
80 if (Client_IsValidNick(Req->argv[0]))
81 cl = Client_Search(Req->argv[0]);
82 if (Channel_IsValidName(Req->argv[0]))
83 chan = Channel_Search(Req->argv[0]);
86 return Client_Mode(Client, Req, origin, cl);
88 return Channel_Mode(Client, Req, origin, chan);
90 /* No target found! */
91 return IRC_WriteErrClient(Client, ERR_NOSUCHNICK_MSG,
92 Client_ID(Client), Req->argv[0]);
96 * Check if the "mode limit" for a client has been reached.
98 * This limit doesn't apply for servers or services!
100 * @param Client The client to check.
101 * @param Count The number of modes already handled.
102 * @return true if the limit has been reached.
105 Mode_Limit_Reached(CLIENT *Client, int Count)
107 if (Client_Type(Client) == CLIENT_SERVER
108 || Client_Type(Client) == CLIENT_SERVICE)
110 if (Count < MAX_HNDL_MODES_ARG)
116 * Handle client mode requests
118 * @param Client The client from which this command has been received.
119 * @param Req Request structure with prefix and all parameters.
120 * @param Origin The originator of the MODE command (prefix).
121 * @param Target The target (client) of this MODE command.
122 * @return CONNECTED or DISCONNECTED.
125 Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
127 char the_modes[COMMAND_LEN], x[2], *mode_ptr;
129 bool send_RPL_HOSTHIDDEN_MSG = false;
133 /* Is the client allowed to request or change the modes? */
134 if (Client_Type(Client) == CLIENT_USER) {
135 /* Users are only allowed to manipulate their own modes! */
136 if (Target != Client)
137 return IRC_WriteErrClient(Client,
138 ERR_USERSDONTMATCH_MSG,
142 /* Mode request: let's answer it :-) */
144 return IRC_WriteStrClient(Origin, RPL_UMODEIS_MSG,
146 Client_Modes(Target));
149 mode_ptr = Req->argv[mode_arg];
151 /* Initial state: set or unset modes? */
152 if (*mode_ptr == '+') {
154 strcpy(the_modes, "+");
155 } else if (*mode_ptr == '-') {
157 strcpy(the_modes, "-");
159 return IRC_WriteErrClient(Origin, ERR_UMODEUNKNOWNFLAG_MSG,
167 /* Try next argument if there's any */
169 if (mode_arg < Req->argc)
170 mode_ptr = Req->argv[mode_arg];
178 if ((*mode_ptr == '+' && !set)
179 || (*mode_ptr == '-' && set)) {
180 /* Action modifier ("+"/"-") must be changed */
181 len = strlen(the_modes) - 1;
182 if (the_modes[len] == '+'
183 || the_modes[len] == '-') {
184 /* Last character in the "result
185 * string" was an "action", so just
186 * overwrite it with the new action */
187 the_modes[len] = *mode_ptr;
189 /* Append new modifier character to
190 * the resulting mode string */
192 strlcat(the_modes, x,
195 if (*mode_ptr == '+')
206 case 'b': /* Block private msgs */
207 case 'C': /* Only messages from clients sharing a channel */
208 case 'i': /* Invisible */
209 case 's': /* Server messages */
210 case 'w': /* Wallops messages */
214 if (Client_Type(Client) == CLIENT_SERVER) {
216 Client_SetAway(Origin, DEFAULT_AWAY_MSG);
218 ok = IRC_WriteErrClient(Origin,
219 ERR_NOPRIVILEGES_MSG,
223 if (Client_HasMode(Client, 'r'))
224 ok = IRC_WriteErrClient(Origin,
230 case 'c': /* Receive connect notices */
231 case 'q': /* KICK-protected user */
232 case 'F': /* disable flood protection */
233 /* (only settable by IRC operators!) */
234 if (!set || Client_Type(Client) == CLIENT_SERVER
235 || Client_HasMode(Origin, 'o'))
238 ok = IRC_WriteErrClient(Origin,
239 ERR_NOPRIVILEGES_MSG,
242 case 'o': /* IRC operator (only unsettable!) */
243 if (!set || Client_Type(Client) == CLIENT_SERVER) {
246 ok = IRC_WriteErrClient(Origin,
247 ERR_NOPRIVILEGES_MSG,
250 case 'r': /* Restricted (only settable) */
251 if (set || Client_Type(Client) == CLIENT_SERVER)
254 ok = IRC_WriteErrClient(Origin,
258 case 'R': /* Registered (not [un]settable by clients) */
259 if (Client_Type(Client) == CLIENT_SERVER)
262 ok = IRC_WriteErrClient(Origin,
263 ERR_NICKREGISTER_MSG,
266 case 'x': /* Cloak hostname */
267 if (Client_HasMode(Client, 'r'))
268 ok = IRC_WriteErrClient(Origin,
271 else if (!set || Conf_CloakHostModeX[0]
272 || Client_Type(Client) == CLIENT_SERVER
273 || Client_HasMode(Origin, 'o')) {
275 send_RPL_HOSTHIDDEN_MSG = true;
277 ok = IRC_WriteErrClient(Origin,
278 ERR_NOPRIVILEGES_MSG,
282 if (Client_Type(Client) != CLIENT_SERVER) {
284 "Unknown mode \"%c%c\" from \"%s\"!?",
285 set ? '+' : '-', *mode_ptr,
287 ok = IRC_WriteErrClient(Origin,
288 ERR_UMODEUNKNOWNFLAG2_MSG,
295 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
296 set ? '+' : '-', *mode_ptr,
297 Client_ID(Origin), Client_ID(Target));
305 /* Is there a valid mode change? */
310 if (Client_ModeAdd(Target, x[0]))
311 strlcat(the_modes, x, sizeof(the_modes));
313 if (Client_ModeDel(Target, x[0]))
314 strlcat(the_modes, x, sizeof(the_modes));
318 /* Are there changed modes? */
320 /* Remove needless action modifier characters */
321 len = strlen(the_modes) - 1;
322 if (the_modes[len] == '+' || the_modes[len] == '-')
323 the_modes[len] = '\0';
325 if (Client_Type(Client) == CLIENT_SERVER) {
326 /* Forward modes to other servers */
327 if (Client_Conn(Target) != NONE) {
328 /* Remote server (service?) changed modes
329 * for one of our clients. Inform it! */
330 IRC_WriteStrClientPrefix(Target, Origin,
335 IRC_WriteStrServersPrefix(Client, Origin,
340 /* Send reply to client and inform other servers */
341 ok = IRC_WriteStrClientPrefix(Client, Origin,
345 IRC_WriteStrServersPrefix(Client, Origin,
351 if (send_RPL_HOSTHIDDEN_MSG && Client_Conn(Target) > NONE) {
352 /* A new (cloaked) hostname must be announced */
353 IRC_WriteStrClientPrefix(Target, Origin,
356 Client_HostnameDisplayed(Target));
360 LogDebug("%s \"%s\": Mode change, now \"%s\".",
361 Client_TypeText(Target), Client_Mask(Target),
362 Client_Modes(Target));
369 * Reply to a channel mode request.
371 * @param Origin The originator of the MODE command (prefix).
372 * @param Channel The channel of which the modes should be sent.
373 * @return CONNECTED or DISCONNECTED.
376 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
378 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
379 const char *mode_ptr;
381 /* Member or not? -- That's the question! */
382 if (!Channel_IsMemberOf(Channel, Origin))
383 return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
384 Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
386 /* The sender is a member: generate extended reply */
387 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
388 mode_ptr = the_modes;
394 snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
395 strlcat(the_args, argadd, sizeof(the_args));
398 strlcat(the_args, " ", sizeof(the_args));
399 strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
405 strlcat(the_modes, the_args, sizeof(the_modes));
407 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
408 Client_ID(Origin), Channel_Name(Channel),
412 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
413 Client_ID(Origin), Channel_Name(Channel),
414 Channel_CreationTime(Channel)))
421 * Handle channel mode and channel-user mode changes
423 * @param Client The client from which this command has been received.
424 * @param Req Request structure with prefix and all parameters.
425 * @param Origin The originator of the MODE command (prefix).
426 * @param Channel The target channel of this MODE command.
427 * @return CONNECTED or DISCONNECTED.
430 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
432 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
433 argadd[CLIENT_PASS_LEN], *mode_ptr;
434 bool connected, set, skiponce, retval, use_servermode,
435 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
436 int mode_arg, arg_arg, mode_arg_count = 0;
441 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
443 if (Channel_IsModeless(Channel))
444 return IRC_WriteErrClient(Client, ERR_NOCHANMODES_MSG,
445 Client_ID(Client), Channel_Name(Channel));
447 /* Mode request: let's answer it :-) */
449 return Channel_Mode_Answer_Request(Origin, Channel);
451 /* Check if origin is oper and opers can use mode */
452 use_servermode = Conf_OperServerMode;
453 if(Client_HasMode(Client, 'o') && Conf_OperCanMode) {
457 /* Check if client is a server/service */
458 if(Client_Type(Client) == CLIENT_SERVER ||
459 Client_Type(Client) == CLIENT_SERVICE) {
463 /* Check if client is member of channel or an oper or an server/service */
464 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
465 return IRC_WriteErrClient(Origin, ERR_NOTONCHANNEL_MSG,
467 Channel_Name(Channel));
470 mode_ptr = Req->argv[mode_arg];
471 if (Req->argc > mode_arg + 1)
472 arg_arg = mode_arg + 1;
476 /* Initial state: set or unset modes? */
490 /* Prepare reply string */
491 strcpy(the_modes, set ? "+" : "-");
495 connected = CONNECTED;
500 /* Try next argument if there's any */
503 if (arg_arg > mode_arg)
508 if (mode_arg >= Req->argc)
510 mode_ptr = Req->argv[mode_arg];
512 if (Req->argc > mode_arg + 1)
513 arg_arg = mode_arg + 1;
522 if (((*mode_ptr == '+') && !set)
523 || ((*mode_ptr == '-') && set)) {
524 /* Action modifier ("+"/"-") must be changed ... */
525 len = strlen(the_modes) - 1;
526 if (the_modes[len] == '+' || the_modes[len] == '-') {
527 /* Adjust last action modifier in result */
528 the_modes[len] = *mode_ptr;
530 /* Append modifier character to result string */
532 strlcat(the_modes, x, sizeof(the_modes));
534 set = *mode_ptr == '+';
539 /* Are there arguments left? */
540 if (arg_arg >= Req->argc)
543 if(!is_machine && !is_oper) {
544 if (Channel_UserHasMode(Channel, Client, 'q'))
546 if (Channel_UserHasMode(Channel, Client, 'a'))
548 if (Channel_UserHasMode(Channel, Client, 'o'))
550 if (Channel_UserHasMode(Channel, Client, 'h'))
559 /* --- Channel modes --- */
560 case 'R': /* Registered users only */
561 case 's': /* Secret channel */
562 case 'z': /* Secure connections only */
563 if(!is_oper && !is_machine && !is_owner &&
564 !is_admin && !is_op) {
565 connected = IRC_WriteErrClient(Origin,
566 ERR_CHANOPRIVSNEEDED_MSG,
567 Client_ID(Origin), Channel_Name(Channel));
570 case 'i': /* Invite only */
571 case 'V': /* Invite disallow */
572 case 'M': /* Only identified nicks can write */
573 case 'm': /* Moderated */
574 case 'n': /* Only members can write */
575 case 'Q': /* No kicks */
576 case 't': /* Topic locked */
577 if(is_oper || is_machine || is_owner ||
578 is_admin || is_op || is_halfop)
581 connected = IRC_WriteErrClient(Origin,
582 ERR_CHANOPRIVSNEEDED_MSG,
583 Client_ID(Origin), Channel_Name(Channel));
585 case 'k': /* Channel key */
586 if (Mode_Limit_Reached(Client, mode_arg_count++))
589 if (is_oper || is_machine || is_owner ||
590 is_admin || is_op || is_halfop) {
592 if (Channel_HasMode(Channel, 'k'))
593 strlcpy(argadd, "*", sizeof(argadd));
594 if (arg_arg > mode_arg)
597 connected = IRC_WriteErrClient(Origin,
598 ERR_CHANOPRIVSNEEDED_MSG,
600 Channel_Name(Channel));
603 if (arg_arg > mode_arg) {
604 if (is_oper || is_machine || is_owner ||
605 is_admin || is_op || is_halfop) {
606 Channel_ModeDel(Channel, 'k');
607 Channel_SetKey(Channel,
609 strlcpy(argadd, Channel_Key(Channel),
613 connected = IRC_WriteErrClient(Origin,
614 ERR_CHANOPRIVSNEEDED_MSG,
616 Channel_Name(Channel));
618 Req->argv[arg_arg][0] = '\0';
622 /* Only send error message in "strict" mode,
623 * this is how ircd2.11 and others behave ... */
624 connected = IRC_WriteErrClient(Origin,
625 ERR_NEEDMOREPARAMS_MSG,
626 Client_ID(Origin), Req->command);
631 case 'l': /* Member limit */
632 if (Mode_Limit_Reached(Client, mode_arg_count++))
635 if (is_oper || is_machine || is_owner ||
636 is_admin || is_op || is_halfop)
639 connected = IRC_WriteErrClient(Origin,
640 ERR_CHANOPRIVSNEEDED_MSG,
642 Channel_Name(Channel));
645 if (arg_arg > mode_arg) {
646 if (is_oper || is_machine || is_owner ||
647 is_admin || is_op || is_halfop) {
648 l = atol(Req->argv[arg_arg]);
649 if (l > 0 && l < 0xFFFF) {
650 Channel_ModeDel(Channel, 'l');
651 Channel_SetMaxUsers(Channel, l);
652 snprintf(argadd, sizeof(argadd),
657 connected = IRC_WriteErrClient(Origin,
658 ERR_CHANOPRIVSNEEDED_MSG,
660 Channel_Name(Channel));
662 Req->argv[arg_arg][0] = '\0';
666 /* Only send error message in "strict" mode,
667 * this is how ircd2.11 and others behave ... */
668 connected = IRC_WriteErrClient(Origin,
669 ERR_NEEDMOREPARAMS_MSG,
670 Client_ID(Origin), Req->command);
675 case 'O': /* IRC operators only */
677 /* Only IRC operators are allowed to
678 * set the 'O' channel mode! */
679 if(is_oper || is_machine)
682 connected = IRC_WriteErrClient(Origin,
683 ERR_NOPRIVILEGES_MSG,
685 } else if(is_oper || is_machine || is_owner ||
689 connected = IRC_WriteErrClient(Origin,
690 ERR_CHANOPRIVSNEEDED_MSG,
692 Channel_Name(Channel));
694 case 'P': /* Persistent channel */
696 /* Only IRC operators are allowed to
697 * set the 'P' channel mode! */
698 if(is_oper || is_machine)
701 connected = IRC_WriteErrClient(Origin,
702 ERR_NOPRIVILEGES_MSG,
704 } else if(is_oper || is_machine || is_owner ||
708 connected = IRC_WriteErrClient(Origin,
709 ERR_CHANOPRIVSNEEDED_MSG,
711 Channel_Name(Channel));
713 /* --- Channel user modes --- */
714 case 'q': /* Owner */
715 case 'a': /* Channel admin */
716 if(!is_oper && !is_machine && !is_owner && !is_admin) {
717 connected = IRC_WriteErrClient(Origin,
718 ERR_CHANOPPRIVTOOLOW_MSG,
720 Channel_Name(Channel));
723 case 'o': /* Channel operator */
724 if(!is_oper && !is_machine && !is_owner &&
725 !is_admin && !is_op) {
726 connected = IRC_WriteErrClient(Origin,
727 ERR_CHANOPRIVSNEEDED_MSG,
729 Channel_Name(Channel));
732 case 'h': /* Half Op */
733 if(!is_oper && !is_machine && !is_owner &&
734 !is_admin && !is_op) {
735 connected = IRC_WriteErrClient(Origin,
736 ERR_CHANOPRIVSNEEDED_MSG,
738 Channel_Name(Channel));
741 case 'v': /* Voice */
742 if (arg_arg > mode_arg) {
743 if (is_oper || is_machine || is_owner ||
744 is_admin || is_op || is_halfop) {
745 client = Client_Search(Req->argv[arg_arg]);
749 connected = IRC_WriteErrClient(Origin,
754 connected = IRC_WriteErrClient(Origin,
755 ERR_CHANOPRIVSNEEDED_MSG,
757 Channel_Name(Channel));
759 Req->argv[arg_arg][0] = '\0';
763 /* Report an error to the client, when a user
764 * mode should be changed but no nickname is
765 * given. But don't do it when not in "strict"
766 * mode, because most other servers don't do
767 * it as well and some clients send "wired"
768 * MODE commands like "MODE #chan -ooo nick". */
769 connected = IRC_WriteErrClient(Origin,
770 ERR_NEEDMOREPARAMS_MSG,
771 Client_ID(Origin), Req->command);
776 /* --- Channel lists --- */
777 case 'I': /* Invite lists */
778 case 'b': /* Ban lists */
779 case 'e': /* Channel exception lists */
780 if (Mode_Limit_Reached(Client, mode_arg_count++))
782 if (arg_arg > mode_arg) {
784 if (is_oper || is_machine || is_owner ||
785 is_admin || is_op || is_halfop) {
787 ? Add_To_List(*mode_ptr, Origin,
790 : Del_From_List(*mode_ptr, Origin,
794 connected = IRC_WriteErrClient(Origin,
795 ERR_CHANOPRIVSNEEDED_MSG,
797 Channel_Name(Channel));
799 Req->argv[arg_arg][0] = '\0';
804 Channel_ShowInvites(Origin, Channel);
807 Channel_ShowBans(Origin, Channel);
810 Channel_ShowExcepts(Origin, Channel);
816 if (Client_Type(Client) != CLIENT_SERVER) {
818 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
819 set ? '+' : '-', *mode_ptr,
820 Client_ID(Origin), Channel_Name(Channel));
821 connected = IRC_WriteErrClient(Origin,
823 Client_ID(Origin), *mode_ptr,
824 Channel_Name(Channel));
828 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
829 set ? '+' : '-', *mode_ptr,
830 Client_ID(Origin), Channel_Name(Channel));
838 /* Is there a valid mode change? */
842 /* Validate target client */
843 if (client && (!Channel_IsMemberOf(Channel, client))) {
844 if (!IRC_WriteErrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
847 Channel_Name(Channel)))
853 /* Channel-User-Mode */
855 ? Channel_UserModeAdd(Channel, client, x[0])
856 : Channel_UserModeDel(Channel, client, x[0]);
858 strlcat(the_args, " ", sizeof(the_args));
859 strlcat(the_args, Client_ID(client),
861 strlcat(the_modes, x, sizeof(the_modes));
863 ("User \"%s\": Mode change on %s, now \"%s\"",
864 Client_Mask(client), Channel_Name(Channel),
865 Channel_UserModes(Channel, client));
870 ? Channel_ModeAdd(Channel, x[0])
871 : Channel_ModeDel(Channel, x[0]);
873 strlcat(the_modes, x, sizeof(the_modes));
874 LogDebug("Channel %s: Mode change, now \"%s\".",
875 Channel_Name(Channel),
876 Channel_Modes(Channel));
880 /* Are there additional arguments to add? */
882 strlcat(the_args, " ", sizeof(the_args));
883 strlcat(the_args, argadd, sizeof(the_args));
888 /* Are there changed modes? */
890 /* Clean up mode string */
891 len = strlen(the_modes) - 1;
892 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
893 the_modes[len] = '\0';
895 if (Client_Type(Client) == CLIENT_SERVER) {
896 /* MODE requests for local channels from other servers
897 * are definitely invalid! */
898 if (Channel_IsLocal(Channel)) {
899 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
903 /* Forward mode changes to channel users and all the
904 * other remote servers: */
905 IRC_WriteStrServersPrefix(Client, Origin,
906 "MODE %s %s%s", Channel_Name(Channel),
907 the_modes, the_args);
908 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
909 false, "MODE %s %s%s", Channel_Name(Channel),
910 the_modes, the_args);
913 Origin = Client_ThisServer();
914 /* Send reply to client and inform other servers and channel users */
915 connected = IRC_WriteStrClientPrefix(Client, Origin,
916 "MODE %s %s%s", Channel_Name(Channel),
917 the_modes, the_args);
918 /* Only forward requests for non-local channels */
919 if (!Channel_IsLocal(Channel))
920 IRC_WriteStrServersPrefix(Client, Origin,
921 "MODE %s %s%s", Channel_Name(Channel),
922 the_modes, the_args);
923 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
924 false, "MODE %s %s%s", Channel_Name(Channel),
925 the_modes, the_args);
933 * Handler for the IRC "AWAY" command.
935 * @param Client The client from which this command has been received.
936 * @param Req Request structure with prefix and all parameters.
937 * @return CONNECTED or DISCONNECTED.
940 IRC_AWAY( CLIENT *Client, REQUEST *Req )
942 assert (Client != NULL);
943 assert (Req != NULL);
945 if (Req->argc == 1 && Req->argv[0][0]) {
946 Client_SetAway(Client, Req->argv[0]);
947 Client_ModeAdd(Client, 'a');
948 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :+a",
950 return IRC_WriteStrClient(Client, RPL_NOWAWAY_MSG,
953 Client_ModeDel(Client, 'a');
954 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :-a",
956 return IRC_WriteStrClient(Client, RPL_UNAWAY_MSG,
962 * Add entries to channel invite, ban and exception lists.
964 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
965 * @param Prefix The originator of the command.
966 * @param Client The sender of the command.
967 * @param Channel The channel of which the list should be modified.
968 * @param Pattern The pattern to add to the list.
969 * @return CONNECTED or DISCONNECTED.
972 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
976 struct list_head *list = NULL;
977 long int current_count;
979 assert(Client != NULL);
980 assert(Channel != NULL);
981 assert(Pattern != NULL);
982 assert(what == 'I' || what == 'b' || what == 'e');
984 Lists_MakeMask(Pattern, mask, sizeof(mask));
985 current_count = Lists_Count(Channel_GetListInvites(Channel))
986 + Lists_Count(Channel_GetListExcepts(Channel))
987 + Lists_Count(Channel_GetListBans(Channel));
991 list = Channel_GetListInvites(Channel);
994 list = Channel_GetListBans(Channel);
997 list = Channel_GetListExcepts(Channel);
1001 if (Lists_CheckDupeMask(list, mask))
1003 if (Client_Type(Client) == CLIENT_USER &&
1004 current_count >= MAX_HNDL_CHANNEL_LISTS)
1005 return IRC_WriteErrClient(Client, ERR_LISTFULL_MSG,
1007 Channel_Name(Channel), mask,
1008 MAX_HNDL_CHANNEL_LISTS);
1012 if (!Channel_AddInvite(Channel, mask, false))
1016 if (!Channel_AddBan(Channel, mask))
1020 if (!Channel_AddExcept(Channel, mask))
1024 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1028 * Delete entries from channel invite, ban and exception lists.
1030 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1031 * @param Prefix The originator of the command.
1032 * @param Client The sender of the command.
1033 * @param Channel The channel of which the list should be modified.
1034 * @param Pattern The pattern to add to the list.
1035 * @return CONNECTED or DISCONNECTED.
1038 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1039 const char *Pattern)
1041 char mask[MASK_LEN];
1042 struct list_head *list = NULL;
1044 assert(Client != NULL);
1045 assert(Channel != NULL);
1046 assert(Pattern != NULL);
1047 assert(what == 'I' || what == 'b' || what == 'e');
1049 Lists_MakeMask(Pattern, mask, sizeof(mask));
1053 list = Channel_GetListInvites(Channel);
1056 list = Channel_GetListBans(Channel);
1059 list = Channel_GetListExcepts(Channel);
1063 if (!Lists_CheckDupeMask(list, mask))
1065 Lists_Del(list, mask);
1067 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1071 * Send information about changed channel invite/ban/exception lists to clients.
1073 * @param IsAdd true if the list item has been added, false otherwise.
1074 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1075 * @param Prefix The originator of the mode list change.
1076 * @param Client The sender of the command.
1077 * @param Channel The channel of which the list has been modified.
1078 * @param Mask The mask which has been added or removed.
1079 * @return CONNECTED or DISCONNECTED.
1082 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1083 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1087 /* Send confirmation to the client */
1088 if (Client_Type(Client) == CLIENT_USER)
1089 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1090 Channel_Name(Channel),
1094 /* to other servers */
1095 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1096 Channel_Name(Channel), IsAdd ? '+' : '-',
1099 /* and local users in channel */
1100 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1101 "MODE %s %c%c %s", Channel_Name(Channel),
1102 IsAdd ? '+' : '-', ModeChar, Mask );
1105 } /* Send_ListChange */