2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2023 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 'I': /* Hide channel list from WHOIS */
210 case 's': /* Server messages */
211 case 'w': /* Wallops messages */
215 if (Client_Type(Client) == CLIENT_SERVER) {
217 Client_SetAway(Origin, DEFAULT_AWAY_MSG);
219 ok = IRC_WriteErrClient(Origin,
220 ERR_NOPRIVILEGES_MSG,
224 if (Client_HasMode(Client, 'r'))
225 ok = IRC_WriteErrClient(Origin,
231 case 'c': /* Receive connect notices */
232 case 'q': /* KICK-protected user */
233 case 'F': /* disable flood protection */
234 /* (only settable by IRC operators!) */
235 if (!set || Client_Type(Client) == CLIENT_SERVER
236 || Client_HasMode(Origin, 'o'))
239 ok = IRC_WriteErrClient(Origin,
240 ERR_NOPRIVILEGES_MSG,
243 case 'o': /* IRC operator (only unsettable!) */
244 if (!set || Client_Type(Client) == CLIENT_SERVER) {
247 ok = IRC_WriteErrClient(Origin,
248 ERR_NOPRIVILEGES_MSG,
251 case 'r': /* Restricted (only settable) */
252 if (set || Client_Type(Client) == CLIENT_SERVER)
255 ok = IRC_WriteErrClient(Origin,
259 case 'R': /* Registered (not [un]settable by clients) */
260 if (Client_Type(Client) == CLIENT_SERVER)
263 ok = IRC_WriteErrClient(Origin,
264 ERR_NICKREGISTER_MSG,
267 case 'x': /* Cloak hostname */
268 if (Client_HasMode(Client, 'r'))
269 ok = IRC_WriteErrClient(Origin,
272 else if (!set || Conf_CloakHostModeX[0]
273 || Client_Type(Client) == CLIENT_SERVER
274 || Client_HasMode(Origin, 'o')) {
276 send_RPL_HOSTHIDDEN_MSG = true;
278 ok = IRC_WriteErrClient(Origin,
279 ERR_NOPRIVILEGES_MSG,
283 if (Client_Type(Client) != CLIENT_SERVER) {
285 "Unknown mode \"%c%c\" from \"%s\"!?",
286 set ? '+' : '-', *mode_ptr,
288 ok = IRC_WriteErrClient(Origin,
289 ERR_UMODEUNKNOWNFLAG2_MSG,
296 "Handling unknown mode \"%c%c\" from \"%s\" for \"%s\" ...",
297 set ? '+' : '-', *mode_ptr,
298 Client_ID(Origin), Client_ID(Target));
306 /* Is there a valid mode change? */
311 if (Client_ModeAdd(Target, x[0]))
312 strlcat(the_modes, x, sizeof(the_modes));
314 if (Client_ModeDel(Target, x[0]))
315 strlcat(the_modes, x, sizeof(the_modes));
319 /* Are there changed modes? */
321 /* Remove needless action modifier characters */
322 len = strlen(the_modes) - 1;
323 if (the_modes[len] == '+' || the_modes[len] == '-')
324 the_modes[len] = '\0';
326 if (Client_Type(Client) == CLIENT_SERVER) {
327 /* Forward modes to other servers */
328 if (Client_Conn(Target) != NONE) {
329 /* Remote server (service?) changed modes
330 * for one of our clients. Inform it! */
331 IRC_WriteStrClientPrefix(Target, Origin,
336 IRC_WriteStrServersPrefix(Client, Origin,
341 /* Send reply to client and inform other servers */
342 ok = IRC_WriteStrClientPrefix(Client, Origin,
346 IRC_WriteStrServersPrefix(Client, Origin,
352 if (send_RPL_HOSTHIDDEN_MSG && Client_Conn(Target) > NONE) {
353 /* A new (cloaked) hostname must be announced */
354 IRC_WriteStrClientPrefix(Target, Origin,
357 Client_HostnameDisplayed(Target));
361 LogDebug("%s \"%s\": Mode change, now \"%s\".",
362 Client_TypeText(Target), Client_Mask(Target),
363 Client_Modes(Target));
370 * Reply to a channel mode request.
372 * @param Origin The originator of the MODE command (prefix).
373 * @param Channel The channel of which the modes should be sent.
374 * @return CONNECTED or DISCONNECTED.
377 Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
379 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
380 const char *mode_ptr;
382 if (!Channel_IsMemberOf(Channel, Origin)) {
383 /* Not a member: "simple" mode reply */
384 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
385 Client_ID(Origin), Channel_Name(Channel),
386 Channel_Modes(Channel)))
389 /* The sender is a member: generate extended reply */
390 strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
391 mode_ptr = the_modes;
397 snprintf(argadd, sizeof(argadd), " %lu",
398 Channel_MaxUsers(Channel));
399 strlcat(the_args, argadd, sizeof(the_args));
402 strlcat(the_args, " ", sizeof(the_args));
403 strlcat(the_args, Channel_Key(Channel),
410 strlcat(the_modes, the_args, sizeof(the_modes));
412 if (!IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
413 Client_ID(Origin), Channel_Name(Channel),
419 /* Channel creation time */
420 if (!IRC_WriteStrClient(Origin, RPL_CREATIONTIME_MSG,
421 Client_ID(Origin), Channel_Name(Channel),
422 Channel_CreationTime(Channel)))
429 * Handle channel mode and channel-user mode changes
431 * @param Client The client from which this command has been received.
432 * @param Req Request structure with prefix and all parameters.
433 * @param Origin The originator of the MODE command (prefix).
434 * @param Channel The target channel of this MODE command.
435 * @return CONNECTED or DISCONNECTED.
438 Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
440 char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
441 argadd[CLIENT_PASS_LEN], *mode_ptr;
442 bool connected, set, skiponce, retval, use_servermode,
443 is_halfop, is_op, is_admin, is_owner, is_machine, is_oper;
444 int mode_arg, arg_arg, mode_arg_count = 0;
449 is_halfop = is_op = is_admin = is_owner = is_machine = is_oper = false;
451 if (Channel_IsModeless(Channel))
452 return IRC_WriteErrClient(Client, ERR_NOCHANMODES_MSG,
453 Client_ID(Client), Channel_Name(Channel));
455 /* Mode request: let's answer it :-) */
457 return Channel_Mode_Answer_Request(Origin, Channel);
459 /* Check if origin is oper and opers can use mode */
460 use_servermode = Conf_OperServerMode;
461 if(Client_HasMode(Client, 'o') && Conf_OperCanMode) {
465 /* Check if client is a server/service */
466 if(Client_Type(Client) == CLIENT_SERVER ||
467 Client_Type(Client) == CLIENT_SERVICE) {
471 /* Check if client is member of channel or an oper or an server/service */
472 if(!Channel_IsMemberOf(Channel, Client) && !is_oper && !is_machine)
473 return IRC_WriteErrClient(Origin, ERR_NOTONCHANNEL_MSG,
475 Channel_Name(Channel));
478 mode_ptr = Req->argv[mode_arg];
479 if (Req->argc > mode_arg + 1)
480 arg_arg = mode_arg + 1;
484 /* Initial state: set or unset modes? */
498 /* Prepare reply string */
499 strcpy(the_modes, set ? "+" : "-");
503 connected = CONNECTED;
508 /* Try next argument if there's any */
511 if (arg_arg > mode_arg)
516 if (mode_arg >= Req->argc)
518 mode_ptr = Req->argv[mode_arg];
520 if (Req->argc > mode_arg + 1)
521 arg_arg = mode_arg + 1;
530 if (((*mode_ptr == '+') && !set)
531 || ((*mode_ptr == '-') && set)) {
532 /* Action modifier ("+"/"-") must be changed ... */
533 len = strlen(the_modes) - 1;
534 if (the_modes[len] == '+' || the_modes[len] == '-') {
535 /* Adjust last action modifier in result */
536 the_modes[len] = *mode_ptr;
538 /* Append modifier character to result string */
540 strlcat(the_modes, x, sizeof(the_modes));
542 set = *mode_ptr == '+';
547 /* Are there arguments left? */
548 if (arg_arg >= Req->argc)
551 if(!is_machine && !is_oper) {
552 if (Channel_UserHasMode(Channel, Client, 'q'))
554 if (Channel_UserHasMode(Channel, Client, 'a'))
556 if (Channel_UserHasMode(Channel, Client, 'o'))
558 if (Channel_UserHasMode(Channel, Client, 'h'))
567 /* --- Channel modes --- */
568 case 'R': /* Registered users only */
569 case 's': /* Secret channel */
570 case 'z': /* Secure connections only */
571 if(!is_oper && !is_machine && !is_owner &&
572 !is_admin && !is_op) {
573 connected = IRC_WriteErrClient(Origin,
574 ERR_CHANOPRIVSNEEDED_MSG,
575 Client_ID(Origin), Channel_Name(Channel));
578 case 'i': /* Invite only */
579 case 'V': /* Invite disallow */
580 case 'M': /* Only identified nicks can write */
581 case 'm': /* Moderated */
582 case 'n': /* Only members can write */
583 case 'N': /* Can't change nick while on this channel */
584 case 'Q': /* No kicks */
585 case 't': /* Topic locked */
586 if(is_oper || is_machine || is_owner ||
587 is_admin || is_op || is_halfop)
590 connected = IRC_WriteErrClient(Origin,
591 ERR_CHANOPRIVSNEEDED_MSG,
592 Client_ID(Origin), Channel_Name(Channel));
594 case 'k': /* Channel key */
595 if (Mode_Limit_Reached(Client, mode_arg_count++))
598 if (is_oper || is_machine || is_owner ||
599 is_admin || is_op || is_halfop) {
601 if (Channel_HasMode(Channel, 'k'))
602 strlcpy(argadd, "*", sizeof(argadd));
603 if (arg_arg > mode_arg)
606 connected = IRC_WriteErrClient(Origin,
607 ERR_CHANOPRIVSNEEDED_MSG,
609 Channel_Name(Channel));
612 if (arg_arg <= mode_arg) {
615 "Got MODE +k without key for \"%s\" from \"%s\"! Ignored.",
616 Channel_Name(Channel), Client_ID(Origin));
618 connected = IRC_WriteErrClient(Origin,
619 ERR_NEEDMOREPARAMS_MSG,
620 Client_ID(Origin), Req->command);
623 if (!Req->argv[arg_arg][0] || strchr(Req->argv[arg_arg], ' ')) {
626 "Got invalid key on MODE +k for \"%s\" from \"%s\"! Ignored.",
627 Channel_Name(Channel), Client_ID(Origin));
629 connected = IRC_WriteErrClient(Origin,
630 ERR_INVALIDMODEPARAM_MSG,
632 Channel_Name(Channel), 'k');
635 if (is_oper || is_machine || is_owner ||
636 is_admin || is_op || is_halfop) {
637 Channel_ModeDel(Channel, 'k');
638 Channel_SetKey(Channel, Req->argv[arg_arg]);
639 strlcpy(argadd, Channel_Key(Channel), sizeof(argadd));
642 connected = IRC_WriteErrClient(Origin,
643 ERR_CHANOPRIVSNEEDED_MSG,
645 Channel_Name(Channel));
647 Req->argv[arg_arg][0] = '\0';
650 case 'l': /* Member limit */
651 if (Mode_Limit_Reached(Client, mode_arg_count++))
654 if (is_oper || is_machine || is_owner ||
655 is_admin || is_op || is_halfop)
658 connected = IRC_WriteErrClient(Origin,
659 ERR_CHANOPRIVSNEEDED_MSG,
661 Channel_Name(Channel));
664 if (arg_arg <= mode_arg) {
667 "Got MODE +l without limit for \"%s\" from \"%s\"! Ignored.",
668 Channel_Name(Channel), Client_ID(Origin));
670 connected = IRC_WriteErrClient(Origin,
671 ERR_NEEDMOREPARAMS_MSG,
672 Client_ID(Origin), Req->command);
675 l = atol(Req->argv[arg_arg]);
676 if (l <= 0 || l >= 0xFFFF) {
679 "Got MODE +l with invalid limit for \"%s\" from \"%s\"! Ignored.",
680 Channel_Name(Channel), Client_ID(Origin));
682 connected = IRC_WriteErrClient(Origin,
683 ERR_INVALIDMODEPARAM_MSG,
685 Channel_Name(Channel), 'l');
688 if (is_oper || is_machine || is_owner ||
689 is_admin || is_op || is_halfop) {
690 Channel_ModeDel(Channel, 'l');
691 Channel_SetMaxUsers(Channel, l);
692 snprintf(argadd, sizeof(argadd), "%ld", l);
695 connected = IRC_WriteErrClient(Origin,
696 ERR_CHANOPRIVSNEEDED_MSG,
698 Channel_Name(Channel));
700 Req->argv[arg_arg][0] = '\0';
703 case 'O': /* IRC operators only */
705 /* Only IRC operators are allowed to
706 * set the 'O' channel mode! */
707 if(is_oper || is_machine)
710 connected = IRC_WriteErrClient(Origin,
711 ERR_NOPRIVILEGES_MSG,
713 } else if(is_oper || is_machine || is_owner ||
717 connected = IRC_WriteErrClient(Origin,
718 ERR_CHANOPRIVSNEEDED_MSG,
720 Channel_Name(Channel));
722 case 'P': /* Persistent channel */
724 /* Only IRC operators are allowed to
725 * set the 'P' channel mode! */
726 if(is_oper || is_machine)
729 connected = IRC_WriteErrClient(Origin,
730 ERR_NOPRIVILEGES_MSG,
732 } else if(is_oper || is_machine || is_owner ||
736 connected = IRC_WriteErrClient(Origin,
737 ERR_CHANOPRIVSNEEDED_MSG,
739 Channel_Name(Channel));
741 /* --- Channel user modes --- */
742 case 'q': /* Owner */
743 case 'a': /* Channel admin */
744 if(!is_oper && !is_machine && !is_owner && !is_admin) {
745 connected = IRC_WriteErrClient(Origin,
746 ERR_CHANOPPRIVTOOLOW_MSG,
748 Channel_Name(Channel));
751 case 'o': /* Channel operator */
752 if(!is_oper && !is_machine && !is_owner &&
753 !is_admin && !is_op) {
754 connected = IRC_WriteErrClient(Origin,
755 ERR_CHANOPRIVSNEEDED_MSG,
757 Channel_Name(Channel));
760 case 'h': /* Half Op */
761 if(!is_oper && !is_machine && !is_owner &&
762 !is_admin && !is_op) {
763 connected = IRC_WriteErrClient(Origin,
764 ERR_CHANOPRIVSNEEDED_MSG,
766 Channel_Name(Channel));
769 case 'v': /* Voice */
770 if (arg_arg > mode_arg) {
771 if (is_oper || is_machine || is_owner ||
772 is_admin || is_op || is_halfop) {
773 client = Client_Search(Req->argv[arg_arg]);
777 connected = IRC_WriteErrClient(Origin,
782 connected = IRC_WriteErrClient(Origin,
783 ERR_CHANOPRIVSNEEDED_MSG,
785 Channel_Name(Channel));
787 Req->argv[arg_arg][0] = '\0';
791 /* Report an error to the client, when a user
792 * mode should be changed but no nickname is
793 * given. But don't do it when not in "strict"
794 * mode, because most other servers don't do
795 * it as well and some clients send "wired"
796 * MODE commands like "MODE #chan -ooo nick". */
797 connected = IRC_WriteErrClient(Origin,
798 ERR_NEEDMOREPARAMS_MSG,
799 Client_ID(Origin), Req->command);
804 /* --- Channel lists --- */
805 case 'I': /* Invite lists */
806 case 'b': /* Ban lists */
807 case 'e': /* Channel exception lists */
808 if (Mode_Limit_Reached(Client, mode_arg_count++))
810 if (arg_arg > mode_arg) {
812 if (is_oper || is_machine || is_owner ||
813 is_admin || is_op || is_halfop) {
815 ? Add_To_List(*mode_ptr, Origin,
818 : Del_From_List(*mode_ptr, Origin,
822 connected = IRC_WriteErrClient(Origin,
823 ERR_CHANOPRIVSNEEDED_MSG,
825 Channel_Name(Channel));
827 Req->argv[arg_arg][0] = '\0';
832 Channel_ShowInvites(Origin, Channel);
835 Channel_ShowBans(Origin, Channel);
838 Channel_ShowExcepts(Origin, Channel);
844 if (Client_Type(Client) != CLIENT_SERVER) {
846 "Unknown mode \"%c%c\" from \"%s\" on %s!?",
847 set ? '+' : '-', *mode_ptr,
848 Client_ID(Origin), Channel_Name(Channel));
849 connected = IRC_WriteErrClient(Origin,
851 Client_ID(Origin), *mode_ptr,
852 Channel_Name(Channel));
856 "Handling unknown mode \"%c%c\" from \"%s\" on %s ...",
857 set ? '+' : '-', *mode_ptr,
858 Client_ID(Origin), Channel_Name(Channel));
866 /* Is there a valid mode change? */
870 /* Validate target client */
871 if (client && (!Channel_IsMemberOf(Channel, client))) {
872 if (!IRC_WriteErrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
875 Channel_Name(Channel)))
881 /* Channel-User-Mode */
883 ? Channel_UserModeAdd(Channel, client, x[0])
884 : Channel_UserModeDel(Channel, client, x[0]);
886 strlcat(the_args, " ", sizeof(the_args));
887 strlcat(the_args, Client_ID(client),
889 strlcat(the_modes, x, sizeof(the_modes));
891 ("User \"%s\": Mode change on %s, now \"%s\"",
892 Client_Mask(client), Channel_Name(Channel),
893 Channel_UserModes(Channel, client));
898 ? Channel_ModeAdd(Channel, x[0])
899 : Channel_ModeDel(Channel, x[0]);
901 strlcat(the_modes, x, sizeof(the_modes));
902 LogDebug("Channel %s: Mode change, now \"%s\".",
903 Channel_Name(Channel),
904 Channel_Modes(Channel));
908 /* Are there additional arguments to add? */
910 strlcat(the_args, " ", sizeof(the_args));
911 strlcat(the_args, argadd, sizeof(the_args));
916 /* Are there changed modes? */
918 /* Clean up mode string */
919 len = strlen(the_modes) - 1;
920 if ((the_modes[len] == '+') || (the_modes[len] == '-'))
921 the_modes[len] = '\0';
923 if (Client_Type(Client) == CLIENT_SERVER) {
924 /* MODE requests for local channels from other servers
925 * are definitely invalid! */
926 if (Channel_IsLocal(Channel) && Client != Client_ThisServer()) {
927 Log(LOG_ALERT, "Got remote MODE command for local channel!? Ignored.");
931 /* Forward mode changes to channel users and all the
932 * other remote servers: */
933 IRC_WriteStrServersPrefix(Client, Origin,
934 "MODE %s %s%s", Channel_Name(Channel),
935 the_modes, the_args);
936 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
937 false, "MODE %s %s%s", Channel_Name(Channel),
938 the_modes, the_args);
941 Origin = Client_ThisServer();
942 /* Send reply to client and inform other servers and channel users */
943 connected = IRC_WriteStrClientPrefix(Client, Origin,
944 "MODE %s %s%s", Channel_Name(Channel),
945 the_modes, the_args);
946 /* Only forward requests for non-local channels */
947 if (!Channel_IsLocal(Channel))
948 IRC_WriteStrServersPrefix(Client, Origin,
949 "MODE %s %s%s", Channel_Name(Channel),
950 the_modes, the_args);
951 IRC_WriteStrChannelPrefix(Client, Channel, Origin,
952 false, "MODE %s %s%s", Channel_Name(Channel),
953 the_modes, the_args);
961 * Handler for the IRC "AWAY" command.
963 * @param Client The client from which this command has been received.
964 * @param Req Request structure with prefix and all parameters.
965 * @return CONNECTED or DISCONNECTED.
968 IRC_AWAY( CLIENT *Client, REQUEST *Req )
970 assert (Client != NULL);
971 assert (Req != NULL);
973 if (Req->argc == 1 && Req->argv[0][0]) {
974 Client_SetAway(Client, Req->argv[0]);
975 Client_ModeAdd(Client, 'a');
976 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :+a",
978 return IRC_WriteStrClient(Client, RPL_NOWAWAY_MSG,
981 Client_ModeDel(Client, 'a');
982 IRC_WriteStrServersPrefix(Client, Client, "MODE %s :-a",
984 return IRC_WriteStrClient(Client, RPL_UNAWAY_MSG,
990 * Add entries to channel invite, ban and exception lists.
992 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
993 * @param Prefix The originator of the command.
994 * @param Client The sender of the command.
995 * @param Channel The channel of which the list should be modified.
996 * @param Pattern The pattern to add to the list.
997 * @return CONNECTED or DISCONNECTED.
1000 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1001 const char *Pattern)
1003 char mask[MASK_LEN];
1004 struct list_head *list = NULL;
1005 long int current_count;
1007 assert(Client != NULL);
1008 assert(Channel != NULL);
1009 assert(Pattern != NULL);
1010 assert(what == 'I' || what == 'b' || what == 'e');
1012 Lists_MakeMask(Pattern, mask, sizeof(mask));
1013 current_count = Lists_Count(Channel_GetListInvites(Channel))
1014 + Lists_Count(Channel_GetListExcepts(Channel))
1015 + Lists_Count(Channel_GetListBans(Channel));
1019 list = Channel_GetListInvites(Channel);
1022 list = Channel_GetListBans(Channel);
1025 list = Channel_GetListExcepts(Channel);
1029 if (Lists_CheckDupeMask(list, mask))
1031 if (Client_Type(Client) == CLIENT_USER &&
1032 current_count >= MAX_HNDL_CHANNEL_LISTS)
1033 return IRC_WriteErrClient(Client, ERR_LISTFULL_MSG,
1035 Channel_Name(Channel), mask,
1036 MAX_HNDL_CHANNEL_LISTS);
1040 if (!Channel_AddInvite(Channel, mask, false, Client_ID(Client)))
1044 if (!Channel_AddBan(Channel, mask, Client_ID(Client)))
1048 if (!Channel_AddExcept(Channel, mask, Client_ID(Client)))
1052 return Send_ListChange(true, what, Prefix, Client, Channel, mask);
1056 * Delete entries from channel invite, ban and exception lists.
1058 * @param what Can be 'I' for invite, 'b' for ban, and 'e' for exception list.
1059 * @param Prefix The originator of the command.
1060 * @param Client The sender of the command.
1061 * @param Channel The channel of which the list should be modified.
1062 * @param Pattern The pattern to add to the list.
1063 * @return CONNECTED or DISCONNECTED.
1066 Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
1067 const char *Pattern)
1069 char mask[MASK_LEN];
1070 struct list_head *list = NULL;
1072 assert(Client != NULL);
1073 assert(Channel != NULL);
1074 assert(Pattern != NULL);
1075 assert(what == 'I' || what == 'b' || what == 'e');
1077 Lists_MakeMask(Pattern, mask, sizeof(mask));
1081 list = Channel_GetListInvites(Channel);
1084 list = Channel_GetListBans(Channel);
1087 list = Channel_GetListExcepts(Channel);
1091 if (!Lists_CheckDupeMask(list, mask))
1093 Lists_Del(list, mask);
1095 return Send_ListChange(false, what, Prefix, Client, Channel, mask);
1099 * Send information about changed channel invite/ban/exception lists to clients.
1101 * @param IsAdd true if the list item has been added, false otherwise.
1102 * @param ModeChar The mode to use (e. g. 'b' or 'I')
1103 * @param Prefix The originator of the mode list change.
1104 * @param Client The sender of the command.
1105 * @param Channel The channel of which the list has been modified.
1106 * @param Mask The mask which has been added or removed.
1107 * @return CONNECTED or DISCONNECTED.
1110 Send_ListChange(const bool IsAdd, const char ModeChar, CLIENT *Prefix,
1111 CLIENT *Client, CHANNEL *Channel, const char *Mask)
1115 /* Send confirmation to the client */
1116 if (Client_Type(Client) == CLIENT_USER)
1117 ok = IRC_WriteStrClientPrefix(Client, Prefix, "MODE %s %c%c %s",
1118 Channel_Name(Channel),
1122 /* to other servers */
1123 IRC_WriteStrServersPrefix(Client, Prefix, "MODE %s %c%c %s",
1124 Channel_Name(Channel), IsAdd ? '+' : '-',
1127 /* and local users in channel */
1128 IRC_WriteStrChannelPrefix(Client, Channel, Prefix, false,
1129 "MODE %s %c%c %s", Channel_Name(Channel),
1130 IsAdd ? '+' : '-', ModeChar, Mask );
1133 } /* Send_ListChange */