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

Method ConnectToServer

src/network/network_coordinator.cpp:526–550  ·  view source on GitHub ↗

* Join a server based on an invite code. * @param invite_code The invite code of the server to connect to. * @param connecter The connecter of the request. */

Source from the content-addressed store, hash-verified

524 * @param connecter The connecter of the request.
525 */
526void ClientNetworkCoordinatorSocketHandler::ConnectToServer(std::string_view invite_code, TCPServerConnecter *connecter)
527{
528 assert(invite_code.starts_with("+"));
529
530 if (this->connecter_pre.find(invite_code) != this->connecter_pre.end()) {
531 /* If someone is hammering the refresh key, one can sent out two
532 * requests for the same invite code. There isn't really a great way
533 * of handling this, so just ignore this request. */
534 connecter->SetFailure();
535 return;
536 }
537
538 /* Initially we store based on invite code; on first reply we know the
539 * token, and will start using that key instead. */
540 this->connecter_pre[std::string(invite_code)] = connecter;
541
542 this->Connect();
543
544 auto p = std::make_unique<Packet>(this, PACKET_COORDINATOR_CLIENT_CONNECT);
545 p->Send_uint8(NETWORK_COORDINATOR_VERSION);
546 p->Send_string(invite_code);
547
548 Debug(net, 9, "Coordinator::SendConnectToClient({})", invite_code);
549 this->SendPacket(std::move(p));
550}
551
552/**
553 * Callback from a Connecter to let the Game Coordinator know the connection failed.

Callers 1

TCPServerConnecterMethod · 0.80

Calls 8

ConnectMethod · 0.95
stringFunction · 0.85
SetFailureMethod · 0.80
Send_stringMethod · 0.80
findMethod · 0.45
endMethod · 0.45
Send_uint8Method · 0.45
SendPacketMethod · 0.45

Tested by

no test coverage detected