void Session::Send(const std::vector<Reply> &out) { // Send all messages for (std::uint32_t i = 0U; i < out.size(); i++) { // To all indicated peers for (std::uint32_t j = 0U; j < out[i].dest.size(); j++) { SendToHost(Protocol::Build(mListener.GetUuid(), out[i].dest[j], out[i].data.ToString(0U))); } } }
//============================================================================== // OnEnumerationResponse() // // Handles host enumeration responses, and connects to the returned session. //============================================================================== void CDarkPeer::OnEnumerationResponse(PDPNMSG_ENUM_HOSTS_RESPONSE pEnumHostsResponseMsg) { #if (GAME == GAME_THIEF || GAME == GAME_DROMED) if (!g_ConnectAttempt.IsActive()) { return; } #endif HRESULT hRes; const DPN_APPLICATION_DESC* pAppDesc = pEnumHostsResponseMsg->pApplicationDescription; #if (GAME == GAME_THIEF || GAME == GAME_DROMED) m_pSessionMgr->SetSessionInfo(pEnumHostsResponseMsg->pApplicationDescription); const SessionInfo& info = GetSessionInfo(); if (info.build != TMP_BUILD) { ConPrintF("Server version (%d) does not match client version. Connection failed.", info.build); CancelEnumeration(); return; } NString sessName = pEnumHostsResponseMsg->pApplicationDescription->pwszSessionName; ConPrintF("Game found: %s Players: %d/%d Build: %d.", sessName.Str(), pAppDesc->dwCurrentPlayers, pAppDesc->dwMaxPlayers, info.build); #endif hRes = SetPlayerInfo(); if (FAILED(hRes)) return Log.Print("Failed to set peer info."); // Set the password, if we have one if (g_ConnectAttempt.GetPassword()) { (WCHAR*)pAppDesc->pwszPassword = (WCHAR*)g_ConnectAttempt.GetPassword(); } hRes = m_pDP->Connect(pAppDesc, pEnumHostsResponseMsg->pAddressSender, pEnumHostsResponseMsg->pAddressDevice, NULL, NULL, NULL, 0, this, NULL, NULL, DPNCONNECT_SYNC); g_ConnectAttempt.Clear(); switch (hRes) { case DPN_OK: #ifdef ALLOW_LATE_JOINS if (info.gameStarted) { g_bNeedSnapshot = true; CNetMsg_RequestSnapshot msg; DbgPrint("Requesting snapshot"); g_pNetMan->m_numStartedSynch = g_pNetMan->NumPlayers(); // 8/8/10 //g_pDarkNet->GetSessionManager()->GetApplicationDesc()->dwCurrentPlayers - 1; DbgPrint("Other players: %d", g_pNetMan->m_numStartedSynch); cNetManagerFns::_LoopFunc((void*)0x006C9420, kMsgBeginFrame, NULL); SendToHost((void*)&msg, sizeof(CNetMsg_RequestSnapshot), DPNSEND_GUARANTEED); } #endif break; // Connection successful case DPNERR_INVALIDPASSWORD: ConPrintF("Incorrect password."); CancelEnumeration(); break; case DPNERR_SESSIONFULL: ConPrintF("The server is full."); CancelEnumeration(); break; case DPNERR_HOSTREJECTEDCONNECTION: ConPrintF("Cannot join server: the host has already started the mission."); CancelEnumeration(); break; default: ConPrintF("Failed to connect to server. (%x)", DPlayErrorToString(hRes)); // Unknown error CancelEnumeration(); } }