Skip to content

Commit 747fe19

Browse files
committed
- Reject connections from players not in the lobby (also requires a corresponding service change)
1 parent ebb69d6 commit 747fe19

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

  • GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline

GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NetworkMesh.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,49 @@ void OnSteamNetConnectionStatusChanged(SteamNetConnectionStatusChangedCallback_t
9191
// Note that we assume we will only ever receive a single connection
9292

9393
#if _DEBUG
94-
assert(pPlayerConnection->m_hSteamConnection == k_HSteamNetConnection_Invalid); // not really a bug in this code, but a bug in the test
94+
if (pPlayerConnection != nullptr)
95+
assert(pPlayerConnection->m_hSteamConnection == k_HSteamNetConnection_Invalid); // not really a bug in this code, but a bug in the test
9596
#endif
9697

97-
NetworkLog(ELogVerbosity::LOG_RELEASE, "[STEAM NETWORKING][%s] Accepting\n", pInfo->m_info.m_szConnectionDescription);
98+
NetworkLog(ELogVerbosity::LOG_RELEASE, "[STEAM NETWORKING][%s] Considering Accepting\n", pInfo->m_info.m_szConnectionDescription);
9899

99100
if (pPlayerConnection != nullptr && pInfo != nullptr)
100101
{
101102
pPlayerConnection->UpdateState(EConnectionState::CONNECTING_DIRECT, pMesh);
102103
pPlayerConnection->m_hSteamConnection = pInfo->m_hConn;
103104
}
104-
SteamNetworkingSockets()->AcceptConnection(pInfo->m_hConn);
105+
106+
// check user is in the lobby, otherwise reject
107+
auto currentLobby = NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->GetCurrentLobby();
108+
bool bPlayerIsInLobby = false;
109+
for (const auto& member : currentLobby.members)
110+
{
111+
// TODO_NGMP: Use bytes or SteamID instead... string compare is nasty
112+
if (std::to_string(member.user_id) == pInfo->m_info.m_identityRemote.GetGenericString())
113+
{
114+
bPlayerIsInLobby = true;
115+
break;
116+
}
117+
}
118+
119+
if (bPlayerIsInLobby)
120+
{
121+
NetworkLog(ELogVerbosity::LOG_RELEASE, "[STEAM NETWORKING][%s] Accepting - Player is in lobby\n", pInfo->m_info.m_szConnectionDescription);
122+
SteamNetworkingSockets()->AcceptConnection(pInfo->m_hConn);
123+
}
124+
else
125+
{
126+
NetworkLog(ELogVerbosity::LOG_RELEASE, "[STEAM NETWORKING][%s] Rejecting - Player is not in lobby\n", pInfo->m_info.m_szConnectionDescription);
127+
SteamNetworkingSockets()->CloseConnection(pInfo->m_hConn, 1000, "Player is not in lobby", false);
128+
}
129+
105130
}
106131
else
107132
{
108133
// Note that we will get notification when our own connection that
109134
// we initiate enters this state.
110135
#if _DEBUG
136+
if (pPlayerConnection != nullptr)
111137
assert(pPlayerConnection->m_hSteamConnection == pInfo->m_hConn);
112138
#endif
113139
NetworkLog(ELogVerbosity::LOG_RELEASE, "[STEAM NETWORKING][%s] Entered connecting state\n", pInfo->m_info.m_szConnectionDescription);

0 commit comments

Comments
 (0)