63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "Packet.h"
|
|
#include <boost/asio.hpp>
|
|
#include <string>
|
|
#include <thread>
|
|
|
|
namespace google::protobuf {
|
|
class Message;
|
|
}
|
|
|
|
using boost::asio::ip::tcp;
|
|
|
|
class BaseClient {
|
|
public:
|
|
BaseClient(boost::asio::io_context &io_context, const std::string &host,
|
|
const std::string &port);
|
|
|
|
virtual ~BaseClient() = default;
|
|
|
|
void SendPacket(PacketID id, const google::protobuf::Message *pkt = nullptr);
|
|
|
|
bool ReceiveHeader(PacketHeader &header);
|
|
|
|
bool Login(const std::string &nickname);
|
|
|
|
// 비동기 수신 시작
|
|
void StartReceive();
|
|
void StopReceive();
|
|
|
|
virtual void Run() = 0;
|
|
|
|
protected:
|
|
tcp::socket socket_;
|
|
uint32_t currentLevel_ = 0;
|
|
uint64_t currentGold_ = 0;
|
|
std::string nickname_;
|
|
|
|
std::jthread receiveThread_;
|
|
|
|
void ReceiveLoop(std::stop_token stopToken);
|
|
void HandlePacket(const PacketHeader &header);
|
|
|
|
void HandleUpgradeResult(const PacketHeader &header);
|
|
void HandleSellResult(const PacketHeader &header);
|
|
};
|
|
|
|
class InteractiveClient : public BaseClient {
|
|
public:
|
|
using BaseClient::BaseClient;
|
|
void Run() override;
|
|
};
|
|
|
|
class ScenarioClient : public BaseClient {
|
|
public:
|
|
ScenarioClient(boost::asio::io_context &io_context, const std::string &host,
|
|
const std::string &port, const std::string &scenarioFile)
|
|
: BaseClient(io_context, host, port), scenarioFile_(scenarioFile) {}
|
|
void Run() override;
|
|
|
|
private:
|
|
std::string scenarioFile_;
|
|
};
|