2 * Solanum: a slightly advanced ircd
3 * shedding.c: Enables/disables user shedding.
5 * Based on oftc-hybrid's m_shedding.c
7 * Copyright (C) 2021 David Schultz <me@zpld.me>
8 * Copyright (C) 2002 by the past and present ircd coders, and others.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
36 #include "s_newconf.h"
40 #define SHED_RATE_MIN 5
42 static struct ev_entry
*user_shedding_ev
= NULL
;
44 static const char shed_desc
[] = "Enables/disables user shedding.";
46 static void mo_shedding(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
47 static void me_shedding(struct MsgBuf
*msgbuf
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[]);
48 static void do_user_shedding(void *unused
);
50 static struct Message shedding_msgtab
= {
51 "SHEDDING", 0, 0, 0, 0,
52 {mg_unreg
, mg_not_oper
, mg_ignore
, mg_ignore
, {me_shedding
, 2}, {mo_shedding
, 3}}
55 mapi_clist_av1 shedding_clist
[] = { &shedding_msgtab
, NULL
};
60 rb_event_delete(user_shedding_ev
);
63 DECLARE_MODULE_AV2(shed
, NULL
, moddeinit
, shedding_clist
, NULL
, NULL
, NULL
, NULL
, shed_desc
);
66 set_shedding_state(struct Client
*source_p
, const char *chr
, const char *reason
)
69 if (irccmp(chr
, "OFF") == 0)
72 sendto_realops_snomask(SNO_GENERAL
, L_ALL
| L_NETWIDE
, "%s disabled user shedding", get_oper_name(source_p
));
73 rb_event_delete(user_shedding_ev
);
74 user_shedding_ev
= NULL
;
80 if(rate
< SHED_RATE_MIN
)
82 sendto_one_notice(source_p
, "Shedding rate must be at least %d", SHED_RATE_MIN
);
86 sendto_realops_snomask(SNO_GENERAL
, L_ALL
| L_NETWIDE
, "%s enabled user shedding (interval: %d seconds, reason: %s)",
87 get_oper_name(source_p
), rate
, reason
);
89 rb_event_delete(user_shedding_ev
);
90 user_shedding_ev
= NULL
;
91 user_shedding_ev
= rb_event_add("user shedding event", do_user_shedding
, NULL
, rate
);
97 * inputs - pointer to server
102 * side effects - user shedding is enabled or disabled
104 * SHEDDING <server> OFF - disable shedding
105 * SHEDDING <server> <approx_seconds_per_userdrop> :<reason>
110 mo_shedding(struct MsgBuf
*msgbuf_p
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
112 if (!HasPrivilege(source_p
, "oper:shedding"))
114 sendto_one(source_p
, form_str(ERR_NOPRIVS
), me
.name
, source_p
->name
, "SHEDDING");
118 /* I can think of a thousand ways this could go wrong... */
119 if (strchr(parv
[1], '*') != NULL
)
121 sendto_one_notice(source_p
, "Wildcards are not permitted for shedding targets");
125 if (parc
!= 4 && !(parc
== 3 && irccmp(parv
[2], "OFF") == 0))
127 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
),
128 me
.name
, source_p
->name
, "SHEDDING");
132 if (irccmp(parv
[1], me
.name
) != 0) {
133 /* it's not for us, pass it around */
134 if (irccmp(parv
[2], "OFF") == 0)
135 sendto_match_servs(source_p
, parv
[1],
137 "ENCAP %s SHEDDING OFF", parv
[1]);
139 sendto_match_servs(source_p
, parv
[1],
141 "ENCAP %s SHEDDING %s :%s",
142 parv
[1], parv
[2], parv
[3]);
146 set_shedding_state(source_p
, parv
[2], parv
[3]);
150 me_shedding(struct MsgBuf
*msgbuf
, struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
152 if(!IsPerson(source_p
))
155 set_shedding_state(source_p
, parv
[1], parv
[2]);
160 do_user_shedding(void *unused
)
163 struct Client
*client_p
;
165 RB_DLINK_FOREACH_PREV(ptr
, lclient_list
.tail
)
167 client_p
= ptr
->data
;
169 if (!IsClient(client_p
)) /* It could be servers */
171 if (IsExemptKline(client_p
))
173 exit_client(client_p
, client_p
, &me
, "Server closed connection");