Esempio n. 1
0
void Client::newConnection(Connection *connection)
{
    connection->setGreetingMessage(peerManager->userName());

    connect(connection, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(connectionError(QAbstractSocket::SocketError)));
    connect(connection, SIGNAL(disconnected()), this, SLOT(disconnected()));
    connect(connection, SIGNAL(readyForUse()), this, SLOT(readyForUse()));
}
Esempio n. 2
0
void TTCP::newConnection(Connection *connection)
{

    QObject::connect(connection, SIGNAL(disconnected()), this, SIGNAL(disconnected()));
    QObject::connect(connection, SIGNAL(disconnected()), this, SLOT(notReadyForUse()));
//    QObject::connect(connection, SIGNAL(readyForUse()), this, SIGNAL(connected()));
    QObject::connect(connection, SIGNAL(readyForUse()), this, SLOT(readyForUse()));
    QObject::connect(connection, SIGNAL(newCommand(QStringList)), this, SLOT(newCommand(QStringList)));
    QObject::connect(connection, SIGNAL(connected()), this, SLOT(setConnected()));
}
Esempio n. 3
0
void Connection::processReadyRead()
{
    if (state == WaitingForGreeting)
    {
        if (!readProtocolHeader())
            return;
        if (currentDataType != Greeting)
        {
            abort();
            return;
        }
        state = ReadingGreeting;
    }

    if (state == ReadingGreeting)
    {
        if (!hasEnoughData())
            return;

        buffer = read(numBytesForCurrentDataType);
        if (buffer.size() != numBytesForCurrentDataType)
        {
            abort();
            return;
        }

        username = QString(buffer) + '@' + peerAddress().toString() + ':' + QString::number(peerPort());
        currentDataType = Undefined;
        numBytesForCurrentDataType = 0;
        buffer.clear();

        if (!isValid())
        {
            abort();
            return;
        }

        if (!isGreetingMessageSent)
            sendGreetingMessage();

        pingTimer.start();
        pongTime.start();
        state = ReadyForUse;
        emit readyForUse();
    }

    do
    {
        if (currentDataType == Undefined)
        {
            if (!readProtocolHeader())
            return;
        }
        if (!hasEnoughData())
            return;
        processData();
    } while (bytesAvailable() > 0);
}
Esempio n. 4
0
void ClientOpt::recvMessageData(MessageData data)
{
    mData->type = data.datatype();
    switch (mData->type) {
    case Ping:
    {
        qDebug() << cns("recv ping");
        MessageData msg;
        MessagePong *pong = new MessagePong();
        msg.setDatatype(pong->datatype());
        msg.setContent(pong);
        NetworkData data;
        msg.toStream(data);
        emit sendMessage(data);
        qDebug() << cns("send pong");
    }
        break;
    case Pong:
        qDebug() << cns("recv pong");
        break;
    case Greeting:
    {
        mData->state = ReadyForUse;
        MessageGreeting *greeting = dynamic_cast<MessageGreeting *>(data.content());
        if (nullptr != greeting)
        {
            mData->clientKey = greeting->greetingKey();
            emit readyForUse(mData->clientKey);
        }
    }
        break;
    case RichText:
        emit sendUIMessage(data);
        break;
    case FileSendType:
        emit sendFileMessage(data);
        break;
    case FileHead:
        emit sendFileMessage(data);
        break;
    case undefine:
        break;
    default:
        break;
    }
}
Esempio n. 5
0
int Client::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: newMessage((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 1: newParticipant((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 2: participantLeft((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 3: newConnection((*reinterpret_cast< Connection*(*)>(_a[1]))); break;
        case 4: connectionError((*reinterpret_cast< QAbstractSocket::SocketError(*)>(_a[1]))); break;
        case 5: disconnected(); break;
        case 6: readyForUse(); break;
        default: ;
        }
        _id -= 7;
    }
    return _id;
}
ScreenLogin::ScreenLogin(QWidget *parent, ScreenManager *manager, const QPoint &pos) :
    CatanScreen(parent, manager, pos),
    ui(new Ui::ScreenLogin)
{
    ui->setupUi(this);

    w_login = new LoginWidget(this);

    connect( w_login, SIGNAL(connectToServer(QHostAddress&,quint16)),
             this, SLOT(connectToServer(QHostAddress&,quint16)));
    connect( net::Connection, SIGNAL(disconnected()),
            w_login ,SLOT(enableConnectButton()));
    connect( net::Connection, SIGNAL(error(QAbstractSocket::SocketError)),
            w_login ,SLOT(enableConnectButton()));
    connect( net::Connection, SIGNAL(error(QAbstractSocket::SocketError)),
             this, SLOT(displayError(QAbstractSocket::SocketError)));
    connect( net::Connection, SIGNAL(disconnected()),
             this, SLOT(onDisconnect()));
    connect( net::Connection, SIGNAL(readyForUse()),
             this, SLOT(onConnectionReady()));
}