[project @ 2005-06-28 03:16:45 by unknown_lamer]
[clinton/bobotpp.git] / source / UserCommands.C
index 3bcfc50..199e9ef 100644 (file)
@@ -1,6 +1,6 @@
 // UserCommands.C  -*- C++ -*-
 // Copyright (c) 1997, 1998 Etienne BERNARD
-// Copyright (C) 2002 Clinton Ebadi
+// Copyright (C) 2002,2005 Clinton Ebadi
 
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -14,7 +14,7 @@
 
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 
 #include <fstream>
 #include <map>
+#include <string>
+#include <cctype>
+#include <cstdlib>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
-#include <ctype.h>
 #include <cstdlib>
 #ifndef _X_OPEN_SOURCE
 #define _X_OPEN_SOURCE
@@ -72,13 +74,13 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from,
   String mask, who, maskChannel, level, prot,
     aop, expiration, passwd;
 
-  mask = who = st.nextToken();
-  maskChannel = st.nextToken();
-  level = st.nextToken();
-  prot = st.nextToken();
-  aop = st.nextToken();
-  expiration = st.nextToken();
-  passwd = st.nextToken();
+  mask = who = st.next_token();
+  maskChannel = st.next_token();
+  level = st.next_token();
+  prot = st.next_token();
+  aop = st.next_token();
+  expiration = st.next_token();
+  passwd = st.next_token();
 
   if (mask == "" || maskChannel == "" || level == "" ||
       prot == "" || aop == "") {
@@ -86,13 +88,13 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from,
     return;
   }
 
-//   if (!Utils::isWildcard(mask)) {
+//   if (!Utils::wildcard_p(mask)) {
 //     mask = cnx->bot->getUserhost(channel, who);
 //     if (mask == "") {
 //       from->sendNotice(String("\002I can not find\002 ") + who);
 //       return;
 //     }
-//     mask = Utils::makeWildcard(mask);
+//     mask = Utils::make_wildcard(mask);
 //   }
   
 //   if (cnx->bot->userList->isInUserList(mask, maskChannel)) {
@@ -108,7 +110,7 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from,
   l = atoi((const char *)level);
   if (l < 0 || l > User::FRIEND)
     return;
-  if (l > Utils::getLevel(cnx->bot, from->getAddress())) {
+  if (l > Utils::get_level(cnx->bot, from->getAddress())) {
     from->sendNotice("\002You can not give a level greater than yours.\002");
     return;
   }
@@ -119,7 +121,7 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from,
   if (a != 0 && a != 1)
     return;
 
-  e = Utils::strToTime(expiration);
+  e = Utils::str2time(expiration);
 
   if (!e)
     e = -1;
@@ -133,11 +135,11 @@ UserCommands::AddUser(ServerConnection *cnx, Person *from,
       from->sendNotice(String("\002Added\002 ") + mask +
                       " \002on channels\002 " + maskChannel);
       from->sendNotice(String("\002Level:\002 ") +
-                      Utils::levelToStr(l) +
+                      Utils::level2str(l) +
                       "  \002Protection:\002 " +
-                      Utils::protToStr(p) +
+                      Utils::prot2str(p) +
                       "  \002Auto-op:\002 " +
-                      Utils::boolToStr(a));
+                      Utils::bool2str(a));
     }
   else
     from->sendNotice(m.getMessage ());
@@ -155,11 +157,11 @@ UserCommands::AddServer(ServerConnection *cnx, Person *from,
   }
 
   StringTokenizer st(rest);
-  String serverName = st.nextToken();
+  String serverName = st.next_token();
   int port = 6667;
 
