[project @ 2003-07-23 05:56:23 by unknown_lamer]
authorunknown_lamer <unknown>
Wed, 23 Jul 2003 05:56:23 +0000 (05:56 +0000)
committerunknown_lamer <unknown>
Wed, 23 Jul 2003 05:56:23 +0000 (05:56 +0000)
* source/Parser.C (parseMessage): use the find method of std::map
to find the command to call instead of [] and then extract the
pointer to the userFunction from that if it exists. This appears
to fix the crash when one uses an undefined command followed by
any defined command.

source/Parser.C

index 9be4f08..a79e92c 100644 (file)
@@ -915,7 +915,16 @@ Parser::parseMessage (ServerConnection * cnx,
   String rest = st.rest ().trim ();
   int level;
   bool identified = false;
-  userFunction * f = cnx->bot->userFunctions[command];
+  std::map<std::string, class userFunction*, 
+    std::less<std::string> >::const_iterator  uf_iter 
+    = cnx->bot->userFunctions.find (command);
+  userFunction * f = 0;
+  
+  if (uf_iter != cnx->bot->userFunctions.end ())
+    f = uf_iter->second;
+  else
+    return;
+  
   if (f)
     {
       if (f->needsChannelName)
@@ -926,61 +935,61 @@ Parser::parseMessage (ServerConnection * cnx,
              to = st.nextToken ();
              rest = st.rest ();
            }
-           if (!Utils::isChannel (to))
-             {
-               from->sendNotice ("\002You need to supply a channel name"
-                                 " for this command\002");
-               return;
-             }
-           if (!cnx->bot->channelList->getChannel (to))
-             {
-               from->sendNotice (String ("\002I am not on channel\002 ") +
-                                 to);
-               return;
-             }
-           level = Utils::getLevel (cnx->bot, from->getAddress (), to);
-           User *u = 0;
-           if (Channel * c = cnx->bot->channelList->getChannel (to))
-             u = c->getUser (from->getNick ());
-           if (!u || !u->userListItem)
-             identified = true;
-           else
-             identified = u->userListItem->passwd == ""
-               || u->userListItem->identified > 0;
-         }
-       else
-         {
-           level = Utils::getLevel (cnx->bot, from->getAddress ());
+         if (!Utils::isChannel (to))
+           {
+             from->sendNotice ("\002You need to supply a channel name"
+                               " for this command\002");
+             return;
+           }
+         if (!cnx->bot->channelList->getChannel (to))
+           {
+             from->sendNotice (String ("\002I am not on channel\002 ") +
+                               to);
+             return;
+           }
+         level = Utils::getLevel (cnx->bot, from->getAddress (), to);
+         User *u = 0;
+         if (Channel * c = cnx->bot->channelList->getChannel (to))
+           u = c->getUser (from->getNick ());
+         if (!u || !u->userListItem)
            identified = true;
-         }
-       if (level >= f->minLevel)
-         {
-           cnx->bot->logLine (from->getAddress () + " did " + command +
-                              " " + rest);
+         else
+           identified = u->userListItem->passwd == ""
+             || u->userListItem->identified > 0;
+       }
+      else
+           {
+             level = Utils::getLevel (cnx->bot, from->getAddress ());
+             identified = true;
+           }
+      if (level >= f->minLevel)
+       {
+         cnx->bot->logLine (from->getAddress () + " did " + command +
+                            " " + rest);
 #ifdef USESCRIPTS
-           if (f->argsCount != -1)
-             {
-               Parser::parseScriptFunction (cnx, to, f->needsChannelName,
-                                            f->scmFunc, f->argsCount,
-                                            rest);
-             }
-           else
-             {
-               f->function (cnx, from, to, rest);
-             }
+         if (f->argsCount != -1)
+           {
+             Parser::parseScriptFunction (cnx, to, f->needsChannelName,
+                                          f->scmFunc, f->argsCount,
+                                          rest);
+           }
+         else
+           {
+             f->function (cnx, from, to, rest);
+           }
 #else
-           f->function (cnx, from, to, rest);
+         f->function (cnx, from, to, rest);
 #endif
-         }
-       else
-         {
-           if (!identified)
-             from->
-               sendNotice (String
-                           ("\002You are not identified on channel\002 ") +
-                           to);
-         }
-      }
+       }
+      else
+       {
+         if (!identified)
+           from->
+             sendNotice (String
+                         ("\002You are not identified on channel\002 ") +
+                         to);
+       }
+    }
 }
 
 #ifdef USESCRIPTS