Exemple #1
0
MultipleBotConnection::CatchChallengerClient * MultipleBotConnection::createClient()
{
    if(haveEnError)
    {
        connectTimer.stop();
        return NULL;
    }
    CatchChallengerClient * client=new CatchChallengerClient;

    QSslSocket *sslSocket=new QSslSocket();

    QNetworkProxy proxyObject;
    if(!proxy().isEmpty())
    {
        proxyObject.setType(QNetworkProxy::Socks5Proxy);
        proxyObject.setHostName(proxy());
        proxyObject.setPort(proxyport());
        sslSocket->setProxy(proxyObject);
    }

    client->sslSocket=sslSocket;
    sslSocketToCatchChallengerClient[client->sslSocket]=client;
    client->socket=new CatchChallenger::ConnectedSocket(client->sslSocket);
    client->api=new CatchChallenger::Api_client_real(client->socket,false);

    if(!connect(sslSocket,static_cast<void(QSslSocket::*)(const QList<QSslError> &errors)>(&QSslSocket::sslErrors),this,&MultipleBotConnection::sslErrors,Qt::QueuedConnection))
        abort();
    if(!connect(sslSocket,static_cast<void(QSslSocket::*)(QAbstractSocket::SocketError)>(&QSslSocket::error),this,&MultipleBotConnection::newSocketError))
        abort();
    sslSocket->connectToHost(host(),port());
    connectTheExternalSocket(client);
    return client;
}
void MainWindow::readForFirstHeader()
{
    if(haveFirstHeader)
        return;
    if(realSslSocket==NULL)
        return;
    QSslSocket *socket=qobject_cast<QSslSocket *>(sender());
    if(socket==NULL)
        return;
    quint8 value;
    if(socket->read((char*)&value,sizeof(value))==sizeof(value))
    {
        haveFirstHeader=true;
        if(value==0x01)
        {
            socket->setPeerVerifyMode(QSslSocket::VerifyNone);
            socket->ignoreSslErrors();
            socket->startClientEncryption();
            connect(socket,&QSslSocket::encrypted,this,&MainWindow::sslHandcheckIsFinished);
        }
        else
            connectTheExternalSocket();
    }
}
void MainWindow::sslHandcheckIsFinished()
{
    connectTheExternalSocket();
}