From 2e2a5d0943a43f16c2d52a98c69323d34815cfd0 Mon Sep 17 00:00:00 2001 From: Janrupf Date: Sat, 22 May 2021 13:15:59 +0200 Subject: NOISSUE Required UI elements for setting a server --- application/pages/instance/InstanceSettingsPage.ui | 54 +++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'application') diff --git a/application/pages/instance/InstanceSettingsPage.ui b/application/pages/instance/InstanceSettingsPage.ui index 64f90fad..50c3ac6b 100644 --- a/application/pages/instance/InstanceSettingsPage.ui +++ b/application/pages/instance/InstanceSettingsPage.ui @@ -39,7 +39,7 @@ QTabWidget::Rounded - 0 + 4 @@ -453,6 +453,58 @@ + + + + Set a server to join on launch + + + true + + + false + + + + + + + + + 0 + 0 + + + + Server address: + + + + + + + + + + Server port: + + + + + + + 65535 + + + 25565 + + + + + + + + -- cgit From f0eb5b4a0c16b0ddd17ee73e7ecebae2def16df7 Mon Sep 17 00:00:00 2001 From: Janrupf Date: Sat, 22 May 2021 13:28:23 +0200 Subject: NOISSUE Register settings for setting a server --- application/pages/instance/InstanceSettingsPage.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'application') diff --git a/application/pages/instance/InstanceSettingsPage.cpp b/application/pages/instance/InstanceSettingsPage.cpp index 05041c82..ff8659c5 100644 --- a/application/pages/instance/InstanceSettingsPage.cpp +++ b/application/pages/instance/InstanceSettingsPage.cpp @@ -191,6 +191,20 @@ void InstanceSettingsPage::applySettings() m_settings->reset("ShowGameTime"); m_settings->reset("RecordGameTime"); } + + // Join server on launch + bool joinServerOnLaunch = ui->serverJoinGroupBox->isChecked(); + m_settings->set("JoinServerOnLaunch", joinServerOnLaunch); + 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"); + } } void InstanceSettingsPage::loadSettings() @@ -257,6 +271,10 @@ void InstanceSettingsPage::loadSettings() ui->gameTimeGroupBox->setChecked(m_settings->get("OverrideGameTime").toBool()); ui->showGameTime->setChecked(m_settings->get("ShowGameTime").toBool()); ui->recordGameTime->setChecked(m_settings->get("RecordGameTime").toBool()); + + 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() -- cgit From d97f13b4aacd00b7157735702fa4484317640a4f Mon Sep 17 00:00:00 2001 From: Janrupf Date: Sat, 22 May 2021 17:00:14 +0200 Subject: NOISSUE Use Vanilla logic for resolving servers --- application/pages/instance/InstanceSettingsPage.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'application') diff --git a/application/pages/instance/InstanceSettingsPage.ui b/application/pages/instance/InstanceSettingsPage.ui index 50c3ac6b..eb8ed13a 100644 --- a/application/pages/instance/InstanceSettingsPage.ui +++ b/application/pages/instance/InstanceSettingsPage.ui @@ -39,7 +39,7 @@ QTabWidget::Rounded - 4 + 0 -- cgit From f33fe05e5febf76d8e11ccd44073d99e00946d71 Mon Sep 17 00:00:00 2001 From: Janrupf Date: Sat, 22 May 2021 17:24:37 +0200 Subject: NOISSUE Use minecraft logic for parsing adresses --- application/pages/instance/InstanceSettingsPage.cpp | 3 --- application/pages/instance/InstanceSettingsPage.ui | 19 +------------------ 2 files changed, 1 insertion(+), 21 deletions(-) (limited to 'application') 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 @@ QTabWidget::Rounded - 0 + 4 @@ -483,23 +483,6 @@ - - - - Server port: - - - - - - - 65535 - - - 25565 - - - -- cgit From ea6c42a93c95e3e62d7ac984ff2cc4f461dc43dd Mon Sep 17 00:00:00 2001 From: Janrupf Date: Sat, 22 May 2021 18:07:08 +0200 Subject: NOISSUE Allow joining servers from the servers page --- application/InstancePageProvider.h | 2 +- application/LaunchController.cpp | 2 +- application/LaunchController.h | 7 +++++++ application/MultiMC.cpp | 9 +++++++-- application/MultiMC.h | 9 ++++++++- application/pages/instance/InstanceSettingsPage.ui | 2 +- application/pages/instance/ServersPage.cpp | 11 +++++++++-- application/pages/instance/ServersPage.h | 5 +++-- application/pages/instance/ServersPage.ui | 6 ++++++ 9 files changed, 43 insertions(+), 10 deletions(-) (limited to 'application') diff --git a/application/InstancePageProvider.h b/application/InstancePageProvider.h index dde36aef..3cb723c4 100644 --- a/application/InstancePageProvider.h +++ b/application/InstancePageProvider.h @@ -46,7 +46,7 @@ public: values.append(new TexturePackPage(onesix.get())); values.append(new NotesPage(onesix.get())); values.append(new WorldListPage(onesix.get(), onesix->worldList())); - values.append(new ServersPage(onesix.get())); + values.append(new ServersPage(onesix)); // values.append(new GameOptionsPage(onesix.get())); values.append(new ScreenshotsPage(FS::PathCombine(onesix->gameRoot(), "screenshots"))); values.append(new InstanceSettingsPage(onesix.get())); diff --git a/application/LaunchController.cpp b/application/LaunchController.cpp index bebc3db1..3c4491a3 100644 --- a/application/LaunchController.cpp +++ b/application/LaunchController.cpp @@ -197,7 +197,7 @@ void LaunchController::launchInstance() return; } - m_launcher = m_instance->createLaunchTask(m_session); + m_launcher = m_instance->createLaunchTask(m_session, m_serverToJoin); if (!m_launcher) { emitFailed(tr("Couldn't instantiate a launcher.")); diff --git a/application/LaunchController.h b/application/LaunchController.h index 1d879028..5f177e00 100644 --- a/application/LaunchController.h +++ b/application/LaunchController.h @@ -3,6 +3,8 @@ #include #include +#include "minecraft/launch/MinecraftServerTarget.h" + class InstanceWindow; class LaunchController: public Task { @@ -33,6 +35,10 @@ public: { m_parentWidget = widget; } + void setServerToJoin(MinecraftServerTargetPtr serverToJoin) + { + m_serverToJoin = std::move(serverToJoin); + } QString id() { return m_instance->id(); @@ -58,4 +64,5 @@ private: InstanceWindow *m_console = nullptr; AuthSessionPtr m_session; shared_qobject_ptr m_launcher; + MinecraftServerTargetPtr m_serverToJoin; }; diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 3429a377..8a81238e 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -1014,8 +1014,12 @@ bool MultiMC::openJsonEditor(const QString &filename) } } -bool MultiMC::launch(InstancePtr instance, bool online, BaseProfilerFactory *profiler) -{ +bool MultiMC::launch( + InstancePtr instance, + bool online, + BaseProfilerFactory *profiler, + MinecraftServerTargetPtr serverToJoin +) { if(m_updateRunning) { qDebug() << "Cannot launch instances while an update is running. Please try again when updates are completed."; @@ -1036,6 +1040,7 @@ bool MultiMC::launch(InstancePtr instance, bool online, BaseProfilerFactory *pro controller->setInstance(instance); controller->setOnline(online); controller->setProfiler(profiler); + controller->setServerToJoin(serverToJoin); if(window) { controller->setParentWidget(window); diff --git a/application/MultiMC.h b/application/MultiMC.h index e6588a14..57a43cb9 100644 --- a/application/MultiMC.h +++ b/application/MultiMC.h @@ -11,6 +11,8 @@ #include +#include "minecraft/launch/MinecraftServerTarget.h" + class LaunchController; class LocalPeer; class InstanceWindow; @@ -150,7 +152,12 @@ signals: void globalSettingsClosed(); public slots: - bool launch(InstancePtr instance, bool online = true, BaseProfilerFactory *profiler = nullptr); + bool launch( + InstancePtr instance, + bool online = true, + BaseProfilerFactory *profiler = nullptr, + MinecraftServerTargetPtr serverToJoin = nullptr + ); bool kill(InstancePtr instance); private slots: diff --git a/application/pages/instance/InstanceSettingsPage.ui b/application/pages/instance/InstanceSettingsPage.ui index de9fa9e3..29024b65 100644 --- a/application/pages/instance/InstanceSettingsPage.ui +++ b/application/pages/instance/InstanceSettingsPage.ui @@ -39,7 +39,7 @@ QTabWidget::Rounded - 4 + 0 diff --git a/application/pages/instance/ServersPage.cpp b/application/pages/instance/ServersPage.cpp index 8b0c655c..d63c6e70 100644 --- a/application/pages/instance/ServersPage.cpp +++ b/application/pages/instance/ServersPage.cpp @@ -556,7 +556,7 @@ private: QTimer m_saveTimer; }; -ServersPage::ServersPage(MinecraftInstance * inst, QWidget* parent) +ServersPage::ServersPage(InstancePtr inst, QWidget* parent) : QMainWindow(parent), ui(new Ui::ServersPage) { ui->setupUi(this); @@ -579,7 +579,7 @@ ServersPage::ServersPage(MinecraftInstance * inst, QWidget* parent) auto selectionModel = ui->serversView->selectionModel(); connect(selectionModel, &QItemSelectionModel::currentChanged, this, &ServersPage::currentChanged); - connect(m_inst, &MinecraftInstance::runningStatusChanged, this, &ServersPage::on_RunningState_changed); + connect(m_inst.get(), &MinecraftInstance::runningStatusChanged, this, &ServersPage::on_RunningState_changed); connect(ui->nameLine, &QLineEdit::textEdited, this, &ServersPage::nameEdited); connect(ui->addressLine, &QLineEdit::textEdited, this, &ServersPage::addressEdited); connect(ui->resourceComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(resourceIndexChanged(int))); @@ -695,6 +695,7 @@ void ServersPage::updateState() ui->actionMove_Down->setEnabled(serverEditEnabled); ui->actionMove_Up->setEnabled(serverEditEnabled); ui->actionRemove->setEnabled(serverEditEnabled); + ui->actionJoin->setEnabled(serverEditEnabled); if(server) { @@ -758,4 +759,10 @@ void ServersPage::on_actionMove_Down_triggered() } } +void ServersPage::on_actionJoin_triggered() +{ + const auto &address = m_model->at(currentServer)->m_address; + MMC->launch(m_inst, true, nullptr, std::make_shared(MinecraftServerTarget::parse(address))); +} + #include "ServersPage.moc" diff --git a/application/pages/instance/ServersPage.h b/application/pages/instance/ServersPage.h index f164da1e..8c5b7eb8 100644 --- a/application/pages/instance/ServersPage.h +++ b/application/pages/instance/ServersPage.h @@ -35,7 +35,7 @@ class ServersPage : public QMainWindow, public BasePage Q_OBJECT public: - explicit ServersPage(MinecraftInstance *inst, QWidget *parent = 0); + explicit ServersPage(InstancePtr inst, QWidget *parent = 0); virtual ~ServersPage(); void openedImpl() override; @@ -74,6 +74,7 @@ private slots: void on_actionRemove_triggered(); void on_actionMove_Up_triggered(); void on_actionMove_Down_triggered(); + void on_actionJoin_triggered(); void on_RunningState_changed(bool running); @@ -88,6 +89,6 @@ private: // data bool m_locked = true; Ui::ServersPage *ui = nullptr; ServersModel * m_model = nullptr; - MinecraftInstance * m_inst = nullptr; + InstancePtr m_inst = nullptr; }; diff --git a/application/pages/instance/ServersPage.ui b/application/pages/instance/ServersPage.ui index e9518e35..d89b7cba 100644 --- a/application/pages/instance/ServersPage.ui +++ b/application/pages/instance/ServersPage.ui @@ -148,6 +148,7 @@ + @@ -169,6 +170,11 @@ Move Down + + + Join + + -- cgit From 52c1150522139f042903321387c6582a99e8ad9a Mon Sep 17 00:00:00 2001 From: Janrupf Date: Sun, 23 May 2021 14:42:20 +0200 Subject: NOISSUE Add --server argument for --launch --- application/MultiMC.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++--- application/MultiMC.h | 1 + 2 files changed, 65 insertions(+), 3 deletions(-) (limited to 'application') diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 8a81238e..2dd4f83f 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -191,6 +191,11 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) parser.addOption("launch"); parser.addShortOpt("launch", 'l'); parser.addDocumentation("launch", "Launch the specified instance (by instance ID)"); + // --server + parser.addOption("server"); + parser.addShortOpt("server", 's'); + parser.addDocumentation("server", "Join the specified server on launch " + "(only valid in combination with --launch)"); // --alive parser.addSwitch("alive"); parser.addDocumentation("alive", "Write a small '" + liveCheckFile + "' file after MultiMC starts"); @@ -232,6 +237,7 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) } } m_instanceIdToLaunch = args["launch"].toString(); + m_serverToJoin = args["server"].toString(); m_liveCheck = args["alive"].toBool(); m_zipToImport = args["import"].toUrl(); @@ -293,6 +299,13 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) return; } + if(m_instanceIdToLaunch.isEmpty() && !m_serverToJoin.isEmpty()) + { + std::cerr << "--server can only be used in combination with --launch!" << std::endl; + m_status = MultiMC::Failed; + return; + } + /* * Establish the mechanism for communication with an already running MultiMC that uses the same data path. * If there is one, tell it what the user actually wanted to do and exit. @@ -318,7 +331,15 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) } else { - m_peerInstance->sendMessage("launch " + m_instanceIdToLaunch, timeout); + if(!m_serverToJoin.isEmpty()) + { + m_peerInstance->sendMessage( + "launch-with-server " + m_instanceIdToLaunch + " " + m_serverToJoin, timeout); + } + else + { + m_peerInstance->sendMessage("launch " + m_instanceIdToLaunch, timeout); + } } m_status = MultiMC::Succeeded; return; @@ -399,6 +420,10 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) { qDebug() << "ID of instance to launch : " << m_instanceIdToLaunch; } + if(!m_serverToJoin.isEmpty()) + { + qDebug() << "Address of server to join :" << m_serverToJoin; + } qDebug() << "<> Paths set."; } @@ -844,8 +869,19 @@ void MultiMC::performMainStartupAction() auto inst = instances()->getInstanceById(m_instanceIdToLaunch); if(inst) { - qDebug() << "<> Instance launching:" << m_instanceIdToLaunch; - launch(inst, true, nullptr); + MinecraftServerTargetPtr serverToJoin = nullptr; + + if(!m_serverToJoin.isEmpty()) + { + serverToJoin.reset(new MinecraftServerTarget(MinecraftServerTarget::parse(m_serverToJoin))); + qDebug() << "<> Instance" << m_instanceIdToLaunch << "launching with server" << m_serverToJoin; + } + else + { + qDebug() << "<> Instance" << m_instanceIdToLaunch << "launching"; + } + + launch(inst, true, nullptr, serverToJoin); return; } } @@ -927,6 +963,31 @@ void MultiMC::messageReceived(const QString& message) launch(inst, true, nullptr); } } + else if(command == "launch-with-server") + { + QString instanceID = message.section(' ', 1, 1); + QString serverToJoin = message.section(' ', 2, 2); + if(instanceID.isEmpty()) + { + qWarning() << "Received" << command << "message without an instance ID."; + return; + } + if(serverToJoin.isEmpty()) + { + qWarning() << "Received" << command << "message without a server to join."; + return; + } + auto inst = instances()->getInstanceById(instanceID); + if(inst) + { + launch( + inst, + true, + nullptr, + std::make_shared(MinecraftServerTarget::parse(serverToJoin)) + ); + } + } else { qWarning() << "Received invalid message" << message; diff --git a/application/MultiMC.h b/application/MultiMC.h index 57a43cb9..af2b41c1 100644 --- a/application/MultiMC.h +++ b/application/MultiMC.h @@ -228,6 +228,7 @@ private: SetupWizard * m_setupWizard = nullptr; public: QString m_instanceIdToLaunch; + QString m_serverToJoin; bool m_liveCheck = false; QUrl m_zipToImport; std::unique_ptr logFile; -- cgit