69 lines
1.5 KiB
C++
69 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include <a8/timer_attacher.h>
|
|
|
|
namespace a8
|
|
{
|
|
class TcpClient;
|
|
class TcpClient2;
|
|
}
|
|
|
|
enum VirtualClientState_e
|
|
{
|
|
VCS_Init,
|
|
VCS_Joined,
|
|
};
|
|
|
|
class VirtualClient
|
|
{
|
|
public:
|
|
int instance_id = 0;
|
|
std::string account;
|
|
std::string remote_ip;
|
|
int remote_port = 0;
|
|
|
|
void Init();
|
|
void UnInit();
|
|
void Update();
|
|
|
|
template <typename T>
|
|
void SendMsg(T& msg)
|
|
{
|
|
static int msgid = f8::Net_GetMessageId(msg);
|
|
f8::Net_SendMsg(tcp_client_, 0, msgid, msg);
|
|
}
|
|
void SendJoin();
|
|
void SendMove();
|
|
|
|
private:
|
|
#if TCP_CLIENT2
|
|
void on_error(a8::TcpClient2* sender, int errorId);
|
|
void on_connect(a8::TcpClient2* sender);
|
|
void on_disconnect(a8::TcpClient2* sender);
|
|
void on_socketread(a8::TcpClient2* sender, char* buf, unsigned int len);
|
|
#else
|
|
void on_error(a8::TcpClient* sender, int errorId);
|
|
void on_connect(a8::TcpClient* sender);
|
|
void on_disconnect(a8::TcpClient* sender);
|
|
void on_socketread(a8::TcpClient* sender, char* buf, unsigned int len);
|
|
#endif
|
|
|
|
private:
|
|
VirtualClientState_e state_ = VCS_Init;
|
|
char *recv_buff_ = nullptr;
|
|
unsigned int recv_bufflen_ = 0;
|
|
long long last_active_tick_ = 0;
|
|
long long last_move_tick_ = 0;
|
|
int move_x = 0;
|
|
int move_y = 0;
|
|
long long last_move_dir_chg_tick_ = 0;
|
|
bool jumped_ = false;
|
|
a8::TimerAttacher timer_attacher_;
|
|
|
|
#if TCP_CLIENT2
|
|
a8::TcpClient2* tcp_client_ = nullptr;
|
|
#else
|
|
a8::TcpClient* tcp_client_ = nullptr;
|
|
#endif
|
|
};
|