Quiet annoying mutex debug logging messages
[clinton/bobotpp.git] / source / Bot.C
index 6115cce..ed8aa50 100644 (file)
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 // 02110-1301, USA.
 
-#include <fstream>
-#include <algorithm>
-#include <iomanip>
 #include <cstring>
 #include <cstdlib>
 #include <cstdio>
+
+#include <fstream>
+#include <algorithm>
+#include <iomanip>
+
 #include <dirent.h>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
+#ifdef USESCRIPTS
+#include <libguile.h>
+#endif
+
 #include "Bot.H"
 #include "DCCConnection.H"
 #include "DCCChatConnection.H"
-#include "StringTokenizer.H"
+#include "ChannelList.H"
+#include "DCCManager.H"
+#include "DCCPerson.H"
+#include "Parser.H"
+#include "Person.H"
+#include "Server.H"
 #include "ServerConnection.H"
-#include "Utils.H"
+#include "ServerList.H"
+#include "ShitList.H"
+#include "StringTokenizer.H"
+#include "User.H"
 #include "UserCommands.H"
-#include "DCCManager.H"
+#include "UserList.H"
+#include "Utils.H"
 
 
+#ifdef USESCRIPTS
+#include "BotInterp.H"
+#include "Interp.H"
+#endif
+
 unsigned int Bot::MAX_MESSAGES = 2;
 unsigned int Bot::MAX_NICKLENGTH = 9;
 
@@ -107,11 +127,10 @@ Bot::Bot(String filename, bool debug_on)
   readConfig();
   userList = new UserList(userListFileName);
   shitList = new ShitList(shitListFileName);
-  todoList = new TodoList();
   dccConnections = new DCCManager ();
 
   // Let's read the alias file
-  std::ifstream initFile(initFileName);
+  std::ifstream initFile(initFileName.c_str ());
 
   if (initFile) 
     {
@@ -188,7 +207,6 @@ Bot::~Bot()
   shitList->save();
   delete channelList;
   delete userList;
-  delete todoList;
   delete serverList;
   delete shitList;
   delete serverConnection;
@@ -217,7 +235,7 @@ Bot::logLine(String line)
 void
 Bot::readConfig()
 {
-  std::ifstream file(configFileName);
+  std::ifstream file(configFileName.c_str ());
   String temp;
   int line = 1;
 
@@ -306,7 +324,7 @@ Bot::readConfig()
     else if (command == "LOCALIP")
       localIP = parameters;
     else if (command == "MAXNICKLENGTH")
-      MAX_NICKLENGTH = std::atoi (parameters);
+      MAX_NICKLENGTH = std::atoi (parameters.c_str ());
     else if (command == "SERVER") {
       if (parameters.indexOf(' ') == -1)
         serverList->addServer(new Server(parameters));
@@ -424,10 +442,12 @@ Bot::waitForInput()
       if ((*it).second > 0)
         (*it).second--;
 
-    String line;
-    while ((line = todoList->getNext()) != "") {
-      serverConnection->queue->sendChannelMode(line);
-    }
+    for (std::map<String, Channel *, std::less<String> >::iterator it = channelList->begin ();
+        it != channelList->end ();
+        ++it)
+      {
+       it->second->purge_expired_bans ();
+      }
 #ifdef USESCRIPTS
     botInterp->RunTimers(currentTime);
 
@@ -487,8 +507,8 @@ Bot::canChangeServer()
        it != channelList->end(); ++it) {
     channel = (*it).first;
     c = channelList->getChannel(channel);
-    if (c->countOp == 1 &&
-        c->count > 1 && this->iAmOp(channel))
+    if (c->operator_count () == 1 &&
+        c->user_count () > 1 && this->iAmOp(channel))
       return false;
   }
   return true;
@@ -605,7 +625,7 @@ Bot::getUserhost(String channel, String nick)
 
 
   if (c && c->hasNick(nick))
-    return c->getUser(nick)->userhost;
+    return c->getUser(nick).userhost;
 
   unsigned long num = sentUserhostID++;
 
@@ -627,8 +647,7 @@ Bot::getUserhost(String channel, String nick)
 bool
 Bot::iAmOp(String channel)
 {
-  User * me = channelList->getChannel(channel)->getUser(nickName);
-  return (me->mode & User::OP_MODE);
+  return channelList->getChannel(channel)->getUser(nickName).mode & User::OP_MODE;
 }
 
 void
@@ -737,10 +756,10 @@ Bot::set_log_file (String name)
   logFile.close ();
   logFile.clear ();
 #if HAVE_IOSBASE
-  logFile.open(logs_dir + logFileName, std::ios_base::out | 
+  logFile.open((logs_dir + logFileName).c_str (), std::ios_base::out | 
               std::ios_base::ate | std::ios_base::app);
 #else
-  logFile.open(logs_dir + logFileName, ios::out | ios::ate 
+  logFile.open((logs_dir + logFileName).c_str (), ios::out | ios::ate 
              | ios::app);
 #endif
 
@@ -752,11 +771,11 @@ Bot::set_log_dir (String dir)
 {
   logs_dir = dir;
 
-  DIR *temp = opendir (logs_dir);
+  DIR *temp = opendir (logs_dir.c_str ());
 
   if (!temp)
     {
-      mkdir (logs_dir, S_IRWXU);
+      mkdir (logs_dir.c_str (), S_IRWXU);
     }
   else
     {