From 5d135a5396eb260238fbe8a7f32980c13b6c942d Mon Sep 17 00:00:00 2001 From: Stubbjax Date: Fri, 26 Sep 2025 22:10:54 +1000 Subject: [PATCH 1/2] bugfix: Always allow players to join a LAN room if there is an open slot --- .../Source/GameNetwork/LANAPIhandlers.cpp | 67 +++++++------------ .../Source/GameNetwork/LANAPIhandlers.cpp | 67 +++++++------------ 2 files changed, 46 insertions(+), 88 deletions(-) diff --git a/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp b/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp index a492c2cfd1..1d154a0082 100644 --- a/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp +++ b/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp @@ -307,55 +307,34 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP ) } } - // See if there's room - // First get the number of players currently in the room. - Int numPlayers = 0; - for (player = 0; player < MAX_SLOTS; ++player) + for (player = 0; canJoin && playergetLANSlot(player)->isOccupied() - && !(m_currentGame->getLANSlot(player)->getPlayerTemplate() == PLAYERTEMPLATE_OBSERVER)) + if (m_currentGame->getLANSlot(player)->isOpen()) { - ++numPlayers; - } - } + // OK, add him in. + reply.LANMessageType = LANMessage::MSG_JOIN_ACCEPT; + wcsncpy(reply.GameJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength); + reply.GameJoined.gameName[g_lanGameNameLength] = 0; + reply.GameJoined.slotPosition = player; + reply.GameJoined.gameIP = m_localIP; + reply.GameJoined.playerIP = senderIP; + + LANGameSlot newSlot; + newSlot.setState(SLOT_PLAYER, UnicodeString(msg->name)); + newSlot.setIP(senderIP); + newSlot.setPort(NETWORK_BASE_PORT_NUMBER); + newSlot.setLastHeard(timeGetTime()); + newSlot.setSerial(msg->GameToJoin.serial); + m_currentGame->setSlot(player,newSlot); + DEBUG_LOG(("LANAPI::handleRequestJoin - added player %ls at ip 0x%08x to the game", msg->name, senderIP)); + + OnPlayerJoin(player, UnicodeString(msg->name)); + responseIP = 0; - // now get the number of starting spots on the map. - Int numStartingSpots = MAX_SLOTS; - const MapMetaData *md = TheMapCache->findMap(m_currentGame->getMap()); - if (md != NULL) - { - numStartingSpots = md->m_numPlayers; - } - - if (numPlayers < numStartingSpots) { - for (player = 0; canJoin && playergetLANSlot(player)->isOpen()) - { - // OK, add him in. - reply.LANMessageType = LANMessage::MSG_JOIN_ACCEPT; - wcsncpy(reply.GameJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameJoined.gameName[g_lanGameNameLength] = 0; - reply.GameJoined.slotPosition = player; - reply.GameJoined.gameIP = m_localIP; - reply.GameJoined.playerIP = senderIP; - - LANGameSlot newSlot; - newSlot.setState(SLOT_PLAYER, UnicodeString(msg->name)); - newSlot.setIP(senderIP); - newSlot.setPort(NETWORK_BASE_PORT_NUMBER); - newSlot.setLastHeard(timeGetTime()); - newSlot.setSerial(msg->GameToJoin.serial); - m_currentGame->setSlot(player,newSlot); - DEBUG_LOG(("LANAPI::handleRequestJoin - added player %ls at ip 0x%08x to the game", msg->name, senderIP)); - - OnPlayerJoin(player, UnicodeString(msg->name)); - responseIP = 0; - - break; - } + break; } } + if (canJoin && player == MAX_SLOTS) { reply.LANMessageType = LANMessage::MSG_JOIN_DENY; diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp index 9ebca7c0c6..f5069d359a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp @@ -308,55 +308,34 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP ) } } - // See if there's room - // First get the number of players currently in the room. - Int numPlayers = 0; - for (player = 0; player < MAX_SLOTS; ++player) + for (player = 0; canJoin && playergetLANSlot(player)->isOccupied() - && !(m_currentGame->getLANSlot(player)->getPlayerTemplate() == PLAYERTEMPLATE_OBSERVER)) + if (m_currentGame->getLANSlot(player)->isOpen()) { - ++numPlayers; - } - } + // OK, add him in. + reply.LANMessageType = LANMessage::MSG_JOIN_ACCEPT; + wcsncpy(reply.GameJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength); + reply.GameJoined.gameName[g_lanGameNameLength] = 0; + reply.GameJoined.slotPosition = player; + reply.GameJoined.gameIP = m_localIP; + reply.GameJoined.playerIP = senderIP; + + LANGameSlot newSlot; + newSlot.setState(SLOT_PLAYER, UnicodeString(msg->name)); + newSlot.setIP(senderIP); + newSlot.setPort(NETWORK_BASE_PORT_NUMBER); + newSlot.setLastHeard(timeGetTime()); + newSlot.setSerial(msg->GameToJoin.serial); + m_currentGame->setSlot(player,newSlot); + DEBUG_LOG(("LANAPI::handleRequestJoin - added player %ls at ip 0x%08x to the game", msg->name, senderIP)); + + OnPlayerJoin(player, UnicodeString(msg->name)); + responseIP = 0; - // now get the number of starting spots on the map. - Int numStartingSpots = MAX_SLOTS; - const MapMetaData *md = TheMapCache->findMap(m_currentGame->getMap()); - if (md != NULL) - { - numStartingSpots = md->m_numPlayers; - } - - if (numPlayers < numStartingSpots) { - for (player = 0; canJoin && playergetLANSlot(player)->isOpen()) - { - // OK, add him in. - reply.LANMessageType = LANMessage::MSG_JOIN_ACCEPT; - wcsncpy(reply.GameJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameJoined.gameName[g_lanGameNameLength] = 0; - reply.GameJoined.slotPosition = player; - reply.GameJoined.gameIP = m_localIP; - reply.GameJoined.playerIP = senderIP; - - LANGameSlot newSlot; - newSlot.setState(SLOT_PLAYER, UnicodeString(msg->name)); - newSlot.setIP(senderIP); - newSlot.setPort(NETWORK_BASE_PORT_NUMBER); - newSlot.setLastHeard(timeGetTime()); - newSlot.setSerial(msg->GameToJoin.serial); - m_currentGame->setSlot(player,newSlot); - DEBUG_LOG(("LANAPI::handleRequestJoin - added player %ls at ip 0x%08x to the game", msg->name, senderIP)); - - OnPlayerJoin(player, UnicodeString(msg->name)); - responseIP = 0; - - break; - } + break; } } + if (canJoin && player == MAX_SLOTS) { reply.LANMessageType = LANMessage::MSG_JOIN_DENY; From 7f487c4e617ead89b193cbef6308900c01a95de4 Mon Sep 17 00:00:00 2001 From: Stubbjax Date: Sat, 27 Sep 2025 01:42:38 +1000 Subject: [PATCH 2/2] docs: Add comments --- Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp | 1 + GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp b/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp index 1d154a0082..fe9f70ee29 100644 --- a/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp +++ b/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp @@ -307,6 +307,7 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP ) } } + // TheSuperHackers @bugfix Stubbjax 26/09/2025 Players can now join open slots regardless of starting spots on the map. for (player = 0; canJoin && playergetLANSlot(player)->isOpen()) diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp index f5069d359a..125895fd95 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp @@ -308,6 +308,7 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP ) } } + // TheSuperHackers @bugfix Stubbjax 26/09/2025 Players can now join open slots regardless of starting spots on the map. for (player = 0; canJoin && playergetLANSlot(player)->isOpen())