* 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. */
| 524 | * @param connecter The connecter of the request. |
| 525 | */ |
| 526 | void 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. |
no test coverage detected