mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-05-11 08:59:46 +00:00
added getPlayerdatacommands
This commit is contained in:
parent
47d19f4492
commit
933fd14f14
SnakeClient/SnakeApp
SnakeServer
@ -14,6 +14,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
SOURCES += \
|
||||
back-end/ProfileViewItems/mainmenumodel.cpp \
|
||||
back-end/ProfileViewItems/networkclient.cpp \
|
||||
back-end/ProfileViewItems/playerclientdata.cpp \
|
||||
back-end/ProfileViewItems/userview.cpp \
|
||||
back-end/asyncimageresponse.cpp \
|
||||
@ -86,6 +87,7 @@ RESOURCES += \
|
||||
|
||||
HEADERS += \
|
||||
back-end/ProfileViewItems/mainmenumodel.h \
|
||||
back-end/ProfileViewItems/networkclient.h \
|
||||
back-end/ProfileViewItems/playerclientdata.h \
|
||||
back-end/ProfileViewItems/userview.h \
|
||||
back-end/asyncimageresponse.h \
|
||||
|
@ -0,0 +1,23 @@
|
||||
#include "networkclient.h"
|
||||
#include "playerclientdata.h"
|
||||
|
||||
#include <updateplayerdata.h>
|
||||
|
||||
int NetworkClient::loginedPlayer() const {
|
||||
return _loginedPlayer;
|
||||
}
|
||||
|
||||
void NetworkClient::handleReceiveData(ClientProtocol::Command cmd,
|
||||
const QByteArray &obj) {
|
||||
|
||||
if (cmd == ClientProtocol::Command::Player) {
|
||||
PlayerClientData data;
|
||||
data.fromBytes(obj);
|
||||
_playersDats[data.id()] = data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NetworkClient::NetworkClient() {
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
|
||||
#include "playerclientdata.h"
|
||||
|
||||
#include <client.h>
|
||||
|
||||
class NetworkClient : public ClientProtocol::Client
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
QHash<int, PlayerClientData> _playersDats;
|
||||
int _loginedPlayer;
|
||||
private slots:
|
||||
void handleReceiveData(ClientProtocol::Command cmd, const QByteArray& obj);
|
||||
public:
|
||||
NetworkClient();
|
||||
int loginedPlayer() const;
|
||||
};
|
||||
|
||||
#endif // CLIENT_H
|
@ -13,6 +13,7 @@
|
||||
#include "login.h"
|
||||
#include "updateplayerdata.h"
|
||||
#include <QHash>
|
||||
#include <player.h>
|
||||
|
||||
#define SOLT "SNAKE"
|
||||
namespace ClientProtocol {
|
||||
@ -311,7 +312,7 @@ bool Client::getItem(int id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id < 0) {
|
||||
if (id <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -336,6 +337,36 @@ bool Client::getItem(int id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Client::getPlayer(int id){
|
||||
if (!isLogin()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (id <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Package pcg;
|
||||
|
||||
UpdatePlayerData rec;
|
||||
rec.setToken(_token);
|
||||
rec.setId(id);
|
||||
|
||||
if (!rec.isValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pcg.create(&rec, Type::Request)) {
|
||||
return false;
|
||||
};
|
||||
|
||||
if (!sendPackage(pcg)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const bool& Client::isOnline() const {
|
||||
return _online;
|
||||
}
|
||||
|
@ -91,6 +91,13 @@ public:
|
||||
*/
|
||||
bool getItem(int id);
|
||||
|
||||
/**
|
||||
* @brief getPlayer
|
||||
* @param id of player
|
||||
* @return player data
|
||||
*/
|
||||
bool getPlayer(int id);
|
||||
|
||||
/**
|
||||
* @brief isOnline
|
||||
* @return true if client is connected to server and get rsapub key
|
||||
|
@ -133,7 +133,18 @@ void MainServer::handleRequest(ClientProtocol::Header hdr,
|
||||
}
|
||||
|
||||
case ClientProtocol::Command::UpdatePlayerData: {
|
||||
ClientProtocol::UpdatePlayerData request;
|
||||
request.fromBytes(data);
|
||||
|
||||
auto tocken = _serverDaemon->getToken(addres);
|
||||
|
||||
if (!tocken.isEmpty() && tocken == request.getToken()) {
|
||||
auto player = _db->getPlayer(request.id());
|
||||
_serverDaemon->sendResponse(&player, addres, hdr);
|
||||
|
||||
}
|
||||
|
||||
_serverDaemon->badRequest(addres, hdr);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user