Skip to content

Commit

Permalink
New cmode.flood_type_action which can be used to indicate a channel…
Browse files Browse the repository at this point in the history
… mode

can be used from +f/+F as an action. You need to specify for which
flood type your mode is, eg `cmode.flood_type_action = 'j';` for joinflood.

Currently a mode can only choose one flood type action due to +f/+F
timer fights that could otherwise occur, but that shouldn't be too
much of an issue since we can live with that in core as well.
  • Loading branch information
syzop committed Apr 2, 2023
1 parent a9b71b5 commit a19b2ae
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
3 changes: 3 additions & 0 deletions doc/RELEASE-NOTES.md
Expand Up @@ -80,6 +80,9 @@ in progress and not a stable version.
`int soft` and for return value you will normally `return 0` here.
You can `return 1` if you resist freeing, which is rare and only used by
`+F` with set::anti-flood::channel::default-profile.
* New `cmode.flood_type_action` which can be used to indicate a channel mode
can be used from +f/+F as an action. You need to specify for which
flood type your mode is, eg `cmode.flood_type_action = 'j';` for joinflood.
* JSON-RPC supports
[UNIX domain sockets](https://www.unrealircd.org/docs/JSON-RPC:Technical_documentation#UNIX_domain_socket)
for making RPC calls. If those are used, we now split on `\n` (newline)
Expand Down
8 changes: 7 additions & 1 deletion include/modules.h
Expand Up @@ -321,14 +321,19 @@ struct Cmode {
/** Unsetting also eats/requires a parameter. Unusual, but possible. */
char unset_with_param;

/** Is this mode available for chanmode +f, and if so for which flood type?
* eg 'j' for join flood.
*/
char flood_type_action;

/** Is this mode being unloaded?
* This is set to 1 if the chanmode module providing this mode is unloaded
* and we are waiting to see if in our new round of loads a "new" chanmode
* module will popup to take this mode. This only happens during a rehash,
* should never be 0 outside an internal rehash.
*/
char unloaded;

/** Slot number - Can be used instead of GETPARAMSLOT() */
int param_slot;

Expand All @@ -355,6 +360,7 @@ typedef struct {
int (*sjoin_check)(Channel *, void *, void *);
char local;
char unset_with_param;
char flood_type_action;
} CmodeInfo;

/** Get a slot number for a param - eg GETPARAMSLOT('k') */
Expand Down
1 change: 1 addition & 0 deletions src/api-channelmode.c
Expand Up @@ -423,6 +423,7 @@ Cmode *CmodeAdd(Module *module, CmodeInfo req, Cmode_t *mode)
cm->sjoin_check = req.sjoin_check;
cm->local = req.local;
cm->unset_with_param = req.unset_with_param;
cm->flood_type_action = req.flood_type_action;
cm->owner = module;
cm->unloaded = 0;

Expand Down
21 changes: 19 additions & 2 deletions src/modules/chanmodes/floodprot.c
Expand Up @@ -98,8 +98,10 @@ struct MemberFlood {

/* Maximum timers, iotw: max number of possible actions.
* Currently this is: CNmMKiRd (8)
* But bumped to 15 because we now have cmode.flood_type_action
* so there could be more ;).
*/
#define MAXCHMODEFACTIONS 8
#define MAXCHMODEFACTIONS 15

/** Per-channel flood protection settings and counters */
struct ChannelFloodProtection {
Expand Down Expand Up @@ -653,6 +655,21 @@ int parse_channel_mode_flood_failed(const char **error_out, ChannelFloodProtecti
return 0;
}

int floodprot_valid_alternate_action(char action, FloodType *floodtype)
{
Cmode *cm;

/* Built-in actions */
if (strchr(floodtype->actions, action))
return 1;

cm = find_channel_mode_handler(action);
if (cm && cm->flood_type_action == floodtype->letter)
return 1;

return 0;
}

/** Parse channel mode +f string.
* @param param The parameter string to parse
* @param fld The setting struct to fill, this MAY already contain data.
Expand Down Expand Up @@ -759,7 +776,7 @@ int parse_channel_mode_flood(const char *param, ChannelFloodProtection *fld, int

index = floodtype->index;
fld->limit[index] = v;
if (a && strchr(floodtype->actions, a))
if (a && floodprot_valid_alternate_action(a, floodtype))
fld->action[index] = a;
else
fld->action[index] = floodtype->default_action;
Expand Down

0 comments on commit a19b2ae

Please sign in to comment.