* Join a client to the server at with the given connection string. * The default for the passwords is \c nullptr. When the server needs a * password and none is given, the user is asked to enter the password in the GUI. * This function will return false whenever some information required to join is not * correct such as the company number or the client's name, or when there is not * networkin
| 784 | * @return Whether the join has started. |
| 785 | */ |
| 786 | bool NetworkClientConnectGame(std::string_view connection_string, CompanyID default_company, const std::string &join_server_password) |
| 787 | { |
| 788 | Debug(net, 9, "NetworkClientConnectGame(): connection_string={}", connection_string); |
| 789 | |
| 790 | CompanyID join_as = default_company; |
| 791 | std::string resolved_connection_string = ServerAddress::Parse(connection_string, NETWORK_DEFAULT_PORT, &join_as).connection_string; |
| 792 | |
| 793 | if (!_network_available) return false; |
| 794 | if (!NetworkValidateOurClientName()) return false; |
| 795 | |
| 796 | _network_join.connection_string = std::move(resolved_connection_string); |
| 797 | _network_join.company = join_as; |
| 798 | _network_join.server_password = join_server_password; |
| 799 | |
| 800 | if (_game_mode == GM_MENU) { |
| 801 | /* From the menu we can immediately continue with the actual join. */ |
| 802 | NetworkClientJoinGame(); |
| 803 | } else { |
| 804 | /* When already playing a game, first go back to the main menu. This |
| 805 | * disconnects the user from the current game, meaning we can safely |
| 806 | * load in the new. After all, there is little point in continuing to |
| 807 | * play on a server if we are connecting to another one. |
| 808 | */ |
| 809 | _switch_mode = SM_JOIN_GAME; |
| 810 | } |
| 811 | return true; |
| 812 | } |
| 813 | |
| 814 | /** |
| 815 | * Actually perform the joining to the server. Use #NetworkClientConnectGame |
no test coverage detected