Skip to content

Commit 1053c58

Browse files
committed
Add --connect-now6 for ipv6 connection
1 parent ab56a4f commit 1053c58

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/main.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,9 @@ void cmdLineHelp()
612612
" --connect-now=ip Connect to a server with IP known now\n"
613613
" (in format x.x.x.x:xxx(port)), the port should be its\n"
614614
" public port.\n"
615+
" --connect-now6=ip Connect to a server with IPV6 known now\n"
616+
" (in format [x:x:x:x:x:x:x:x]:xxx(port)), the port should be its\n"
617+
" public port.\n"
615618
" --server-id=n Server id in stk addons for --connect-now.\n"
616619
" --network-ai=n Numbers of AI for connecting to linear race server, used\n"
617620
" together with --connect-now.\n"
@@ -1323,7 +1326,11 @@ int handleCmdLine(bool has_server_config, bool has_parent_process)
13231326
}
13241327
}
13251328

1326-
if (CommandLine::has("--connect-now", &s))
1329+
std::string ipv4;
1330+
std::string ipv6;
1331+
bool has_ipv4 = CommandLine::has("--connect-now", &ipv4);
1332+
bool has_ipv6 = CommandLine::has("--connect-now6", &ipv6);
1333+
if (has_ipv4 || has_ipv6)
13271334
{
13281335
NetworkConfig::get()->setIsServer(false);
13291336
if (CommandLine::has("--network-ai", &n))
@@ -1343,10 +1350,26 @@ int handleCmdLine(bool has_server_config, bool has_parent_process)
13431350
input_manager->getDeviceManager()->getLatestUsedDevice(),
13441351
PlayerManager::getCurrentPlayer(), PLAYER_DIFFICULTY_NORMAL);
13451352
}
1346-
TransportAddress server_addr(s);
1353+
std::string fixed_ipv6 = StringUtils::findAndReplace(ipv6, "[", " ");
1354+
fixed_ipv6 = StringUtils::findAndReplace(fixed_ipv6, "]", " ");
1355+
auto split_ipv6 = StringUtils::split(fixed_ipv6, ' ');
1356+
std::string ipv6_port;
1357+
if (split_ipv6.size() == 3)
1358+
{
1359+
ipv4 = "0.0.0.1" + split_ipv6[2];
1360+
fixed_ipv6 = split_ipv6[1];
1361+
}
1362+
else
1363+
fixed_ipv6.clear();
1364+
TransportAddress server_addr(ipv4);
13471365
auto server = std::make_shared<Server>(0,
13481366
StringUtils::utf8ToWide(server_addr.toString()), 0, 0, 0, 0,
13491367
server_addr, !server_password.empty(), false);
1368+
if (!fixed_ipv6.empty())
1369+
{
1370+
server->setIPV6Address(fixed_ipv6);
1371+
server->setIPV6Connection(true);
1372+
}
13501373
NetworkConfig::get()->doneAddingNetworkPlayers();
13511374
if (server_id != 0)
13521375
{

0 commit comments

Comments
 (0)