chore: reformat

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu
2023-08-02 18:35:35 +02:00
parent ce2ca13815
commit 1d468ac35a
594 changed files with 16040 additions and 16536 deletions

View File

@ -18,50 +18,43 @@
#include <QStringList>
// FIXME: the way this is written, it can't ever do any sort of validation and can accept total junk
MinecraftServerTarget MinecraftServerTarget::parse(const QString &fullAddress) {
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 Prism Launcher when entering server addresses.
if (fullAddress.startsWith("["))
{
if (fullAddress.startsWith("[")) {
int bracket = fullAddress.indexOf("]");
if (bracket > 0)
{
if (bracket > 0) {
QString ipv6 = fullAddress.mid(1, bracket - 1);
QString port = fullAddress.mid(bracket + 1).trimmed();
if (port.startsWith(":") && !ipv6.isEmpty())
{
if (port.startsWith(":") && !ipv6.isEmpty()) {
port = port.mid(1);
split = QStringList({ ipv6, port });
}
else
{
split = QStringList({ipv6});
} else {
split = QStringList({ ipv6 });
}
}
}
if (split.size() > 2)
{
split = QStringList({fullAddress});
if (split.size() > 2) {
split = QStringList({ fullAddress });
}
QString realAddress = split[0];
quint16 realPort = 25565;
if (split.size() > 1)
{
if (split.size() > 1) {
bool ok;
realPort = split[1].toUInt(&ok);
if (!ok)
{
if (!ok) {
realPort = 25565;
}
}
return MinecraftServerTarget { realAddress, realPort };
return MinecraftServerTarget{ realAddress, realPort };
}