From b7e54e3fb50ceac8d0ceb2afbd03191584c9584f Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Tue, 3 Feb 2026 01:29:57 +0100 Subject: [PATCH 1/3] feat(lanapi): Add function to look up host game by IP address. --- Core/GameEngine/Include/GameNetwork/LANAPI.h | 1 + Core/GameEngine/Source/GameNetwork/LANAPI.cpp | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Core/GameEngine/Include/GameNetwork/LANAPI.h b/Core/GameEngine/Include/GameNetwork/LANAPI.h index 9ea41bb6463..76aa309e150 100644 --- a/Core/GameEngine/Include/GameNetwork/LANAPI.h +++ b/Core/GameEngine/Include/GameNetwork/LANAPI.h @@ -198,6 +198,7 @@ class LANAPI : public LANAPIInterface // Misc utility functions virtual LANGameInfo * LookupGame( UnicodeString gameName ); ///< return a pointer to a game we know about virtual LANGameInfo * LookupGameByListOffset( Int offset ); ///< return a pointer to a game we know about + virtual LANGameInfo * LookupGameByHost( UnsignedInt hostIP ); ///< return a pointer to a game we know about virtual LANPlayer * LookupPlayer( UnsignedInt playerIP ); ///< return a pointer to a player we know about virtual Bool SetLocalIP( UnsignedInt localIP ); ///< For multiple NIC machines virtual void SetLocalIP( AsciiString localIP ); ///< For multiple NIC machines diff --git a/Core/GameEngine/Source/GameNetwork/LANAPI.cpp b/Core/GameEngine/Source/GameNetwork/LANAPI.cpp index 6c4ebe15b43..0bd09a4ef2d 100644 --- a/Core/GameEngine/Source/GameNetwork/LANAPI.cpp +++ b/Core/GameEngine/Source/GameNetwork/LANAPI.cpp @@ -1112,6 +1112,27 @@ LANGameInfo * LANAPI::LookupGameByListOffset( Int offset ) return theGame; // null means we didn't find anything. } +LANGameInfo * LANAPI::LookupGameByHost( UnsignedInt hostIP ) +{ + LANGameInfo *latestGame = m_games; + LANGameInfo *theGame = m_games; + + // search through games to find the latest game from the host in case there are multiple + while (theGame) + { + if (theGame->getHostIP() == hostIP && theGame->getLastHeard() > latestGame->getLastHeard()) + latestGame = theGame; + + theGame = theGame->getNext(); + } + + // sanity check to verify if latest game actually exists and belongs to the host + if (latestGame && latestGame->getHostIP() == hostIP) + return latestGame; + + return nullptr; +} + void LANAPI::removeGame( LANGameInfo *game ) { LANGameInfo *g = m_games; From fc7c9e8b7bb435e895162d176dc84fefc1fc77a5 Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Wed, 4 Feb 2026 21:57:01 +0100 Subject: [PATCH 2/3] Applied feedback - simplified logic. --- Core/GameEngine/Source/GameNetwork/LANAPI.cpp | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Core/GameEngine/Source/GameNetwork/LANAPI.cpp b/Core/GameEngine/Source/GameNetwork/LANAPI.cpp index 0bd09a4ef2d..03a99fa76a5 100644 --- a/Core/GameEngine/Source/GameNetwork/LANAPI.cpp +++ b/Core/GameEngine/Source/GameNetwork/LANAPI.cpp @@ -1112,25 +1112,21 @@ LANGameInfo * LANAPI::LookupGameByListOffset( Int offset ) return theGame; // null means we didn't find anything. } -LANGameInfo * LANAPI::LookupGameByHost( UnsignedInt hostIP ) +LANGameInfo* LANAPI::LookupGameByHost(UnsignedInt hostIP) { - LANGameInfo *latestGame = m_games; - LANGameInfo *theGame = m_games; + LANGameInfo* lastGame = nullptr; + UnsignedInt lastHeard = 0; - // search through games to find the latest game from the host in case there are multiple - while (theGame) + for (LANGameInfo* game = m_games; game; game = game->getNext()) { - if (theGame->getHostIP() == hostIP && theGame->getLastHeard() > latestGame->getLastHeard()) - latestGame = theGame; - - theGame = theGame->getNext(); + if (game->getHostIP() == hostIP && game->getLastHeard() >= lastHeard) + { + lastGame = game; + lastHeard = game->getLastHeard(); + } } - // sanity check to verify if latest game actually exists and belongs to the host - if (latestGame && latestGame->getHostIP() == hostIP) - return latestGame; - - return nullptr; + return lastGame; } void LANAPI::removeGame( LANGameInfo *game ) From bc8ae47fc3015d6e4b1c30c16f4c006dce5df769 Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Wed, 4 Feb 2026 23:31:11 +0100 Subject: [PATCH 3/3] Added function to 'LANAPIInterface' interface class. Improved function comments. --- Core/GameEngine/Include/GameNetwork/LANAPI.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Core/GameEngine/Include/GameNetwork/LANAPI.h b/Core/GameEngine/Include/GameNetwork/LANAPI.h index 76aa309e150..bf488bd44f0 100644 --- a/Core/GameEngine/Include/GameNetwork/LANAPI.h +++ b/Core/GameEngine/Include/GameNetwork/LANAPI.h @@ -130,6 +130,7 @@ class LANAPIInterface : public SubsystemInterface // Misc utility functions virtual LANGameInfo * LookupGame( UnicodeString gameName ) = 0; ///< return a pointer to a game we know about virtual LANGameInfo * LookupGameByListOffset( Int offset ) = 0; ///< return a pointer to a game we know about + virtual LANGameInfo * LookupGameByHost( UnsignedInt hostIP ) = 0; ///< return a pointer to the most recent game associated to the host IP address virtual Bool SetLocalIP( UnsignedInt localIP ) = 0; ///< For multiple NIC machines virtual void SetLocalIP( AsciiString localIP ) = 0; ///< For multiple NIC machines virtual Bool AmIHost( void ) = 0; ///< Am I hosting a game? @@ -198,7 +199,7 @@ class LANAPI : public LANAPIInterface // Misc utility functions virtual LANGameInfo * LookupGame( UnicodeString gameName ); ///< return a pointer to a game we know about virtual LANGameInfo * LookupGameByListOffset( Int offset ); ///< return a pointer to a game we know about - virtual LANGameInfo * LookupGameByHost( UnsignedInt hostIP ); ///< return a pointer to a game we know about + virtual LANGameInfo * LookupGameByHost( UnsignedInt hostIP ); ///< return a pointer to the most recent game associated to the host IP address virtual LANPlayer * LookupPlayer( UnsignedInt playerIP ); ///< return a pointer to a player we know about virtual Bool SetLocalIP( UnsignedInt localIP ); ///< For multiple NIC machines virtual void SetLocalIP( AsciiString localIP ); ///< For multiple NIC machines