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

Method ConnectSuccess

src/network/network_coordinator.cpp:580–612  ·  view source on GitHub ↗

* Callback from a Connecter to let the Game Coordinator know the connection * to the game server is established. * @param token Token of the connecter that succeeded. * @param sock The socket that the connecter can now use. */

Source from the content-addressed store, hash-verified

578 * @param sock The socket that the connecter can now use.
579 */
580void ClientNetworkCoordinatorSocketHandler::ConnectSuccess(std::string_view token, SOCKET sock, NetworkAddress &address)
581{
582 assert(sock != INVALID_SOCKET);
583
584 /* Connecter will destroy itself. */
585 this->game_connecter = nullptr;
586
587 if (_network_server) {
588 if (!ServerNetworkGameSocketHandler::ValidateClient(sock, address)) return;
589 Debug(net, 3, "[{}] Client connected from {} on frame {}", ServerNetworkGameSocketHandler::GetName(), address.GetHostname(), _frame_counter);
590 ServerNetworkGameSocketHandler::AcceptConnection(sock, address);
591 } else {
592 /* The client informs the Game Coordinator about the success. The server
593 * doesn't have to, as it is implied by the client telling. */
594 auto p = std::make_unique<Packet>(this, PACKET_COORDINATOR_CLIENT_CONNECTED);
595 p->Send_uint8(NETWORK_COORDINATOR_VERSION);
596 p->Send_string(token);
597 Debug(net, 9, "Coordinator::SendConnectSuccess({})", token);
598 this->SendPacket(std::move(p));
599
600 /* Find the connecter; it can happen it no longer exist, in cases where
601 * we aborted the connect but the Game Coordinator was already in the
602 * processes of connecting us. */
603 auto connecter_it = this->connecter.find(token);
604 if (connecter_it != this->connecter.end()) {
605 connecter_it->second.second->SetConnected(sock);
606 this->connecter.erase(connecter_it);
607 }
608 }
609
610 /* Close all remaining connections. */
611 this->CloseToken(token);
612}
613
614/**
615 * Callback from the STUN connecter to inform the Game Coordinator about the

Callers 3

OnConnectMethod · 0.80
OnConnectMethod · 0.80

Calls 8

CloseTokenMethod · 0.95
Send_stringMethod · 0.80
SetConnectedMethod · 0.80
Send_uint8Method · 0.45
SendPacketMethod · 0.45
findMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected