]> jfr.im git - solanum.git/commitdiff
flood_recalc moved on ratbox3 event engine
authorValery Yatsko <redacted>
Wed, 2 Apr 2008 17:10:29 +0000 (21:10 +0400)
committerValery Yatsko <redacted>
Wed, 2 Apr 2008 17:10:29 +0000 (21:10 +0400)
include/packet.h
src/client.c
src/packet.c

index 7962e6b3aa93ebb8a45359a3db1abe7640b0dba4..6f7e3d3bf61331581f354dc7bf95d9f761d5c46f 100644 (file)
@@ -48,7 +48,7 @@
 
 extern PF read_ctrl_packet;
 extern PF read_packet;
-extern PF flood_recalc;
+extern EVH flood_recalc;
 extern void flood_endgrace(struct Client *);
 
 #endif /* INCLUDED_packet_h */
index ecc87224787198a3b05fb05746d2d4f28aff269a..f8894da39c3a25a8b2d520d4fbe6a2e164261651 100644 (file)
@@ -126,6 +126,7 @@ init_client(void)
        rb_event_addish("check_pings", check_pings, NULL, 30);
        rb_event_addish("free_exited_clients", &free_exited_clients, NULL, 4);
        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);
 }
index 6d203a1b8689d6e508e3e69efe5593fe1313ba87..f1d87cdc435675d20c621695258ff61fc0c8eea6 100644 (file)
@@ -165,43 +165,63 @@ flood_endgrace(struct Client *client_p)
        client_p->localClient->sent_parsed = 0;
 }
 
-/*
- * flood_recalc
- *
- * recalculate the number of allowed flood lines. this should be called
- * once a second on any given client. We then attempt to flush some data.
- */
-void
-flood_recalc(int fd, void *data)
-{
-       struct Client *client_p = data;
-       struct LocalUser *lclient_p = client_p->localClient;
-
-       /* This can happen in the event that the client detached. */
-       if(!lclient_p)
-               return;
-
-       /* allow a bursting client their allocation per second, allow
-        * a client whos flooding an extra 2 per second
-        */
-       if(IsFloodDone(client_p))
-               lclient_p->sent_parsed -= 2;
-       else
-               lclient_p->sent_parsed = 0;
-
-       if(lclient_p->sent_parsed < 0)
-               lclient_p->sent_parsed = 0;
-
-       if(--lclient_p->actually_read < 0)
-               lclient_p->actually_read = 0;
-
-       parse_client_queued(client_p);
-
-       if(IsAnyDead(client_p))
-               return;
-
-       /* and finally, reset the flood check */
-       rb_setflush(fd, 1000, flood_recalc, client_p);
+/*\r
+ * flood_recalc\r
+ *\r
+ * recalculate the number of allowed flood lines. this should be called\r
+ * once a second on any given client. We then attempt to flush some data.\r
+ */\r
+void\r
+flood_recalc(void *unused)\r
+{\r
+       rb_dlink_node *ptr, *next;\r
+       struct Client *client_p;\r
+\r
+       RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head)\r
+       {\r
+               client_p = ptr->data;\r
+\r
+               if(unlikely(IsMe(client_p)))\r
+                       continue;\r
+                       \r
+               if(unlikely(client_p->localClient == NULL))\r
+                       continue;\r
+               \r
+               if(IsFloodDone(client_p))\r
+                       client_p->localClient->sent_parsed -= 2;\r
+               else\r
+                       client_p->localClient->sent_parsed = 0;\r
+                       \r
+               if(client_p->localClient->sent_parsed < 0)\r
+                       client_p->localClient->sent_parsed = 0;\r
+\r
+               if(--client_p->localClient->actually_read < 0)\r
+                       client_p->localClient->actually_read = 0;\r
+\r
+               parse_client_queued(client_p);\r
+               \r
+               if(unlikely(IsAnyDead(client_p)))\r
+                       continue;\r
+\r
+       }\r
+\r
+       RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head)\r
+       {\r
+               client_p = ptr->data;\r
+\r
+               if(client_p->localClient == NULL)\r
+                       continue;\r
+\r
+               client_p->localClient->sent_parsed--;\r
+\r
+               if(client_p->localClient->sent_parsed < 0)\r
+                       client_p->localClient->sent_parsed = 0;\r
+\r
+               if(--client_p->localClient->actually_read < 0)\r
+                       client_p->localClient->actually_read = 0;\r
+\r
+               parse_client_queued(client_p);\r
+       }\r
 }
 
 /*