Remove String->const char* conversion operator in favor of c_str method
[clinton/bobotpp.git] / source / DCCChatConnection.C
CommitLineData
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
cfa82921 19#include "DCCChatConnection.H"
20
4edefeb6 21#include <ctime>
22#include <string>
23
4edefeb6 24#include "DCCParser.H"
cfa82921 25#include "DCCPerson.H"
4edefeb6 26#include "Person.H"
cfa82921 27#include "Socket.H"
28#include "User.H"
4edefeb6 29#include "Utils.H"
30
cfa82921 31#ifdef USESCRIPTS
32#include "BotInterp.H"
33#endif
34
35
4edefeb6 36DCCChatConnection::DCCChatConnection(Bot *b, String n, unsigned long address,
37 int port)
38 : DCCConnection(b, n, address, port)
39{ }
40
41bool
42DCCChatConnection::connect()
43{
44 if (!socket.connect())
45 return false;
46
c8f13c06 47 DCCPerson *from = new DCCPerson (this);
48
a6339323 49 if (Utils::get_level (bot, from->getAddress()) < User::FRIEND)
c8f13c06 50 {
51 from->sendNotice
52 ("\002You do not have permission to DCC CHAT the bot\002");
53 delete from;
54 return false;
55 }
56
4edefeb6 57#ifdef USESCRIPTS
58 // run hooks/dcc/chat-begin
4edefeb6 59 bot->botInterp->RunHooks (Hook::DCC_CHAT_BEGIN,
c8f13c06 60 from->getAddress (),
4edefeb6 61 scm_list_n (Utils::
a6339323 62 str2scm (from->getAddress ()),
4edefeb6 63 SCM_UNDEFINED));
4edefeb6 64#endif
65
66
c8f13c06 67 delete from;
4edefeb6 68 return true;
69}
70
71bool
72DCCChatConnection::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
89void
90DCCChatConnection::sendNotice(String message)
91{
92 socket.write(message, true);
93}