Commits

Anonymous committed a54c4a0

Add target change for channels.

This has a separate enabling option channel::channel_target_change.

It applies to PRIVMSG, NOTICE and TOPIC by unvoiced unopped non-opers.

The same slots are used for channels and users.

Comments (0)

Files changed (10)

 	cycle_host_change = yes;
 	host_in_topic = yes;
 	resv_forcepart = yes;
+	channel_target_change = yes;
 };
 
 serverhide {

doc/reference.conf

 	 * when a RESV is issued.
 	 */
 	resv_forcepart = yes;
+
+	/* channel target change: restrict how many channels users can
+	 * message per unit of time. IRC operators, channel operators and
+	 * voiced users are exempt.
+	 */
+	channel_target_change = yes;
 };
 
 
 ---------------------------
 
 Reworked by Jilles Tjoelker, February 2010.
+Channel target change added by Jilles Tjoelker, August 2010.
 
 If the server you are using uses the target change mechanism, then
-restrictions are placed on how many different users you can message in a set
-timeframe. This also applies to invites.
+restrictions are placed on how many different users and/or channels you can
+message in a set timeframe.  This also applies to invites (for the target
+user) and topic changes.
 
-Target change does not apply to channels, ctcp replies, messages to
-yourself or messages to services.
+Target change does not apply to ctcp replies, messages to yourself, messages
+to services and joins.
 
-You will have a set number of 'slots', each different client you message
+You will have a set number of 'slots', each different target you message
 will take up one slot.  A client doing a nick change will not use a new slot,
 however a client disconnecting from the server it is on and reconnecting
 will.  You will receive 1 new slot roughly every minute.
 small number of special slots, in many cases allowing replies without using
 a slot.
 
-When all slots are filled, messages to new clients will not be accepted.
-Messages to clients already filling a slot will be accepted.  If all slots
+When all slots are filled, messages to new targets will not be accepted.
+Messages to targets already filling a slot will be accepted.  If all slots
 are full, you will receive the ERR_TARGCHANGE numeric, number 707 in the
 form:
-:<server> 707 <yournick> <targetnick> :Targets changing too fast, message dropped
+:<server> 707 <yournick> <target> :Targets changing too fast, message dropped
 
-The slots are operated in an LRU (least recently used), so the person you
-have talked to least recently will be replaced.
+The slots are operated in an LRU (least recently used), so the person or
+channel you have talked to least recently will be replaced.
 
 The number of slots in use will be kept through a reconnection, though the
 information in those slots will be dropped.  However, you will always
 will also be made aware of details about slots.
 
 Target change does not apply if you are opped or voiced in a channel, and
-you are messaging a client within that channel.  This can be done explicitly
-using the CNOTICE and CPRIVMSG commands, see /quote help cnotice and /quote
-help cprivmsg, but is also implicit in a normal /msg, /notice or /invite.
+you are messaging that channel or a client within that channel.  The latter
+can be done explicitly using the CNOTICE and CPRIVMSG commands, see
+/quote help cnotice and /quote help cprivmsg, but is also implicit in a
+normal /msg, /notice or /invite.
 
 -- 
 	int cycle_host_change;
 	int host_in_topic;
 	int resv_forcepart;
+	int channel_target_change;
 
 	int exempt_cmode_c;
 	int exempt_cmode_C;

include/tgchange.h

 struct Channel *find_allowing_channel(struct Client *source_p, struct Client *target_p);
 /* checks if source_p is allowed to send to target_p */
 int add_target(struct Client *source_p, struct Client *target_p);
+/* checks if source_p is allowed to send to chptr */
+int add_channel_target(struct Client *source_p, struct Channel *chptr);
 /* allows source_p to send to target_p */
 void add_reply_target(struct Client *source_p, struct Client *target_p);
 

modules/core/m_message.c

 	/* chanops and voiced can flood their own channel with impunity */
 	if((result = can_send(chptr, source_p, NULL)))
 	{
+		if(result != CAN_SEND_OPV && MyClient(source_p) &&
+		   !IsOper(source_p) &&
+		   !add_channel_target(source_p, chptr))
+		{
+			sendto_one(source_p, form_str(ERR_TARGCHANGE),
+				   me.name, source_p->name, chptr->chname);
+			return;
+		}
 		if(result == CAN_SEND_OPV ||
 		   !flood_attack_channel(p_or_n, source_p, chptr, chptr->chname))
 		{
 			(!(chptr->mode.mode & MODE_NOPRIVMSGS) ||
 			 IsMember(source_p, chptr)))
 	{
+		if(MyClient(source_p) && !IsOper(source_p) &&
+		   !add_channel_target(source_p, chptr))
+		{
+			sendto_one(source_p, form_str(ERR_TARGCHANGE),
+				   me.name, source_p->name, chptr->chname);
+			return;
+		}
 		if(!flood_attack_channel(p_or_n, source_p, chptr, chptr->chname))
 		{
 			sendto_channel_opmod(client_p, source_p, chptr,

modules/m_topic.c

 #include "parse.h"
 #include "modules.h"
 #include "packet.h"
+#include "tgchange.h"
 
 static int m_topic(struct Client *, struct Client *, int, const char **);
 static int ms_topic(struct Client *, struct Client *, int, const char **);
 			return 0;
 		}
 
+		if(MyClient(source_p) && !is_chanop_voiced(msptr) &&
+				!IsOper(source_p) &&
+				!add_channel_target(source_p, chptr))
+		{
+			sendto_one(source_p, form_str(ERR_TARGCHANGE),
+				   me.name, source_p->name, chptr->chname);
+			return 0;
+		}
+
 		if(MyClient(source_p) && (chptr->mode.mode & MODE_TOPICLIMIT) && !is_any_op(msptr))
 		{
 			if(IsOverride(source_p))
 	{ "use_knock",		CF_YESNO, NULL, 0, &ConfigChannel.use_knock		},
 	{ "use_local_channels",	CF_YESNO, NULL, 0, &ConfigChannel.use_local_channels	},
 	{ "resv_forcepart",     CF_YESNO, NULL, 0, &ConfigChannel.resv_forcepart	},
+	{ "channel_target_change", CF_YESNO, NULL, 0, &ConfigChannel.channel_target_change  },
 	{ "exempt_cmode_c",	CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_c	},
 	{ "exempt_cmode_C",	CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_C	},
 	{ "exempt_cmode_D",	CF_YESNO, NULL, 0, &ConfigChannel.exempt_cmode_D	},
 	ConfigChannel.no_join_on_split = NO;
 	ConfigChannel.no_create_on_split = YES;
 	ConfigChannel.resv_forcepart = YES;
+	ConfigChannel.channel_target_change = YES;
 
 	ConfigChannel.exempt_cmode_c = NO;
 	ConfigChannel.exempt_cmode_C = NO;
 #include "hash.h"
 #include "s_newconf.h"
 
+static int add_hashed_target(struct Client *source_p, uint32_t hashv);
+
 struct Channel *
 find_allowing_channel(struct Client *source_p, struct Client *target_p)
 {
 int
 add_target(struct Client *source_p, struct Client *target_p)
 {
-	int i, j;
 	uint32_t hashv;
-	uint32_t *targets;
 
 	/* can msg themselves or services without using any target slots */
 	if(source_p == target_p || IsService(target_p))
 		return 1;
 
 	hashv = fnv_hash_upper((const unsigned char *)use_id(target_p), 32);
+	return add_hashed_target(source_p, hashv);
+}
+
+int
+add_channel_target(struct Client *source_p, struct Channel *chptr)
+{
+	uint32_t hashv;
+
+	hashv = fnv_hash_upper((const unsigned char *)chptr->chname, 32);
+	return add_hashed_target(source_p, hashv);
+}
+
+static int
+add_hashed_target(struct Client *source_p, uint32_t hashv)
+{
+	int i, j;
+	uint32_t *targets;
+
 	targets = source_p->localClient->targets;
 
 	/* check for existing target, and move it to the head */