[project @ 2004-06-13 02:04:44 by unknown_lamer]
[clinton/bobotpp.git] / source / DCCChatConnection.C
CommitLineData
4edefeb6 1// DCCConnection.C -*- C++ -*-
2// Copyright (c) 1998 Etienne BERNARD
3// Copyright (C) 2002 Clinton Ebadi
4
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation; either version 2 of the License, or
8// any later version.
9
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18
19#include <ctime>
20#include <string>
21
22#include "Socket.H"
23#include "DCCParser.H"
24#include "DCCChatConnection.H"
25#include "Person.H"
26#include "BotInterp.H"
27#include "Utils.H"
28
29DCCChatConnection::DCCChatConnection(Bot *b, String n, unsigned long address,
30 int port)
31 : DCCConnection(b, n, address, port)
32{ }
33
34bool
35DCCChatConnection::connect()
36{
37 if (!socket.connect())
38 return false;
39
40#ifdef USESCRIPTS
41 // run hooks/dcc/chat-begin
42 DCCPerson *tmp = new DCCPerson (this);
43 bot->botInterp->RunHooks (Hook::DCC_CHAT_BEGIN,
44 tmp->getAddress (),
45 scm_list_n (Utils::
46 string2SCM (tmp->getAddress ()),
47 SCM_UNDEFINED));
48 delete tmp;
49#endif
50
51
52 return true;
53}
54
55bool
56DCCChatConnection::handleInput()
57{
58 std::string line = socket.readLine();
59
60 lastSpoken = time(0);
61
62 if (line.length() == 0)
63 return true;
64
65 if (bot->debug)
66 std::cout << "DCC: <" << line << ">" << std::endl;
67
68 DCCParser::parseLine(this, line);
69
70 return false;
71}
72
73void
74DCCChatConnection::sendNotice(String message)
75{
76 socket.write(message, true);
77}