[eggheads-patches] PATCH1.4: penalties3

Florian Sander gquann at gmx.de
Mon Oct 11 16:08:59 CST 1999


Hi :)

Well, not much to say about. Same as penalties2 but it now also
calculates how many lines of burst can be sent. Penalties2 didn't
calculate MODE #chan1,#chan2,#chan3... correctly, penalties3 does.

  bye

PS: I hope the attachment has the correct format.
-- 
G`Quann at IRCNet
http://www.visions-of-fantasy.de
-------------- next part --------------
diff -rc eggdrop1.4/src/mod/server.mod/server.c patched1.4/src/mod/server.mod/server.c
*** eggdrop1.4/src/mod/server.mod/server.c	Sat Oct  9 21:31:57 1999
--- patched1.4/src/mod/server.mod/server.c	Sun Oct 10 01:40:03 1999
***************
*** 80,85 ****
--- 80,90 ----
  static void empty_msgq(void);
  static void next_server(int *, char *, int *, char *);
  static char *get_altbotnick(void);
+ static int calc_penalty(char *);
+ char *splitnicks(char **);
+ static time_t last_time = 0;
+ static int use_penalties;
+ #define MAXPENALTY 10
  
  #include "servmsg.c"
  
***************
*** 108,118 ****
  static void deq_msg()
  {
    struct msgq *q;
-   static time_t last_time = 0;
    int ok = 0;
  
    /* now < last_time tested 'cause clock adjustments could mess it up */
!   if (((now - last_time) >= msgrate) || (now < last_time)) {
      last_time = now;
      if (burst > 0)
        burst--;
--- 113,122 ----
  static void deq_msg()
  {
    struct msgq *q;
    int 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;
      if (burst > 0)
        burst--;
***************
*** 122,130 ****
      return;
    /* send upto 4 msgs to server if the *critical queue* has anything in it */
    if (modeq.head) {
!     while (modeq.head && (burst < 4)) {
        tputs(serv, modeq.head->msg, modeq.head->len);
        modeq.tot--;
        q = modeq.head->next;
        nfree(modeq.head->msg);
        nfree(modeq.head);
--- 126,138 ----
      return;
    /* send upto 4 msgs to server if the *critical queue* has anything in it */
    if (modeq.head) {
!     while (modeq.head && (burst < 4) && ((last_time - now) < MAXPENALTY)) {
        tputs(serv, modeq.head->msg, modeq.head->len);
+       if (debug_output) {
+         putlog(LOG_SRVOUT, "*", "[m->] %s", modeq.head->msg);
+       }
        modeq.tot--;
+       last_time += calc_penalty(modeq.head->msg);
        q = modeq.head->next;
        nfree(modeq.head->msg);
        nfree(modeq.head);
***************
*** 141,147 ****
--- 149,159 ----
    if (mq.head) {
      burst++;
      tputs(serv, mq.head->msg, mq.head->len);
+     if (debug_output) {
+       putlog(LOG_SRVOUT, "*", "[s->] %s", mq.head->msg);
+     }
      mq.tot--;
+     last_time += calc_penalty(mq.head->msg);
      q = mq.head->next;
      nfree(mq.head->msg);
      nfree(mq.head);
***************
*** 155,161 ****
--- 167,177 ----
    if (!hq.head || burst || !ok)
      return;
    tputs(serv, hq.head->msg, hq.head->len);
+   if (debug_output) {
+     putlog(LOG_SRVOUT, "*", "[h->] %s", hq.head->msg);
+   }
    hq.tot--;
+   last_time += calc_penalty(hq.head->msg);
    q = hq.head->next;
    nfree(hq.head->msg);
    nfree(hq.head);
***************
*** 164,169 ****
--- 180,312 ----
      hq.last = 0;
  }
  
+ static int calc_penalty(char * msg)
+ {
+   char * cmd;
+   char * par1;
+   char * par2;
+   char * par3;
+   int penalty, i, ii;
+   
+   context;
+   if (!use_penalties)
+     return 0;
+   penalty = 0;
+   if (msg[strlen(msg) - 1] == '\n')
+     msg[strlen(msg) - 1] = '\0';
+   cmd = newsplit(&msg);
+   if (!strcasecmp(cmd, "KICK")) {
+     par1 = newsplit(&msg); /* channel */
+     par2 = newsplit(&msg); /* victim(s) */
+     par3 = splitnicks(&par2);
+     penalty++;
+     while (strlen(par3) > 0) {
+       par3 = splitnicks(&par2);
+       penalty++;
+     }
+     ii = penalty;
+     par3 = splitnicks(&par1);
+     while (strlen(par1) > 0) {
+       par3 = splitnicks(&par1);
+       penalty += ii;
+     }
+   } else if (!strcasecmp(cmd, "MODE")) {
+     par1 = newsplit(&msg); /* channel */
+     par2 = newsplit(&msg); /* mode(s) */
+     par3 = newsplit(&msg); /* victim(s) */
+     if (strlen(par3) < 1) /* ban/exempt/invite list query */
+       penalty++;
+     else {
+       for (i = 0; i < strlen(par2); i++) {
+         if (!strchr("+-", par2[i]))
+           penalty += 3;
+       }
+     }
+     ii = penalty;
+     par3 = splitnicks(&par1);
+     while (strlen(par1) > 0) {
+       par3 = splitnicks(&par1);
+       penalty += ii;
+     }
+   } else if (!strcasecmp(cmd, "TOPIC")) {
+     penalty++;
+     par1 = newsplit(&msg); /* channel */
+     par2 = newsplit(&msg); /* topic */
+     if (strlen(par2) > 0) {  /* topic manipulation => 2 penalty points */
+       penalty += 2;
+       par3 = splitnicks(&par1);
+       while (strlen(par1) > 0) {
+         par3 = splitnicks(&par1);
+         penalty += 2;
+       }
+     }
+   } else if (!strcasecmp(cmd, "PRIVMSG") || !strcasecmp(cmd, "NOTICE")) {
+     par1 = newsplit(&msg); /* channel(s)/nick(s) */
+     par2 = par1;
+     while (strlen(par1) > 0) {              /* one penalty point for each additional recipient */
+       par2 = splitnicks(&par1);
+       if (strlen(par1) > 0) penalty++;
+     }
+   } else if (!strcasecmp(cmd, "WHO")) {
+     par1 = newsplit(&msg); /* masks */
+     par2 = par1;
+     while (strlen(par1) > 0) {
+       par2 = splitnicks(&par1);
+       if (strlen(par2) > 4)   /* long WHO-masks receive less penalty */
+         penalty += 3;
+       else
+         penalty += 5;
+     }
+   } else if (!strcasecmp(cmd, "AWAY")) {
+     if (strlen(msg) > 0)
+       penalty += 2;
+     else
+       penalty += 1;
+   } else if (!strcasecmp(cmd, "INVITE")) {
+     penalty += 3; /* successful invite receives 2 or 3 penalty points. Let's go with the maximum */
+   } else if (!strcasecmp(cmd, "JOIN")) {
+     penalty += 2;
+   } else if (!strcasecmp(cmd, "PART")) {
+     penalty += 4;
+   } else if (!strcasecmp(cmd, "VERSION")) {
+     penalty += 2;
+   } else if (!strcasecmp(cmd, "TIME")) {
+     penalty += 2;
+   } else if (!strcasecmp(cmd, "TRACE")) {
+     penalty += 2;
+   } else if (!strcasecmp(cmd, "NICK")) {
+     penalty += 3;
+   } else if (!strcasecmp(cmd, "ISON")) {
+     penalty += 1;
+   } else if (!strcasecmp(cmd, "WHOIS")) {
+     penalty += 2;
+   } else if (!strcasecmp(cmd, "DNS")) {
+     penalty += 2;
+   }
+   if (penalty > 90) penalty = 90; /* shouldn't happen, but you never know... */
+   if (debug_output && (penalty != 0))
+     putlog(LOG_SRVOUT, "*", "Adding penalty: %i", penalty);
+   return penalty;
+ }
+ 
+ char *splitnicks(char **rest)
+ {
+   register char *o, *r;
+ 
+   if (!rest)
+     return *rest = "";
+   o = *rest;
+   while (*o == ' ')
+     o++;
+   r = o;
+   while (*o && (*o != ','))
+     o++;
+   if (*o)
+     *o++ = 0;
+   *rest = o;
+   return r;
+ }
+ 
  /* clean out the msg queues (like when changing servers) */
  static void empty_msgq()
  {
***************
*** 567,572 ****
--- 710,716 ----
    case 1:
      use_silence = 0;
      check_mode_r = 1;
+     use_penalties = 1;
      break;
    case 2:
      use_silence = 1;
***************
*** 631,636 ****
--- 775,781 ----
    {"double-mode", &double_mode, 0}, /* G`Quann */
    {"double-server", &double_server, 0},
    {"double-help", &double_help, 0},
