Browse Source

Fixed issues with CNetManager::getPeerCount() returning incorrect number of peers.

master
rna88 5 years ago
parent
commit
f9b49365c0
  1. 17
      examples/03.ClientManagement/main.cpp
  2. 22
      source/CNetManager.cpp

17
examples/03.ClientManagement/main.cpp

@ -85,9 +85,15 @@ public:
core::stringc message;
message = "Client number ";
message += playerId;
message += " has just connected.";
message += " has just connected. ";
message += netManager->getPeerCount();
message += " peer(s) total.";
packet << message;
netManager->sendOutPacket(packet);
std::cout << "Client number " << playerId << " connected. "
<< netManager->getPeerCount() << " peer(s) total." << std::endl;
}
}
@ -100,10 +106,15 @@ public:
core::stringc message;
message = "Client number ";
message += playerId;
message += " has just left the building.";
message += " has just left the building. ";
message += netManager->getPeerCount();
message += " peer(s) left.";
packet << message;
netManager->sendOutPacket(packet);
std::cout << "Client number " << playerId << " disconnected" << std::endl;
std::cout << "Client number " << playerId << " disconnected. "
<< netManager->getPeerCount() << " peer(s) left." << std::endl;
}
// Handle the packets, as usual.

22
source/CNetManager.cpp

@ -316,16 +316,18 @@ namespace irr
if(pData)
{
u16 disconnectingPID = pData->playerID;
if(verbose)
std::cout << "irrNetLite: Player number "
<< pData->playerID
<< disconnectingPID
<< " disconnected.\n";
if(pHandler) pHandler->onDisconnect(pData->playerID);
players[pData->playerID] = 0;
players[disconnectingPID] = 0;
delete pData;
event.peer->data = 0;
if(pHandler) pHandler->onDisconnect(disconnectingPID);
}
}
default:
@ -366,7 +368,17 @@ namespace irr
const u32 CNetManager::getPeerCount()
{
return (u32)host->peerCount;
u32 count = 0;
for (u32 i = 1; i < netParams.maxClients; ++i)
{
if (players[i])
{
++count;
}
}
return count;
}
const u16 CNetManager::getPlayerNumber()

Loading…
Cancel
Save