Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <client.hpp>
- using namespace Qt;
- Client::Client(QLineEdit* pline1, QLineEdit* pline2, QObject* pointer) : QObject(pointer), sizeOfData(0) {
- name = pline1;
- password = pline2;
- pTcpSocket = new QTcpSocket(this);
- pTcpSocket->connectToHost("77.223.89.11", 2323);
- connect(pTcpSocket, SIGNAL(connected()), SLOT(slotConnected()));
- connect(pTcpSocket, SIGNAL(readyRead()), SLOT(slotReadyRead()));
- connect(pTcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotError(QAbstractSocket::SocketError)));
- }
- void Client::slotReadyRead () {
- QDataStream in(pTcpSocket);
- in.setVersion(QDataStream::Qt_5_3);
- in>>sizeOfData;
- while(pTcpSocket->bytesAvailable() < sizeOfData) {
- pTcpSocket->waitForReadyRead();
- }
- if (!str[0].contains("Authorization")) {
- str.clear();
- in>>imgs;
- }
- else if (str[1] != "Signing up") {
- str.clear();
- in>>str;
- if (!str[0].isNull()) {
- QMessageBox::about(nullptr, "MuseumQuest", "Вы успешно вошли в свой аккаунт!");
- }
- else {
- QMessageBox::about(nullptr, "MuseumQuest", "Вы не зарегистрировались!");
- }
- }
- else {
- str.clear();
- in>>str;
- }
- }
- void Client::slotError(QAbstractSocket::SocketError err) {
- QString strError = "Error: " + (err == QAbstractSocket::HostNotFoundError ? "The host was not fount." : err == QAbstractSocket::RemoteHostClosedError ? "The remote host is closed." : err == QAbstractSocket::ConnectionRefusedError ? "The connection was refused." : QString(pTcpSocket->errorString()));
- qDebug()<<strError;
- }
- void Client::slotSendToServer() {
- QByteArray arrBlock;
- QDataStream out(&arrBlock, QIODevice::WriteOnly);
- out.setVersion(QDataStream::Qt_5_3);
- QMessageBox::about(nullptr, "MuseumQuest", "Hello");
- str << sender()->objectName();
- QString info = QString("SELECT \"Name\" FROM \"Authorization\" WHERE \"Name\" = '%1' AND \"password\" = '%2'").arg(name->text()).arg(password->text());
- out<<int(0)<<info;
- out.device()->seek(0);
- out << int(arrBlock.size() - sizeof(int));
- pTcpSocket->write(arrBlock);
- }
- void Client::slotConnected() {
- qDebug()<<"Received the connected() signal";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement