mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 10:32:19 +08:00
chore: code analysis
This commit is contained in:
@@ -164,13 +164,13 @@ namespace asst
|
||||
struct ReplacementHome
|
||||
{
|
||||
Point location;
|
||||
BattleDeployDirection direction;
|
||||
BattleDeployDirection direction = BattleDeployDirection::Right;
|
||||
};
|
||||
|
||||
struct ForceDeployDirection
|
||||
{
|
||||
BattleDeployDirection direction;
|
||||
std::unordered_set<BattleRole> role;
|
||||
BattleDeployDirection direction = BattleDeployDirection::Right;
|
||||
std::unordered_set<BattleRole> role = {};
|
||||
};
|
||||
|
||||
struct RoguelikeBattleData
|
||||
@@ -180,7 +180,7 @@ namespace asst
|
||||
std::unordered_set<Point> blacklist_location;
|
||||
std::unordered_map<Point, ForceDeployDirection> force_deploy_direction;
|
||||
std::vector<int> key_kills;
|
||||
std::array<BattleRole, 9> role_order;
|
||||
std::array<BattleRole, 9> role_order = {};
|
||||
bool use_dice_stage = true;
|
||||
int stop_deploy_blocking_num = INT_MAX;
|
||||
int force_deploy_air_defense_num = 0;
|
||||
@@ -206,7 +206,7 @@ namespace asst
|
||||
struct BattleCharData
|
||||
{
|
||||
std::string name;
|
||||
BattleRole role;
|
||||
BattleRole role = BattleRole::Unknown;
|
||||
std::array<std::string, 3> ranges;
|
||||
int rarity = 0;
|
||||
bool with_direction = true;
|
||||
|
||||
@@ -95,7 +95,7 @@ std::optional<std::string> asst::Controller::call_command(const std::string& cmd
|
||||
std::string pipe_data;
|
||||
std::string sock_data;
|
||||
asst::platform::single_page_buffer<char> pipe_buffer;
|
||||
std::optional<asst::platform::single_page_buffer<char>> sock_buffer;
|
||||
asst::platform::single_page_buffer<char> sock_buffer;
|
||||
|
||||
auto start_time = steady_clock::now();
|
||||
std::unique_lock<std::mutex> callcmd_lock(m_callcmd_mutex);
|
||||
@@ -151,9 +151,9 @@ std::optional<std::string> asst::Controller::call_command(const std::string& cmd
|
||||
sockov.hEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr);
|
||||
client_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
DWORD dummy;
|
||||
if (!m_server_accept_ex(m_server_sock, client_socket, sock_buffer.value().get(),
|
||||
(DWORD)sock_buffer.value().size() - ((sizeof(sockaddr_in) + 16) * 2),
|
||||
sizeof(sockaddr_in) + 16, sizeof(sockaddr_in) + 16, &dummy, &sockov)) {
|
||||
if (!m_server_accept_ex(m_server_sock, client_socket, sock_buffer.get(),
|
||||
(DWORD)sock_buffer.size() - ((sizeof(sockaddr_in) + 16) * 2), sizeof(sockaddr_in) + 16,
|
||||
sizeof(sockaddr_in) + 16, &dummy, &sockov)) {
|
||||
err = WSAGetLastError();
|
||||
if (err == ERROR_IO_PENDING) {
|
||||
accept_pending = true;
|
||||
@@ -242,8 +242,7 @@ std::optional<std::string> asst::Controller::call_command(const std::string& cmd
|
||||
DWORD len = 0;
|
||||
if (GetOverlappedResult(reinterpret_cast<HANDLE>(m_server_sock), &sockov, &len, FALSE)) {
|
||||
accept_pending = false;
|
||||
if (recv_by_socket)
|
||||
sock_data.insert(sock_data.end(), sock_buffer.value().get(), sock_buffer.value().get() + len);
|
||||
if (recv_by_socket) sock_data.insert(sock_data.end(), sock_buffer.get(), sock_buffer.get() + len);
|
||||
|
||||
if (len == 0) {
|
||||
socket_eof = true;
|
||||
@@ -255,8 +254,8 @@ std::optional<std::string> asst::Controller::call_command(const std::string& cmd
|
||||
sockov = {};
|
||||
sockov.hEvent = event;
|
||||
|
||||
(void)ReadFile(reinterpret_cast<HANDLE>(client_socket), sock_buffer.value().get(),
|
||||
(DWORD)sock_buffer.value().size(), nullptr, &sockov);
|
||||
(void)ReadFile(reinterpret_cast<HANDLE>(client_socket), sock_buffer.get(),
|
||||
(DWORD)sock_buffer.size(), nullptr, &sockov);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -264,15 +263,14 @@ std::optional<std::string> asst::Controller::call_command(const std::string& cmd
|
||||
// ReadFile
|
||||
DWORD len = 0;
|
||||
if (GetOverlappedResult(reinterpret_cast<HANDLE>(client_socket), &sockov, &len, FALSE)) {
|
||||
if (recv_by_socket)
|
||||
sock_data.insert(sock_data.end(), sock_buffer.value().get(), sock_buffer.value().get() + len);
|
||||
if (recv_by_socket) sock_data.insert(sock_data.end(), sock_buffer.get(), sock_buffer.get() + len);
|
||||
if (len == 0) {
|
||||
socket_eof = true;
|
||||
::closesocket(client_socket);
|
||||
}
|
||||
else {
|
||||
(void)ReadFile(reinterpret_cast<HANDLE>(client_socket), sock_buffer.value().get(),
|
||||
(DWORD)sock_buffer.value().size(), nullptr, &sockov);
|
||||
(void)ReadFile(reinterpret_cast<HANDLE>(client_socket), sock_buffer.get(),
|
||||
(DWORD)sock_buffer.size(), nullptr, &sockov);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -332,11 +330,11 @@ std::optional<std::string> asst::Controller::call_command(const std::string& cmd
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
ssize_t read_num = ::read(client_socket, sock_buffer.value().get(), sock_buffer.value().size());
|
||||
ssize_t read_num = ::read(client_socket, sock_buffer.get(), sock_buffer.size());
|
||||
|
||||
while (read_num > 0) {
|
||||
sock_data.insert(sock_data.end(), sock_buffer.value().get(), sock_buffer.value().get() + read_num);
|
||||
read_num = ::read(client_socket, sock_buffer.value().get(), sock_buffer.value().size());
|
||||
sock_data.insert(sock_data.end(), sock_buffer.get(), sock_buffer.get() + read_num);
|
||||
read_num = ::read(client_socket, sock_buffer.get(), sock_buffer.size());
|
||||
}
|
||||
|
||||
::close(client_socket);
|
||||
|
||||
Reference in New Issue
Block a user