diff options
author | Janrupf <business.janrupf@gmail.com> | 2021-05-22 17:24:37 +0200 |
---|---|---|
committer | Janrupf <business.janrupf@gmail.com> | 2021-05-22 17:24:37 +0200 |
commit | f33fe05e5febf76d8e11ccd44073d99e00946d71 (patch) | |
tree | 181aa7ca4447c4e4fcf15a90218dc54dfda41485 | |
parent | d97f13b4aacd00b7157735702fa4484317640a4f (diff) | |
download | PrismLauncher-f33fe05e5febf76d8e11ccd44073d99e00946d71.tar.gz PrismLauncher-f33fe05e5febf76d8e11ccd44073d99e00946d71.tar.bz2 PrismLauncher-f33fe05e5febf76d8e11ccd44073d99e00946d71.zip |
NOISSUE Use minecraft logic for parsing adresses
-rw-r--r-- | api/logic/minecraft/MinecraftInstance.cpp | 55 | ||||
-rw-r--r-- | application/pages/instance/InstanceSettingsPage.cpp | 3 | ||||
-rw-r--r-- | application/pages/instance/InstanceSettingsPage.ui | 19 |
3 files changed, 49 insertions, 28 deletions
diff --git a/api/logic/minecraft/MinecraftInstance.cpp b/api/logic/minecraft/MinecraftInstance.cpp index abb360f2..00ac7964 100644 --- a/api/logic/minecraft/MinecraftInstance.cpp +++ b/api/logic/minecraft/MinecraftInstance.cpp @@ -115,7 +115,6 @@ MinecraftInstance::MinecraftInstance(SettingsObjectPtr globalSettings, SettingsO // Join server on launch, this does not have a global override m_settings->registerSetting("JoinServerOnLaunch", false); m_settings->registerSetting("JoinServerOnLaunchAddress", ""); - m_settings->registerSetting("JoinServerOnLaunchPort", 25565); // DEPRECATED: Read what versions the user configuration thinks should be used m_settings->registerSetting({"IntendedVersion", "MinecraftVersion"}, ""); @@ -859,17 +858,59 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt if (m_settings->get("JoinServerOnLaunch").toBool()) { - quint16 port = m_settings->get("JoinServerOnLaunchPort").toInt(); - QString address = m_settings->get("JoinServerOnLaunchAddress").toString(); + QString fullAddress = m_settings->get("JoinServerOnLaunchAddress").toString(); + QStringList split = fullAddress.split(":"); - serverToJoin->port = port; - serverToJoin->address = address; + // The logic below replicates the exact logic minecraft uses for parsing server addresses. + // While the conversion is not lossless and eats errors, it ensures the same behavior + // within Minecraft and MultiMC when entering server addresses. + if (fullAddress.startsWith("[")) + { + int bracket = fullAddress.indexOf("]"); + if (bracket > 0) + { + QString ipv6 = fullAddress.mid(1, bracket - 1); + QString port = fullAddress.mid(bracket + 1).trimmed(); + + if (port.startsWith(":") && !ipv6.isEmpty()) + { + port = port.mid(1); + split = QStringList({ ipv6, port }); + } + else + { + split = QStringList({ipv6}); + } + } + } + + if (split.size() > 2) + { + split = QStringList({fullAddress}); + } + + QString realAddress = split[0]; + + quint16 realPort = 25565; + if (split.size() > 1) + { + bool ok; + realPort = split[1].toUInt(&ok); + + if (!ok) + { + realPort = 25565; + } + } + + serverToJoin->port = realPort; + serverToJoin->address = realAddress; - if(port == 25565) + if(realPort == 25565) { // Resolve server address to join on launch auto *step = new LookupServerAddress(pptr); - step->setLookupAddress(address); + step->setLookupAddress(realAddress); step->setOutputAddressPtr(serverToJoin); process->appendStep(step); } diff --git a/application/pages/instance/InstanceSettingsPage.cpp b/application/pages/instance/InstanceSettingsPage.cpp index ff8659c5..00fc19af 100644 --- a/application/pages/instance/InstanceSettingsPage.cpp +++ b/application/pages/instance/InstanceSettingsPage.cpp @@ -198,12 +198,10 @@ void InstanceSettingsPage::applySettings() if (joinServerOnLaunch) { m_settings->set("JoinServerOnLaunchAddress", ui->serverJoinAddress->text()); - m_settings->set("JoinServerOnLaunchPort", ui->serverJoinPort->value()); } else { m_settings->reset("JoinServerOnLaunchAddress"); - m_settings->reset("JoinServerOnLaunchPort"); } } @@ -274,7 +272,6 @@ void InstanceSettingsPage::loadSettings() ui->serverJoinGroupBox->setChecked(m_settings->get("JoinServerOnLaunch").toBool()); ui->serverJoinAddress->setText(m_settings->get("JoinServerOnLaunchAddress").toString()); - ui->serverJoinPort->setValue(m_settings->get("JoinServerOnLaunchPort").toInt()); } void InstanceSettingsPage::on_javaDetectBtn_clicked() diff --git a/application/pages/instance/InstanceSettingsPage.ui b/application/pages/instance/InstanceSettingsPage.ui index eb8ed13a..de9fa9e3 100644 --- a/application/pages/instance/InstanceSettingsPage.ui +++ b/application/pages/instance/InstanceSettingsPage.ui @@ -39,7 +39,7 @@ <enum>QTabWidget::Rounded</enum> </property> <property name="currentIndex"> - <number>0</number> + <number>4</number> </property> <widget class="QWidget" name="minecraftTab"> <attribute name="title"> @@ -483,23 +483,6 @@ <item row="0" column="1"> <widget class="QLineEdit" name="serverJoinAddress"/> </item> - <item row="1" column="0"> - <widget class="QLabel" name="serverJoinPortLabel"> - <property name="text"> - <string>Server port:</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QSpinBox" name="serverJoinPort"> - <property name="maximum"> - <number>65535</number> - </property> - <property name="value"> - <number>25565</number> - </property> - </widget> - </item> </layout> </item> </layout> |