Skip to content

Commit 5d135a5

Browse files
committed
bugfix: Always allow players to join a LAN room if there is an open slot
1 parent 04b968f commit 5d135a5

File tree

2 files changed

+46
-88
lines changed

2 files changed

+46
-88
lines changed

Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -307,55 +307,34 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
307307
}
308308
}
309309

310-
// See if there's room
311-
// First get the number of players currently in the room.
312-
Int numPlayers = 0;
313-
for (player = 0; player < MAX_SLOTS; ++player)
310+
for (player = 0; canJoin && player<MAX_SLOTS; ++player)
314311
{
315-
if (m_currentGame->getLANSlot(player)->isOccupied()
316-
&& !(m_currentGame->getLANSlot(player)->getPlayerTemplate() == PLAYERTEMPLATE_OBSERVER))
312+
if (m_currentGame->getLANSlot(player)->isOpen())
317313
{
318-
++numPlayers;
319-
}
320-
}
314+
// OK, add him in.
315+
reply.LANMessageType = LANMessage::MSG_JOIN_ACCEPT;
316+
wcsncpy(reply.GameJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength);
317+
reply.GameJoined.gameName[g_lanGameNameLength] = 0;
318+
reply.GameJoined.slotPosition = player;
319+
reply.GameJoined.gameIP = m_localIP;
320+
reply.GameJoined.playerIP = senderIP;
321+
322+
LANGameSlot newSlot;
323+
newSlot.setState(SLOT_PLAYER, UnicodeString(msg->name));
324+
newSlot.setIP(senderIP);
325+
newSlot.setPort(NETWORK_BASE_PORT_NUMBER);
326+
newSlot.setLastHeard(timeGetTime());
327+
newSlot.setSerial(msg->GameToJoin.serial);
328+
m_currentGame->setSlot(player,newSlot);
329+
DEBUG_LOG(("LANAPI::handleRequestJoin - added player %ls at ip 0x%08x to the game", msg->name, senderIP));
330+
331+
OnPlayerJoin(player, UnicodeString(msg->name));
332+
responseIP = 0;
321333

322-
// now get the number of starting spots on the map.
323-
Int numStartingSpots = MAX_SLOTS;
324-
const MapMetaData *md = TheMapCache->findMap(m_currentGame->getMap());
325-
if (md != NULL)
326-
{
327-
numStartingSpots = md->m_numPlayers;
328-
}
329-
330-
if (numPlayers < numStartingSpots) {
331-
for (player = 0; canJoin && player<MAX_SLOTS; ++player)
332-
{
333-
if (m_currentGame->getLANSlot(player)->isOpen())
334-
{
335-
// OK, add him in.
336-
reply.LANMessageType = LANMessage::MSG_JOIN_ACCEPT;
337-
wcsncpy(reply.GameJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength);
338-
reply.GameJoined.gameName[g_lanGameNameLength] = 0;
339-
reply.GameJoined.slotPosition = player;
340-
reply.GameJoined.gameIP = m_localIP;
341-
reply.GameJoined.playerIP = senderIP;
342-
343-
LANGameSlot newSlot;
344-
newSlot.setState(SLOT_PLAYER, UnicodeString(msg->name));
345-
newSlot.setIP(senderIP);
346-
newSlot.setPort(NETWORK_BASE_PORT_NUMBER);
347-
newSlot.setLastHeard(timeGetTime());
348-
newSlot.setSerial(msg->GameToJoin.serial);
349-
m_currentGame->setSlot(player,newSlot);
350-
DEBUG_LOG(("LANAPI::handleRequestJoin - added player %ls at ip 0x%08x to the game", msg->name, senderIP));
351-
352-
OnPlayerJoin(player, UnicodeString(msg->name));
353-
responseIP = 0;
354-
355-
break;
356-
}
334+
break;
357335
}
358336
}
337+
359338
if (canJoin && player == MAX_SLOTS)
360339
{
361340
reply.LANMessageType = LANMessage::MSG_JOIN_DENY;

GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -308,55 +308,34 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP )
308308
}
309309
}
310310

