[project @ 2005-06-28 03:16:45 by unknown_lamer]
authorunknown_lamer <unknown>
Tue, 28 Jun 2005 03:16:45 +0000 (03:16 +0000)
committerunknown_lamer <unknown>
Tue, 28 Jun 2005 03:16:45 +0000 (03:16 +0000)
+ NOTICEs and PRIVMSGs are now sent correctly if they contain an
  embedded newline
+ Max nick length is now configurable via 'maxnicklength' option in
  bot.conf (defaults to 9)
+ A few internal cleanups

13 files changed:
AUTHORS
ChangeLog
NEWS
TODO
examples/bot.conf
source/Bot.C
source/Bot.H
source/Commands.C
source/Parser.C
source/ScriptCommands.C
source/UserCommands.C
source/Utils.C
source/Utils.H

diff --git a/AUTHORS b/AUTHORS
index d80a9a9..176f0de 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -6,3 +6,7 @@ eb on IRCNet
 Current Maintainer (1.98 and above):
 Clinton Ebadi <clinton@unknownlamer.org>
 unknown_lamer on OpenProjects and OFTC
+
+Patches by:
+Jos Hulzink
+Dale Smith
\ No newline at end of file
index 8d5e0ad..f986ac2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2005-06-27  Clinton Ebadi  <clinton@unknownlamer.org>
+
+       * examples/bot.conf (maxnicklength): Update example config
+
+       * source/Utils.C (valid_nickname_p): Use b->MAX_NICKLENGTH
+
+       * source/Bot.C (readConfig): Look for MAXNICKLENGTH parameter
+
+       * source/Bot.H: Added MAX_NICKLENGTH member
+
+       * source/Utils.H (valid_nickname_p): Now takes Bot* as first argument
+
+       * source/Commands.C (Msg): Send multiple PRIVMSGs when a message
+       is multiple lines
+
+       * source/UserCommands.C (SetVersion): Convert to use Commands::Notice
+
+       * source/Commands.C (Notice): Send multiple NOTICEs when a message
+       is multiple lines
+
 2005-06-25  Clinton Ebadi  <clinton@unknownlamer.org>
 
        * source/Main.C (real_main): Enable Guile debugging mode when
diff --git a/NEWS b/NEWS
index abd164e..01c3d4d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,11 @@ Version 2.1.8:
     * The debugging evaluator is now enabled when --debug is passed to the bot
 - Documentation
   + Merged documentation patch from Dale Smith (thanks)
+- Misc
+  + NOTICEs and PRIVMSGs are now sent correctly if they contain an
+    embedded newline
+  + Max nick length is now configurable via 'maxnicklength' option in
+    bot.conf (defaults to 9)
 
 
 Version 2.1.7:
diff --git a/TODO b/TODO
index 3842b65..b55c38f 100644 (file)
--- a/TODO
+++ b/TODO
@@ -6,6 +6,7 @@ Done:
 * Compile without warnings
 * bot:protection/[none|no-ban|no-kick|no-deop] constants
 * bot:aop/[no|yes] constants
+* Utils::valid_nickname_p should have a configurable max nick length
 
 2.2:
 * Finish Texinfo manual
@@ -20,6 +21,7 @@ Done:
 * Add util functions for doing stuff like quoting CTCP messages
 * Finish adding hooks/send hooks
 * Add DCC_CHAT_END hook for Scheme
+* Commands::sendCTCP, Commands::sendCTCPReply
 
 2.4: 
 * Use configuration database class
index b50b523..b8753a6 100644 (file)
@@ -10,6 +10,10 @@ nick = TestBot
 # username = <string>
 username = lamerbot
 
+# Maximum nick length of the bot (default to 9)
+# maxnicklength = <positive integer>
+maxnicklength = 9
+
 # IRCname of the bot (shown with /whois)
 # ircname = <string>
 ircname = Scheme Me!
index 53dbc90..af8cb31 100644 (file)
@@ -37,6 +37,7 @@
 
 
 unsigned int Bot::MAX_MESSAGES = 2;
+unsigned int Bot::MAX_NICKLENGTH = 9;
 
 #define DEFAULT_NICKNAME "Bobot"
 #define DEFAULT_USERNAME "bobot"
@@ -288,6 +289,8 @@ Bot::readConfig()
       initFileName = parameters;
     else if (command == "LOCALIP")
       localIP = parameters;
