NOISSUE Add --server argument for --launch
This commit is contained in:
parent
58ab005f7e
commit
52c1150522
@ -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.
|
||||
@ -317,9 +330,17 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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>(MinecraftServerTarget::parse(serverToJoin))
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Received invalid message" << message;
|
||||
|
@ -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<QFile> logFile;
|
||||
|
Loading…
Reference in New Issue
Block a user