4edefeb6 |
1 | // DCCConnection.C -*- C++ -*- |
2 | // Copyright (c) 1998 Etienne BERNARD |
a6339323 |
3 | // Copyright (C) 2002,2005 Clinton Ebadi |
4edefeb6 |
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 |
39b022cb |
17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
4edefeb6 |
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 | |
29 | DCCChatConnection::DCCChatConnection(Bot *b, String n, unsigned long address, |
30 | int port) |
31 | : DCCConnection(b, n, address, port) |
32 | { } |
33 | |
34 | bool |
35 | DCCChatConnection::connect() |
36 | { |
37 | if (!socket.connect()) |
38 | return false; |
39 | |
c8f13c06 |
40 | DCCPerson *from = new DCCPerson (this); |
41 | |
a6339323 |
42 | if (Utils::get_level (bot, from->getAddress()) < User::FRIEND) |
c8f13c06 |
43 | { |
44 | from->sendNotice |
45 | ("\002You do not have permission to DCC CHAT the bot\002"); |
46 | delete from; |
47 | return false; |
48 | } |
49 | |
4edefeb6 |
50 | #ifdef USESCRIPTS |
51 | // run hooks/dcc/chat-begin |
4edefeb6 |
52 | bot->botInterp->RunHooks (Hook::DCC_CHAT_BEGIN, |
c8f13c06 |
53 | from->getAddress (), |
4edefeb6 |
54 | scm_list_n (Utils:: |
a6339323 |
55 | str2scm (from->getAddress ()), |
4edefeb6 |
56 | SCM_UNDEFINED)); |
4edefeb6 |
57 | #endif |
58 | |
59 | |
c8f13c06 |
60 | delete from; |
4edefeb6 |
61 | return true; |
62 | } |
63 | |
64 | bool |
65 | DCCChatConnection::handleInput() |
66 | { |
67 | std::string line = socket.readLine(); |
68 | |
69 | lastSpoken = time(0); |
70 | |
71 | if (line.length() == 0) |
72 | return true; |
73 | |
74 | if (bot->debug) |
75 | std::cout << "DCC: <" << line << ">" << std::endl; |
76 | |
77 | DCCParser::parseLine(this, line); |
78 | |
79 | return false; |
80 | } |
81 | |
82 | void |
83 | DCCChatConnection::sendNotice(String message) |
84 | { |
85 | socket.write(message, true); |
86 | } |