82 lines
2.2 KiB
C++
82 lines
2.2 KiB
C++
#pragma once
|
|
|
|
#include "GameProto.h"
|
|
#include "GameProto.pb.h"
|
|
#include "AceClientInterface.h"
|
|
#include "AceReportInterface.h"
|
|
#include "NetbarInterface.h"
|
|
|
|
class GameClient
|
|
{
|
|
public:
|
|
enum Status
|
|
{
|
|
STATUS_DISCONNECTED = 0,
|
|
//call connectToGameServer...
|
|
STATUS_CONNECTING,
|
|
//onConnected
|
|
STATUS_CONNECTED,
|
|
//call sendLoginRequest...
|
|
STATUS_LOGGING_IN,
|
|
//onServerLoginReply
|
|
STATUS_LOGGED_IN,
|
|
|
|
//call sendLogoutRequest...
|
|
|
|
STATUS_LOGGING_OUT,
|
|
//socket closed
|
|
STATUS_LOGGED_OUT,
|
|
|
|
STATUS_FAILED,
|
|
};
|
|
|
|
const static char* s_default_account_id;
|
|
const static uint32_t s_default_world_id;
|
|
|
|
public:
|
|
bool init();
|
|
void deinit();
|
|
void connectToGameServer(const std::string& server_ip, uint16_t server_port);
|
|
void disconnectFromGameServer();
|
|
|
|
void sendProtobufMessage(uint16_t id, ::google::protobuf::Message* message);
|
|
void sendUGCContent(int32_t ugcSceneID, const char* content);
|
|
|
|
ACEReport* getAceReportInterface(void) { return &m_reportInterface; }
|
|
TencentNetbarInterface* getNetbarInterface(void) { return &m_clientNetbarInterface; }
|
|
|
|
void tick();
|
|
cyclone::TcpClientPtr get_client(void) { return m_client; }
|
|
|
|
protected:
|
|
uint32_t onConnected(cyclone::TcpClientPtr client, bool success);
|
|
void onMessage(cyclone::TcpConnectionPtr conn);
|
|
void onClose(void);
|
|
|
|
protected:
|
|
void sendLoginRequest(const char* accountID, int32_t worldID);
|
|
void onServerLoginReply(cyclone::TcpConnectionPtr conn, Game::LoginReply* reply);
|
|
void onServerTickPacket(cyclone::TcpConnectionPtr conn, Game::ServerTickPacket* reply);
|
|
void onServerUGCReply(cyclone::TcpConnectionPtr conn, Game::UGCReply* reply);
|
|
void onServerNetbarResponse(cyclone::TcpConnectionPtr conn, Game::NetbarStatusRes* reply);
|
|
void sendHeartBeat();
|
|
private:
|
|
Status m_status = STATUS_DISCONNECTED;
|
|
cyclone::TcpClientPtr m_client;
|
|
cyclone::Looper* m_looper;
|
|
std::string m_server_ip;
|
|
uint16_t m_server_port;
|
|
uint64_t m_lastHeartBeatTime = 0;
|
|
|
|
AceClientInterface m_aceClientInterface;
|
|
uint8_t* m_clientTickBuffer = nullptr;
|
|
|
|
ACEReport m_reportInterface;
|
|
int32_t m_nextUGCContextID = 1;
|
|
|
|
TencentNetbarInterface m_clientNetbarInterface;
|
|
public:
|
|
GameClient();
|
|
~GameClient();
|
|
};
|