| 14 | #include "MaaUtils/Uuid.h" |
| 15 | |
| 16 | MAA_AGENT_CLIENT_NS_BEGIN |
| 17 | |
| 18 | AgentClient::AgentClient(const std::string& identifier) |
| 19 | { |
| 20 | LogFunc; |
| 21 | |
| 22 | if (auto port_opt = parse_tcp_port(identifier)) { |
| 23 | LogInfo << "Using TCP mode" << VAR(*port_opt); |
| 24 | uint16_t port = init_tcp_socket(*port_opt, true); |
| 25 | identifier_ = std::to_string(port); |
| 26 | } |
| 27 | // Windows 上检测 IPC 是否可能失败,如果失败则自动使用 TCP |
| 28 | else if (should_fallback_to_tcp()) { |
| 29 | LogInfo << "IPC may fail on this system, using TCP instead"; |
| 30 | uint16_t port = init_tcp_socket(0, true); |
| 31 | identifier_ = std::to_string(port); |
| 32 | } |
| 33 | else { |
| 34 | identifier_ = identifier.empty() ? make_uuid() : identifier; |
| 35 | init_socket(identifier_, true); |
| 36 | } |
| 37 | |
| 38 | LogInfo << VAR(identifier) << VAR(identifier_); |
| 39 | } |
| 40 | |
| 41 | AgentClient::~AgentClient() |
| 42 | { |