Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <client.hpp>
- using namespace Qt;
- /**
- * Create the constructor of class Client
- */
- Client::Client(QObject* pointer) : QObject(pointer), sizeOfData(0) {
- pTcpSocket = new QTcpSocket(this);
- pTcpSocket->connectToHost("77.223.89.11", 2323);
- connect(pTcpSocket, SIGNAL(readyRead()), SLOT(slotReadyRead()));
- }
- /**
- * Create the slot the reception of data from server
- */
- void Client::slotReadyRead () {
- QDataStream in(pTcpSocket);
- in.setVersion(QDataStream::Qt_5_3);
- in>>sizeOfData;
- while(pTcpSocket->bytesAvailable() < sizeOfData) {
- pTcpSocket->waitForReadyRead();
- }
- if (str[0] == "SigningIn") {
- str.clear();
- in>>number;
- in>>str;
- if (!str.isEmpty() && str[0] == name) {
- accesSigningIn(name, number);
- name = "";
- number = 0;
- }
- else {
- notAccesSigningIn(name);
- name = "";
- }
- }
- else if (str[0] == "SigningUp") {
- str.clear();
- in>>number;
- in>>str;
- if (!str.isEmpty() && str[0] == name) {
- accesSigningUp(name, number);
- name = "";
- number = 0;
- }
- else {
- notAccesSigningUp(name);
- name = "";
- }
- }
- name = "";
- str.clear();
- }
- /**
- * Create the slot that send to server messages
- */
- void Client::slotSendToServer(QString argName, QString argPassword) {
- name = argName.trimmed();
- password = argPassword.trimmed();
- if (name.isEmpty() || password.isEmpty()) {
- somethingEmpty(name);
- return;
- }
- QByteArray arrBlock;
- QDataStream out(&arrBlock, QIODevice::WriteOnly);
- out.setVersion(QDataStream::Qt_5_3);
- QString info;
- str << sender()->objectName();
- if (str[0] == "SigningIn") {
- info = QString("SELECT \"Name\" FROM \"Authorization\" WHERE \"Name\" = '%1' AND \"password\" = '%2';|SELECT * FROM \"Amount\"").arg(name).arg(password);
- }
- else {
- info = QString("INSERT INTO \"Authorization\"(\"Name\", \"password\") VALUES('%1', '%2');|SELECT \"Name\" FROM \"Authorization\" WHERE \"password\" = '%2';|SELECT * FROM \"Amount\";").arg(name).arg(password);
- }
- out<<int(0)<<info;
- out.device()->seek(0);
- out << int(arrBlock.size() - sizeof(int));
- pTcpSocket->write(arrBlock);
- }
- /**
- * Create the deconstructor
- */
- Client::~Client() {
- delete this;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement