Update to version 2.9.3a master
authorFrancois Fleuret <francois@fleuret.org>
Sun, 6 Oct 2013 09:16:25 +0000 (11:16 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Sun, 6 Oct 2013 09:16:25 +0000 (11:16 +0200)
Makefile
README.txt
tropbot.cc

index 1c72caf..1e3359a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,7 @@ OPTIONS =       -g
 # add -lsocket -lnsl for SOLARIS
 LIBS   =
 
+ARCHIVE_NAME = tropbot_2.9.3a
 
 all:   tropbot
 
@@ -25,9 +26,7 @@ clean:
        rm *.o tropbot
 
 archive:
-       rm -f ../tropbot.tar.gz
-       tar -cvf ../tropbot.tar *.cc *.h *.txt Makefile
-       gzip ../tropbot.tar
+       cd ..; tar -cvf $(ARCHIVE_NAME).tar tropbot/*.cc tropbot/*.h tropbot/Makefile tropbot/*.txt; gzip $(ARCHIVE_NAME).tar; mv -f $(ARCHIVE_NAME).tar.gz $(ARCHIVE_NAME).tgz
 
 count:
        wc *.cc *.h Makefile
index 5bff2f7..6ba3206 100644 (file)
@@ -233,6 +233,10 @@ when the bot lagged because of network troubles.
 
 "cop" switch the cop-mode on/off
 
+"ctcpreply" (alias "cr") switch the ctcp replies
+
+"anticlones" (alias "ac") switch the "restricted-sites" stuff
+
 "deban { list of patterns }" (alias "db") remove from the ban-list all
 the entries who match one of the pattern
 
index f3f2161..ac6f980 100644 (file)
@@ -5,7 +5,7 @@
   Check http://www.eleves.ens.fr:8080/home/fleuret for latest version
 -----------------------------------------------------------------------------*/
 
-#define VERSION "v2.9.2d"
+#define VERSION "v2.9.3a"
 #define OPTIONS ""
 
 #include <time.h>
@@ -36,7 +36,7 @@
 
 #define DEFAULT_CONTROL_CHAR '|'
 #define DELAY_NICK_BACK 300
-#define DELAY_MAX_RECONNECT 300
+#define DELAY_MAX_RECONNECT 120
 #define DELAY_DEAD_SERVER 900
 
 #define DEFAULT_SERVER "sil.polytechnique.fr"
@@ -112,7 +112,7 @@ int op_delay = DEFAULT_OP_DELAY;
 int deban_delay = DEFAULT_DEBAN_DELAY;
 char control_char = DEFAULT_CONTROL_CHAR;
 
-int cop_mode;
+int cop_mode, anti_flood, anti_clone, ctcp_reply;
 
 int delay;
 timeval delay_pause;
@@ -1386,6 +1386,31 @@ int LoadConfigFile(char *name, int recurse)
                      if(buffer[0] != '\0') control_char = buffer[0];
                    }
                }
+             else if(strcmp(buffer, "COPMODE") == 0)
+               {
+                 cop_mode = 1;
+               }
+             else if(strcmp(buffer, "ANTIFLOOD") == 0)
+               {
+                 anti_flood = 1;
+                 anti_flood_off_until = current_time;
+               }
+             else if(strcmp(buffer, "ANTICLONES") == 0)
+               {
+                 anti_clone = 1;
+               }
+             else if(strcmp(buffer, "CTCPREPLY") == 0)
+               {
+                 ctcp_reply = 1;
+               }
+             else if(strcmp(buffer, "CHANNEL") == 0)
+               {
+                 if(r != NULL)
+                   {
+                     r = next_word(buffer, r, SMALL_BUFFER_SIZE);
+                     strncpy(home_channel, buffer, SMALL_BUFFER_SIZE);
+                   }
+               }
            }
        }
       shit_list.Reverse();
@@ -1414,12 +1439,37 @@ int SaveConfigFile(char *name)
       (*file)<<"% Config file for a TropBot " VERSION "\n";
       (*file)<<"\n";
 
+      (*file)<<"% Delay in s before +o on level 2 users\n";
       (*file)<<"OPDELAY "<<op_delay<<"\n";
+      (*file)<<"% Delay before auto -b on servers +b\n";
       (*file)<<"DEBANDELAY "<<deban_delay<<"\n";
+      (*file)<<"% Charactere used for public commands\n";
       (*file)<<"CONTROLCHAR "<<control_char<<"\n";
 
       (*file)<<"\n";
+      (*file)<<"% Home channel\n";
+      (*file)<<"CHANNEL "<<home_channel<<"\n";
+
+      (*file)<<"\n";
+      (*file)<<"% Cop-mode activation/desactivation\n";
+      if(cop_mode) (*file)<<"COPMODE\n";
+      else (*file)<<"% COPMODE\n";
+
+      (*file)<<"% Anti-flood activation/desactivation\n";
+      if(anti_flood) (*file)<<"ANTIFLOOD\n";
+      else (*file)<<"% ANTIFLOOD\n";
 
+      (*file)<<"% Anti-clones activation/desactivation\n";
+      if(anti_clone) (*file)<<"ANTICLONES\n";
+      else (*file)<<"% ANTICLONES\n";
+
+      (*file)<<"% Ctcp replies activation/desactivation\n";
+      if(ctcp_reply) (*file)<<"CTCPREPLY\n";
+      else (*file)<<"% CTCPREPLY\n";
+
+      (*file)<<"\n";
+
+      (*file)<<"% Friends list\n";
       for(person=level_list.first; person != NULL; person=person->next)
        {
          (*file)<<"FRIEND "<<person->body->level<<" "<<person->body->pattern;
@@ -1429,6 +1479,7 @@ int SaveConfigFile(char *name)
 
       (*file)<<"\n";
 
+      (*file)<<"% Restricted-sites list\n";
       for(restricted=restricted_list.first;
          restricted != NULL;
          restricted=restricted->next)
@@ -1436,11 +1487,14 @@ int SaveConfigFile(char *name)
 
       (*file)<<"\n";
 
+      (*file)<<"% Shit list\n";
       for(welcome=shit_list.first; welcome != NULL; welcome=welcome->next)
        (*file)<<"SHIT "<<welcome->body->pattern<<" "<<
          welcome->body->time_max - current_time<<" "<<
          welcome->body->comment<<"\n";
 
+      (*file)<<"\n";
+      (*file)<<"% End of config file\n";
       error = 0;
     }
   else error = 1;
@@ -1775,6 +1829,26 @@ void tropbot_cmd(DCCChat *chat, char *prefix, char *nick, char *msg)
            }
          else no_authorized = 1;
        }
+      else if(eq("cr", buffer) || eq("ctcpreply", buffer))
+       {
+         if(level >= LEVEL_OP)
+           {
+             ctcp_reply = !ctcp_reply;
+             if(ctcp_reply) tell(chat, nick, "CTCP reply ON\n");
+             else tell(chat, nick, "CTCP reply OFF\n");
+           }
+         else no_authorized = 1;
+       }
+      else if(eq("ac", buffer) || eq("anticlones", buffer))
+       {
+         if(level >= LEVEL_OP)
+           {
+             anti_clone = !anti_clone;
+             if(anti_clone) tell(chat, nick, "Anti-clones ON\n");
+             else tell(chat, nick, "Anti-clones OFF\n");
+           }
+         else no_authorized = 1;
+       }
       else if(eq("ao", buffer) || eq("antifloodoff", buffer))
        {
          if(level >= LEVEL_OP)
@@ -1784,7 +1858,16 @@ void tropbot_cmd(DCCChat *chat, char *prefix, char *nick, char *msg)
                  r = next_word(buffer_time, r, SMALL_BUFFER_SIZE);
                  duration =  string_to_seconds(buffer_time);
                  anti_flood_off_until = current_time + duration;
+                 anti_flood = 1;
                }
+             else
+               {
+                 anti_flood_off_until = current_time;
+                 anti_flood = !anti_flood;
+               }
+
+             if(!anti_flood)
+               tell(chat, nick, "Anti-flood off\n");
              if(anti_flood_off_until > current_time)
                {
                  string_duration = seconds_to_string(anti_flood_off_until - 
@@ -1795,7 +1878,8 @@ void tropbot_cmd(DCCChat *chat, char *prefix, char *nick, char *msg)
                  
                  tell(chat, nick, IRC_buffer);
                }
-             else tell(chat, nick, "Anti-flood on\n");
+             else
+               tell(chat, nick, "Anti-flood on\n");
            }
          else no_authorized = 1;
        }
