File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424
2525ListAddress ListAddress::Array[8 ] = {};
2626
27- bool NetHack::PortHack = true ;
27+ bool NetHack::RequirePortMatch = false ;
2828
2929u_short Tunnel::Id = 0 ;
3030u_long Tunnel::Ip = 0 ;
@@ -80,7 +80,7 @@ int WINAPI NetHack::RecvFrom(
8080 continue ;
8181
8282 // compare port
83- if (! NetHack::PortHack && src_addr->sin_port != player.Port )
83+ if (NetHack::RequirePortMatch && src_addr->sin_port != player.Port )
8484 continue ;
8585
8686 // found it, set this index to source addr
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ struct ListAddress
2727class NetHack
2828{
2929public:
30- static bool PortHack ;
30+ static bool RequirePortMatch ;
3131
3232 static int WINAPI SendTo (
3333 int sockfd,
Original file line number Diff line number Diff line change @@ -245,7 +245,7 @@ bool Spawner::StartScenario(const char* pScenarioName)
245245 }
246246
247247 { // Added Human Players
248- NetHack::PortHack = true ;
248+ NetHack::RequirePortMatch = false ;
249249 const char maxPlayers = Spawner::Config->IsCampaign ? 1 : (char )std::size (Spawner::Config->Players );
250250 for (char playerIndex = 0 ; playerIndex < maxPlayers; playerIndex++)
251251 {
@@ -274,14 +274,17 @@ bool Spawner::StartScenario(const char* pScenarioName)
274274
275275 if (playerIndex > 0 )
276276 {
277+ const auto playerPort = static_cast <u_short>(pPlayer->Port );
278+ const auto listenPort = static_cast <u_short>(Spawner::Config->ListenPort );
279+
277280 pNode->Address .sin_addr .s_addr = playerIndex;
281+ ListAddress::Array[playerIndex - 1 ].Ip = inet_addr (pPlayer->Ip );
282+ ListAddress::Array[playerIndex - 1 ].Port = htons (playerPort);
278283
279- const auto Ip = inet_addr (pPlayer->Ip );
280- const auto Port = htons ((u_short)pPlayer->Port );
281- ListAddress::Array[playerIndex - 1 ].Ip = Ip;
282- ListAddress::Array[playerIndex - 1 ].Port = Port;
283- if (Port != (u_short)Spawner::Config->ListenPort )
284- NetHack::PortHack = false ;
284+ // Accumulate this flag across all players in the loop.
285+ // Do not overwrite it on each iteration.
286+ if (playerPort != listenPort)
287+ NetHack::RequirePortMatch = true ;
285288 }
286289 }
287290
You can’t perform that action at this time.
0 commit comments