Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "GameNetwork/GeneralsOnline/json.hpp"

// Optional field: dest keeps its default when the key is missing or null
template <typename T>
inline void JsonGetOptional(const nlohmann::json& j, const char* szKey, T& dest)
{
auto it = j.find(szKey);
if (it != j.end() && !it->is_null())
{
it->get_to(dest);
}
}

// Required field: throws when the key is missing or the wrong type
template <typename T>
inline void JsonGetRequired(const nlohmann::json& j, const char* szKey, T& dest)
{
j.at(szKey).get_to(dest);
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,16 @@ class WebSocket
// lobby ID the check was started for; a stale reply (different lobby) is ignored
int64_t m_connectivityCheckLobbyID = -1;

// when the check was sent; Tick() gives up on it after a client-side timeout
int64_t m_connectivityCheckStartMs = -1;

void SendData_StartFullMeshConnectivityCheck(std::function<void(bool, std::list<std::pair<int64_t, int64_t>>, std::string)> cbOnConnectivityCheckComplete);

void ClearConnectivityCheckCallback()
{
m_cbOnConnectivityCheckComplete = nullptr;
m_connectivityCheckLobbyID = -1;
m_connectivityCheckStartMs = -1;
}

void Tick();
Expand All @@ -215,6 +219,13 @@ class WebSocket
m_pendingSignals.push(std::move(payload));
}

// signals queued for a lobby we've since left must not reach the next one
void ClearPendingSignals()
{
std::scoped_lock<std::mutex> lock(m_pendingSignalsMutex);
m_pendingSignals = std::queue<std::vector<uint8_t>>();
}

std::queue<std::vector<uint8_t>> DrainPendingSignals()
{
std::scoped_lock<std::mutex> lock(m_pendingSignalsMutex);
Expand All @@ -224,6 +235,8 @@ class WebSocket
}

private:
CURLcode ReceiveOneFrame();

CURL* m_pCurlWS = nullptr;
CURLM* m_pMulti = nullptr;
struct curl_slist* m_pHeaders = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ class NGMP_OnlineServices_LobbyInterface

NetworkMesh* GetNetworkMeshForLobby() { return m_pLobbyMesh; }

void JoinLobby(LobbyEntry lobby, std::string strPassword);
// false when a join is already in progress and this request was dropped
bool JoinLobby(LobbyEntry lobby, std::string strPassword);

void LeaveCurrentLobby();
void ResetForMatchmakingRequeue();
Expand Down Expand Up @@ -551,6 +552,10 @@ class NGMP_OnlineServices_LobbyInterface
#endif

bool m_bAttemptingToJoinLobby = false;

// GET Lobby/{id} responses can arrive out of order; only apply ones newer than the last applied
std::atomic<uint64_t> m_LobbyUpdateRequestSeq = 0;
std::atomic<uint64_t> m_LobbyUpdateAppliedSeq = 0;
// Invalidates asynchronous callbacks left behind by an abandoned lobby join.
std::atomic<uint64_t> m_LobbyJoinGeneration = 0;
LobbyEntry m_LobbyTryingToJoin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,10 @@ static void StartPressed()

// who is missing who?
//std::list<std::pair<int64_t, int64_t>> missingConnections
GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"Connections: Missing links:"), GameMakeColor(255, 194, 15, 255), -1, -1);
if (!missingConnections.empty())
{
GadgetListBoxAddEntryText(listboxGameSetupChat, UnicodeString(L"Connections: Missing links:"), GameMakeColor(255, 194, 15, 255), -1, -1);
}
for (auto& missingPair : missingConnections)
{
bool bFoundPlayer = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,14 @@ void WOLQuickMatchMenuInit( WindowLayout *layout, void *userData )

if (!pLobbyInterface->IsInLobby())
{
Int index = GadgetListBoxAddEntryText(quickmatchTextWindow, UnicodeString(L"Could not join the match lobby, waiting for the matchmaker..."), GameSpyColor[GSCOLOR_DEFAULT], -1, -1);
GadgetListBoxSetItemData(quickmatchTextWindow, (void*)-1, index);

matchFoundTimeoutStart = 0;
matchStartCountdownLastSecond = 0;

buttonBack->winEnable(TRUE);
buttonStop->winEnable(TRUE);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,23 +266,16 @@ void OnSteamNetConnectionStatusChanged(SteamNetConnectionStatusChangedCallback_t
}
}

// the server started signalling with this peer, so accept it even if our roster is stale
if (bPlayerIsInLobby)
{
NetworkLog(ELogVerbosity::LOG_RELEASE, "[STEAM NETWORKING][%s] Accepting - Player is in lobby\n", pInfo->m_info.m_szConnectionDescription);
SteamNetworkingSockets()->AcceptConnection(pInfo->m_hConn);
}
else
{
NetworkLog(ELogVerbosity::LOG_RELEASE, "[STEAM NETWORKING][%s] Rejecting - Player is not in lobby\n", pInfo->m_info.m_szConnectionDescription);

NetworkLog(ELogVerbosity::LOG_RELEASE, "[DC] Closing connection not in lobby %lld", plrConnection.m_userID);
SteamNetworkingSockets()->CloseConnection(pInfo->m_hConn, 1000, "Player is not in lobby (Rejected)", false);

if (TheNetwork != nullptr)
{
TheNetwork->GetConnectionManager()->disconnectPlayer(plrConnection.m_userID);
}
NetworkLog(ELogVerbosity::LOG_RELEASE, "[STEAM NETWORKING][%s] Accepting - Server started signalling, roster not refreshed yet\n", pInfo->m_info.m_szConnectionDescription);
}
SteamNetworkingSockets()->AcceptConnection(pInfo->m_hConn);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,7 @@ void WebSocket::SendData_StartFullMeshConnectivityCheck(std::function<void(bool,

NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface<NGMP_OnlineServices_LobbyInterface>();
m_connectivityCheckLobbyID = pLobbyInterface != nullptr ? pLobbyInterface->GetCurrentLobby().lobbyID : -1;
m_connectivityCheckStartMs = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();

nlohmann::json j;
j["msg_id"] = EWebSocketMessageID::FULL_MESH_CONNECTIVITY_CHECK_HOST_REQUESTS_BEGIN;
Expand Down
Loading
Loading