-
Notifications
You must be signed in to change notification settings - Fork 0
/
XDCC.cpp
78 lines (70 loc) · 2.34 KB
/
XDCC.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* BotChan : Scriptable IRC Bot
* Copyright (C) 2008 Alexander Roper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "XDCC.h"
#include "QIrc.h"
XDCC::XDCC( QIrc * bot, QString dest, QString filename )
{
parent_irc = bot;
server = new QTcpServer( this );
socket = 0;
if( !server->listen(QHostAddress::Any, 5990) )
{
parent_irc->warning( tr( "can't lister on port 5990" ) );
deleteLater();
return;
}
connect( server, SIGNAL( newConnection() ), this, SLOT( onConnexion() ) );
connect( server, SIGNAL( destroyed( QObject * ) ), this, SLOT( onDeletion( QObject * ) ) );
fichier = QFileInfo( filename );
parent_irc->send( dest, QString( "DCC SEND \"%1\" %2 %3 %4" ).arg( fichier.fileName() ).arg( parent_irc->ip() ).arg( 5990 ).arg( fichier.size() ) );
QTimer::singleShot( 10000, this, SLOT( onTimerTimeout() ) );
}
void XDCC::onTimerTimeout()
{
if( !socket )
{
server->close();
deleteLater();
}
}
void XDCC::onDeletion( QObject * obj )
{
parent_irc->debug( tr( "the server listening on port %1 has been deleted" ).arg( 5990 ) );
}
void XDCC::onConnexion()
{
socket = server->nextPendingConnection();
connect( socket, SIGNAL( connected() ), this, SLOT( connecte() ) );
connect( socket, SIGNAL( disconnected() ), this, SLOT( deconnecte() ) );
connect( socket, SIGNAL( error( QAbstractSocket::SocketError ) ), this, SIGNAL( onError( QAbstractSocket::SocketError ) ) );
}
void XDCC::connecte()
{
QFile f( fichier.canonicalFilePath() );
f.open( QIODevice::ReadOnly );
socket->write( f.readAll() );
parent_irc->debug( tr( "transfert beginning" ) );
}
void XDCC::deconnecte()
{
socket->deleteLater();
deleteLater();
}
void XDCC::displayError( QAbstractSocket::SocketError erreur )
{
emit onError( erreur );
}