Skip to content

Commit f91a058

Browse files
committed
Improved LANAPI::LookupGameByHost to return latest game.
1 parent 8feddcd commit f91a058

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Core/GameEngine/Source/GameNetwork/LANAPI.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,14 +1137,23 @@ LANGameInfo * LANAPI::LookupGameByListOffset( Int offset )
11371137

11381138
LANGameInfo * LANAPI::LookupGameByHost( UnsignedInt hostIP )
11391139
{
1140-
LANGameInfo* theGame = m_games;
1140+
LANGameInfo *latestGame = m_games;
1141+
LANGameInfo *theGame = m_games;
11411142

1142-
while (theGame && theGame->getHostIP() != hostIP)
1143+
// search through games to find the last game from the host in case there are multiple
1144+
while (theGame)
11431145
{
1146+
if (theGame->getHostIP() == hostIP && theGame->getLastHeard() > latestGame->getLastHeard())
1147+
latestGame = theGame;
1148+
11441149
theGame = theGame->getNext();
11451150
}
11461151

1147-
return theGame; // NULL means we didn't find anything.
1152+
// sanity check to verify if latest game actually exists and belongs to the host
1153+
if (latestGame && latestGame->getHostIP() == hostIP)
1154+
return latestGame;
1155+
1156+
return NULL;
11481157
}
11491158

11501159
void LANAPI::removeGame( LANGameInfo *game )

0 commit comments

Comments
 (0)