[project @ 2005-06-01 00:27:44 by unknown_lamer]
[clinton/bobotpp.git] / source / Bot.C
index c3a83a1..9c67822 100644 (file)
@@ -109,37 +109,53 @@ Bot::Bot(String filename, bool debug_on)
   // Let's read the alias file
   std::ifstream initFile(initFileName);
 
-  if (initFile) {
-    String temp, alias, command;
-    int line = 0;
-    while (initFile >> temp, temp.length() != 0) {
-      line++;
-      StringTokenizer st(temp);
-      temp = Utils::trim_str (temp);
-      if (temp[(unsigned int)0]=='#') continue;
-      if (st.count_tokens (' ') != 2) {
-        std::cerr << "Error when reading alias file (" << initFileName 
-                 << ") line " << line << "...\n";
-        continue;
-      }
-      alias = Utils::to_upper (st.next_token());
-      command = Utils::to_upper (st.next_token());
-
-      // Does the function already exist ?
-      if (!userFunctions[alias])
+  if (initFile) 
+    {
+      // FIXME: these variables are current String instead of
+      // std::string because String>> reads an entire line. This code
+      // needs to be rewritten to use std::string and std::getline (or
+      // better yet, be removed entirely once BotConfig is in place)
+      String temp, alias, command;
+      int line = 0;
+
+      while (initFile >> temp, temp.length() != 0) 
        {
-         if (userFunction *u = userFunctions[command])
-           userFunctions[alias] = 
-             new
-             userFunction(u->function,
-                          u->minLevel,
-                          u->needsChannelName);
+         StringTokenizer st(temp);
+
+         line++;
+         temp = Utils::trim_str (temp);
+
+         if (temp[0]=='#')
+           {
+             continue;
+           }
+
+         if (st.count_tokens (' ') != 2) 
+           {
+             std::cerr << "Error when reading alias file (" << initFileName 
+                       << ") line " << line << "...\n";
+             continue;
+           }
+
+         alias = Utils::to_upper (st.next_token());
+         command = Utils::to_upper (st.next_token());
+
+         // Does the function already exist ?
+         if (!userFunctions[alias])
+           {
+             if (userFunction *u = userFunctions[command])
+               userFunctions[alias] = 
+                 new
+                 userFunction(u->function,
+                              u->minLevel,
+                              u->needsChannelName);
+           }
        }
     }
-  }
 
 
   std::srand (std::time (0)); // srand for bot-random
+
 #ifdef USESCRIPTS
   botInterp = new BotInterp(this, logs_dir + scriptLogFileName);
   botInterp->LoadScript(autoexecFileName);
@@ -383,10 +399,10 @@ Bot::waitForInput()
       {
        char s[6];
        std::sprintf(s, "%2d:%2d", thisTime->tm_hour, thisTime->tm_min);
-       // FIXME: uses gh_list
+       
        botInterp->RunHooks(Hook::TIMER, String(s),
-                           gh_list(Utils::str2scm (std::string (s)), 
-                                   SCM_UNDEFINED));
+                           scm_list_n (Utils::str2scm (std::string (s)), 
+                                       SCM_UNDEFINED));
       }
 #endif
 
@@ -407,15 +423,19 @@ Bot::waitForInput()
          serverConnection->queue->sendJoin((*it).first, (*it).second->key);
   }
 
-  if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken + Bot::PING_TIME) && !sentPing) {
-    serverConnection->queue->sendPing("Testing connection");
-    sentPing = true;
-  }
+  if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken 
+                                  + Bot::PING_TIME) && !sentPing) 
+    {
+      serverConnection->queue->sendPing("Testing connection");
+      sentPing = true;
+    }
 
-  if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken + Bot::TIMEOUT)) {
-    sentPing = false;
-    nextServer();
-  }
+  if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken 
+                                  + Bot::TIMEOUT)) 
+    {
+      sentPing = false;
+      nextServer();
+    }
 }
 
 // We can change server if we will not lose op on a channel
@@ -506,16 +526,21 @@ Bot::addDCC(Person * from, unsigned long address, int port, int type)
   DCCConnection *d = 0;
 
   if (type == CHAT)
-    d = new DCCChatConnection(this, from->getAddress (),
-                             address, port);
+    {
+      d = new DCCChatConnection(this, from->getAddress (),
+                               address, port);
+    }
   else
-    return;
+    {
+      return;
+    }
 
   if (!d->connect())
     {
       logLine ("DCC Connection failed from " + from->getAddress ());
       return;
     }
+
   logLine ("DCC CHAT accepted from" + from->getAddress ());
   dccConnections->addConnection (d);
 }