| 550 | } |
| 551 | |
| 552 | void JoinServer(std::string address) |
| 553 | { |
| 554 | int32_t port = Network::kDefaultPort; |
| 555 | auto endBracketIndex = address.find(']'); |
| 556 | auto colonIndex = address.find_last_of(':'); |
| 557 | if (colonIndex != std::string::npos) |
| 558 | { |
| 559 | if (auto dotIndex = address.find('.'); endBracketIndex != std::string::npos || dotIndex != std::string::npos) |
| 560 | { |
| 561 | auto ret = std::sscanf(&address[colonIndex + 1], "%d", &port); |
| 562 | assert(ret); |
| 563 | if (ret > 0) |
| 564 | { |
| 565 | address = address.substr(0, colonIndex); |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | if (auto beginBracketIndex = address.find('['); |
| 571 | beginBracketIndex != std::string::npos && endBracketIndex != std::string::npos) |
| 572 | { |
| 573 | address = address.substr(beginBracketIndex + 1, endBracketIndex - beginBracketIndex - 1); |
| 574 | } |
| 575 | |
| 576 | if (!Network::BeginClient(address, port)) |
| 577 | { |
| 578 | ContextShowError(STR_UNABLE_TO_CONNECT_TO_SERVER, kStringIdNone, {}); |
| 579 | } |
| 580 | } |
| 581 | } // namespace OpenRCT2::Ui::Windows |
| 582 | #endif |
no test coverage detected