1
This commit is contained in:
parent
b3fb8beff5
commit
da61f163bf
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <a8/tcpclient.h>
|
#include <a8/tcpclient.h>
|
||||||
#include <a8/tcpclient2.h>
|
#include <a8/tcpclient2.h>
|
||||||
|
#include <a8/timer.h>
|
||||||
|
|
||||||
#include "virtualclient.h"
|
#include "virtualclient.h"
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
@ -39,7 +40,25 @@ void VirtualClient::UnInit()
|
|||||||
|
|
||||||
void VirtualClient::Update()
|
void VirtualClient::Update()
|
||||||
{
|
{
|
||||||
|
if (state_ == VCS_Joined) {
|
||||||
|
long long tick = a8::XGetTickCount() - last_active_tick_;
|
||||||
|
if (tick > 1200) {
|
||||||
|
// abort();
|
||||||
|
}
|
||||||
|
if (a8::XGetTickCount() - last_move_tick_ > 100) {
|
||||||
|
last_move_tick_ = a8::XGetTickCount();
|
||||||
|
SendMove();
|
||||||
|
}
|
||||||
|
if (a8::XGetTickCount() - last_move_dir_chg_tick_ > 2000 + 1000 * (rand() % 5)) {
|
||||||
|
last_move_dir_chg_tick_ = a8::XGetTickCount();
|
||||||
|
move_x = rand() % 1000;
|
||||||
|
move_y = rand() % 1000;
|
||||||
|
if (rand() % 5 == 0) {
|
||||||
|
move_x = -move_x;
|
||||||
|
move_y = -move_y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualClient::SendJoin()
|
void VirtualClient::SendJoin()
|
||||||
@ -49,11 +68,32 @@ void VirtualClient::SendJoin()
|
|||||||
msg.set_account_id(account);
|
msg.set_account_id(account);
|
||||||
msg.set_baseskin(14001);
|
msg.set_baseskin(14001);
|
||||||
SendMsg(msg);
|
SendMsg(msg);
|
||||||
|
a8::XPrintf("sendjoin %s\n", {account});
|
||||||
|
a8::Timer::Instance()->AddDeadLineTimerAndAttach(
|
||||||
|
1000 * 30 + (rand() % 15) * 1000,
|
||||||
|
a8::XParams()
|
||||||
|
.SetSender(this),
|
||||||
|
[] (const a8::XParams& param)
|
||||||
|
{
|
||||||
|
VirtualClient* client = (VirtualClient*)param.sender.GetUserData();
|
||||||
|
client->jumped_ = true;
|
||||||
|
},
|
||||||
|
&timer_attacher_.timer_list_
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualClient::SendMove()
|
void VirtualClient::SendMove()
|
||||||
{
|
{
|
||||||
|
cs::CMMove msg;
|
||||||
|
if (move_x != 0 && move_y != 0) {
|
||||||
|
auto p = msg.mutable_move_dir();
|
||||||
|
p->set_x(move_x);
|
||||||
|
p->set_y(move_y);
|
||||||
|
}
|
||||||
|
msg.set_shot_start(true);
|
||||||
|
msg.set_shot_hold(true);
|
||||||
|
msg.set_jump(jumped_);
|
||||||
|
SendMsg(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TCP_CLIENT2
|
#if TCP_CLIENT2
|
||||||
@ -62,6 +102,7 @@ void VirtualClient::on_error(a8::TcpClient2* sender, int errorId)
|
|||||||
void VirtualClient::on_error(a8::TcpClient* sender, int errorId)
|
void VirtualClient::on_error(a8::TcpClient* sender, int errorId)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
abort();
|
||||||
a8::UdpLog::Instance()->Error("VirtualClient errorid=%d", {errorId});
|
a8::UdpLog::Instance()->Error("VirtualClient errorid=%d", {errorId});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +126,7 @@ void VirtualClient::on_disconnect(a8::TcpClient2* sender)
|
|||||||
void VirtualClient::on_disconnect(a8::TcpClient* sender)
|
void VirtualClient::on_disconnect(a8::TcpClient* sender)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
abort();
|
||||||
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});
|
||||||
App::Instance()->AddIMMsg(IM_VirtualClientDisconnect,
|
App::Instance()->AddIMMsg(IM_VirtualClientDisconnect,
|
||||||
@ -138,5 +180,6 @@ void VirtualClient::on_socketread(a8::TcpClient* sender, char* buf, unsigned int
|
|||||||
memmove(recv_buff_, recv_buff_ + offset, recv_bufflen_ - offset);
|
memmove(recv_buff_, recv_buff_ + offset, recv_bufflen_ - offset);
|
||||||
}
|
}
|
||||||
recv_bufflen_ -= offset;
|
recv_bufflen_ -= offset;
|
||||||
|
state_ = VCS_Joined;
|
||||||
|
last_active_tick_ = a8::XGetTickCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <a8/timer_attacher.h>
|
||||||
|
|
||||||
namespace a8
|
namespace a8
|
||||||
{
|
{
|
||||||
class TcpClient;
|
class TcpClient;
|
||||||
@ -50,6 +52,13 @@ class VirtualClient
|
|||||||
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;
|
||||||
|
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
|
#if TCP_CLIENT2
|
||||||
a8::TcpClient2* tcp_client_ = nullptr;
|
a8::TcpClient2* tcp_client_ = nullptr;
|
||||||
|
2
third_party/a8engine
vendored
2
third_party/a8engine
vendored
@ -1 +1 @@
|
|||||||
Subproject commit f9222e376f8a678a252932c4a3fb93860d7625f2
|
Subproject commit 6e5c873aecdd5464324818307237bca83860e16a
|
Loading…
x
Reference in New Issue
Block a user