feat: server, client 디렉토리 조정 및 client 헤더 파일 추가. 시나리오
혹은 대화형 클라이언트로 수정
This commit is contained in:
parent
b887f15662
commit
1d103d7f16
12 changed files with 281 additions and 112 deletions
59
include/Client.h
Normal file
59
include/Client.h
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#pragma once
|
||||
|
||||
#include "Packet.h"
|
||||
#include <boost/asio.hpp>
|
||||
#include <string>
|
||||
|
||||
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 void *payload = nullptr,
|
||||
size_t payloadSize = 0);
|
||||
|
||||
bool ReceiveHeader(PacketHeader &header);
|
||||
|
||||
template <typename T> bool ReceivePayload(T &payload) {
|
||||
try {
|
||||
boost::asio::read(socket_, boost::asio::buffer(&payload, sizeof(T)));
|
||||
return true;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Login(const std::string &nickname);
|
||||
|
||||
virtual void Run() = 0;
|
||||
|
||||
protected:
|
||||
tcp::socket socket_;
|
||||
uint32_t currentLevel_ = 0;
|
||||
uint64_t currentGold_ = 0;
|
||||
std::string nickname_;
|
||||
|
||||
void HandleUpgradeResult();
|
||||
void HandleSellResult();
|
||||
};
|
||||
|
||||
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_;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue