MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / Receive_GC_STUN_CONNECT

Method Receive_GC_STUN_CONNECT

src/network/network_coordinator.cpp:328–360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

326}
327
328bool ClientNetworkCoordinatorSocketHandler::Receive_GC_STUN_CONNECT(Packet &p)
329{
330 std::string token = p.Recv_string(NETWORK_TOKEN_LENGTH);
331 uint8_t tracking_number = p.Recv_uint8();
332 uint8_t family = p.Recv_uint8();
333 std::string host = p.Recv_string(NETWORK_HOSTNAME_PORT_LENGTH);
334 uint16_t port = p.Recv_uint16();
335
336 /* Check if we know this token. */
337 auto stun_it = this->stun_handlers.find(token);
338 if (stun_it == this->stun_handlers.end()) return true;
339 auto family_it = stun_it->second.find(family);
340 if (family_it == stun_it->second.end()) return true;
341
342 /* Ensure all other pending connection attempts are killed. */
343 if (this->game_connecter != nullptr) {
344 this->game_connecter->Kill();
345 this->game_connecter = nullptr;
346 }
347
348 /* We now mark the connection as closed, but we do not really close the
349 * socket yet. We do this when the NetworkReuseStunConnecter is connected.
350 * This prevents any NAT to already remove the route while we create the
351 * second connection on top of the first. */
352 family_it->second->CloseConnection(false);
353
354 /* Connect to our peer from the same local address as we use for the
355 * STUN server. This means that if there is any NAT in the local network,
356 * the public ip:port is still pointing to the local address, and as such
357 * a connection can be established. */
358 this->game_connecter = TCPConnecter::Create<NetworkReuseStunConnecter>(host, port, family_it->second->local_addr, std::move(token), tracking_number, family);
359 return true;
360}
361
362bool ClientNetworkCoordinatorSocketHandler::Receive_GC_NEWGRF_LOOKUP(Packet &p)
363{

Callers

nothing calls this directly

Calls 7

Recv_stringMethod · 0.80
Recv_uint8Method · 0.80
Recv_uint16Method · 0.80
findMethod · 0.45
endMethod · 0.45
KillMethod · 0.45
CloseConnectionMethod · 0.45

Tested by

no test coverage detected