311-
// See if there's room
312-
// First get the number of players currently in the room.
313-
Int numPlayers = 0;
314-
for (player = 0; player < MAX_SLOTS; ++player)
311+
for (player = 0; canJoin && player<MAX_SLOTS; ++player)
315312
{
316-
if (m_currentGame->getLANSlot(player)->isOccupied()
317-
&& !(m_currentGame->getLANSlot(player)->getPlayerTemplate() == PLAYERTEMPLATE_OBSERVER))
313+
if (m_currentGame->getLANSlot(player)->isOpen())
318314
{
319-
++numPlayers;
320-
}
321-
}
315+
// OK, add him in.
316+
reply.LANMessageType = LANMessage::MSG_JOIN_ACCEPT;
317+
wcsncpy(reply.GameJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength);
318+
reply.GameJoined.gameName[g_lanGameNameLength] = 0;
319+
reply.GameJoined.slotPosition = player;
320+
reply.GameJoined.gameIP = m_localIP;
321+
reply.GameJoined.playerIP = senderIP;
322+
323+
LANGameSlot newSlot;
324+
newSlot.setState(SLOT_PLAYER, UnicodeString(msg->name));
325+
newSlot.setIP(senderIP);
326+
newSlot.setPort(NETWORK_BASE_PORT_NUMBER);
327+
newSlot.setLastHeard(timeGetTime());
328+
newSlot.setSerial(msg->GameToJoin.serial);
329+
m_currentGame->setSlot(player,newSlot);
330+
DEBUG_LOG(("LANAPI::handleRequestJoin - added player %ls at ip 0x%08x to the game", msg->name, senderIP));
331+
332+
OnPlayerJoin(player, UnicodeString(msg->name));
333+
responseIP = 0;
322334

323-
// now get the number of starting spots on the map.
324-
Int numStartingSpots = MAX_SLOTS;
325-
const MapMetaData *md = TheMapCache->findMap(m_currentGame->getMap());
326-
if (md != NULL)
327-
{
328-
numStartingSpots = md->m_numPlayers;
329-
}
330-
331-
if (numPlayers < numStartingSpots) {
332-
for (player = 0; canJoin && player<MAX_SLOTS; ++player)
333-
{
334-
if (m_currentGame->getLANSlot(player)->isOpen())
335-
{
336-
// OK, add him in.
337-
reply.LANMessageType = LANMessage::MSG_JOIN_ACCEPT;
338-
wcsncpy(reply.GameJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength);
339-
reply.GameJoined.gameName[g_lanGameNameLength] = 0;
340-
reply.GameJoined.slotPosition = player;
341-
reply.GameJoined.gameIP = m_localIP;
342-
reply.GameJoined.playerIP = senderIP;
343-
344-
LANGameSlot newSlot;
345-
newSlot.setState(SLOT_PLAYER, UnicodeString(msg->name));
346-
newSlot.setIP(senderIP);
347-
newSlot.setPort(NETWORK_BASE_PORT_NUMBER);
348-
newSlot.setLastHeard(timeGetTime());
349-
newSlot.setSerial(msg->GameToJoin.serial);
350-
m_currentGame->setSlot(player,newSlot);
351-
DEBUG_LOG(("LANAPI::handleRequestJoin - added player %ls at ip 0x%08x to the game", msg->name, senderIP));
352-
353-
OnPlayerJoin(player, UnicodeString(msg->name));
354-
responseIP = 0;
355-
356-
break;
357-
}
335+
break;
358336
}
359337
}
338+
360339
if (canJoin && player == MAX_SLOTS)
361340
{
362341
reply.LANMessageType = LANMessage::MSG_JOIN_DENY;

0 commit comments

Comments
 (0)