From 6b7614a8f1ae00cb470a620af4e0b6ffbbaa1951 Mon Sep 17 00:00:00 2001 From: unknown_lamer Date: Tue, 28 Jun 2005 03:16:45 +0000 Subject: [PATCH] [project @ 2005-06-28 03:16:45 by unknown_lamer] + 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 --- AUTHORS | 4 ++++ ChangeLog | 20 ++++++++++++++++++++ NEWS | 5 +++++ TODO | 2 ++ examples/bot.conf | 4 ++++ source/Bot.C | 3 +++ source/Bot.H | 1 + source/Commands.C | 19 ++++++++++++++++--- source/Parser.C | 4 +++- source/ScriptCommands.C | 3 ++- source/UserCommands.C | 7 +++++-- source/Utils.C | 4 ++-- source/Utils.H | 2 +- 13 files changed, 68 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index d80a9a9..176f0de 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,3 +6,7 @@ eb on IRCNet Current Maintainer (1.98 and above): Clinton Ebadi unknown_lamer on OpenProjects and OFTC + +Patches by: +Jos Hulzink +Dale Smith \ No newline at end of file diff --git a/ChangeLog b/ChangeLog index 8d5e0ad..f986ac2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2005-06-27 Clinton Ebadi + + * 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 * source/Main.C (real_main): Enable Guile debugging mode when diff --git a/NEWS b/NEWS index abd164e..01c3d4d 100644 --- 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 --- 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 diff --git a/examples/bot.conf b/examples/bot.conf index b50b523..b8753a6 100644 --- a/examples/bot.conf +++ b/examples/bot.conf @@ -10,6 +10,10 @@ nick = TestBot # username = username = lamerbot +# Maximum nick length of the bot (default to 9) +# maxnicklength = +maxnicklength = 9 + # IRCname of the bot (shown with /whois) # ircname = ircname = Scheme Me! diff --git a/source/Bot.C b/source/Bot.C index 53dbc90..af8cb31 100644 --- a/source/Bot.C +++ b/source/Bot.C @@ -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)); diff --git a/source/Bot.H b/source/Bot.H index fc43f12..f38e253 100644 --- a/source/Bot.H +++ b/source/Bot.H @@ -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; diff --git a/source/Commands.C b/source/Commands.C index fcd2d82..ba538bb 100644 --- a/source/Commands.C +++ b/source/Commands.C @@ -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; } diff --git a/source/Parser.C b/source/Parser.C index 418fdc3..9ea7733 100644 --- a/source/Parser.C +++ b/source/Parser.C @@ -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; diff --git a/source/ScriptCommands.C b/source/ScriptCommands.C index 0bc1009..c320f7a 100644 --- a/source/ScriptCommands.C +++ b/source/ScriptCommands.C @@ -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; } diff --git a/source/UserCommands.C b/source/UserCommands.C index 2ba0cc9..199e9ef 100644 --- a/source/UserCommands.C +++ b/source/UserCommands.C @@ -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 diff --git a/source/Utils.C b/source/Utils.C index bdddb59..28530cb 100644 --- a/source/Utils.C +++ b/source/Utils.C @@ -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++) diff --git a/source/Utils.H b/source/Utils.H index a214c20..f287f29 100644 --- a/source/Utils.H +++ b/source/Utils.H @@ -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); -- 2.20.1