From 6530edbf15c57acffc224cdc864f0dd611d0fa3f Mon Sep 17 00:00:00 2001 From: unknown_lamer Date: Thu, 8 Aug 2002 15:21:08 +0000 Subject: [PATCH] [project @ 2002-08-08 15:21:08 by unknown_lamer] Fixed a bug in String, and added a new class, DCCManager, for managing DCC Connections (ugh, it seems a bit kludgey, but I am working on some big changes to how the bot works right now...). Probably some other changes I forgot about. --- ChangeLog | 54 ++++++++++++++++++++ NEWS | 8 +++ TODO | 16 +++--- bobot++.info | 42 ++++++++-------- source/Bot.C | 76 ++++++++++++++-------------- source/Bot.H | 3 +- source/BotInterp.H | 4 +- source/DCCConnection.C | 19 ++++++- source/DCCConnection.H | 1 + source/DCCManager.C | 106 ++++++++++++++++++++++++++++++++++++++++ source/DCCManager.H | 47 ++++++++++++++++++ source/DCCParser.C | 17 ++++++- source/DCCPerson.C | 6 +++ source/DCCPerson.H | 6 ++- source/Interp.C | 8 ++- source/Makefile.am | 2 + source/Makefile.in | 33 +++++++------ source/ScriptCommands.C | 3 +- source/ScriptCommands.H | 1 - source/String.C | 8 ++- source/UserCommands.C | 11 +++-- 21 files changed, 370 insertions(+), 101 deletions(-) create mode 100644 source/DCCManager.C create mode 100644 source/DCCManager.H diff --git a/ChangeLog b/ChangeLog index cbd5a0e..e78405d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,57 @@ +2002-08-08 Clinton Ebadi + + * source/String.C (String): The std::string copy constructor now + extracts the c_str of the std::string and then takes the strlen of + that before copying it. This fixes a bug with DCC where if you did + e.g. "!help" the bot would reply with "No TOPIC PRIVMSG FOUND" or + something like that, depending on what the last message was + because Socket will insert a \0 into its semi-static buffer, so + the len of the String will not equal the strlen of its char*. + +2002-08-07 Clinton Ebadi + + * source/DCCPerson.H: Removed destructor (I = idiot) + + * source/DCCConnection.H: DCCManager is now a friend of + DCCConnection (ugh, the bot has way too many friends). + + * source/DCCPerson.H: Added DCC member that returns a const + DCCConnection* (the dcc connection). This isn't saved anywhere + because when a DCCPerson is destroyed, its connection is also + destroyed. + + * source/Bot.H: dccConnections is now a DCCManager + + * source/DCCPerson.H: Added destructor + Added handleInput method + + * source/DCCManager.C: New file + (addConnection): Wrote method, add a DCCConection to the manager + + * source/DCCManager.H: New file + + * source/Interp.C (Startup): Register bot:DCC-chat-send + (Startup): Removed sendDCCChatMessage stuff + + * source/ScriptCommands.C (sendDCCChatMessage): New method: + sendDCCChatMessage (to, message) sends message to to. + + * source/DCCConnection.C (connect): Run DCC_CHAT_BEGIN hook with + one arg: from (user!nick@host). + + * source/DCCParser.C (parseLine): Runs DCC_CHAT_MESSAGE hook with + two args: from (user!nick@host) and line + +2002-08-06 Clinton Ebadi + + * source/Interp.C (Startup): Two new Scheme values: + hooks/dcc/chat-begin and hooks/dcc/chat-message for the + DCC_CHAT_BEGIN and DCC_CHAT_MESSAGE hooks. + + * source/BotInterp.H: Added two new enum values to Hook: + DCC_CHAT_BEGIN and DCC_CHAT_MESSAGE for the DCC chat start and DCC + chat message hooks + 2002-08-05 Clinton Ebadi * source/Parser.C (parseCTCP): Removed call to htonl and fixed diff --git a/NEWS b/NEWS index dc46be3..8743d91 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,14 @@ Version 2.1.1: foom ACTION, sends a CTCP (_not_ a ctcp-reply), sends a PRIVMSG to a channel, or sends a PRIVMSG to another user, respectively. There will be more send hooks added later. +- New hooks: hooks/dcc/chat-begin and + hooks/dcc/chat-message. chat-begin is called when the chat starts + and has one argument: the address (in user!nick@host + format). chat-message has two arguments: from (user!nick@host) and + message, which is the raw message (since there is no real protocol + for DCC). chat-start hooks are matched against the address and + chat-message hooks are matched against the text "ADDRESS MESSAGE" + where ADDRESS is the sender's address and MESSAGE is the message. Version 2.1.0: Zug Zug - Hooks can now be fallthrough or non fallthrough. You can set a hooks diff --git a/TODO b/TODO index 9872758..03c8fe3 100644 --- a/TODO +++ b/TODO @@ -9,21 +9,19 @@ General: changed the log file doesn't change after the Bot is started). Scripting: -* Make bot:random use the Guile RNG instead of C RNG (better?) - - definition would be (define (bot:random) (random BIG_NUMBER)) - - Just use max-fixnum from the test scripts for BIG_NUMBER * Add commands to delete a hook - - return an iterator to the hook and let the user kill it? + - return an iterator to the Hook - this would require a new SMOB to be created + - Scheme could pass Hook objects around and do nifty things * Add Scheme utils function to convert "normal" dates into time since 1970. * Finish adding commands to Scheme for sending messages (e.g. bot:send-CTCP to send a CTCP message) * Add util functions for doing stuff like quoting CTCP messages -* Make it possible to use Scheme functions in the Parser itself +* Finish adding hooks/send hooks Networking: -* Add hooks for DCC CHAT? +* Add functions to talk to DCC chatters * Add a networked interface to guile repl - Admins only - Telnet @@ -32,10 +30,12 @@ Networking: - MUST HAVE PASSWORD * Make connecting to irc.oftc.net work...I wonder if their ircd is broken -* DCC FILE support +* DCC FILE support (this can be done as a script) Documentation: * Work on Texinfo manual (especially scripting section) Other (post 2.2 release): -* Remove gh_* when Guile 1.8 is released \ No newline at end of file +* Remove gh_* when Guile 1.8 is released +* Make it possible to use Scheme functions in the Parser itself +* Complete rewrite ;-) \ No newline at end of file diff --git a/bobot++.info b/bobot++.info index eec3c07..a9712c3 100644 --- a/bobot++.info +++ b/bobot++.info @@ -177,17 +177,17 @@ Hooks ===== Hooks are a powerful feature of Bobot++. Hooks are a hybrid of ircII -hooks and tiny fugue (a MUD bot) hooks. The basic idea of a hook if -that you match a text against regular expression and call a function if -text in a message matches that regex. The different types of hooks -provided by Bobot++ correspond to the different classes of messages -that Bobot++ can recieve. A Hook also has several properties, including -its priority and whether or not it is a fallthrough hook. Higher -priority hooks are executed before lower priority hooks and fallthrough -hooks are executed before non-fallthrough hooks of the same priority. A -fallthrough hook can match and processing of hooks will continue; as -soon as the first non-fallthrough hooks matches processing of hooks -stops. +and tiny fugue (a MUD bot) hooks with a little bit of extra stuff added +in. The basic idea of a hook if that you match a text against regular +expression and call a function if text in a message matches that regex. +The different types of hooks provided by Bobot++ correspond to the +different classes of messages that Bobot++ can recieve. A Hook also has +several properties, including its priority and whether or not it is a +fallthrough hook. Higher priority hooks are executed before lower +priority hooks and fallthrough hooks are executed before +non-fallthrough hooks of the same priority. A fallthrough hook can +match and processing of hooks will continue; as soon as the first +non-fallthrough hooks matches processing of hooks stops. * Menu: @@ -511,15 +511,15 @@ Node: User Levels2673 Node: Scripting3677 Node: Adding New Commands4585 Node: Hooks5852 -Node: Creating a Hook6790 -Node: Hook Types7929 -Node: Scheme User Levels10869 -Node: Sending Messages11998 -Node: High Level Message Functions12595 -Node: Low Level Message Functions12809 -Node: Misc Scripting Stuff13562 -Node: Concept Index13981 -Node: Function Index14163 -Node: Variable Index14424 +Node: Creating a Hook6826 +Node: Hook Types7965 +Node: Scheme User Levels10905 +Node: Sending Messages12034 +Node: High Level Message Functions12631 +Node: Low Level Message Functions12845 +Node: Misc Scripting Stuff13598 +Node: Concept Index14017 +Node: Function Index14199 +Node: Variable Index14460  End Tag Table diff --git a/source/Bot.C b/source/Bot.C index bbddcd3..45e5c6e 100644 --- a/source/Bot.C +++ b/source/Bot.C @@ -32,6 +32,7 @@ #include "ServerConnection.H" #include "Utils.H" #include "UserCommands.H" +#include "DCCManager.H" #define DEFAULT_NICKNAME "Bobot" #define DEFAULT_USERNAME "bobot" @@ -93,6 +94,7 @@ Bot::Bot(String filename, bool debug_on) userList = new UserList(userListFileName); shitList = new ShitList(shitListFileName); todoList = new TodoList(); + dccConnections = new DCCManager (); // Let's read the alias file std::ifstream initFile(initFileName); @@ -142,13 +144,7 @@ Bot::~Bot() spyList.erase(spyList.begin()); delete p; } - DCCConnection *d; - while (dccConnections.size() != 0) { - d = *dccConnections.begin(); - dccConnections.erase(dccConnections.begin()); - delete d; - } - + delete dccConnections; destroy_user_functions (); wantedChannel *w; @@ -298,6 +294,7 @@ Bot::run() while (!stop) { waitForInput(); // This is the main event loop + dccConnections->checkStale (); if (!serverConnection->queue->flush()) nextServer(); } @@ -323,9 +320,10 @@ Bot::waitForInput() FD_SET(sock, &rd); #endif - for (std::list::iterator it = dccConnections.begin(); - it != dccConnections.end(); ++it) { - int s = (*it)->getFileDescriptor(); + DCC_MAP* dccmap = dccConnections->MAP (); + for (DCC_MAP::iterator it = dccmap->begin (); + it != dccmap->end(); ++it) { + int s = it->second->DCC()->getFileDescriptor(); #ifdef _HPUX_SOURCE rd |= s; #else @@ -352,23 +350,25 @@ Bot::waitForInput() if (serverConnection->handleInput()) nextServer(); - std::list::iterator it = dccConnections.begin(); - std::list::iterator it2; - - while (it != dccConnections.end()) { - it2 = it; - ++it; -#ifdef _HPUX_SOURCE - if (rd & (*it2)->getFileDescriptor()) { -#else - if (FD_ISSET((*it2)->getFileDescriptor(), &rd)) { -#endif - if ((*it2)->handleInput()) { - delete *it2; - dccConnections.erase(it2); - } - } - } +// std::list::iterator it = dccConnections.begin(); +// std::list::iterator it2; + +// while (it != dccConnections.end()) { +// it2 = it; +// ++it; +// #ifdef _HPUX_SOURCE +// if (rd & (*it2)->getFileDescriptor()) { +// #else +// if (FD_ISSET((*it2)->getFileDescriptor(), &rd)) { +// #endif +// if ((*it2)->handleInput()) { +// delete *it2; +// dccConnections.erase(it2); +// } +// } +// } +// } + dccConnections->checkInput (rd); } if (currentTime < std::time(NULL)) { // Actions that we do each second @@ -414,17 +414,17 @@ Bot::waitForInput() serverConnection->queue->sendJoin((*it).first, (*it).second->key); } - std::list::iterator it2; +// std::list::iterator it2; - for (std::list::iterator it = dccConnections.begin(); - it != dccConnections.end(); ) { - it2 = it; - ++it; - if ((*it2)->autoRemove && currentTime >= (std::time_t)((*it2)->lastSpoken + Bot::DCC_DELAY)) { - delete *it2; - dccConnections.erase(it2); - } - } +// for (std::list::iterator it = dccConnections.begin(); +// it != dccConnections.end(); ) { +// it2 = it; +// ++it; +// if ((*it2)->autoRemove && currentTime >= (std::time_t)((*it2)->lastSpoken + Bot::DCC_DELAY)) { +// delete *it2; +// dccConnections.erase(it2); +// } +// } if (currentTime >= (std::time_t)(serverConnection->serverLastSpoken + Bot::PING_TIME) && !sentPing) { serverConnection->queue->sendPing("Testing connection"); @@ -531,7 +531,7 @@ Bot::addDCC(Person * from, unsigned long address, int port) return; } logLine ("DCC CHAT accepted from" + from->getAddress ()); - dccConnections.push_back(d); + dccConnections->addConnection (d); } void diff --git a/source/Bot.H b/source/Bot.H index 7234817..27bc225 100644 --- a/source/Bot.H +++ b/source/Bot.H @@ -53,6 +53,7 @@ class Channel; class DCCConnection; class Parser; class DCCParser; +class DCCManager; class ServerConnection; class Commands; class UserCommands; @@ -99,7 +100,7 @@ public: std::time_t startTime, currentTime, lastNickNameChange, lastChannelJoin; ServerConnection * serverConnection; - std::list dccConnections; + DCCManager* dccConnections; std::map > userhostMap; unsigned long sentUserhostID; diff --git a/source/BotInterp.H b/source/BotInterp.H index ff01019..ce0ecc7 100644 --- a/source/BotInterp.H +++ b/source/BotInterp.H @@ -65,7 +65,9 @@ struct Hook { MODE, MESSAGE, NAMES, NOTICE, PUBLIC, PUBLIC_NOTICE, RAW, TIMER, TOPIC, // send hooks - SEND_ACTION, SEND_CTCP, SEND_PUBLIC, SEND_MESSAGE + SEND_ACTION, SEND_CTCP, SEND_PUBLIC, SEND_MESSAGE, + // DCC hooks + DCC_CHAT_BEGIN, DCC_CHAT_MESSAGE }; }; diff --git a/source/DCCConnection.C b/source/DCCConnection.C index a708aaf..d5cd487 100644 --- a/source/DCCConnection.C +++ b/source/DCCConnection.C @@ -17,10 +17,14 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. #include +#include #include "Socket.H" #include "DCCParser.H" #include "DCCConnection.H" +#include "Person.H" +#include "BotInterp.H" +#include "Utils.H" DCCConnection::DCCConnection(Bot *b, String n, unsigned long address, int port) @@ -33,13 +37,26 @@ DCCConnection::connect() { if (!socket.connect()) return false; + +#ifdef USESCRIPTS + // run hooks/dcc/chat-begin + DCCPerson *tmp = new DCCPerson (this); + bot->botInterp->RunHooks (Hook::DCC_CHAT_BEGIN, + tmp->getAddress (), + scm_list_n (Utils:: + string2SCM (tmp->getAddress ()), + SCM_UNDEFINED)); + delete tmp; +#endif + + return true; } bool DCCConnection::handleInput() { - String line = socket.readLine(); + std::string line = socket.readLine(); lastSpoken = time(0); diff --git a/source/DCCConnection.H b/source/DCCConnection.H index b869e37..31c9e15 100644 --- a/source/DCCConnection.H +++ b/source/DCCConnection.H @@ -46,6 +46,7 @@ public: friend class DCCPerson; friend class DCCParser; friend class UserCommands; + friend class DCCManager; }; #endif diff --git a/source/DCCManager.C b/source/DCCManager.C new file mode 100644 index 0000000..4c89b36 --- /dev/null +++ b/source/DCCManager.C @@ -0,0 +1,106 @@ +// DCCManager.H -*- C++ -*- +// Copyright (c) 2002 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 +// the Free Software Foundation; either version 2 of the License, or +// any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// 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. + +#include "DCCManager.H" + +void +DCCManager::addConnection (DCCConnection *cnx) +{ + DCCPerson *person = new DCCPerson (cnx); + String temp = person->getAddress (); + if (dcc_map[temp]) + delete dcc_map[temp]; + dcc_map[person->getAddress ()] = person; +} + +bool +DCCManager::sendMessage (String to, String message) +{ + DCCPerson *person = dcc_map[to]; + if (!person) + return false; + + person->sendNotice (message); + return true; + return false; +} + +// checks for stale connections and removes them +void +DCCManager::checkStale () +{ + DCC_MAP::iterator it, it2; + DCCConnection const* temp_cnx; + + for (it = dcc_map.begin (),it2 = dcc_map.end (); + it != it2; ++it) + { + temp_cnx = it->second->DCC (); + if (temp_cnx->autoRemove && std::time (0) >= + (std::time_t)(temp_cnx->lastSpoken + Bot::DCC_DELAY)) + { + delete it->second; + dcc_map.erase (it); + } + } +} + +void +#ifdef _HPUX_SOURCE +DCCManager::checkInput (int rd) +#else +DCCManager::checkInput (fd_set rd) +#endif +{ + + DCC_MAP::iterator it = dcc_map.begin(); + DCC_MAP::iterator it2; + + while (it != dcc_map.end ()) + { + it2 = it; + ++it; +#ifdef _HPUX_SOURCE + if (rd & it2->second->DCC()->getFileDescriptor()) +#else + if (FD_ISSET(it2->second->DCC()->getFileDescriptor(), &rd)) +#endif + { + if (it2->second->handleInput()) + { + // I am an evil, evil person + delete const_cast (it2->second->DCC()); + delete it2->second; + dcc_map.erase(it2); + } + } + } +} + +DCCManager::~DCCManager () +{ + DCC_MAP::iterator it, it2; + it = dcc_map.begin (); + it2 = dcc_map.end(); + + for (; it != it2; ++it) + { + // I am an evil, evil person + delete const_cast (it->second->DCC()); + delete it->second; + } +} diff --git a/source/DCCManager.H b/source/DCCManager.H new file mode 100644 index 0000000..c17f5e3 --- /dev/null +++ b/source/DCCManager.H @@ -0,0 +1,47 @@ +// DCCManager.H -*- C++ -*- +// Copyright (c) 2002 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 +// the Free Software Foundation; either version 2 of the License, or +// any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// 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. + +#ifndef DCC_MANAGER_H +#define DCC_MANAGER_H + +#include +#include +#include "DCCPerson.H" +#include "DCCConnection.H" +#include "String.H" + +typedef std::map > DCC_MAP; + +// Manages all active DCC connections and allows you to send a message +// to each one using the string representation of the user's address +class DCCManager +{ + DCC_MAP dcc_map; +public: + void addConnection (DCCConnection*); + bool sendMessage (String, String); + void checkStale (); +#ifdef _HPUX_SOURCE + void checkInput (int); +#else + void checkInput (fd_set); +#endif + DCC_MAP* MAP () { return &dcc_map; }; + ~DCCManager (); +}; + +#endif diff --git a/source/DCCParser.C b/source/DCCParser.C index 6604197..b34d857 100644 --- a/source/DCCParser.C +++ b/source/DCCParser.C @@ -16,16 +16,29 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "DCCParser.H" #include "DCCPerson.H" -#include "Macros.H" #include "Parser.H" -#include "Bot.H" +#include "BotInterp.H" +#include "Utils.H" void DCCParser::parseLine(DCCConnection *cnx, String line) { Person * from = new DCCPerson(cnx); +#ifdef USESCRIPTS + // Call hooks/dcc/chat-message hook functions + cnx->bot->botInterp->RunHooks (Hook::DCC_CHAT_MESSAGE, + from->getAddress () + " " + line, + scm_list_n (Utils:: + string2SCM (from->getAddress ()), + Utils::string2SCM (line), + SCM_UNDEFINED)); +#endif Parser::parseMessage(cnx->bot->serverConnection, from, cnx->bot->nickName, line); delete from; diff --git a/source/DCCPerson.C b/source/DCCPerson.C index b41bae9..24227f1 100644 --- a/source/DCCPerson.C +++ b/source/DCCPerson.C @@ -43,3 +43,9 @@ DCCPerson::keepAlive() { dcc->autoRemove = false; } + +bool +DCCPerson::handleInput () +{ + return dcc->handleInput (); +} diff --git a/source/DCCPerson.H b/source/DCCPerson.H index 55d00c0..1f7348c 100644 --- a/source/DCCPerson.H +++ b/source/DCCPerson.H @@ -30,10 +30,12 @@ public: Person * copy(); - String getNick() const; - String getAddress() const; + // String getNick() const; + // String getAddress() const; void keepAlive(); + bool handleInput (); + const DCCConnection* DCC () const { return dcc; }; void sendNotice(String); }; diff --git a/source/Interp.C b/source/Interp.C index 3ea9947..1e542af 100644 --- a/source/Interp.C +++ b/source/Interp.C @@ -78,18 +78,22 @@ Interp::Startup() scm_c_define ("hooks/part", scm_long2num(Hook::LEAVE)); scm_c_define ("hooks/mode", scm_long2num(Hook::MODE)); scm_c_define ("hooks/message", scm_long2num(Hook::MESSAGE)); - // scm_c_define ("hooks/names", scm_long2num(Hook::NAMES)); scm_c_define ("hooks/notice", scm_long2num(Hook::NOTICE)); scm_c_define ("hooks/public", scm_long2num(Hook::PUBLIC)); scm_c_define ("hooks/public-notice", scm_long2num(Hook::PUBLIC_NOTICE)); scm_c_define ("hooks/raw", scm_long2num(Hook::RAW)); scm_c_define ("hooks/timer", scm_long2num(Hook::TIMER)); scm_c_define ("hooks/topic", scm_long2num(Hook::TOPIC)); + // send hooks scm_c_define ("hooks/send/public", scm_long2num (Hook::SEND_PUBLIC)); scm_c_define ("hooks/send/message", scm_long2num (Hook::SEND_MESSAGE)); scm_c_define ("hooks/send/action", scm_long2num (Hook::SEND_ACTION)); scm_c_define ("hooks/send/ctcp", scm_long2num (Hook::SEND_CTCP)); - + // dcc hooks + scm_c_define ("hooks/dcc/chat-begin", + scm_long2num (Hook::DCC_CHAT_BEGIN)); + scm_c_define ("hooks/dcc/chat-message", + scm_long2num (Hook::DCC_CHAT_MESSAGE)); // procedures bot_new_procedure ("bot:action", (SCMFunc)ScriptCommands::Action, 2, 0, 0); diff --git a/source/Makefile.am b/source/Makefile.am index 5b59448..97f458a 100644 --- a/source/Makefile.am +++ b/source/Makefile.am @@ -8,6 +8,8 @@ bobotpp_SOURCES = BanEntry.C \ Commands.C \ Connection.C \ DCCConnection.C \ + DCCManager.H \ + DCCManager.C \ DCCParser.C \ DCCPerson.C \ Interp.C \ diff --git a/source/Makefile.in b/source/Makefile.in index a467687..a4e2861 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -84,6 +84,8 @@ bobotpp_SOURCES = BanEntry.C \ Commands.C \ Connection.C \ DCCConnection.C \ + DCCManager.H \ + DCCManager.C \ DCCParser.C \ DCCPerson.C \ Interp.C \ @@ -157,15 +159,15 @@ PROGRAMS = $(bin_PROGRAMS) am_bobotpp_OBJECTS = BanEntry.$(OBJEXT) Bot.$(OBJEXT) \ BotInterp.$(OBJEXT) Channel.$(OBJEXT) ChannelList.$(OBJEXT) \ Commands.$(OBJEXT) Connection.$(OBJEXT) DCCConnection.$(OBJEXT) \ - DCCParser.$(OBJEXT) DCCPerson.$(OBJEXT) Interp.$(OBJEXT) \ - Main.$(OBJEXT) Mask.$(OBJEXT) Parser.$(OBJEXT) Person.$(OBJEXT) \ - Queue.$(OBJEXT) ScriptCommands.$(OBJEXT) Server.$(OBJEXT) \ - ServerConnection.$(OBJEXT) ServerList.$(OBJEXT) \ - ServerQueue.$(OBJEXT) ServerQueueItem.$(OBJEXT) \ - ShitEntry.$(OBJEXT) ShitList.$(OBJEXT) Socket.$(OBJEXT) \ - String.$(OBJEXT) StringTokenizer.$(OBJEXT) TodoList.$(OBJEXT) \ - User.$(OBJEXT) UserCommands.$(OBJEXT) UserList.$(OBJEXT) \ - Utils.$(OBJEXT) + DCCManager.$(OBJEXT) DCCParser.$(OBJEXT) DCCPerson.$(OBJEXT) \ + Interp.$(OBJEXT) Main.$(OBJEXT) Mask.$(OBJEXT) Parser.$(OBJEXT) \ + Person.$(OBJEXT) Queue.$(OBJEXT) ScriptCommands.$(OBJEXT) \ + Server.$(OBJEXT) ServerConnection.$(OBJEXT) \ + ServerList.$(OBJEXT) ServerQueue.$(OBJEXT) \ + ServerQueueItem.$(OBJEXT) ShitEntry.$(OBJEXT) \ + ShitList.$(OBJEXT) Socket.$(OBJEXT) String.$(OBJEXT) \ + StringTokenizer.$(OBJEXT) TodoList.$(OBJEXT) User.$(OBJEXT) \ + UserCommands.$(OBJEXT) UserList.$(OBJEXT) Utils.$(OBJEXT) bobotpp_OBJECTS = $(am_bobotpp_OBJECTS) bobotpp_DEPENDENCIES = bobotpp_LDFLAGS = @@ -180,12 +182,12 @@ depcomp = $(SHELL) $(top_srcdir)/depcomp @AMDEP_TRUE@ $(DEPDIR)/BotInterp.Po $(DEPDIR)/Channel.Po \ @AMDEP_TRUE@ $(DEPDIR)/ChannelList.Po $(DEPDIR)/Commands.Po \ @AMDEP_TRUE@ $(DEPDIR)/Connection.Po $(DEPDIR)/DCCConnection.Po \ -@AMDEP_TRUE@ $(DEPDIR)/DCCParser.Po $(DEPDIR)/DCCPerson.Po \ -@AMDEP_TRUE@ $(DEPDIR)/Interp.Po $(DEPDIR)/Main.Po \ -@AMDEP_TRUE@ $(DEPDIR)/Mask.Po $(DEPDIR)/Parser.Po \ -@AMDEP_TRUE@ $(DEPDIR)/Person.Po $(DEPDIR)/Queue.Po \ -@AMDEP_TRUE@ $(DEPDIR)/ScriptCommands.Po $(DEPDIR)/Server.Po \ -@AMDEP_TRUE@ $(DEPDIR)/ServerConnection.Po \ +@AMDEP_TRUE@ $(DEPDIR)/DCCManager.Po $(DEPDIR)/DCCParser.Po \ +@AMDEP_TRUE@ $(DEPDIR)/DCCPerson.Po $(DEPDIR)/Interp.Po \ +@AMDEP_TRUE@ $(DEPDIR)/Main.Po $(DEPDIR)/Mask.Po \ +@AMDEP_TRUE@ $(DEPDIR)/Parser.Po $(DEPDIR)/Person.Po \ +@AMDEP_TRUE@ $(DEPDIR)/Queue.Po $(DEPDIR)/ScriptCommands.Po \ +@AMDEP_TRUE@ $(DEPDIR)/Server.Po $(DEPDIR)/ServerConnection.Po \ @AMDEP_TRUE@ $(DEPDIR)/ServerList.Po $(DEPDIR)/ServerQueue.Po \ @AMDEP_TRUE@ $(DEPDIR)/ServerQueueItem.Po $(DEPDIR)/ShitEntry.Po \ @AMDEP_TRUE@ $(DEPDIR)/ShitList.Po $(DEPDIR)/Socket.Po \ @@ -260,6 +262,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/Commands.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/Connection.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/DCCConnection.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/DCCManager.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/DCCParser.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/DCCPerson.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/Interp.Po@am__quote@ diff --git a/source/ScriptCommands.C b/source/ScriptCommands.C index bb43426..266c969 100644 --- a/source/ScriptCommands.C +++ b/source/ScriptCommands.C @@ -28,6 +28,7 @@ #include "ServerQueue.H" #include "ScriptCommands.H" #include "Interp.H" +#include "DCCPerson.H" #include #define VERIFY_STRING(par) if (!SCM_STRINGP((par))) \ @@ -601,6 +602,4 @@ ScriptCommands::sendCTCP(SCM to, SCM command , SCM message) Utils::scm2String (message)); return SCM_UNSPECIFIED; } - - #endif diff --git a/source/ScriptCommands.H b/source/ScriptCommands.H index f24b193..d192182 100644 --- a/source/ScriptCommands.H +++ b/source/ScriptCommands.H @@ -102,7 +102,6 @@ public: SCM sendWho(SCM); SCM sendWhois(SCM); */ - }; #endif diff --git a/source/String.C b/source/String.C index d208288..d257111 100644 --- a/source/String.C +++ b/source/String.C @@ -39,9 +39,13 @@ String::String(const char *s) String::String(const std::string & s) { p = new srep; - len = s.length (); + // We do this instead of just s.length () because there might be a + // \0 in the string before the end (e.g. this is a message from the + // Socket's buffer). + const char* temp_str = s.c_str (); + len = strlen (temp_str); p->s = new char[len + 1]; - std::strcpy (p->s, s.c_str ()); + std::strcpy (p->s, temp_str); } String::String(const String & s) diff --git a/source/UserCommands.C b/source/UserCommands.C index abb5b38..e9ac592 100644 --- a/source/UserCommands.C +++ b/source/UserCommands.C @@ -42,6 +42,7 @@ #include "Commands.H" #include "UserCommands.H" #include "DCCConnection.H" +#include "DCCManager.H" #include "Parser.H" #include "Macros.H" #include "StringTokenizer.H" @@ -404,13 +405,13 @@ UserCommands::DCCList(ServerConnection *cnx, Person *from, from->sendNotice("\002DCClist:\002"); from->sendNotice("\002Hostname Last used\002"); - for (std::list::iterator it = - cnx->bot->dccConnections.begin(); - it != cnx->bot->dccConnections.end(); + for (DCC_MAP::iterator it = + cnx->bot->dccConnections->MAP()->begin (); + it != cnx->bot->dccConnections->MAP()->end(); ++it) { - from->sendNotice((*it)->nuh.pad(32) + " " + + from->sendNotice(String(it->second->DCC()->nuh).pad(32) + " " + String((long)(current_time - - (*it)->lastSpoken))); + it->second->DCC()->lastSpoken))); } from->sendNotice("\002End of dcclist.\002"); -- 2.20.1