diff --git a/server/robotserver/virtualclient.cc b/server/robotserver/virtualclient.cc index 9dc2ef6..07c3c73 100644 --- a/server/robotserver/virtualclient.cc +++ b/server/robotserver/virtualclient.cc @@ -4,6 +4,7 @@ #include #include +#include #include "virtualclient.h" #include "app.h" @@ -39,7 +40,25 @@ void VirtualClient::UnInit() 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() @@ -49,11 +68,32 @@ void VirtualClient::SendJoin() msg.set_account_id(account); msg.set_baseskin(14001); 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() { - + 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 @@ -62,6 +102,7 @@ void VirtualClient::on_error(a8::TcpClient2* sender, int errorId) void VirtualClient::on_error(a8::TcpClient* sender, int errorId) #endif { + abort(); 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) #endif { + abort(); recv_bufflen_ = 0; a8::UdpLog::Instance()->Info("target server %d disconnected after 10s later reconnect", {instance_id}); 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); } recv_bufflen_ -= offset; + state_ = VCS_Joined; + last_active_tick_ = a8::XGetTickCount(); } - diff --git a/server/robotserver/virtualclient.h b/server/robotserver/virtualclient.h index ed7f95c..cf52f90 100644 --- a/server/robotserver/virtualclient.h +++ b/server/robotserver/virtualclient.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace a8 { class TcpClient; @@ -50,6 +52,13 @@ class VirtualClient 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; diff --git a/third_party/a8engine b/third_party/a8engine index f9222e3..6e5c873 160000 --- a/third_party/a8engine +++ b/third_party/a8engine @@ -1 +1 @@ -Subproject commit f9222e376f8a678a252932c4a3fb93860d7625f2 +Subproject commit 6e5c873aecdd5464324818307237bca83860e16a