[project @ 2002-08-08 15:21:08 by unknown_lamer]
[clinton/bobotpp.git] / source / DCCManager.C
CommitLineData
6530edbf 1// DCCManager.H -*- C++ -*-
2// Copyright (c) 2002 Clinton Ebadi
3
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
7// any later version.
8
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.
13
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17
18#include "DCCManager.H"
19
20void
21DCCManager::addConnection (DCCConnection *cnx)
22{
23 DCCPerson *person = new DCCPerson (cnx);
24 String temp = person->getAddress ();
25 if (dcc_map[temp])
26 delete dcc_map[temp];
27 dcc_map[person->getAddress ()] = person;
28}
29
30bool
31DCCManager::sendMessage (String to, String message)
32{
33 DCCPerson *person = dcc_map[to];
34 if (!person)
35 return false;
36
37 person->sendNotice (message);
38 return true;
39 return false;
40}
41
42// checks for stale connections and removes them
43void
44DCCManager::checkStale ()
45{
46 DCC_MAP::iterator it, it2;
47 DCCConnection const* temp_cnx;
48
49 for (it = dcc_map.begin (),it2 = dcc_map.end ();
50 it != it2; ++it)
51 {
52 temp_cnx = it->second->DCC ();
53 if (temp_cnx->autoRemove && std::time (0) >=
54 (std::time_t)(temp_cnx->lastSpoken + Bot::DCC_DELAY))
55 {
56 delete it->second;
57 dcc_map.erase (it);
58 }
59 }
60}
61
62void
63#ifdef _HPUX_SOURCE
64DCCManager::checkInput (int rd)
65#else
66DCCManager::checkInput (fd_set rd)
67#endif
68{
69
70 DCC_MAP::iterator it = dcc_map.begin();
71 DCC_MAP::iterator it2;
72
73 while (it != dcc_map.end ())
74 {
75 it2 = it;
76 ++it;
77#ifdef _HPUX_SOURCE
78 if (rd & it2->second->DCC()->getFileDescriptor())
79#else
80 if (FD_ISSET(it2->second->DCC()->getFileDescriptor(), &rd))
81#endif
82 {
83 if (it2->second->handleInput())
84 {
85 // I am an evil, evil person
86 delete const_cast<DCCConnection*> (it2->second->DCC());
87 delete it2->second;
88 dcc_map.erase(it2);
89 }
90 }
91 }
92}
93
94DCCManager::~DCCManager ()
95{
96 DCC_MAP::iterator it, it2;
97 it = dcc_map.begin ();
98 it2 = dcc_map.end();
99
100 for (; it != it2; ++it)
101 {
102 // I am an evil, evil person
103 delete const_cast<DCCConnection*> (it->second->DCC());
104 delete it->second;
105 }
106}