+   {"use-penalties", &use_penalties, 0},
    {0, 0, 0}
  };
  
***************
*** 1389,1394 ****
--- 1534,1540 ----
    double_mode = 0;
    double_server = 0;
    double_help = 0;
+   use_penalties = 0;
    context;
    server_table[4] = (Function) botname;
    module_register(MODULE_NAME, server_table, 1, 0);
***************
*** 1467,1472 ****
--- 1613,1619 ----
    if (net_type == 1) {		/* Ircnet */
      use_silence = 0;
      check_mode_r = 1;
+     use_penalties = 1;
    }
    if (net_type == 2) {		/* Undernet */
      use_silence = 1;
diff -rc eggdrop1.4/src/mod/server.mod/servmsg.c patched1.4/src/mod/server.mod/servmsg.c
*** eggdrop1.4/src/mod/server.mod/servmsg.c	Sat Oct  9 21:31:57 1999
--- patched1.4/src/mod/server.mod/servmsg.c	Sun Oct 10 01:40:16 1999
***************
*** 1015,1020 ****
--- 1015,1078 ----
    return 0;
  }
  
+ /* 2sec penalty for each successful kick */
+ static int kickpenalty(char *from, char *msg)
+ {
+   char buf[UHOSTLEN], *nick, *uhost = buf;
+   
+   if (!use_penalties)
+     return 0;
+   strcpy(uhost, from);
+   nick = splitnick(&uhost);
+   if (!strcmp(nick,botname)) {
+     last_time += 2;
+     if (debug_output)
+       putlog(LOG_SRVOUT, "*", "adding 2secs penalty (successful kick)");
+   }
+   return 0;
+ }
+ 
+ /* additional 3sec penalty if a link was traced */
+ static int tracepenalty(char *from, char *msg)
+ {
+   if (use_penalties) {
+     last_time += 3;
+     if (debug_output)
+       putlog(LOG_SRVOUT, "*", "adding 3secs penalty (traced link)");
+   }
+   return 0;
+ }
+ 
+ /* another sec penalty if bot did a whois on another server */
+ static int whoispenalty(char *from, char *msg)
+ {
+   struct server_list *x = serverlist;
+   int i, ii;
+ 
+   if (x && use_penalties) {
+     i = ii = 0;
+     while (x != NULL) {
+       if (i == curserv) {
+         if (strict_servernames == 1) {
+           if (strcmp(x->name, from))
+             ii = 1;
+         } else {
+           if (strcmp(x->realname, from))
+             ii = 1;
+         }
+       }
+       x = x->next;
+       i++;
+     }
+     if (ii) {
+       last_time += 1;
+       if (debug_output)
+         putlog(LOG_SRVOUT, "*", "adding 1sec penalty (remote whois)");
+     }
+   }
+   return 0;
+ }
+ 
  /* update the add/rem_builtins in server.c if you add to this list!! */
  static cmd_t my_raw_binds[] =
  {
***************
*** 1037,1042 ****
--- 1095,1103 ----
    {"451", "", (Function) got451, NULL},
    {"NICK", "", (Function) gotnick, NULL},
    {"ERROR", "", (Function) goterror, NULL},
+   {"KICK", "", (Function) kickpenalty, NULL},
+   {"200", "", (Function) tracepenalty, NULL},
+   {"318", "", (Function) whoispenalty, NULL},
    {0, 0, 0, 0}
  };
  


More information about the Patches mailing list