-  if (st.hasMoreTokens()) {
-    String temp = st.nextToken();
+  if (st.more_tokens_p()) {
+    String temp = st.next_token();
     port = atoi((const char *)temp);
   }
 
@@ -181,11 +183,11 @@ UserCommands::AddShit(ServerConnection *cnx, Person *from,
   StringTokenizer st(rest);
   String mask, who, maskChannel, level, expiration, reason;
 
-  mask = who = st.nextToken();
-  maskChannel = st.nextToken();
-  level = st.nextToken();
-  expiration = st.nextToken();
-  reason = st.rest().trim();
+  mask = who = st.next_token();
+  maskChannel = st.next_token();
+  level = st.next_token();
+  expiration = st.next_token();
+  reason = Utils::trim_str (st.rest());
 
   /*  if (mask == "" || maskChannel == "" || level == "") {
     from->sendNotice("\002Invalid syntax for this command.\002");
@@ -199,13 +201,13 @@ UserCommands::AddShit(ServerConnection *cnx, Person *from,
   */
 
   /*
-  if (!Utils::isWildcard(mask)) {
+  if (!Utils::wildcard_p(mask)) {
     mask = cnx->bot->getUserhost(channel, who);
     if (mask == "") {
       from->sendNotice(String("\002I can not find\002 ") + who);
       return;
     }
-    mask = Utils::makeWildcard(mask);
+    mask = Utils::make_wildcard(mask);
     if (cnx->bot->shitList->getShit(mask, maskChannel)) {
       from->sendNotice(mask + " \002is already in shitlist on channel(s)\002 " +
                        maskChannel);
@@ -220,7 +222,7 @@ UserCommands::AddShit(ServerConnection *cnx, Person *from,
   if (l < 0 || l > ShitEntry::SHIT_NODEBAN)
     return;
 
-  e = Utils::strToTime(expiration);
+  e = Utils::str2time(expiration);
 
   if (!e)
     e = -1;
@@ -250,8 +252,8 @@ UserCommands::Alias(ServerConnection *cnx, Person *from,
                     String channel, String rest)
 {
   StringTokenizer st(rest);
-  String newF = st.nextToken().toUpper();
-  String oldF = st.nextToken().toUpper();
+  String newF = Utils::to_upper (st.next_token());
+  String oldF = Utils::to_upper (st.next_token());
 
   if (newF == "" || oldF == "") {
     from->sendNotice("\002Invalid syntax for this command.\002");
@@ -320,16 +322,16 @@ UserCommands::BanList(ServerConnection *cnx, Person *from,
 //   StringTokenizer st(rest);
   
 //   String who;
-//   String mask = who = st.nextToken();
-//   String maskChannel = st.nextToken();
-//   String level = st.nextToken();
+//   String mask = who = st.next_token();
+//   String maskChannel = st.next_token();
+//   String level = st.next_token();
   
 //   if (mask == "" || maskChannel == "" || level == "") {
 //     from->sendNotice("\002Invalid syntax for this command.\002");
 //     return;
 //   }
   
-//   if (!Utils::isWildcard(mask)) {
+//   if (!Utils::wildcard_p(mask)) {
 //     mask = cnx->bot->getUserhost(channel, who);
 //     if (mask == "") {
 //       from->sendNotice(String("\002I can not find\002 ") + who);
@@ -354,12 +356,12 @@ UserCommands::BanList(ServerConnection *cnx, Person *from,
 //     return;
 //   }
   
-//   if (l > Utils::getLevel(cnx->bot, from->getAddress())) {
+//   if (l > Utils::get_level(cnx->bot, from->getAddress())) {
 //     from->sendNotice("\002You can not give a level greater than yours.\002");
 //     return;
 //   }
   
-//   if (Utils::getLevel(cnx->bot, from->getAddress()) < uli->level) {
+//   if (Utils::get_level(cnx->bot, from->getAddress()) < uli->level) {
 //     from->sendNotice("\002You can not change the level for a person "
 //                      "whose level is greater than yours.\002");
 //     return;
@@ -462,21 +464,21 @@ UserCommands::DelUser(ServerConnection *cnx, Person *from,
   StringTokenizer st(rest);
 
   String who;
-  String mask = who = st.nextToken();
-  String maskChannel = st.nextToken();
+  String mask = who = st.next_token();
+  String maskChannel = st.next_token();
 
   if (mask == "" || maskChannel == "") {
     from->sendNotice("\002Invalid syntax for this command.\002");
     return;
   }
 
-  if (!Utils::isWildcard(mask)) {
+  if (!Utils::wildcard_p(mask)) {
     mask = cnx->bot->getUserhost(channel, who);
     if (mask == "") {
       from->sendNotice(String("\002I can not find\002 ") + who);
       return;
     }
-    mask = Utils::makeWildcard(mask);
+    mask = Utils::make_wildcard(mask);
   }
   
   if (!cnx->bot->userList->isInUserList(mask, maskChannel)) {
@@ -498,21 +500,21 @@ UserCommands::DelShit(ServerConnection *cnx, Person *from,
   StringTokenizer st(rest);
   
   String who;
-  String mask = who = st.nextToken();
-  String maskChannel = st.nextToken();
+  String mask = who = st.next_token();
+  String maskChannel = st.next_token();
 
   if (mask == "" || maskChannel == "") {
     from->sendNotice("\002Invalid syntax for this command.\002");
     return;
   }
 
-  if (!Utils::isWildcard(mask)) {
+  if (!Utils::wildcard_p(mask)) {
     mask = cnx->bot->getUserhost(channel, who);
     if (mask == "") {
       from->sendNotice(String("\002I can not find\002 ") + who);
       return;
     }
-    mask = Utils::makeWildcard(mask);
+    mask = Utils::make_wildcard(mask);
   }
   
   if (!cnx->bot->shitList->getShit(mask, maskChannel)) {
@@ -577,7 +579,7 @@ UserCommands::Help(ServerConnection *cnx, Person *from,
 {
   if (rest.length() == 0) {
     from->sendNotice("\002Available topics for you are:\002");
-    int level = Utils::getLevel(cnx->bot, from->getAddress());
+    int level = Utils::get_level(cnx->bot, from->getAddress());
     String result = "";
     int length = 0;
     std::map<std::string, class userFunction*, std::less<std::string> >::iterator it;
@@ -598,7 +600,7 @@ UserCommands::Help(ServerConnection *cnx, Person *from,
   }
 
   StringTokenizer st(rest);
-  String command = st.nextToken().toUpper();
+  String command = Utils::to_upper (st.next_token());
   std::ifstream helpFile(cnx->bot->helpFileName);
 
   if (!helpFile) {
@@ -688,9 +690,9 @@ UserCommands::Join(ServerConnection *cnx, Person *from,
                    String channel, String rest)
 {
   StringTokenizer st(rest);
-  channel = st.nextToken();
+  channel = st.next_token();
 
-  if (!Utils::isValidChannelName(channel)) {
+  if (!Utils::valid_channel_name_p(channel)) {
     from->sendNotice(String("\002") + channel +
                      " is not a valid channel name\002");
     return;
@@ -741,9 +743,9 @@ UserCommands::Kick(ServerConnection *cnx, Person *from,
   }
 
   StringTokenizer st(rest);
-  String who = st.nextToken();
+  String who = st.next_token();
 
-  if (Utils::isWildcard(who)) {
+  if (Utils::wildcard_p(who)) {
     User * u = c->getUser(nick);
     if (!u)
       return;
@@ -760,7 +762,7 @@ UserCommands::Kick(ServerConnection *cnx, Person *from,
     return;
   }
 
-  if (Utils::isWildcard(who)) {
+  if (Utils::wildcard_p(who)) {
     Mask m(who);
     for (std::map<String, User *, std::less<String> >::iterator it =
            c->channelMemory.begin();
@@ -793,7 +795,7 @@ UserCommands::KickBan(ServerConnection *cnx, Person *from,
 {
   StringTokenizer st(rest);
 
-  Ban(cnx, 0, channel, st.nextToken());
+  Ban(cnx, 0, channel, st.next_token());
   Kick(cnx, from, channel, rest);
 }
 
@@ -854,7 +856,7 @@ UserCommands::Msg(ServerConnection *cnx, Person *from,
                    String channel, String rest)
 {
   StringTokenizer st(rest);
-  String who = st.nextToken();
+  String who = st.next_token();
   String message = st.rest();
 
   Message m = Commands::Msg(cnx->bot, who, message);
@@ -926,14 +928,14 @@ UserCommands::Nick(ServerConnection *cnx, Person *from,
 {
   // We parse the parameters
   StringTokenizer st(rest);
-  String nick = st.nextToken();
+  String nick = st.next_token();
 
   if (rest == "") {
     from->sendNotice(String("\002No nickname given.\002"));
     return;
   }
 
-  if (!Utils::isValidNickName(nick)) {
+  if (!Utils::valid_nickname_p (cnx->bot, nick)) {
     from->sendNotice(String("\002") + nick +
                      " is not a valid nickname\002");
     return;
@@ -957,7 +959,7 @@ UserCommands::NsLookup(ServerConnection *cnx, Person *from,
 
   if (rest.find('.') == -1) {
     StringTokenizer st(cnx->bot->getUserhost("", rest));
-    st.nextToken('@');
+    st.next_token('@');
     target = st.rest();
     if (target.length() == 0) {
       from->sendNotice(String("\002I could not find\002 ") +
@@ -1009,7 +1011,7 @@ UserCommands::Op(ServerConnection *cnx, Person *from,
     return;
   }
 
-  if (Utils::isWildcard(rest)) {
+  if (Utils::wildcard_p(rest)) {
     from->sendNotice("\002Mass op is not allowed.\002");
     return;
   }
@@ -1185,8 +1187,11 @@ UserCommands::SetVersion(ServerConnection *cnx, Person *from,
                          String channel, String rest)
 {
   Message m = Commands::SetVersion(cnx->bot, rest);
+
   if (m.getCode() < 0)
-    from->sendNotice(m.getMessage());
+    {
+      Commands::Notice (cnx->bot, from->getNick (), m.getMessage());
+    }
 }
 
 void
@@ -1301,8 +1306,8 @@ UserCommands::TBan(ServerConnection *cnx, Person *from,
   Channel * c = cnx->bot->channelList->getChannel(channel);
 
   StringTokenizer st(rest);
-  String who = st.nextToken();
-  String t = st.nextToken();
+  String who = st.next_token();
+  String t = st.next_token();
   String dest;
 
   if (who == "" || t == "") {
@@ -1311,7 +1316,7 @@ UserCommands::TBan(ServerConnection *cnx, Person *from,
     return;
   }
 
-  if (Utils::isWildcard(who) && from) {
+  if (Utils::wildcard_p(who) && from) {
     User * u = c->getUser(from->getNick());
     if (u && u->getLevel() < User::TRUSTED_USER) {
       if (from)
@@ -1328,7 +1333,7 @@ UserCommands::TBan(ServerConnection *cnx, Person *from,
     return;
   }
 
-  if (!Utils::isWildcard(who))
+  if (!Utils::wildcard_p(who))
     dest = cnx->bot->getUserhost(channel, who);
   else
     dest = who;
@@ -1341,13 +1346,13 @@ UserCommands::TBan(ServerConnection *cnx, Person *from,
 
   time_t w;
 
-  if ((w = Utils::strToTime(t)) == 0) {
+  if ((w = Utils::str2time(t)) == 0) {
     if (from)
       from->sendNotice(t + " \002is an invalid time.\002");
     return;
   }
 
-  dest = Utils::makeWildcard(dest);
+  dest = Utils::make_wildcard(dest);
   Mask m(dest);
 
   for (std::list<UserListItem *>::iterator it = cnx->bot->userList->l.begin();
@@ -1379,8 +1384,8 @@ UserCommands::TKBan(ServerConnection *cnx, Person *from,
                    String channel, String rest)
 {
   StringTokenizer st(rest);
-  String who = st.nextToken();
-  String t = st.nextToken();
+  String who = st.next_token();
+  String t = st.next_token();
 
   TBan(cnx, 0, channel, who + " " + t);
   Kick(cnx, from, channel, who + " " + st.rest());
@@ -1420,13 +1425,18 @@ UserCommands::UserList(ServerConnection *cnx, Person *from,
   for (std::list<UserListItem *>::iterator it = cnx->bot->userList->l.begin();
        it != cnx->bot->userList->l.end();
        it++)
-    from->sendNotice((*it)->mask.getMask().pad(25) + " " +
-                     (*it)->channelMask.getMask().pad(10) + " " +
-                     Utils::levelToStr((*it)->level).pad(12) + " " +
-                     Utils::protToStr((*it)->prot).pad(7) + " " +
-                     Utils::boolToStr((*it)->aop).pad(5) + " " +
-                     String((long)(*it)->expirationDate));
-
+    from->sendNotice((*it)->mask.getMask().pad(25)
+                    + " "
+                    + (*it)->channelMask.getMask().pad(10)
+                    + " " +
+                    String(Utils::level2str((*it)->level)).pad(12)
+                    + " " +
+                    String(Utils::prot2str((*it)->prot)).pad(7)
+                    + " " +
+                    String(Utils::bool2str((*it)->aop)).pad(5)
+                    + " " +
+                    String(Utils::long2str ((*it)->expirationDate)));
+  
   from->sendNotice("\002End of userlist.\002");
 }
 
@@ -1449,16 +1459,16 @@ UserCommands::Who(ServerConnection *cnx, Person *from,
                       uli->mask.getMask() + " \002on\002 " +
                       uli->channelMask.getMask());
     from->sendNotice(String("\002Lvl:\002 ") +
-                     Utils::levelToStr(uli->level) +
+                     Utils::level2str(uli->level) +
                      " \002Prot:\002 " +
-                     Utils::protToStr(uli->prot) +
+                     Utils::prot2str(uli->prot) +
                      " \002Aop:\002 " +
-                     Utils::boolToStr(uli->aop) +
+                     Utils::bool2str(uli->aop) +
                      " \002Expired:\002 " +
-                     Utils::boolToStr(!uli->isStillValid()) +
+                     Utils::bool2str(!uli->isStillValid()) +
                      " \002Ident:\002 " +
                      (uli && !uli->identified ? "\026" : "") +
-                     Utils::boolToStr(uli && uli->identified) +
+                     Utils::bool2str(uli && uli->identified) +
                      (uli && !uli->identified ? "\026" : ""));
   } else
     from->sendNotice(String("\002You are not in the userlist for\002 ") +
@@ -1477,7 +1487,7 @@ UserCommands::Whois(ServerConnection *cnx, Person *from,
   }
 
   StringTokenizer st(rest);
-  String otherNick = st.nextToken();
+  String otherNick = st.next_token();
 
   User * u = cnx->bot->channelList->getChannel(channel)->getUser(otherNick);
   UserListItem * uli;
@@ -1495,15 +1505,15 @@ UserCommands::Whois(ServerConnection *cnx, Person *from,
                      " \002is\002 " + uli->mask.getMask() +
                      " \002on\002 " + uli->channelMask.getMask());
     from->sendNotice(String("\002Lvl:\002 ") +
-                     Utils::levelToStr(uli->level) +
+                     Utils::level2str(uli->level) +
                      " \002Prot:\002 " +
-                     Utils::protToStr(uli->prot) +
+                     Utils::prot2str(uli->prot) +
                      " \002Aop:\002 " +
-                     Utils::boolToStr(uli->aop) +
+                     Utils::bool2str(uli->aop) +
                      " \002Expired:\002 " +
-                     Utils::boolToStr(!uli->isStillValid()) +
+                     Utils::bool2str(!uli->isStillValid()) +
                      " \002Ident:\002 " +
-                     Utils::boolToStr(uli && uli->identified));
+                     Utils::bool2str(uli && uli->identified));
   } else
     from->sendNotice(otherNick +
                       " \002is not in the userlist for\002 " +