NOISSUE Allow joining servers from the servers page
This commit is contained in:
@ -822,7 +822,7 @@ shared_qobject_ptr<Task> MinecraftInstance::createUpdateTask(Net::Mode mode)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPtr session)
|
||||
shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin)
|
||||
{
|
||||
// FIXME: get rid of shared_from_this ...
|
||||
auto process = LaunchTask::create(std::dynamic_pointer_cast<MinecraftInstance>(shared_from_this()));
|
||||
@ -854,66 +854,19 @@ shared_qobject_ptr<LaunchTask> MinecraftInstance::createLaunchTask(AuthSessionPt
|
||||
process->appendStep(new CreateGameFolders(pptr));
|
||||
}
|
||||
|
||||
MinecraftServerTargetPtr serverToJoin = std::make_shared<MinecraftServerTarget>();
|
||||
|
||||
if (m_settings->get("JoinServerOnLaunch").toBool())
|
||||
if (!serverToJoin && m_settings->get("JoinServerOnLaunch").toBool())
|
||||
{
|
||||
QString fullAddress = m_settings->get("JoinServerOnLaunchAddress").toString();
|
||||
QStringList split = fullAddress.split(":");
|
||||
serverToJoin.reset(new MinecraftServerTarget(MinecraftServerTarget::parse(fullAddress)));
|
||||
}
|
||||
|
||||
// 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(realPort == 25565)
|
||||
{
|
||||
// Resolve server address to join on launch
|
||||
auto *step = new LookupServerAddress(pptr);
|
||||
step->setLookupAddress(realAddress);
|
||||
step->setOutputAddressPtr(serverToJoin);
|
||||
process->appendStep(step);
|
||||
}
|
||||
if(serverToJoin && serverToJoin->port == 25565)
|
||||
{
|
||||
// Resolve server address to join on launch
|
||||
auto *step = new LookupServerAddress(pptr);
|
||||
step->setLookupAddress(serverToJoin->address);
|
||||
step->setOutputAddressPtr(serverToJoin);
|
||||
process->appendStep(step);
|
||||
}
|
||||
|
||||
// run pre-launch command if that's needed
|
||||
|
@ -77,7 +77,7 @@ public:
|
||||
|
||||
////// Launch stuff //////
|
||||
shared_qobject_ptr<Task> createUpdateTask(Net::Mode mode) override;
|
||||
shared_qobject_ptr<LaunchTask> createLaunchTask(AuthSessionPtr account) override;
|
||||
shared_qobject_ptr<LaunchTask> createLaunchTask(AuthSessionPtr account, MinecraftServerTargetPtr serverToJoin) override;
|
||||
QStringList extraArguments() const override;
|
||||
QStringList verboseDescription(AuthSessionPtr session, MinecraftServerTargetPtr serverToJoin) override;
|
||||
QList<Mod> getJarMods() const;
|
||||
|
66
api/logic/minecraft/launch/MinecraftServerTarget.cpp
Normal file
66
api/logic/minecraft/launch/MinecraftServerTarget.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
/* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "MinecraftServerTarget.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
MinecraftServerTarget MinecraftServerTarget::parse(const QString &fullAddress) {
|
||||
QStringList split = fullAddress.split(":");
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
return MinecraftServerTarget { realAddress, realPort };
|
||||
}
|
@ -17,9 +17,14 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QString>
|
||||
#include <multimc_logic_export.h>
|
||||
|
||||
struct MinecraftServerTarget {
|
||||
QString address;
|
||||
quint16 port;
|
||||
|
||||
static MULTIMC_LOGIC_EXPORT MinecraftServerTarget parse(const QString &fullAddress);
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<MinecraftServerTarget> MinecraftServerTargetPtr;
|
||||
|
@ -111,7 +111,8 @@ public:
|
||||
{
|
||||
return false;
|
||||
}
|
||||
shared_qobject_ptr<LaunchTask> createLaunchTask(AuthSessionPtr account) override
|
||||
shared_qobject_ptr<LaunchTask> createLaunchTask(
|
||||
AuthSessionPtr account, MinecraftServerTargetPtr serverToJoin) override
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
Reference in New Issue
Block a user