UINT __stdcall CreateFolder (MSIHANDLE hInstall) { WCHAR sz_path[MAX_PATH + 1] = {0}; DWORD dw_len = MAX_PATH; HRESULT h_r = SHGetFolderPath (NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, sz_path); if (S_OK != h_r) { std::wstring str_msg (L"Unable to obtain application data folder path. Aborting setup."); MessageBox (NULL, str_msg.data(), L"Kai Installation Error", MB_ICONERROR); return ERROR_DIRECTORY; } WCHAR sz_folderName[MAX_PATH + 1] = {0}; UINT ui_ret = MsiGetProperty (hInstall, L"CustomActionData", sz_folderName, &dw_len); if (ui_ret != ERROR_SUCCESS) { std::wstring str_msg (L"Unable to access MSI custom action property. Aborting setup."); MessageBox (NULL, str_msg.data(), L"Kai Installation Error", MB_ICONERROR); return ui_ret; } ui_ret = PathAppend (sz_path, sz_folderName); if (!ui_ret) { std::wstring str_msg (L"Unable to create target path. Aborting setup."); MessageBox (NULL, str_msg.data(), L"Kai Installation Error", MB_ICONERROR); return ui_ret; } ui_ret = CreateDirectory (sz_path, NULL); if (!ui_ret) { UINT err = GetLastError(); std::basic_stringstream<WCHAR> io_; io_ << err; if (GetLastError() != ERROR_ALREADY_EXISTS) { std::wstring str_msg (L"Unable to create application data folder. Aborting setup."); str_msg += L"\n" + std::wstring (io_.str()); MessageBox (NULL, str_msg.data(), L"Kai Installation Error", MB_ICONERROR); return ui_ret; } } return 0; } // CreateFolder()
void ZGWServer::responseMsg(zmq_msg_t& msg_t) { size_t msg_size = zmq_msg_size(&msg_t); assert( msg_size > 0 ); std::string str_msg(static_cast<char*>(zmq_msg_data(&msg_t)), msg_size); ZMSG msg; int rc = msg.deserialize(str_msg); if( rc != 0 ) { LOG_ERROR << "PULL线程反序列化消息失败, ret: " << rc; return; } //LOG_INFO << "PULL线程反序列化消息成功, msg[id]: " << msg.flow_id << ", msg[type]: " // << msg.msg_type << ", msg[body size]:" << msg.msg_body.size(); std::map<uint32_t, TcpConnectionPtr>::iterator iter = id2conn_.find(msg.flow_id); if( iter == id2conn_.end() ) { LOG_ERROR << "PULL线程查找flow_id: " << msg.flow_id << "对应的连接失败"; return; } TcpConnectionPtr conn = iter->second; muduo::net::Buffer buf; buf.prependInt8(msg.msg_type); buf.prependInt32(static_cast<int32_t>(msg.msg_body.size())); buf.append(msg.msg_body.c_str(), msg.msg_body.size()); conn->send(&buf); stat_.msg_recv_cnt.increment(); stat_.msg_recv_bytes.addAndGet(msg_size); }
// ---------------------------------------------------------------------------- void ConnectToServer::asynchronousUpdate() { if (STKHost::get()->isClientServer() && !NetworkConfig::get()->getServerIdFile().empty()) { getClientServerInfo(); } switch(m_state.load()) { case SET_PUBLIC_ADDRESS: { if (!m_server) { while (!ServersManager::get()->refresh(false)) { if (ProtocolManager::lock()->isExiting()) return; StkTime::sleep(1); } while (!ServersManager::get()->listUpdated()) { if (ProtocolManager::lock()->isExiting()) return; StkTime::sleep(1); } auto servers = std::move(ServersManager::get()->getServers()); // Remove password protected servers servers.erase(std::remove_if(servers.begin(), servers.end(), [] (const std::shared_ptr<Server> a)->bool { return a->isPasswordProtected(); }), servers.end()); if (!servers.empty()) { // For quick play we choose the server with the least player std::sort(servers.begin(), servers.end(), [] (const std::shared_ptr<Server> a, const std::shared_ptr<Server> b)->bool { return a->getCurrentPlayers() < b->getCurrentPlayers(); }); m_server = servers[0]; m_server_address = m_server->getAddress(); } else { // Shutdown STKHost (go back to online menu too) STKHost::get()->setErrorMessage(m_quick_play_err_msg); STKHost::get()->requestShutdown(); m_state = EXITING; return; } servers.clear(); } if (m_server->supportsEncryption()) { STKHost::get()->setPublicAddress(); registerWithSTKServer(); } // Set to DONE will stop STKHost is not connected m_state = STKHost::get()->getPublicAddress().isUnset() ? DONE : GOT_SERVER_ADDRESS; break; } case GOT_SERVER_ADDRESS: { if (!STKHost::get()->isClientServer() && m_server_address.getIP() == STKHost::get()->getPublicAddress().getIP()) { Log::info("ConnectToServer", "Server is in the same lan"); std::string str_msg("connection-request"); BareNetworkString message(str_msg + StringUtils::toString(m_server->getPrivatePort())); // If use lan connection for wan server, send to all broadcast // addresses for (auto& addr : ServersManager::get()->getBroadcastAddresses()) { for (int i = 0; i < 5; i++) { STKHost::get()->sendRawPacket(message, addr); StkTime::sleep(1); } } } // 30 seconds connecting timeout total, use another port to try // direct connection to server first, if failed than use the one // that has stun mapped, the first 8 seconds allow the server to // start the connect to peer protocol first before the port is // remapped if (tryConnect(2000, 4, true/*another_port*/)) break; if (!tryConnect(2000, 11)) m_state = DONE; break; } case DONE: case EXITING: break; } } // asynchronousUpdate