@@ -1856,15 +1940,19 @@ void tropbot_cmd(DCCChat *chat, char *prefix, char *nick, char *msg)
        {
          if(dont_flood_server() || (level >= LEVEL_FRIEND))
            {
-             char *a;
-             if(cop_mode) a = "ON"; else a = "OFF";
+             char *cop, *ao, *ac, *cr;
+             if(cop_mode) cop = "ON"; else cop = "OFF";
+             if(anti_flood) ao = "ON"; else ao = "OFF";
+             if(anti_clone) ac = "ON"; else ac = "OFF";
+             if(ctcp_reply) cr = "ON"; else cr = "OFF";
              if(father)
                {
                  sprintf(IRC_buffer,
                          "control_char '%c' op_delay %ds  deban_delay %ds "
-                         "cop-mode %s"
+                         "cop-mode %s anti-flood %s anti-clone %s ctcp-reply %s"
                          " your level is %d. I am a father with %d sons.\n",
-                         control_char, op_delay, deban_delay, a,
+                         control_char, op_delay, deban_delay,
+                         cop, ao, ac, cr,
                          level, nb_sons);
                  tell(chat, nick, IRC_buffer);
                }
@@ -1872,9 +1960,10 @@ void tropbot_cmd(DCCChat *chat, char *prefix, char *nick, char *msg)
                {
                  sprintf(IRC_buffer,
                          "control_char '%c' op_delay %ds  deban_delay %ds "
-                         "cop-mode %s"
-                         " your level is %d. I'm a clone.\n",
-                         control_char, op_delay, deban_delay, a,
+                         "cop-mode %s anti-flood %s anti-clone %s ctcp-reply %s"
+                         " your level is %d. I am a son.\n",
+                         control_char, op_delay, deban_delay,
+                         cop, ao, ac, cr,
                          level);
                  tell(chat, nick, IRC_buffer);
                }
@@ -1955,7 +2044,7 @@ void tropbot_cmd(DCCChat *chat, char *prefix, char *nick, char *msg)
        }
       else if(eq("db", buffer) || eq("deban", buffer))
        {
-         if(level >= LEVEL_OP)
+         if(level >= LEVEL_FRIEND)
            {
              while(r != NULL)
                {
@@ -2691,73 +2780,76 @@ void IRC_PRIVMSG(char *prefix,
        tropbot_cmd(NULL, prefix, nick, msg);
     }
   
-  version = 0;
-  ping = 0;
-  for(k=0; k<n_ctcp; k++)
+  if(ctcp_reply)
     {
-      r = slice_ctcp[k];
-      r = next_word(buffer, r, SMALL_BUFFER_SIZE);
-      
-      // Reply the CTCP VERSION
-      if(eq("VERSION", buffer) && !version)
+      version = 0;
+      ping = 0;
+      for(k=0; k<n_ctcp; k++)
        {
-         if(dont_flood_server())
+         r = slice_ctcp[k];
+         r = next_word(buffer, r, SMALL_BUFFER_SIZE);
+      
+         // Reply the CTCP VERSION
+         if(eq("VERSION", buffer) && !version)
            {
-             version = 1;
-             sprintf(IRC_buffer, "NOTICE %s :"
-                     "\001VERSION \002TropBot\002 " VERSION OPTIONS
-                     ", " SYSTEM " system, " DATE ". "
-                     "Contact THX-1138 on IRCNet, or <francois.fleuret@inria.fr>"
-                     "\001\n",
-                     nick);
-             write_irc(IRC_buffer);
+             if(dont_flood_server())
+               {
+                 version = 1;
+                 sprintf(IRC_buffer, "NOTICE %s :"
+                         "\001VERSION \002TropBot\002 " VERSION OPTIONS
+                         ", " SYSTEM " system, " DATE ". "
+                         "Contact THX-1138 on IRCNet, or <francois.fleuret@inria.fr>"
+                         "\001\n",
+                         nick);
+                 write_irc(IRC_buffer);
+               }
            }
-       }
-      // Reply the CTCP PING
-      else if(eq("PING", buffer) && !ping)
-       {
-         ping = 1;
-         if(r != NULL)
-           if(dont_flood_server())
-             {
-               ping = 1;
-               r = next_word(buffer, r, SMALL_BUFFER_SIZE);
-               sprintf(IRC_buffer,
-                       "NOTICE %s :\001PING %s\001\n", nick, buffer);
-               write_irc(IRC_buffer);
-             }
-       }
-      // DCC (chat)
-      else if(eq("DCC", buffer))
-       {
-         if(level >= LEVEL_OP)
+         // Reply the CTCP PING
+         else if(eq("PING", buffer) && !ping)
            {
+             ping = 1;
              if(r != NULL)
+               if(dont_flood_server())
+                 {
+                   ping = 1;
+                   r = next_word(buffer, r, SMALL_BUFFER_SIZE);
+                   sprintf(IRC_buffer,
+                           "NOTICE %s :\001PING %s\001\n", nick, buffer);
+                   write_irc(IRC_buffer);
+                 }
+           }
+         // DCC (chat)
+         else if(eq("DCC", buffer))
+           {
+             if(level >= LEVEL_OP)
                {
-                 r = next_word(buffer, r, SMALL_BUFFER_SIZE);
-                 if(eq("CHAT", buffer))
+                 if(r != NULL)
                    {
-                     if(accepting_dcc_chat(prefix, nick, level, r) != 0)
+                     r = next_word(buffer, r, SMALL_BUFFER_SIZE);
+                     if(eq("CHAT", buffer))
                        {
-                         sprintf(IRC_buffer, "NOTICE %s :\002Error\002"
-                                 " can't connect\n", nick);
+                         if(accepting_dcc_chat(prefix, nick, level, r) != 0)
+                           {
+                             sprintf(IRC_buffer, "NOTICE %s :\002Error\002"
+                                     " can't connect\n", nick);
+                             write_irc(IRC_buffer);
+                           }
+                       }
+                     else
+                       {
+                         sprintf(IRC_buffer,
+                                 "NOTICE %s :I can only DCC CHAT\n", nick);
                          write_irc(IRC_buffer);
                        }
                    }
-                 else
-                   {
-                     sprintf(IRC_buffer,
-                             "NOTICE %s :I can only DCC CHAT\n", nick);
-                     write_irc(IRC_buffer);
-                   }
                }
-           }
-         else if(dont_flood_server())
-           {
-             sprintf(IRC_buffer,
-                     "NOTICE %s :Sorry, can't accept DCC from you\n",
-                     nick, buffer);
-             write_irc(IRC_buffer);
+             else if(dont_flood_server())
+               {
+                 sprintf(IRC_buffer,
+                         "NOTICE %s :Sorry, can't accept DCC from you\n",
+                         nick, buffer);
+                 write_irc(IRC_buffer);
+               }
            }
        }
     }
@@ -2919,7 +3011,7 @@ void IRC_JOIN(char *prefix, char *where)
       
       l =  level_person(prefix, NULL);
 
-      if((l < LEVEL_FRIEND) && (restricted_list.Matches(prefix)))
+      if(anti_clone && (l < LEVEL_FRIEND) && (restricted_list.Matches(prefix)))
        restricted = check_restricted(where, prefix);
       else restricted = 0;
       
@@ -3626,7 +3718,7 @@ void check_stuffs()
 {
   NodeList<DelayModeChange *> *md;
 
-  if(current_time > anti_flood_off_until) check_flood();
+  if(anti_flood && (current_time > anti_flood_off_until)) check_flood();
   check_delay_mode_change();
   send_mode(current_channel);
   
@@ -3727,6 +3819,12 @@ int main(int argc, char **argv)
   last_answer_time = 0;
   anti_flood_off_until = 0;
 
+  // The bot does NOTHING at first
+  anti_flood = 0;
+  anti_clone = 0;
+  ctcp_reply = 0;
+  cop_mode = 0;
+
   src = buffer;
   endsrc = buffer;
   delay = socket_delay;