MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / OnAfterTransition

Method OnAfterTransition

Sources/Jazz2/UI/Menu/ServerSelectSection.cpp:675–726  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

673 }
674
675 void ServerSelectSection::OnAfterTransition()
676 {
677 if (_isConnecting) {
678 return;
679 }
680
681 _isConnecting = true;
682
683#if defined(DEATH_TARGET_EMSCRIPTEN) && defined(WITH_WEBSOCKET)
684 // On Emscripten, always connect via WebSocket
685 StringView firstEndpoint = _selectedServer.EndpointString;
686 firstEndpoint = firstEndpoint.prefix(firstEndpoint.findOr('|', firstEndpoint.end()).begin());
687
688 String wsUrl;
689 if (_selectedServer.WsPort != 0) {
690 // Server from list: construct ws[s]://host:WsPort from the ENet endpoint
691 StringView host; std::uint16_t enetPort;
692 if (Jazz2::Multiplayer::NetworkManagerBase::TrySplitAddressAndPort(firstEndpoint, host, enetPort)) {
693 StringView protocol = (_selectedServer.WsSecure ? "wss://"_s : "ws://"_s);
694 char portBuf[8];
695 std::size_t portLen = formatInto(portBuf, "{}", (std::int32_t)_selectedServer.WsPort);
696 bool isIpv6 = host.contains(':');
697 if (isIpv6) {
698 wsUrl = protocol + "["_s + host + "]:"_s + StringView(portBuf, portLen);
699 } else {
700 wsUrl = protocol + host + ":"_s + StringView(portBuf, portLen);
701 }
702 }
703 }
704 if (wsUrl.empty()) {
705 // Manual IP entry or fallback: wrap in ws:// if not already a WebSocket URL
706 if (!firstEndpoint.hasPrefix("ws://"_s) && !firstEndpoint.hasPrefix("wss://"_s)) {
707 // Bare IPv6 (more than one colon, no brackets yet) needs to be enclosed in [...]
708 StringView host; std::uint16_t port;
709 Jazz2::Multiplayer::NetworkManagerBase::TrySplitAddressAndPort(firstEndpoint, host, port);
710 bool isIpv6 = host.contains(':');
711 if (isIpv6) {
712 char portBuf[12] {};
713 std::size_t portLen = (port != 0 ? formatInto(portBuf, ":{}", (std::int32_t)port) : 0);
714 wsUrl = "wss://["_s + host + "]"_s + StringView(portBuf, portLen);
715 } else {
716 wsUrl = "wss://"_s + firstEndpoint;
717 }
718 } else {
719 wsUrl = firstEndpoint;
720 }
721 }
722 _root->ConnectToServer(wsUrl, 0);
723#else
724 _root->ConnectToServer(_selectedServer.EndpointString, 0);
725#endif
726 }
727
728 void ServerSelectSection::EnsureVisibleSelected(std::int32_t offset)
729 {

Callers

nothing calls this directly

Calls 9

formatIntoFunction · 0.85
prefixMethod · 0.45
beginMethod · 0.45
findOrMethod · 0.45
endMethod · 0.45
containsMethod · 0.45
emptyMethod · 0.45
hasPrefixMethod · 0.45
ConnectToServerMethod · 0.45

Tested by

no test coverage detected