1 // DCCManager.H -*- C++ -*-
2 // Copyright (c) 2002,2005 Clinton Ebadi
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 #include "DCCManager.H"
21 #include "DCCConnection.H"
22 #include "DCCPerson.H"
23 #include "UserCommands.H"
27 #include "BotInterp.H"
31 DCCManager::addConnection (DCCConnection *cnx)
33 DCCPerson *person = new DCCPerson (cnx);
34 String temp = person->getAddress ();
41 dcc_map[person->getAddress ()] = person;
45 DCCManager::sendMessage (String to, String message)
47 DCCPerson *person = dcc_map[to];
51 person->sendNotice (message);
56 // checks for stale connections and removes them
58 DCCManager::checkStale ()
60 DCC_MAP::iterator it, it2;
61 DCCConnection const* temp_cnx;
63 for (it = dcc_map.begin (),it2 = dcc_map.end ();
66 temp_cnx = it->second->dcc;
67 if (temp_cnx->get_autoRemove () && std::time (0) >=
68 (std::time_t)(temp_cnx->get_lastSpoken () + Bot::DCC_DELAY))
71 DCCPerson *dp = new DCCPerson ((DCCConnection *) temp_cnx);
73 // run hooks/dcc/chat-end
74 dp->bot->botInterp->RunHooks
78 str2scm (dp->getAddress ()),
90 DCCManager::checkInput (int rd)
92 DCCManager::checkInput (fd_set rd)
96 DCC_MAP::iterator it = dcc_map.begin();
97 DCC_MAP::iterator it2;
99 while (it != dcc_map.end ())
104 if (rd & it2->second->dcc->getFileDescriptor())
106 if (FD_ISSET(it2->second->dcc->getFileDescriptor(), &rd))
109 if (it2->second->handleInput())
112 DCCPerson *dp = new DCCPerson (*it2->second);
114 // run hooks/dcc/chat-end
115 dp->bot->botInterp->RunHooks
119 str2scm (dp->getAddress ()),
124 delete it2->second->dcc;
132 DCCManager::~DCCManager ()
134 DCC_MAP::iterator it, it2;
135 it = dcc_map.begin ();
138 for (; it != it2; ++it)
140 delete it->second->dcc;