0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-20 08:51:18 +01:00

flood_recalc moved on ratbox3 event engine

This commit is contained in:
Valery Yatsko 2008-04-02 21:10:29 +04:00
parent 60eb0cdc9c
commit 5a606a8f8c
3 changed files with 59 additions and 38 deletions

View file

@ -48,7 +48,7 @@
extern PF read_ctrl_packet; extern PF read_ctrl_packet;
extern PF read_packet; extern PF read_packet;
extern PF flood_recalc; extern EVH flood_recalc;
extern void flood_endgrace(struct Client *); extern void flood_endgrace(struct Client *);
#endif /* INCLUDED_packet_h */ #endif /* INCLUDED_packet_h */

View file

@ -126,6 +126,7 @@ init_client(void)
rb_event_addish("check_pings", check_pings, NULL, 30); rb_event_addish("check_pings", check_pings, NULL, 30);
rb_event_addish("free_exited_clients", &free_exited_clients, NULL, 4); rb_event_addish("free_exited_clients", &free_exited_clients, NULL, 4);
rb_event_addish("exit_aborted_clients", exit_aborted_clients, NULL, 1); rb_event_addish("exit_aborted_clients", exit_aborted_clients, NULL, 1);
rb_event_add("flood_recalc", flood_recalc, NULL, 1);
nd_dict = irc_dictionary_create(irccmp); nd_dict = irc_dictionary_create(irccmp);
} }

View file

@ -172,36 +172,56 @@ flood_endgrace(struct Client *client_p)
* once a second on any given client. We then attempt to flush some data. * once a second on any given client. We then attempt to flush some data.
*/ */
void void
flood_recalc(int fd, void *data) flood_recalc(void *unused)
{ {
struct Client *client_p = data; rb_dlink_node *ptr, *next;
struct LocalUser *lclient_p = client_p->localClient; struct Client *client_p;
/* This can happen in the event that the client detached. */ RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head)
if(!lclient_p) {
return; client_p = ptr->data;
/* allow a bursting client their allocation per second, allow if(unlikely(IsMe(client_p)))
* a client whos flooding an extra 2 per second continue;
*/
if(IsFloodDone(client_p))
lclient_p->sent_parsed -= 2;
else
lclient_p->sent_parsed = 0;
if(lclient_p->sent_parsed < 0) if(unlikely(client_p->localClient == NULL))
lclient_p->sent_parsed = 0; continue;
if(--lclient_p->actually_read < 0) if(IsFloodDone(client_p))
lclient_p->actually_read = 0; client_p->localClient->sent_parsed -= 2;
else
client_p->localClient->sent_parsed = 0;
parse_client_queued(client_p); if(client_p->localClient->sent_parsed < 0)
client_p->localClient->sent_parsed = 0;
if(IsAnyDead(client_p)) if(--client_p->localClient->actually_read < 0)
return; client_p->localClient->actually_read = 0;
/* and finally, reset the flood check */ parse_client_queued(client_p);
rb_setflush(fd, 1000, flood_recalc, client_p);
if(unlikely(IsAnyDead(client_p)))
continue;
}
RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head)
{
client_p = ptr->data;
if(client_p->localClient == NULL)
continue;
client_p->localClient->sent_parsed--;
if(client_p->localClient->sent_parsed < 0)
client_p->localClient->sent_parsed = 0;
if(--client_p->localClient->actually_read < 0)
client_p->localClient->actually_read = 0;
parse_client_queued(client_p);
}
} }
/* /*