Move OnPuncherConnect to C4Network2

All the other puncher handling functions are there as well.
alut-include-path
Lukas Werling 2017-03-21 16:55:58 +01:00
parent 70ad55ddf1
commit d4bb760b17
4 changed files with 24 additions and 25 deletions

View File

@ -1038,6 +1038,28 @@ C4NetpuncherID::value& C4Network2::getNetpuncherGameID(C4NetIO::HostAddress::Add
return NetpuncherGameID.v4;
}
void C4Network2::OnPuncherConnect(C4NetIO::addr_t addr)
{
// NAT punching is only relevant for IPv4, so convert here to show a proper address.
auto maybe_v4 = addr.AsIPv4();
Application.InteractiveThread.ThreadLogS("Adding address from puncher: %s", maybe_v4.ToString().getData());
// Add for local client
C4Network2Client *pLocal = Clients.GetLocal();
if (pLocal)
{
pLocal->AddAddr(C4Network2Address(maybe_v4, P_UDP), true);
// If the outside port matches the inside port, there is no port translation and the
// TCP address will probably work as well.
if (addr.GetPort() == Config.Network.PortUDP && Config.Network.PortTCP > 0)
{
maybe_v4.SetPort(Config.Network.PortTCP);
pLocal->AddAddr(C4Network2Address(maybe_v4, P_TCP), true);
}
// Do not ::Network.InvalidateReference(); yet, we're expecting an ID from the netpuncher
}
}
void C4Network2::InitPuncher()
{
// We have an internet connection, so let's punch the puncher server here in order to open an udp port

View File

@ -258,6 +258,7 @@ public:
void HandlePacket(char cStatus, const C4PacketBase *pBasePkt, C4Network2IOConnection *pConn);
void HandleLobbyPacket(char cStatus, const C4PacketBase *pBasePkt, C4Network2IOConnection *pConn);
bool HandlePuncherPacket(C4NetpuncherPacket::uptr, C4NetIO::HostAddress::AddressFamily family);
void OnPuncherConnect(C4NetIO::addr_t addr);
// runtime join stuff
void OnGameSynchronized();

View File

@ -506,7 +506,7 @@ bool C4Network2IO::OnConn(const C4NetIO::addr_t &PeerAddr, const C4NetIO::addr_t
{
// got an address?
if (pOwnAddr)
OnPuncherConnect(*pOwnAddr);
::Network.OnPuncherConnect(*pOwnAddr);
return true;
}
@ -1290,27 +1290,6 @@ void C4Network2IO::SendConnPackets()
}
void C4Network2IO::OnPuncherConnect(C4NetIO::addr_t addr)
{
// NAT punching is only relevant for IPv4, so convert here to show a proper address.
auto maybe_v4 = addr.AsIPv4();
Application.InteractiveThread.ThreadLogS("Adding address from puncher: %s", maybe_v4.ToString().getData());
// Add for local client
C4Network2Client *pLocal = ::Network.Clients.GetLocal();
if (pLocal)
{
pLocal->AddAddr(C4Network2Address(maybe_v4, P_UDP), true);
// If the outside port matches the inside port, there is no port translation and the
// TCP address will probably work as well.
if (addr.GetPort() == Config.Network.PortUDP && Config.Network.PortTCP > 0)
{
maybe_v4.SetPort(Config.Network.PortTCP);
pLocal->AddAddr(C4Network2Address(maybe_v4, P_TCP), true);
}
// Do not ::Network.InvalidateReference(); yet, we're expecting an ID from the netpuncher
}
}
// *** C4Network2IOConnection
C4Network2IOConnection::C4Network2IOConnection()

View File

@ -196,9 +196,6 @@ protected:
void CheckTimeout();
void GenerateStatistics(int iInterval);
void SendConnPackets();
// puncher
void OnPuncherConnect(C4NetIO::addr_t addr);
};
enum C4Network2IOConnStatus