Repository navigation
Expand file tree
/
Copy pathclient.cpp
More file actions
94 lines (85 loc) · 2.39 KB
/
Copy pathclient.cpp
File metadata and controls
94 lines (85 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "client.h"
Client::Client()
{
socket = new QTcpSocket();
QObject::connect(socket,&QTcpSocket::readyRead,this,&Client::readDataSlot);
logined = false;
}
bool Client::registerNewUser(QString userName, QString password){
socket->connectToHost("127.0.0.1",8888);
this->username = userName;
this->password = password;
QByteArray content;
content.append("REGISTER");
content.append('&');
content.append(userName.toLocal8Bit());
content.append('&');
content.append(password.toLocal8Bit());
socket->write(content);
if(socket->waitForReadyRead(1000)==false){
}
return false;
}
bool Client::verifyUser(QString userName, QString password){
socket->connectToHost("127.0.0.1",8888);
this->username = userName;
this->password = password;
QByteArray content;
content.append("VERIFY");
content.append('&');
content.append(userName.toLocal8Bit());
content.append('&');
content.append(password.toLocal8Bit());
socket->write(content);
if(socket->waitForReadyRead(1000)==false){
}
}
void Client::getProfile(){
socket->connectToHost("127.0.0.1",8888);
QByteArray content;
content.append("PROFILE");
socket->write(content);
if(socket->waitForReadyRead(1000)==false){
}
}
void Client::getRankList() {
socket->connectToHost("127.0.0.1",8888);
QByteArray content;
content.append("RANKLIST");
socket->write(content);
if(socket->waitForReadyRead(1000)==false){
}
}
void Client::readDataSlot() {
auto buffer = socket->readAll();
auto instruction = buffer.split('&');
for(int i = 0; i < instruction.size(); i++) {
qDebug() << instruction[i] << "\n";
}
if (instruction[0] == "REG_RESULT"){
registerFlag = instruction[1].toInt();
}
if (instruction[0] == "VER_RESULT"){
verifyFlag = instruction[1].toInt();
}
if (instruction[0] == "PRO_RESULT"){
userlist = instruction[1];
}
if (instruction[0] == "RAN_RESULT"){
ranklist = instruction[1];
}
if (instruction[0] == "UPD_RESULT"){
}
socket->abort();
}
void Client::update(int score) {
socket->connectToHost("127.0.0.1",8888);
QByteArray content;
content.append("UPDATE");
content.append('&');
content.append(username.toLocal8Bit());
content.append('&');
content.append(QString::number(score).toLocal8Bit());
qDebug() << content << "\n";
socket->write(content);
}