Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Private
4 changes: 2 additions & 2 deletions src/Spawner/NetHack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

ListAddress ListAddress::Array[8] = {};

bool NetHack::PortHack = true;
bool NetHack::RequirePortMatch = false;

u_short Tunnel::Id = 0;
u_long Tunnel::Ip = 0;
Expand Down Expand Up @@ -80,7 +80,7 @@ int WINAPI NetHack::RecvFrom(
continue;

// compare port
if (!NetHack::PortHack && src_addr->sin_port != player.Port)
if (NetHack::RequirePortMatch && src_addr->sin_port != player.Port)
continue;

// found it, set this index to source addr
Expand Down
2 changes: 1 addition & 1 deletion src/Spawner/NetHack.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct ListAddress
class NetHack
{
public:
static bool PortHack;
static bool RequirePortMatch;

static int WINAPI SendTo(
int sockfd,
Expand Down
17 changes: 10 additions & 7 deletions src/Spawner/Spawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ bool Spawner::StartScenario(const char* pScenarioName)
}

{ // Added Human Players
NetHack::PortHack = true;
NetHack::RequirePortMatch = false;
const char maxPlayers = Spawner::Config->IsCampaign ? 1 : (char)std::size(Spawner::Config->Players);
for (char playerIndex = 0; playerIndex < maxPlayers; playerIndex++)
{
Expand Down Expand Up @@ -274,14 +274,17 @@ bool Spawner::StartScenario(const char* pScenarioName)

if (playerIndex > 0)
{
const auto playerPort = static_cast<u_short>(pPlayer->Port);
const auto listenPort = static_cast<u_short>(Spawner::Config->ListenPort);

pNode->Address.sin_addr.s_addr = playerIndex;
ListAddress::Array[playerIndex - 1].Ip = inet_addr(pPlayer->Ip);
ListAddress::Array[playerIndex - 1].Port = htons(playerPort);

const auto Ip = inet_addr(pPlayer->Ip);
const auto Port = htons((u_short)pPlayer->Port);
ListAddress::Array[playerIndex - 1].Ip = Ip;
ListAddress::Array[playerIndex - 1].Port = Port;
if (Port != (u_short)Spawner::Config->ListenPort)
NetHack::PortHack = false;
// Accumulate this flag across all players in the loop.
// Do not overwrite it on each iteration.
if (playerPort != listenPort)
NetHack::RequirePortMatch = true;
}
}

Expand Down
Loading