1
This commit is contained in:
parent
cb711bea74
commit
3de8c89359
@ -10,7 +10,7 @@ endif()
|
|||||||
|
|
||||||
set(CMAKE_BUILD_TYPE "Debug")
|
set(CMAKE_BUILD_TYPE "Debug")
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "-std=gnu++11 -fsanitize=address -fno-omit-frame-pointer")
|
set(CMAKE_CXX_FLAGS_RELEASE "-std=gnu++11 -fsanitize=address -fno-omit-frame-pointer")
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID}")
|
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=gnu++11 -DGAME_ID=${GAME_ID} -DTCP_CLIENT2=1")
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
AFTER
|
AFTER
|
||||||
|
@ -60,8 +60,8 @@ public:
|
|||||||
int instance_id = 0;
|
int instance_id = 0;
|
||||||
bool is_test_mode = false;
|
bool is_test_mode = false;
|
||||||
int test_param = 0;
|
int test_param = 0;
|
||||||
std::string wsp_host;
|
std::string wsp_host = "192.168.100.21";
|
||||||
int wsp_port = 0;
|
int wsp_port = 7102;
|
||||||
std::set<int> flags;
|
std::set<int> flags;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <a8/tcpclient.h>
|
#include <a8/tcpclient.h>
|
||||||
|
#include <a8/tcpclient2.h>
|
||||||
|
|
||||||
#include "virtualclient.h"
|
#include "virtualclient.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
@ -16,7 +17,11 @@ void VirtualClient::Init()
|
|||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
recv_buff_ = (char*) malloc(PACK_MAX * 2);
|
recv_buff_ = (char*) malloc(PACK_MAX * 2);
|
||||||
|
|
||||||
|
#if TCP_CLIENT2
|
||||||
|
tcp_client_ = new a8::TcpClient2();
|
||||||
|
#else
|
||||||
tcp_client_ = new a8::TcpClient();
|
tcp_client_ = new a8::TcpClient();
|
||||||
|
#endif
|
||||||
tcp_client_->remote_address = remote_ip;
|
tcp_client_->remote_address = remote_ip;
|
||||||
tcp_client_->remote_port = remote_port;
|
tcp_client_->remote_port = remote_port;
|
||||||
tcp_client_->on_error = std::bind(&VirtualClient::on_error, this, std::placeholders::_1, std::placeholders::_2);
|
tcp_client_->on_error = std::bind(&VirtualClient::on_error, this, std::placeholders::_1, std::placeholders::_2);
|
||||||
@ -51,12 +56,20 @@ void VirtualClient::SendMove()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TCP_CLIENT2
|
||||||
|
void VirtualClient::on_error(a8::TcpClient2* sender, int errorId)
|
||||||
|
#else
|
||||||
void VirtualClient::on_error(a8::TcpClient* sender, int errorId)
|
void VirtualClient::on_error(a8::TcpClient* sender, int errorId)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
a8::UdpLog::Instance()->Error("VirtualClient errorid=%d", {errorId});
|
a8::UdpLog::Instance()->Error("VirtualClient errorid=%d", {errorId});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TCP_CLIENT2
|
||||||
|
void VirtualClient::on_connect(a8::TcpClient2* sender)
|
||||||
|
#else
|
||||||
void VirtualClient::on_connect(a8::TcpClient* sender)
|
void VirtualClient::on_connect(a8::TcpClient* sender)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
a8::UdpLog::Instance()->Info("target server connected", {});
|
a8::UdpLog::Instance()->Info("target server connected", {});
|
||||||
@ -66,7 +79,11 @@ void VirtualClient::on_connect(a8::TcpClient* sender)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TCP_CLIENT2
|
||||||
|
void VirtualClient::on_disconnect(a8::TcpClient2* sender)
|
||||||
|
#else
|
||||||
void VirtualClient::on_disconnect(a8::TcpClient* sender)
|
void VirtualClient::on_disconnect(a8::TcpClient* sender)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
a8::UdpLog::Instance()->Info("target server %d disconnected after 10s later reconnect", {instance_id});
|
a8::UdpLog::Instance()->Info("target server %d disconnected after 10s later reconnect", {instance_id});
|
||||||
@ -76,7 +93,11 @@ void VirtualClient::on_disconnect(a8::TcpClient* sender)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TCP_CLIENT2
|
||||||
|
void VirtualClient::on_socketread(a8::TcpClient2* sender, char* buf, unsigned int len)
|
||||||
|
#else
|
||||||
void VirtualClient::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len)
|
void VirtualClient::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
if (recv_bufflen_ + len > 2 * PACK_MAX) {
|
if (recv_bufflen_ + len > 2 * PACK_MAX) {
|
||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
@ -118,3 +139,4 @@ void VirtualClient::on_socketread(a8::TcpClient* sender, char* buf, unsigned int
|
|||||||
}
|
}
|
||||||
recv_bufflen_ -= offset;
|
recv_bufflen_ -= offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
class TcpClient;
|
class TcpClient;
|
||||||
|
class TcpClient2;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum VirtualClientState_e
|
enum VirtualClientState_e
|
||||||
@ -33,15 +34,26 @@ class VirtualClient
|
|||||||
void SendMove();
|
void SendMove();
|
||||||
|
|
||||||
private:
|
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_error(a8::TcpClient* sender, int errorId);
|
||||||
void on_connect(a8::TcpClient* sender);
|
void on_connect(a8::TcpClient* sender);
|
||||||
void on_disconnect(a8::TcpClient* sender);
|
void on_disconnect(a8::TcpClient* sender);
|
||||||
void on_socketread(a8::TcpClient* sender, char* buf, unsigned int len);
|
void on_socketread(a8::TcpClient* sender, char* buf, unsigned int len);
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VirtualClientState_e state_ = VCS_Init;
|
VirtualClientState_e state_ = VCS_Init;
|
||||||
char *recv_buff_ = nullptr;
|
char *recv_buff_ = nullptr;
|
||||||
unsigned int recv_bufflen_ = 0;
|
unsigned int recv_bufflen_ = 0;
|
||||||
|
|
||||||
|
#if TCP_CLIENT2
|
||||||
|
a8::TcpClient2* tcp_client_ = nullptr;
|
||||||
|
#else
|
||||||
a8::TcpClient* tcp_client_ = nullptr;
|
a8::TcpClient* tcp_client_ = nullptr;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
2
third_party/a8engine
vendored
2
third_party/a8engine
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 9c2a3520f5459f6260ac4b9b34958ef4c8776a80
|
Subproject commit f9222e376f8a678a252932c4a3fb93860d7625f2
|
2
third_party/framework
vendored
2
third_party/framework
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 7af5d3b84aeaa84a2979c24db9db5ed5a43cea2d
|
Subproject commit 7f6c831d8dbef97267f3a87053249d7beb0bf615
|
Loading…
x
Reference in New Issue
Block a user