2022-01-24 02:23:08 +00:00
|
|
|
#include "client.h"
|
|
|
|
#include "client_socket.h"
|
|
|
|
#include "clientplayer.h"
|
|
|
|
|
|
|
|
Client *ClientInstance;
|
|
|
|
ClientPlayer *Self;
|
|
|
|
|
|
|
|
Client::Client(QObject* parent)
|
|
|
|
: QObject(parent), callback(0)
|
|
|
|
{
|
|
|
|
ClientInstance = this;
|
|
|
|
Self = nullptr;
|
|
|
|
|
|
|
|
ClientSocket *socket = new ClientSocket;
|
|
|
|
connect(socket, &ClientSocket::error_message, this, &Client::error_message);
|
|
|
|
router = new Router(this, socket, Router::TYPE_CLIENT);
|
|
|
|
|
|
|
|
L = CreateLuaState();
|
|
|
|
DoLuaScript(L, "lua/freekill.lua");
|
|
|
|
DoLuaScript(L, "lua/client/client.lua");
|
|
|
|
}
|
|
|
|
|
|
|
|
Client::~Client()
|
|
|
|
{
|
|
|
|
ClientInstance = nullptr;
|
2022-03-24 13:23:42 +00:00
|
|
|
lua_close(L);
|
2022-03-01 05:18:00 +00:00
|
|
|
router->getSocket()->disconnectFromHost();
|
2022-01-24 02:23:08 +00:00
|
|
|
router->getSocket()->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::connectToHost(const QHostAddress& server, ushort port)
|
|
|
|
{
|
|
|
|
router->getSocket()->connectToHost(server, port);
|
|
|
|
}
|
|
|
|
|
2022-03-02 12:56:37 +00:00
|
|
|
void Client::requestServer(const QString& command, const QString& jsonData, int timeout)
|
2022-01-24 02:23:08 +00:00
|
|
|
{
|
|
|
|
int type = Router::TYPE_REQUEST | Router::SRC_CLIENT | Router::DEST_SERVER;
|
2022-03-02 12:56:37 +00:00
|
|
|
router->request(type, command, jsonData, timeout);
|
2022-01-24 02:23:08 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 12:56:37 +00:00
|
|
|
void Client::replyToServer(const QString& command, const QString& jsonData)
|
2022-01-24 02:23:08 +00:00
|
|
|
{
|
2022-03-01 05:18:00 +00:00
|
|
|
int type = Router::TYPE_REPLY | Router::SRC_CLIENT | Router::DEST_SERVER;
|
2022-03-02 12:56:37 +00:00
|
|
|
router->reply(type, command, jsonData);
|
2022-01-24 02:23:08 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 12:56:37 +00:00
|
|
|
void Client::notifyServer(const QString& command, const QString& jsonData)
|
2022-01-24 02:23:08 +00:00
|
|
|
{
|
2022-03-01 05:18:00 +00:00
|
|
|
int type = Router::TYPE_NOTIFICATION | Router::SRC_CLIENT | Router::DEST_SERVER;
|
2022-03-02 12:56:37 +00:00
|
|
|
router->notify(type, command, jsonData);
|
2022-01-24 02:23:08 +00:00
|
|
|
}
|