Prechádzať zdrojové kódy

* Change msgrate to milliseconds

Bryan Drewery 16 rokov pred
rodič
commit
e540ccd937
3 zmenil súbory, kde vykonal 32 pridanie a 18 odobranie
  1. 24 14
      src/mod/server.mod/server.c
  2. 6 2
      src/mod/server.mod/servmsg.c
  3. 2 2
      src/set.c

+ 24 - 14
src/mod/server.mod/server.c

@@ -91,7 +91,7 @@ static bool resolvserv;		/* in the process of resolving a server host */
 static time_t lastpingtime;	/* IRCNet LAGmeter support -- drummer */
 static char stackablecmds[511] = "";
 static char stackable2cmds[511] = "";
-static time_t last_time;
+static egg_timeval_t last_time;
 static bool use_penalties;
 static int use_fastdeq;
 size_t nick_len = 9;			/* Maximal nick length allowed on the network. */
@@ -142,6 +142,9 @@ static int burst;
  */
 static void deq_msg()
 {
+  if (serv < 0)
+    return;
+
   static const struct {
     struct msgq_head *q;
     int idx;
@@ -153,24 +156,26 @@ static void deq_msg()
   bool ok = 0;
 
   /* now < last_time tested 'cause clock adjustments could mess it up */
-  if ((now - last_time) >= msgrate || now < (last_time - 90)) {
-    last_time = now;
+  long usecs = timeval_diff(&egg_timeval_now, &last_time);
+  if (usecs >= msgrate || now < (last_time.sec - 90)) {
+    last_time.sec = egg_timeval_now.sec;
+    last_time.usec = egg_timeval_now.usec;
     if (burst > 0)
       burst = 0;
     ok = 1;
   }
-  if (serv < 0)
-    return;
+
+  if (!ok) return;
 
   struct msgq *q = NULL;
 
-  /* Send upto 4 msgs to server if the *critical queue* has anything in it;
-   * otherwise, dequeue and burst up to 4 messages from the `normal' message
+  /* Send upto 'set msgburst' msgs to server if the *critical queue* has anything in it;
+   * otherwise, dequeue and burst up to 'set msgburst' messages from the `normal' message
    * queue.
    */
   bool nm = 0;
   for(size_t nq = 0; nq < (sizeof(qdsc) / sizeof(qdsc[0])); ++nq) {
-    while (qdsc[nq].q->head && (burst < msgburst) && ((last_time - now) < MAXPENALTY)) {
+    while (qdsc[nq].q->head && (burst < msgburst) && ((last_time.sec - now) < MAXPENALTY)) {
 #ifdef not_implemented
       if (deq_kick(qdsc[nq].idx)) {
         ++burst;
@@ -188,7 +193,7 @@ static void deq_msg()
       if (debug_output)
         putlog(LOG_SRVOUT, "*", "%s %s", qdsc[nq].pfx, qdsc[nq].q->head->msg);
       --(qdsc[nq].q->tot);
-      last_time += calc_penalty(qdsc[nq].q->head->msg);
+      last_time.sec += calc_penalty(qdsc[nq].q->head->msg);
       q = qdsc[nq].q->head->next;
       free(qdsc[nq].q->head->msg);
       free(qdsc[nq].q->head);
@@ -213,7 +218,7 @@ static void deq_msg()
     putlog(LOG_SRVOUT, "@", "[h->] %s", hq.head->msg);
   }
   hq.tot--;
-  last_time += calc_penalty(hq.head->msg);
+  last_time.sec += calc_penalty(hq.head->msg);
   q = hq.head->next;
   free(hq.head->msg);
   free(hq.head);
@@ -235,9 +240,9 @@ static int calc_penalty(char * msg)
     i = strlen(msg);
   else
     i = strlen(cmd);
-  last_time -= 2; /* undo eggdrop standard flood prot */
+  last_time.sec -= 2; /* undo eggdrop standard flood prot */
   if (net_type == NETT_UNDERNET || net_type == NETT_HYBRID_EFNET) {
-    last_time += (2 + i / 120);
+    last_time.sec += (2 + i / 120);
     return 0;
   }
   penalty = (1 + i / 100);
@@ -505,7 +510,7 @@ static bool fast_deq(int which)
           break;
       }
     }
-    last_time += calc_penalty(tosend);
+    last_time.sec += calc_penalty(tosend);
     return 1;
   }
   return 0;
@@ -975,7 +980,6 @@ static void server_secondly()
 {
   if (cycle_time)
     --cycle_time;
-  deq_msg();
   if (!resolvserv && serv < 0 && !trying_server)
     connect_server();
 }
@@ -1101,6 +1105,12 @@ void server_init()
   add_builtins("dcc", C_dcc_serv);
   add_builtins("ctcp", my_ctcps);
 
+  egg_timeval_t howlong;
+
+  howlong.sec = 0;
+  howlong.usec = 400 * 1000;
+
+  timer_create_repeater(&howlong, "server_queue", (Function) deq_msg);
   timer_create_secs(1, "server_secondly", (Function) server_secondly);
   timer_create_secs(30, "server_check_lag", (Function) server_check_lag);
   timer_create_secs(300, "server_5minutely", (Function) server_5minutely);

+ 6 - 2
src/mod/server.mod/servmsg.c

@@ -1239,7 +1239,7 @@ static int gotkick(char *from, char *msg)
     /* Not my kick, I don't need to bother about it. */
     return 0;
   if (use_penalties) {
-    last_time += 2;
+    last_time.sec += 2;
     if (debug_output)
       putlog(LOG_SRVOUT, "*", "adding 2secs penalty (successful kick)");
   }
@@ -1264,7 +1264,7 @@ static int whoispenalty(char *from, char *msg)
       i++;
     }
     if (ii) {
-      last_time += 1;
+      last_time.sec += 1;
       if (debug_output)
         putlog(LOG_SRVOUT, "*", "adding 1sec penalty (remote whois)");
     }
@@ -1776,6 +1776,10 @@ static void server_dns_callback(int id, void *client_data, const char *host, bd:
     /* reset counter so first ctcp is dumped for tcms */
     first_ctcp_check = 0;
 
+    // Just connecting, set last queue time to the past.
+    last_time.sec = now - 100;
+    last_time.usec = 0;
+
     if (serverpass[0])
       dprintf(DP_MODE, "PASS %s\n", serverpass);
     dprintf(DP_MODE, "NICK %s\n", botname);

+ 2 - 2
src/set.c

@@ -105,8 +105,8 @@ static variable_t vars[] = {
  VAR("msg-invite",	msginvite,		VAR_WORD|VAR_NOLHUB,				0, 0, NULL),
  VAR("msg-op",		msgop,			VAR_WORD|VAR_NOLHUB,				0, 0, NULL),
  VAR("msg-pass",	msgpass,		VAR_WORD|VAR_NOLHUB,				0, 0, NULL),
- VAR("msgburst",	&msgburst,		VAR_INT|VAR_NOLHUB,				1, 90, "4"),
- VAR("msgrate",		&msgrate,		VAR_INT|VAR_NOLHUB,				0, 90, "2"),
+ VAR("msgburst",	&msgburst,		VAR_INT|VAR_NOLHUB,				1, 90, "5"),
+ VAR("msgrate",		&msgrate,		VAR_INT|VAR_NOLHUB,				0, 10000, "2200"),
  VAR("nick",		origbotname,		VAR_WORD|VAR_NOHUB|VAR_NICK|VAR_NODEF,	0, 0, NULL),
  VAR("notify-time",	&ison_time,		VAR_INT|VAR_NOLHUB,				1, 30, "10"),
  VAR("oidentd",		&oidentd,		VAR_INT|VAR_BOOL|VAR_NOLHUB,			0, 1, "0"),