[project @ 2005-05-31 05:59:57 by unknown_lamer]
[clinton/bobotpp.git] / source / Commands.C
index 44fc761..d007e33 100644 (file)
@@ -676,45 +676,72 @@ Commands::TBan(Bot *bot, String channel, String who, int seconds)
   CHECK_CONNECTION;
 
   Channel *c = CHANNEL(channel);
+  String dest;
 
+  // Make sure all of the inputs are valid
   if (!c)
-    return NotOnChannel(channel);
+    {
+      return NotOnChannel(channel);
+    }
 
   if (!bot->iAmOp(channel))
-    return NotChannelOp(channel);
+    {
+      return NotChannelOp(channel);
+    }
 
   if (seconds <= 0)
-    return InvalidTime(seconds);
-
-  String dest;
+    {
+      return InvalidTime(seconds);
+    }
 
+  // Look for user
   if (!Utils::wildcard_p(who))
-    dest = bot->getUserhost(channel, who);
+    {
+      dest = bot->getUserhost(channel, who);
+    }
   else
-    dest = who;
+    {
+      dest = who;
+    }
 
   if (dest.length() == 0)
-    return UserNotFound(who, channel);
+    {
+      return UserNotFound(who, channel);
+    }
+
 
   dest = Utils::make_wildcard(dest);
   Mask m(dest);
 
+  // Make sure the user isn't protected from bans
   for (std::list<UserListItem *>::iterator it = bot->userList->l.begin();
        it != bot->userList->l.end();
        it++)
-    if (m.matches((*it)->mask) &&
-        (*it)->channelMask.matches(channel) &&
-        (*it)->prot >= User::NO_BAN)
-      return UserProtected(who, channel);
+    {
+      if (m.matches((*it)->mask) &&
+         (*it)->channelMask.matches(channel) &&
+         (*it)->prot >= User::NO_BAN)
+       {
+         return UserProtected(who, channel);
+       }
+    }
 
+  // Clear existing bans on the user
   for (std::vector<BanEntry *>::iterator it = c->channelBanlist.begin();
        it != c->channelBanlist.end(); ++it)
-    if (m.matches((*it)->banMask))
-      QUEUE->sendChannelMode(channel, "-b", (*it)->banMask.getMask());
+    {
+      if (m.matches((*it)->banMask))
+       {
+         QUEUE->sendChannelMode(channel, "-b", (*it)->banMask.getMask());
+       }
+    }
 
+  // Ban them
   CHANNEL(channel)->addBan(dest, seconds);
   QUEUE->sendChannelMode(channel, "+b", dest);
   bot->todoList->addDeban(channel, dest, seconds);
+
+  return Ok;
 }