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