+    else if (command == "MAXNICKLENGTH")
+      MAX_NICKLENGTH = std::atoi (parameters);
     else if (command == "SERVER") {
       if (parameters.indexOf(' ') == -1)
         serverList->addServer(new Server(parameters));
index fc43f12..f38e253 100644 (file)
@@ -106,6 +106,7 @@ public:
   unsigned long receivedUserhostID;
 
   static unsigned int MAX_MESSAGES;
+  static unsigned int MAX_NICKLENGTH;
   static const std::time_t NICK_CHANGE  = 60;
   static const std::time_t CHANNEL_JOIN = 60;
   static const std::time_t IGNORE_DELAY = 180;
index fcd2d82..ba538bb 100644 (file)
@@ -20,6 +20,7 @@
 #include "Message.H"
 #include "Commands.H"
 #include "Utils.H"
+#include "StringTokenizer.H"
 
 
 #define CHECK_CONNECTION if (!bot->serverConnection) return NotConnected
@@ -488,7 +489,13 @@ Commands::Msg(Bot *bot, String who, String message)
       return EmptyMessage;
     }
 
-  QUEUE->sendPrivmsg(who, message);
+  // Send multi-line messages as seperate privmsgs
+  StringTokenizer st_message (message);
+
+  while (st_message.more_tokens_p ('\n'))
+    {
+      QUEUE->sendPrivmsg(who, st_message.next_token ('\n'));
+    }
 
   return Ok;
 }
@@ -515,7 +522,7 @@ Commands::Nick(Bot *bot, String nick)
 {
   CHECK_CONNECTION;
 
-  if (nick == "" || !Utils::valid_nickname_p(nick))
+  if (nick == "" || !Utils::valid_nickname_p(bot, nick))
     return InvalidNick(nick);
   
   bot->wantedNickName = nick;
@@ -538,7 +545,13 @@ Commands::Notice(Bot *bot, String who, String message)
   if (message == "")
     return EmptyMessage;
 
-  QUEUE->sendNotice(who, message);
+  // Send multiple lines as multiple notices
+  StringTokenizer st_message (message);
+
+  while (st_message.more_tokens_p ('\n'))
+    {
+      QUEUE->sendNotice(who, st_message.next_token ('\n'));
+    }
 
   return Ok;
 }
index 418fdc3..9ea7733 100644 (file)
@@ -832,7 +832,9 @@ Parser::parseCTCP (ServerConnection * cnx,
   if (command == "PING")
     cnx->queue->sendCTCPReply (nick, "PING", rest);
   else if (command == "VERSION")
-    cnx->queue->sendCTCPReply (nick, "VERSION", cnx->bot->versionString);
+    {
+      cnx->queue->sendCTCPReply (nick, "VERSION", cnx->bot->versionString);
+    }
   else if (command == "CLOCK")
     {
       time_t diff = time (NULL) - cnx->bot->startTime;
index 0bc1009..c320f7a 100644 (file)
@@ -648,7 +648,8 @@ ScriptCommands::sendCTCP(SCM to, SCM command , SCM message)
   VERIFY_STRING(message);
 
   IQUEUE->sendCTCP (Utils::scm2str (to), Utils::scm2str (command),
-                  Utils::scm2str (message));
+                   Utils::scm2str (message));
+
   return SCM_UNSPECIFIED;
 }
 
index 2ba0cc9..199e9ef 100644 (file)
@@ -935,7 +935,7 @@ UserCommands::Nick(ServerConnection *cnx, Person *from,
     return;
   }
 
-  if (!Utils::valid_nickname_p(nick)) {
+  if (!Utils::valid_nickname_p (cnx->bot, nick)) {
     from->sendNotice(String("\002") + nick +
                      " is not a valid nickname\002");
     return;
@@ -1187,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
index bdddb59..28530cb 100644 (file)
@@ -123,10 +123,10 @@ Utils::valid_channel_name_p (std::string c)
 #define isvalid(c) (((c) >= 'A' && (c) <= '~') || std::isdigit(c) || (c) == '-')
 
 bool
-Utils::valid_nickname_p (std::string n)
+Utils::valid_nickname_p (const Bot *b, std::string n)
 {
   // FIXME: make max nick length configurable
-  if (n[0] == '-' || std::isdigit(n[0]) || n.length() > 9)
+  if (n[0] == '-' || std::isdigit(n[0]) || n.length() > b->MAX_NICKLENGTH)
     return false;
 
   for (std::string::size_type i = 0; i < n.length(); i++)
index a214c20..f287f29 100644 (file)
@@ -46,7 +46,7 @@ namespace Utils {
   bool channel_p (std::string);
   bool wildcard_p (std::string);
   bool valid_channel_name_p (std::string);
-  bool valid_nickname_p (std::string);
+  bool valid_nickname_p (const Bot *, std::string);
   bool IP_p (std::string);
   
   std::string level2str (int);