Example #1
0
GameState::GameState(
    const QString            & host,
    quint16                    port,
    const QString            & userName,
    NetworkClient::TcpClient & tcpClient) :

    NetworkClient::BaseGameState(nullptr),
    m_host(host),
    m_port(port),
    m_userName(userName)
{
    nc::LoginHandler * loginHandler = new nc::LoginHandler;
    // Special signals are connected manually for now.
    connect(loginHandler, SIGNAL(compressionThresholdChanged(int)), &tcpClient, SLOT(setCompressionThreshold(int)));
    connect(loginHandler, SIGNAL(loginFinished()), this, SLOT(onLoginFinished()));
    addMessageHandler(loginHandler);

    addMessageHandler(new nc::KeepAliveHandler);

    ChatHandler * chatHandler = new ChatHandler;
    connect(chatHandler, SIGNAL(chatMessageReceived(QString)), this, SIGNAL(chatMessageReceived(QString)));
    addMessageHandler(chatHandler);

    DisconnectHandler * disconnectHandler = new DisconnectHandler;
    connect(disconnectHandler, SIGNAL(disconnectedFromServer(QString)), this, SIGNAL(disconnectedFromServer(QString)));
    addMessageHandler(disconnectHandler);
}
Example #2
0
void MainWindow::on_connectButton_clicked()
{
    if(m_connectionState == ConnectionState::Disconnected)
    {
        QString host = ui->hostLineEdit->text();
        quint16 port = ui->portSpinBox->value();
        QString name = ui->nameLineEdit->text();

        m_tcpClient.reset(new nc::TcpClient);
        m_gameState.reset(new GameState(host, port, name, *m_tcpClient.get()));

        connect(m_tcpClient.get(), SIGNAL(messageRead(QByteArray)), m_gameState.get(), SLOT(onInboundMessage(QByteArray)));
        connect(m_gameState.get(), SIGNAL(outboundMessage(QByteArray)), m_tcpClient.get(), SLOT(writeMessage(QByteArray)));
        connect(m_gameState.get(), SIGNAL(chatMessageReceived(QString)), this, SLOT(onChatMessageReceived(QString)));
        connect(m_gameState.get(), SIGNAL(disconnectedFromServer(QString)), this, SLOT(onDisconnected(QString)));
        connect(this, SIGNAL(chatMessageSent(QString)), m_gameState.get(), SLOT(onChatMessageSent(QString)));
        connect(m_tcpClient.get(), SIGNAL(connected()), this, SLOT(onConnected()));
        connect(m_tcpClient.get(), SIGNAL(disconnected()), this, SLOT(onDisconnected()));
        connect(m_tcpClient.get(), SIGNAL(socketError(QAbstractSocket::SocketError)), this, SLOT(onSocketError(QAbstractSocket::SocketError)));

        m_tcpClient->connectToHost(host, port);
        changeConnectionState(ConnectionState::Connecting);

        qDebug() << "Connecting.";
        appendHtml(QString("<b>Connecting to %1:%2.</b><br>").arg(host).arg(port));
    }
    else
    {
        m_tcpClient->disconnectFromHost();
    }
}
Example #3
0
void MorseConnection::doConnect(Tp::DBusError *error)
{
    Q_UNUSED(error);

    CAppInformation appInfo;
    appInfo.setAppId(14617);
    appInfo.setAppHash(QLatin1String("e17ac360fd072f83d5d08db45ce9a121"));
    appInfo.setAppVersion(QLatin1String("0.1"));
    appInfo.setDeviceInfo(QLatin1String("pc"));
    appInfo.setOsInfo(QLatin1String("GNU/Linux"));
    appInfo.setLanguageCode(QLatin1String("en"));

    m_authReconnectionsCount = 0;
    m_core = new CTelegramCore(0);
    m_core->setPingInterval(m_keepaliveInterval * 1000);
    m_core->setAppInformation(&appInfo);
    m_core->setMessageReceivingFilterFlags(TelegramNamespace::MessageFlagOut|TelegramNamespace::MessageFlagRead);
    m_core->setAcceptableMessageTypes(TelegramNamespace::MessageTypeText);

    setStatus(Tp::ConnectionStatusConnecting, Tp::ConnectionStatusReasonNoneSpecified);

    connect(m_core, SIGNAL(connectionStateChanged(TelegramNamespace::ConnectionState)),
            this, SLOT(whenConnectionStateChanged(TelegramNamespace::ConnectionState)));
    connect(m_core, SIGNAL(authorizationErrorReceived()),
            this, SLOT(whenAuthErrorReceived()));
    connect(m_core, SIGNAL(phoneCodeRequired()),
            this, SLOT(whenPhoneCodeRequired()));
    connect(m_core, SIGNAL(authSignErrorReceived(TelegramNamespace::AuthSignError,QString)),
            this, SLOT(whenAuthSignErrorReceived(TelegramNamespace::AuthSignError,QString)));
    connect(m_core, SIGNAL(avatarReceived(QString,QByteArray,QString,QString)),
            this, SLOT(whenAvatarReceived(QString,QByteArray,QString,QString)));
    connect(m_core, SIGNAL(contactListChanged()),
            this, SLOT(whenContactListChanged()));
    connect(m_core, SIGNAL(messageReceived(QString,QString,TelegramNamespace::MessageType,quint32,quint32,quint32)),
            this, SLOT(whenMessageReceived(QString,QString,TelegramNamespace::MessageType,quint32,quint32,quint32)));
    connect(m_core, SIGNAL(chatMessageReceived(quint32,QString,QString,TelegramNamespace::MessageType,quint32,quint32,quint32)),
            this, SLOT(whenChatMessageReceived(quint32,QString,QString,TelegramNamespace::MessageType,quint32,quint32,quint32)));
    connect(m_core, SIGNAL(chatChanged(quint32)),
            this, SLOT(whenChatChanged(quint32)));
    connect(m_core, SIGNAL(contactStatusChanged(QString,TelegramNamespace::ContactStatus)),
            this, SLOT(updateContactPresence(QString)));

    const QByteArray sessionData = getSessionData(m_selfPhone);

    if (sessionData.isEmpty()) {
        qDebug() << "init connection...";
        m_core->initConnection(QLatin1String("149.154.175.50"), 443);
    } else {
        qDebug() << "restore connection...";
        m_core->restoreConnection(sessionData);
    }
}
Example #4
0
void NotifyQt::notifyChatMessage(const ChatMessage &msg)
{
    {
        QMutexLocker m(&_mutex) ;
        if(!_enabled)
            return ;
    }

#ifdef NOTIFY_DEBUG
    std::cerr << "notifyQt: Received chat message " << std::endl ;
#endif
    emit chatMessageReceived(msg);
}
Example #5
0
void ChatHandler::onInboundMessage(int serverState, QByteArray data)
{
    nc::ServerState trueState = static_cast<nc::ServerState>(serverState);

    if(trueState != nc::ServerState::Play)
    {
        return;
    }

    nc::MessageBuffer buffer(data);
    nc::VarInt messageCode;

    buffer >> messageCode;

    if(messageCode.getValue() != 0x02) // chat message
    {
        return;
    }

    QString chatMessage;
    buffer >> chatMessage;

    emit chatMessageReceived(chatMessage);
}
Example #6
0
ChatUserNotify::ChatUserNotify(QObject *parent) :
    UserNotify(parent)
{
    connect(NotifyQt::getInstance(), SIGNAL(chatMessageReceived(ChatMessage)), this, SLOT(chatMessageReceived(ChatMessage)));
    instance = this;
}
Example #7
0
void ChatClient::receiveMessage(std::unique_ptr<ChatMessage> chatMessage) {
    chatMessageReceived(chatMessage->text(), 
                        chatMessage->from().user_name(), 
                        chatMessage->has_target() ? chatMessage->target().user_name() : "");
}