MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / parse

Method parse

launcher/minecraft/launch/MinecraftServerTarget.cpp:21–67  ·  view source on GitHub ↗

FIXME: the way this is written, it can't ever do any sort of validation and can accept total junk

Source from the content-addressed store, hash-verified

19
20// FIXME: the way this is written, it can't ever do any sort of validation and can accept total junk
21MinecraftServerTarget MinecraftServerTarget::parse(const QString &fullAddress) {
22 QStringList split = fullAddress.split(":");
23
24 // The logic below replicates the exact logic minecraft uses for parsing server addresses.
25 // While the conversion is not lossless and eats errors, it ensures the same behavior
26 // within Minecraft and PolyMC when entering server addresses.
27 if (fullAddress.startsWith("["))
28 {
29 int bracket = fullAddress.indexOf("]");
30 if (bracket > 0)
31 {
32 QString ipv6 = fullAddress.mid(1, bracket - 1);
33 QString port = fullAddress.mid(bracket + 1).trimmed();
34
35 if (port.startsWith(":") && !ipv6.isEmpty())
36 {
37 port = port.mid(1);
38 split = QStringList({ ipv6, port });
39 }
40 else
41 {
42 split = QStringList({ipv6});
43 }
44 }
45 }
46
47 if (split.size() > 2)
48 {
49 split = QStringList({fullAddress});
50 }
51
52 QString realAddress = split[0];
53
54 quint16 realPort = 25565;
55 if (split.size() > 1)
56 {
57 bool ok;
58 realPort = split[1].toUInt(&ok);
59
60 if (!ok)
61 {
62 realPort = 25565;
63 }
64 }
65
66 return MinecraftServerTarget { realAddress, realPort };
67}

Callers

nothing calls this directly

Calls 2

isEmptyMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected