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.
This commit is contained in:
Jilles Tjoelker 2010-08-29 01:26:00 +02:00
parent 8a419c6092
commit 717238d2a2
10 changed files with 73 additions and 15 deletions

View file

@ -337,6 +337,7 @@ channel {
kick_on_split_riding = no;
only_ascii_channels = no;
resv_forcepart = yes;
channel_target_change = yes;
};
serverhide {

View file

@ -755,6 +755,12 @@ channel {
* 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;
};

View file

@ -3,15 +3,17 @@ Lee H <lee -at- leeh.co.uk>
---------------------------
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.
@ -20,14 +22,14 @@ Additionally, clients that message or invite you are placed in one of a
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
@ -35,9 +37,10 @@ receive one free slot on a reconnection. Other servers using this mechanism
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.
--
$Id: tgchange.txt 6 2005-09-10 01:02:21Z nenolod $

View file

@ -246,6 +246,7 @@ struct config_channel_entry
int kick_on_split_riding;
int only_ascii_channels;
int resv_forcepart;
int channel_target_change;
};
struct config_server_hide

View file

@ -30,6 +30,8 @@
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);

View file

@ -510,6 +510,14 @@ msg_channel(int p_or_n, const char *command,
/* 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))
{
@ -533,6 +541,13 @@ msg_channel(int p_or_n, const char *command,
(!(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,

View file

@ -39,6 +39,7 @@
#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 **);
@ -114,6 +115,15 @@ m_topic(struct Client *client_p, struct Client *source_p, int parc, 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(((chptr->mode.mode & MODE_TOPICLIMIT) == 0 ||
is_chanop(msptr)) &&
(!MyClient(source_p) ||

View file

@ -2199,6 +2199,7 @@ static struct ConfEntry conf_channel_table[] =
{ "use_knock", CF_YESNO, NULL, 0, &ConfigChannel.use_knock },
{ "use_forward", CF_YESNO, NULL, 0, &ConfigChannel.use_forward },
{ "resv_forcepart", CF_YESNO, NULL, 0, &ConfigChannel.resv_forcepart },
{ "channel_target_change", CF_YESNO, NULL, 0, &ConfigChannel.channel_target_change },
{ "\0", 0, NULL, 0, NULL }
};

View file

@ -772,6 +772,7 @@ set_default_conf(void)
ConfigChannel.no_join_on_split = NO;
ConfigChannel.no_create_on_split = YES;
ConfigChannel.resv_forcepart = YES;
ConfigChannel.channel_target_change = YES;
ConfigServerHide.flatten_links = 0;
ConfigServerHide.links_delay = 300;

View file

@ -30,6 +30,8 @@
#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)
{
@ -48,9 +50,7 @@ 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))
@ -65,6 +65,24 @@ add_target(struct Client *source_p, struct Client *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 */