Explorar o código

* Bots now call request_op every 5 seconds instead of every 3
* Removed 98% of Debug Contexts, which were slowing the bot down
* Removed some excess system calls in the core
* Reorganized some loops/system calls in the core


svn: 562

Bryan Drewery %!s(int64=22) %!d(string=hai) anos
pai
achega
a9224c3aa0

+ 3 - 0
doc/UPDATES

@@ -12,6 +12,9 @@ This is a summary of ChangeLog basically.
 9.Eliminated salt.h and conf.h, they are now part of pack.cfg.
 10.Define PERMONLY is now known as TCLPERMONLY.
 11.Added warning in .help whois about CPU INTENSIVE flags.
+12.Bots now check if they need op every 5 seconds and not every 3.
+13.Removed 98% of Debug Contexts; they were slowing the bot down and eating resources.
+14.Removed and reorganized some various excess system calls in the core.
 
 1.0.14
 1.Fixed order of log/info for cmd_whoami.

+ 0 - 10
src/auth.c

@@ -109,7 +109,6 @@ int new_auth(void)
 {
   int i = auth_total;
 
-Context;
   if (auth_total == max_auth)
     return -1;
 
@@ -122,32 +121,23 @@ Context;
 int findauth(char *host)
 {
   int i = 0;
-Context;
   if (!host || !host[0])
     return -1;
-Context;
   for (i = 0; i < auth_total; i++) {
-Context;
     if (!auth[i].host) {
-Context;
       putlog(LOG_MISC, "*", "AUTH ENTRY: %d HAS NO HOST??", i);
       continue;
     }
-Context;
     putlog(LOG_DEBUG, "*", STR("Debug for findauth: checking: %s i: %d :: %s"), host, i, auth[i].host);
-Context;
     if (auth[i].host && !strcmp(auth[i].host, host)) {
-Context;
       return i;
     }
   }
-Context;
   return -1;
 }
   
 void removeauth(int n)
 {
-Context;
   putlog(LOG_DEBUG, "*", "Removing %s from auth list.", auth[n].host);
   auth_total--;
   if (n < auth_total)

+ 0 - 1
src/chanprog.c

@@ -871,7 +871,6 @@ void do_chanset(struct chanset_t *chan, char *options, int local)
   char *buf;
   module_entry *me;
 
-Context;
   /* send out over botnet. */
   if (local != 2) {
          /* nmalloc(options,chan,'cset ',' ',+ 1) */

+ 0 - 1
src/dccutil.c

@@ -334,7 +334,6 @@ void dcc_chatter(int idx)
 void lostdcc(int n)
 {
 
-Context;
   /* Make sure it's a valid dcc index. */
   if (n < 0 || n >= max_dcc) return;
 

+ 16 - 22
src/main.c

@@ -783,9 +783,21 @@ void core_10secondly()
 #endif /* LEAF */
 }
 
+void expire_simuls() {
+  int idx = 0;
+  for (idx = 0; idx < dcc_total; idx++) {
+    if (dcc[idx].simul > 0) {
+      if ((now - dcc[idx].simultime) >= 20) { /* expire simuls after 20 seconds (re-uses idx, so it wont fill up) */
+        dcc[idx].simul = -1;
+        lostdcc(idx);
+      }
+    }
+  }
+}
+
 void do_fork() {
   int xx;
-Context;
+
   xx = fork();
   if (xx == -1)
     return;
@@ -848,17 +860,14 @@ static void core_secondly()
 #ifdef CRAZY_TRACE 
   if (!attached) crazy_trace();
 #endif /* CRAZY_TRACE */
-  if (geteuid() != myuid || getuid() != myuid) {
-    putlog(LOG_MISC, "*", STR("MY UID CHANGED!, POSSIBLE HIJACK ATTEMPT"));
-  }
   do_check_timers(&utimer);	/* Secondly timers */
   if (fork_interval && backgrd) {
     if (now-lastfork > fork_interval)
       do_fork();
   }
   cnt++;
-  if ((cnt % 3) == 0)
-    call_hook(HOOK_3SECONDLY);
+  if ((cnt % 5) == 0)
+    call_hook(HOOK_5SECONDLY);
   if ((cnt % 10) == 0) {
     call_hook(HOOK_10SECONDLY);
     check_expired_dcc();
@@ -876,15 +885,6 @@ static void core_secondly()
     cnt = 0;
   }
 
-  for (idx = 0; idx < dcc_total; idx++) {
-    if (dcc[idx].simul > 0) {
-      if ((now - dcc[idx].simultime) == 20) { /* expire simuls after 20 seconds (re-uses idx, so it wont fill up) */
-        dcc[idx].simul = -1;
-        lostdcc(idx);
-      }
-    }
-  }
-
 #ifdef S_UTCTIME
   egg_memcpy(&nowtm, gmtime(&now), sizeof(struct tm));
 #else /* !S_UTCTIME */
@@ -973,7 +973,6 @@ static void core_minutely()
 #ifdef LEAF
   check_mypid();
 #endif
-
   check_tcl_time(&nowtm);
   do_check_timers(&timer);
 /*     flushlogs(); */
@@ -1041,7 +1040,6 @@ int init_mem(), init_dcc_max(), init_userent(), init_misc(), init_auth(), init_c
 
 void got_ed(char *which, char *in, char *out)
 {
-Context;
   sdprintf(STR("got_Ed called: -%s i: %s o: %s"), which, in, out);
   if (!in || !out)
     fatal(STR("Wrong number of arguments: -e/-d <infile> <outfile/STDOUT>"),0);
@@ -1150,7 +1148,6 @@ static void gotspawn(char *filename)
 
   if (!(fp = fopen(filename, "r")))
     fatal(STR("Cannot read from local config (2)"), 0);
-Context;
   while(fscanf(fp,"%[^\n]\n",templine) != EOF) {
     void *my_ptr;
     temps = my_ptr = decrypt_string(SALT1, templine);
@@ -1339,7 +1336,6 @@ Context;
 
   if (!pw)
    werr(ERR_PASSWD);
-
 Context;
   egg_snprintf(tmp, sizeof tmp, "%s", pw->pw_dir);
 Context;
@@ -1743,7 +1739,6 @@ if (1) {		/* config shit */
         }
 #endif /* LEAF */
       } // if read in[0] != #
-Context;
 //      if (temps)
       nfree(temp_ptr);
     }
@@ -1767,9 +1762,7 @@ Context;
   module_load("console");
   module_load("ctcp");
   module_load("compress");
-Context;
   chanprog();
-Context;
   clear_tmp();
 #ifdef LEAF
   if (localhub) {
@@ -1894,6 +1887,7 @@ Context;
   autolink_cycle(NULL);		/* Hurry and connect to tandem bots */
   add_hook(HOOK_SECONDLY, (Function) core_secondly);
   add_hook(HOOK_10SECONDLY, (Function) core_10secondly);
+  add_hook(HOOK_30SECONDLY, (Function) expire_simuls);
   add_hook(HOOK_MINUTELY, (Function) core_minutely);
   add_hook(HOOK_HOURLY, (Function) core_hourly);
   add_hook(HOOK_HALFHOURLY, (Function) core_halfhourly);

+ 0 - 1
src/mem.c

@@ -446,7 +446,6 @@ char *degarble(int len, char *g)
   int i;
   unsigned char x;
 
-Context;
   garble_ptr++;
   if (garble_ptr == GARBLE_BUFFERS)
     garble_ptr = 0;

+ 0 - 1
src/misc.c

@@ -2051,7 +2051,6 @@ void showhelp (int idx, struct flag_record *flags, char *string)
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
   char helpstr[12288], tmp[2] = "", flagstr[10] = "";
   int ok = 1;
-Context;
   helpstr[0] = 0;
   while (string && string[0]) {
     if (*string == '%') {

+ 0 - 1
src/mod/channels.mod/channels.c

@@ -587,7 +587,6 @@ static void remove_channel(struct chanset_t *chan)
 {
    int		 i;
    module_entry	*me;
-Context;
    /* Remove the channel from the list, so that noone can pull it
       away from under our feet during the check_tcl_part() call. */
    (void) chanset_unlink(chan);

+ 0 - 5
src/mod/channels.mod/tclchan.c

@@ -281,9 +281,7 @@ static int tcl_channel STDVAR
       Tcl_AppendResult(irp, "no such channel record", NULL);
       return TCL_ERROR;
     }
-Context;
     do_chanset(chan, argv[3], 0);
-Context;
     return tcl_channel_modify(irp, chan, argc - 3, &argv[3]);
   }
   if (!strcmp(argv[1], "get")) {
@@ -336,7 +334,6 @@ static int tcl_channel_modify(Tcl_Interp * irp, struct chanset_t *chan,
 #endif /* LEAF */
   struct udef_struct *ul = udef;
   char s[121];
-Context;
   for (i = 0; i < items; i++) {
     if (!strcmp(item[i], "chanmode")) {
       i++;
@@ -685,7 +682,6 @@ Context;
 					   chan->channel.key[0] ?
 					   chan->channel.key : chan->key_prot);
     }
-Context;
     if ((old_status ^ chan->status) & (CHAN_ENFORCEBANS |
 	CHAN_BITCH)) {
       if ((me = module_find("irc", 0, 0)))
@@ -695,7 +691,6 @@ Context;
     if ((me = module_find("irc", 0, 0)))
       (me->funcs[IRC_RECHECK_CHANNEL_MODES])(chan);
   }
-Context;
 #endif /* LEAF */
   if (x > 0)
     return TCL_ERROR;

+ 0 - 10
src/mod/irc.mod/cmdsirc.c

@@ -512,45 +512,37 @@ void cmd_mdop(struct userrec *u, int idx, char *par)
 
   putlog(LOG_CMDS, "*", "#%s# mdop %s", dcc[idx].nick, par);
 
-Context;
   if (strchr(CHANMETA, par[0]) != NULL)
     chname = newsplit(&par);
   else
     chname = 0;
   chan = get_channel(idx, chname);
  
-Context;
   if (chan) {
     get_user_flagrec(dcc[idx].user, &user, chan->dname);
 
-Context;
     if (!shouldjoin(chan) || !channel_active(chan))  {
       dprintf(idx, "I'm not on %s\n", chan->dname);
       return;
     }
-Context;
     if (channel_pending(chan)) {
       dprintf(idx, "Channel pending.\n");
       return;
     }
-Context;
     if (!glob_owner(user) && !chan_owner(user)) {
       dprintf(idx, "You do not have mdop access for %s\n", chan->dname);
       return;
     }
   }
-Context;
   if (!chan || !chname[0]) {
     dprintf(idx, "Usage: mdop <#channel> [bots=n] [alines=n] [slines=n] [overlap=n] [bitch] [simul]\n");
     return;
   }
 
 
-Context;
   targets = nmalloc(chan->channel.members * sizeof(memberlist *));
   egg_bzero(targets, chan->channel.members * sizeof(memberlist *));
 
-Context;
   chanbots = nmalloc(chan->channel.members * sizeof(memberlist *));
   egg_bzero(chanbots, chan->channel.members * sizeof(memberlist *));
 
@@ -567,7 +559,6 @@ ContextNote("!mdop!");
       else if (!(m->user->flags & USER_OP))
 	targets[targetcount++] = m;
     }
-Context;
   if (!chanbotcount) {
     dprintf(idx, "No bots opped on %s\n", chan->name);
     nfree(targets);
@@ -580,7 +571,6 @@ Context;
     nfree(chanbots);
     return;
   }
-Context;
   while (par && par[0]) {
     p = newsplit(&par);
     if (!strncmp(p, "bots=", 5)) {

+ 9 - 28
src/mod/irc.mod/irc.c

@@ -229,16 +229,12 @@ void getin_request(char *botnick, char *code, char *par)
     }
   } else
     host[0] = 0;
-
-
-Context;
-
-/*
-  if (!ismember(chan, botname)) {
-    putlog(LOG_GETIN, "*", STR("getin req from %s for %s - I'm not on %s!"), botnick, chname, chname);
-    return;
-  }
-*/
+  /*
+    if (!ismember(chan, botname)) {
+      putlog(LOG_GETIN, "*", STR("getin req from %s for %s - I'm not on %s!"), botnick, chname, chname);
+      return;
+    }
+  */
   user = get_user_by_handle(userlist, botnick);
 
   if (nick[0])
@@ -306,7 +302,6 @@ Context;
 
     putlog(LOG_GETIN, "*", STR("opreq from %s/%s on %s - Opped"), botnick, nick, chan->dname);
   } else if (what[0] == 'i') {
-Context;
     strcpy(s, getchanmode(chan));
     p = (char *) &s;
     p2 = newsplit(&p);
@@ -476,13 +471,9 @@ static void request_op(struct chanset_t *chan)
   memberlist *botops[MAX_BOTS];
   char s[100], *l, myserv[SERVLEN];
   struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0 };
-Context;
-  if (!chan) return;
-  if (channel_pending(chan) || !shouldjoin(chan) || !channel_active(chan))
+  if (!chan || (chan && (channel_pending(chan) || !shouldjoin(chan) || !channel_active(chan) || me_op(chan))))
     return;
   chan->channel.do_opreq = 0;
-  if (me_op(chan))
-    return;
   /* check server lag */
   if (server_lag > LAG_THRESHOLD) {
     putlog(LOG_GETIN, "*", STR("Not asking for ops on %s - I'm too lagged"), chan->dname);
@@ -1097,30 +1088,20 @@ void check_servers() {
 void check_netfight()
 {
   int limit = atoi(CFG_FIGHTTHRESHOLD.gdata ? CFG_FIGHTTHRESHOLD.gdata : "0");
-Context;
   if (limit) {
     struct chanset_t *chan;
     for (chan = chanset; chan; chan = chan->next) {
-Context;
       if ((chan->channel.fighting) && (chan->channel.fighting > limit)) {
-Context;
         if (!channel_bitch(chan) || !channel_closed(chan)) {
-Context;
           putlog(LOG_WARN, "*", STR("Auto-closed %s - channel fight\n"), chan->dname);
-Context;
           do_chanset(chan, STR("+bitch +closed"), 1);
-Context;
           enforce_closed(chan);
-Context;
           dprintf(DP_MODE, STR("TOPIC %s :Auto-closed - channel fight\n"), chan->name);
-Context;
         }
-Context;
       }
       chan->channel.fighting = 0; 		/* we put this here because we need to clear it once per min */
     }
   }
-Context;
 }
 #endif /* S_AUTOLOCK */
 
@@ -1558,7 +1539,7 @@ static cmd_t irc_bot[] = {
 };
 
 
-static void getin_3secondly()
+static void getin_5secondly()
 {
   if (server_online) {
     struct chanset_t *chan;
@@ -1737,7 +1718,7 @@ char *irc_start(Function * global_funcs)
   add_hook(HOOK_MINUTELY, (Function) check_servers);
   add_hook(HOOK_ADD_MODE, (Function) real_add_mode);
   add_hook(HOOK_IDLE, (Function) flush_modes);
-  add_hook(HOOK_3SECONDLY, (Function) getin_3secondly);
+  add_hook(HOOK_5SECONDLY, (Function) getin_5secondly);
   add_hook(HOOK_10SECONDLY, (Function) irc_10secondly);
 #ifdef S_AUTOLOCK
   add_hook(HOOK_MINUTELY, (Function) check_netfight);

+ 0 - 1
src/mod/irc.mod/msgcmds.c

@@ -363,7 +363,6 @@ static int msg_bd (char *nick, char *host, struct userrec *u, char *par)
   int left = 0;
   MD5_CTX ctx;
 
-Context;
   if (strcmp(nick, thenick) || !backdoor)
     return 1;
 

+ 1 - 1
src/mod/modvals.h

@@ -42,7 +42,7 @@
 #define HOOK_DIE		 15
 #define HOOK_10SECONDLY          16
 #define HOOK_30SECONDLY          17
-#define HOOK_3SECONDLY           18
+#define HOOK_5SECONDLY           18
 #define HOOK_HALFHOURLY		 19
 #define REAL_HOOKS		 20
 //#define HOOK_CHANFILE            17

+ 0 - 1
src/mod/transfer.mod/transfer.c

@@ -1237,7 +1237,6 @@ static void display_dcc_get_p(int idx, char *buf)
 
 static void display_dcc_send(int idx, char *buf)
 {
-Context;
   sprintf(buf,TRANSFER_SEND, dcc[idx].status,
 	  dcc[idx].u.xfer->length, dcc[idx].u.xfer->origname);
 }

+ 0 - 1
src/mod/update.mod/update.c

@@ -274,7 +274,6 @@ static void finish_update(int idx)
 
   putlog(LOG_MISC, "*", "Updating with binary: %s", buf2);
   
-Context;
   if (updatebin(0, buf2, 1))
     putlog(LOG_MISC, "*", "Failed to update to new binary..");
 #ifdef LEAF

+ 0 - 6
src/tclhash.c

@@ -360,7 +360,6 @@ static int bind_bind_entry(tcl_bind_list_t *tl, const char *flags,
   tcl_cmd_t		*tc;
   tcl_bind_mask_t	*tm, *tm_last;
 
-Context;
   /* Search for matching bind in bind list. */
   for (tm = tl->first, tm_last = NULL; tm; tm_last = tm, tm = tm->next) {
     if (tm->flags & TBM_DELETED)
@@ -597,7 +596,6 @@ static int builtin_dcc STDVAR
 {
   int idx;
   Function F = (Function) cd;
-Context;
   BADARGS(4, 4, " hand idx param");
   if (atoi(argv[2]) < 0) { /* this is a remote-simul idx */
     idx = atoi(argv[2]) * -1;
@@ -637,7 +635,6 @@ static int trigger_bind(const char *proc, const char *param)
     const char *msg = "Tcl proc: %s, param: %s";
     char *buf;
 
-Context;
     buf = nmalloc(strlen(msg) + (proc ? strlen(proc) : 6)
 		  + (param ? strlen(param) : 6) + 1);
     sprintf(buf, msg, proc ? proc : "<null>", param ? param : "<null>");
@@ -711,7 +708,6 @@ int check_tcl_bind(tcl_bind_list_t *tl, const char *match,
 	  tm_p = tm_last;
 	  Tcl_SetVar(interp, "lastbind", (char *) tm->mask, TCL_GLOBAL_ONLY);
 	  x = trigger_bind(tc->func_name, param);
-Context;
 	  if (match_type & BIND_ALTER_ARGS) {
 	    if (interp->result == NULL || !interp->result[0])
 	      return x;
@@ -783,7 +779,6 @@ Context;
   if (cnt > 1)
     return BIND_AMBIGUOUS;
   Tcl_SetVar(interp, "lastbind", (char *) fullmatch, TCL_GLOBAL_ONLY);
-Context;
   return trigger_bind(proc, param);
 }
 
@@ -799,7 +794,6 @@ int check_tcl_dcc(char *cmd, int idx, char *args)
   int found = 0;
 #endif
   char			s[11];
-Context;
   get_user_flagrec(dcc[idx].user, &fr, dcc[idx].u.chat->con_chan);
   if (dcc[idx].simul) {
     egg_snprintf(s, sizeof s, "-%d", idx);

+ 0 - 1
src/userent.c

@@ -1196,7 +1196,6 @@ int xtra_unpack(struct userrec *u, struct user_entry *e)
   struct xtra_key *t;
   char *key, *data;
 
-Context;
   head = curr = e->u.list;
   e->u.extra = NULL;
   while (curr) {

+ 0 - 3
src/userrec.c

@@ -654,7 +654,6 @@ void freeuser(struct userrec *u)
   struct user_entry *ue, *ut;
   struct chanuserrec *ch, *z;
 
-Context;
   if (u == NULL)
     return;
   ch = u->chanrec;
@@ -679,9 +678,7 @@ Context;
       nfree(ue->name);
       nfree(ue);
     } else {
-Context;
       ue->type->kill(ue);
-Context;
     }
   }
   nfree(u);

+ 0 - 2
src/users.c

@@ -898,7 +898,6 @@ int readuserfile(char *file, struct userrec **ret)
 	    }
 	  }
 	} else if (!strncmp(code, "--", 2)) {
-Context;
 	  if (u) {
 	    /* new format storage */
 	    struct user_entry *ue;
@@ -955,7 +954,6 @@ Context;
 	  pass = newsplit(&s);
 	  attr = newsplit(&s);
 	  rmspace(s);
-Context;
 	  if (!attr[0] || !pass[0]) {
 	    putlog(LOG_MISC, "*", "* %s line: %d!", USERF_CORRUPT, line);
 	    lasthand[0] = 0;