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 if (!Channel_IsMemberOf(Channel, Origin)) {
382 /* Not a member: "simple" mode reply */
383 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
384 Client_ID(Origin), Channel_Name(Channel),
385 Channel_Modes(Channel)))
388 /* The sender is a member: generate extended reply */
389 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
390 mode_ptr = the_modes;
396 snprintf(argadd, sizeof(argadd), " %lu",
397 Channel_MaxUsers(Channel));
398 strlcat(the_args, argadd, sizeof(the_args));
401 strlcat(the_args, " ", sizeof(the_args));
402 strlcat(the_args, Channel_Key(Channel),
409 strlcat(the_modes, the_args, sizeof(the_modes));
411 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
412 Client_ID(Origin), Channel_Name(Channel),
418 /* Channel creation time */
419 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
420 Client_ID(Origin), Channel_Name(Channel),
421 Channel_CreationTime(Channel)))
428 * Handle channel mode and channel-user mode changes
430 * @param Client The client from which this command has been received.
431 * @param Req Request structure with prefix and all parameters.
432 * @param Origin The originator of the MODE command (prefix).
433 * @param Channel The target channel of this MODE command.
434 * @return CONNECTED or DISCONNECTED.
437 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
439 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
440 argadd[CLIENT_PASS_LEN], *mode_ptr;
441 bool connected, set, skiponce, retval, use_servermode,
442 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
443 int mode_arg, arg_arg, mode_arg_count = 0;
448 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
450 if (Channel_IsModeless(Channel))
451 return IRC_WriteErrClient(Client, ERR_NOCHANMODES_MSG,
452 Client_ID(Client), Channel_Name(Channel));
454 /* Mode request: let's answer it :-) */
456 return Channel_Mode_Answer_Request(Origin, Channel);
458 /* Check if origin is oper and opers can use mode */
459 use_servermode = Conf_OperServerMode;
460 if(Client_HasMode(Client, 'o') && Conf_OperCanMode) {
464 /* Check if client is a server/service */
465 if(Client_Type(Client) == CLIENT_SERVER ||
466 Client_Type(Client) == CLIENT_SERVICE) {
470 /* Check if client is member of channel or an oper or an server/service */
471 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
472 return IRC_WriteErrClient(Origin, ERR_NOTONCHANNEL_MSG,
474 Channel_Name(Channel));
477 mode_ptr = Req->argv[mode_arg];
478 if (Req->argc > mode_arg + 1)
479 arg_arg = mode_arg + 1;
483 /* Initial state: set or unset modes? */
497 /* Prepare reply string */
498 strcpy(the_modes, set ? "+" : "-");
502 connected = CONNECTED;
507 /* Try next argument if there's any */
510 if (arg_arg > mode_arg)
515 if (mode_arg >= Req->argc)
517 mode_ptr = Req->argv[mode_arg];
519 if (Req->argc > mode_arg + 1)
520 arg_arg = mode_arg + 1;
529 if (((*mode_ptr == '+') && !set)
530 || ((*mode_ptr == '-') && set)) {
531 /* Action modifier ("+"/"-") must be changed ... */
532 len = strlen(the_modes) - 1;
533 if (the_modes[len] == '+' || the_modes[len] == '-') {
534 /* Adjust last action modifier in result */
535 the_modes[len] = *mode_ptr;
537 /* Append modifier character to result string */
539 strlcat(the_modes, x, sizeof(the_modes));
541 set = *mode_ptr == '+';
546 /* Are there arguments left? */
547 if (arg_arg >= Req->argc)
550 if(!is_machine && !is_oper) {
551 if (Channel_UserHasMode(Channel, Client, 'q'))
553 if (Channel_UserHasMode(Channel, Client, 'a'))
555 if (Channel_UserHasMode(Channel, Client, 'o'))
557 if (Channel_UserHasMode(Channel, Client, 'h'))
566 /* --- Channel modes --- */
567 case 'R': /* Registered users only */
568 case 's': /* Secret channel */
569 case 'z': /* Secure connections only */
570 if(!is_oper && !is_machine && !is_owner &&
571 !is_admin && !is_op) {
572 connected = IRC_WriteErrClient(Origin,
573 ERR_CHANOPRIVSNEEDED_MSG,
574 Client_ID(Origin), Channel_Name(Channel));
577 case 'i': /* Invite only */
578 case 'V': /* Invite disallow */
579 case 'M': /* Only identified nicks can write */
580 case 'm': /* Moderated */
581 case 'n': /* Only members can write */
582 case 'Q': /* No kicks */
583 case 't': /* Topic locked */
584 if(is_oper || is_machine || is_owner ||
585 is_admin || is_op || is_halfop)
588 connected = IRC_WriteErrClient(Origin,
589 ERR_CHANOPRIVSNEEDED_MSG,
590 Client_ID(Origin), Channel_Name(Channel));
592 case 'k': /* Channel key */
593 if (Mode_Limit_Reached(Client, mode_arg_count++))
596 if (is_oper || is_machine || is_owner ||
597 is_admin || is_op || is_halfop) {
599 if (Channel_HasMode(Channel, 'k'))
600 strlcpy(argadd, "*", sizeof(argadd));
601 if (arg_arg > mode_arg)
604 connected = IRC_WriteErrClient(Origin,
605 ERR_CHANOPRIVSNEEDED_MSG,
607 Channel_Name(Channel));
610 if (arg_arg > mode_arg) {
611 if (is_oper || is_machine || is_owner ||
612 is_admin || is_op || is_halfop) {
613 Channel_ModeDel(Channel, 'k');
614 Channel_SetKey(Channel,
616 strlcpy(argadd, Channel_Key(Channel),
620 connected = IRC_WriteErrClient(Origin,
621 ERR_CHANOPRIVSNEEDED_MSG,
623 Channel_Name(Channel));
625 Req->argv[arg_arg][0] = '\0';
629 /* Only send error message in "strict" mode,
630 * this is how ircd2.11 and others behave ... */
631 connected = IRC_WriteErrClient(Origin,
632 ERR_NEEDMOREPARAMS_MSG,
633 Client_ID(Origin), Req->command);
638 case 'l': /* Member limit */
639 if (Mode_Limit_Reached(Client, mode_arg_count++))
642 if (is_oper || is_machine || is_owner ||
643 is_admin || is_op || is_halfop)
646 connected = IRC_WriteErrClient(Origin,
647 ERR_CHANOPRIVSNEEDED_MSG,
649 Channel_Name(Channel));
652 if (arg_arg > mode_arg) {
653 if (is_oper || is_machine || is_owner ||
654 is_admin || is_op || is_halfop) {
655 l = atol(Req->argv[arg_arg]);
656 if (l > 0 && l < 0xFFFF) {
657 Channel_ModeDel(Channel, 'l');
658 Channel_SetMaxUsers(Channel, l);
659 snprintf(argadd, sizeof(argadd),
664 connected = IRC_WriteErrClient(Origin,
665 ERR_CHANOPRIVSNEEDED_MSG,
667 Channel_Name(Channel));
669 Req->argv[arg_arg][0] = '\0';
673 /* Only send error message in "strict" mode,
674 * this is how ircd2.11 and others behave ... */
675 connected = IRC_WriteErrClient(Origin,
676 ERR_NEEDMOREPARAMS_MSG,
677 Client_ID(Origin), Req->command);
682 case 'O': /* IRC operators only */
684 /* Only IRC operators are allowed to
685 * set the 'O' channel mode! */
686 if(is_oper || is_machine)
689 connected = IRC_WriteErrClient(Origin,
690 ERR_NOPRIVILEGES_MSG,
692 } else if(is_oper || is_machine || is_owner ||
696 connected = IRC_WriteErrClient(Origin,
697 ERR_CHANOPRIVSNEEDED_MSG,
699 Channel_Name(Channel));
701 case 'P': /* Persistent channel */
703 /* Only IRC operators are allowed to
704 * set the 'P' channel mode! */
705 if(is_oper || is_machine)
708 connected = IRC_WriteErrClient(Origin,
709 ERR_NOPRIVILEGES_MSG,
711 } else if(is_oper || is_machine || is_owner ||
715 connected = IRC_WriteErrClient(Origin,
716 ERR_CHANOPRIVSNEEDED_MSG,
718 Channel_Name(Channel));
720 /* --- Channel user modes --- */
721 case 'q': /* Owner */
722 case 'a': /* Channel admin */
723 if(!is_oper && !is_machine && !is_owner && !is_admin) {
724 connected = IRC_WriteErrClient(Origin,
725 ERR_CHANOPPRIVTOOLOW_MSG,
727 Channel_Name(Channel));
730 case 'o': /* Channel operator */
731 if(!is_oper && !is_machine && !is_owner &&
732 !is_admin && !is_op) {
733 connected = IRC_WriteErrClient(Origin,
734 ERR_CHANOPRIVSNEEDED_MSG,
736 Channel_Name(Channel));
739 case 'h': /* Half Op */
740 if(!is_oper && !is_machine && !is_owner &&
741 !is_admin && !is_op) {
742 connected = IRC_WriteErrClient(Origin,
743 ERR_CHANOPRIVSNEEDED_MSG,
745 Channel_Name(Channel));
748 case 'v': /* Voice */
749 if (arg_arg > mode_arg) {
750 if (is_oper || is_machine || is_owner ||
751 is_admin || is_op || is_halfop) {
752 client = Client_Search(Req->argv[arg_arg]);
756 connected = IRC_WriteErrClient(Origin,
761 connected = IRC_WriteErrClient(Origin,
762 ERR_CHANOPRIVSNEEDED_MSG,
764 Channel_Name(Channel));
766 Req->argv[arg_arg][0] = '\0';
770 /* Report an error to the client, when a user
771 * mode should be changed but no nickname is
772 * given. But don't do it when not in "strict"
773 * mode, because most other servers don't do
774 * it as well and some clients send "wired"
775 * MODE commands like "MODE #chan -ooo nick". */
776 connected = IRC_WriteErrClient(Origin,
777 ERR_NEEDMOREPARAMS_MSG,
778 Client_ID(Origin), Req->command);
783 /* --- Channel lists --- */
784 case 'I': /* Invite lists */
785 case 'b': /* Ban lists */
786 case 'e': /* Channel exception lists */
787 if (Mode_Limit_Reached(Client, mode_arg_count++))
789 if (arg_arg > mode_arg) {
791 if (is_oper || is_machine || is_owner ||
792 is_admin || is_op || is_halfop) {
794 ? Add_To_List(*mode_ptr, Origin,
797 : Del_From_List(*mode_ptr, Origin,
801 connected = IRC_WriteErrClient(Origin,
802 ERR_CHANOPRIVSNEEDED_MSG,
804 Channel_Name(Channel));
806 Req->argv[arg_arg][0] = '\0';
811 Channel_ShowInvites(Origin, Channel);
814 Channel_ShowBans(Origin, Channel);
817 Channel_ShowExcepts(Origin, Channel);
823 if (Client_Type(Client) != CLIENT_SERVER) {
825 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
826 set ? '+' : '-', *mode_ptr,
827 Client_ID(Origin), Channel_Name(Channel));
828 connected = IRC_WriteErrClient(Origin,
830 Client_ID(Origin), *mode_ptr,
831 Channel_Name(Channel));
835 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
836 set ? '+' : '-', *mode_ptr,
837 Client_ID(Origin), Channel_Name(Channel));
845 /* Is there a valid mode change? */
849 /* Validate target client */
850 if (client && (!Channel_IsMemberOf(Channel, client))) {
851 if (!IRC_WriteErrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
854 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);
940 * Handler for the IRC "AWAY" command.
942 * @param Client The client from which this command has been received.
943 * @param Req Request structure with prefix and all parameters.
944 * @return CONNECTED or DISCONNECTED.
947 IRC_AWAY( CLIENT *Client, REQUEST *Req )
949 assert (Client != NULL);
950 assert (Req != NULL);
952 if (Req->argc == 1 && Req->argv[0][0]) {
953 Client_SetAway(Client, Req->argv[0]);
954 Client_ModeAdd(Client, 'a');
955 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :+a",
957 return IRC_WriteStrClient(Client, RPL_NOWAWAY_MSG,
960 Client_ModeDel(Client, 'a');
961 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :-a",
963 return IRC_WriteStrClient(Client, RPL_UNAWAY_MSG,
969 * Add entries to channel invite, ban and exception lists.
971 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
972 * @param Prefix The originator of the command.
973 * @param Client The sender of the command.
974 * @param Channel The channel of which the list should be modified.
975 * @param Pattern The pattern to add to the list.
976 * @return CONNECTED or DISCONNECTED.
979 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
983 struct list_head *list = NULL;
984 long int current_count;
986 assert(Client != NULL);
987 assert(Channel != NULL);
988 assert(Pattern != NULL);
989 assert(what == 'I' || what == 'b' || what == 'e');
991 Lists_MakeMask(Pattern, mask, sizeof(mask));
992 current_count = Lists_Count(Channel_GetListInvites(Channel))
993 + Lists_Count(Channel_GetListExcepts(Channel))
994 + Lists_Count(Channel_GetListBans(Channel));
998 list = Channel_GetListInvites(Channel);
1001 list = Channel_GetListBans(Channel);
1004 list = Channel_GetListExcepts(Channel);
1008 if (Lists_CheckDupeMask(list, mask))
1010 if (Client_Type(Client) == CLIENT_USER &&
1011 current_count >= MAX_HNDL_CHANNEL_LISTS)
1012 return IRC_WriteErrClient(Client, ERR_LISTFULL_MSG,
1014 Channel_Name(Channel), mask,
1015 MAX_HNDL_CHANNEL_LISTS);
1019 if (!Channel_AddInvite(Channel, mask, false))
1023 if (!Channel_AddBan(Channel, mask))
1027 if (!Channel_AddExcept(Channel, mask))
1031 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1035 * Delete entries from channel invite, ban and exception lists.
1037 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1038 * @param Prefix The originator of the command.
1039 * @param Client The sender of the command.
1040 * @param Channel The channel of which the list should be modified.
1041 * @param Pattern The pattern to add to the list.
1042 * @return CONNECTED or DISCONNECTED.
1045 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1046 const char *Pattern)
1048 char mask[MASK_LEN];
1049 struct list_head *list = NULL;
1051 assert(Client != NULL);
1052 assert(Channel != NULL);
1053 assert(Pattern != NULL);
1054 assert(what == 'I' || what == 'b' || what == 'e');
1056 Lists_MakeMask(Pattern, mask, sizeof(mask));
1060 list = Channel_GetListInvites(Channel);
1063 list = Channel_GetListBans(Channel);
1066 list = Channel_GetListExcepts(Channel);
1070 if (!Lists_CheckDupeMask(list, mask))
1072 Lists_Del(list, mask);
1074 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1078 * Send information about changed channel invite/ban/exception lists to clients.
1080 * @param IsAdd true if the list item has been added, false otherwise.
1081 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1082 * @param Prefix The originator of the mode list change.
1083 * @param Client The sender of the command.
1084 * @param Channel The channel of which the list has been modified.
1085 * @param Mask The mask which has been added or removed.
1086 * @return CONNECTED or DISCONNECTED.
1089 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1090 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1094 /* Send confirmation to the client */
1095 if (Client_Type(Client) == CLIENT_USER)
1096 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1097 Channel_Name(Channel),
1101 /* to other servers */
1102 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1103 Channel_Name(Channel), IsAdd ? '+' : '-',
1106 /* and local users in channel */
1107 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1108 "MODE %s %c%c %s", Channel_Name(Channel),
1109 IsAdd ? '+' : '-', ModeChar, Mask );
1112 } /* Send_ListChange */