Skip to content
This repository was archived by the owner on Jan 24, 2026. It is now read-only.

Commit c63db1c

Browse files
committed
Fix some network- and server-related issues
1 parent 3c4ad59 commit c63db1c

9 files changed

Lines changed: 121 additions & 42 deletions

File tree

build.gradle.kts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,8 @@ tasks.register<Exec>("runServer") {
796796

797797
// Combine classpaths manually
798798
val cp = files(
799-
project(":desktop").configurations.runtimeClasspath.get().files,
800-
project(":desktop").sourceSets.main.get().output
799+
project(":dedicated").configurations.runtimeClasspath.get().files,
800+
project(":dedicated").sourceSets.main.get().output
801801
)
802802

803803
executable = javaToolchains.launcherFor {
@@ -808,18 +808,14 @@ tasks.register<Exec>("runServer") {
808808

809809
doFirst {
810810
Paths.get(workingDir.path, "vmargs").toFile().writeText("""
811-
-Xmx4g
812-
-Xms4g
813-
${if ("Mac" in System.getProperty("os.name")) "-XstartOnFirstThread" else ""}
814-
-Dfabric.development=true
815-
-Dlog4j2.formatMsgNoLookups=true
816-
-Dfabric.log.disableAnsi=false
817-
-Dfabric.skipMcProvider=true
818-
-Dfabric.zipfs.use_temp_file=false
819-
-Dlog4j.configurationFile=${rootProject.projectDir}/log4j.xml
820-
-cp "${cp.asPath}"
821-
${project.properties["serverMainClass"] ?: ""}
822-
--gameDir=.
811+
-Xmx4g
812+
-Xms4g
813+
${if ("Mac" in System.getProperty("os.name")) "-XstartOnFirstThread" else ""}
814+
-Dxeox.development=true
815+
-Dlog4j2.formatMsgNoLookups=true
816+
-Dlog4j.configurationFile=${rootProject.projectDir}/log4j.xml
817+
-cp "${cp.asPath}"
818+
dev.ultreon.xeox.impl.main.Main
823819
""".trimIndent())
824820
}
825821

client/src/main/java/dev/ultreon/quantum/client/QuantumClient.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2992,7 +2992,6 @@ public void connectToServer(String location) {
29922992
this.world = new ClientWorld(this, DimensionInfo.OVERWORLD);
29932993

29942994
// Establish connection to the server
2995-
String[] split = location.split(":");
29962995
this.connection = ClientWebSocketConnection.connectToServer(this, location, () -> {
29972996
var conn = this.connection;
29982997
if (conn == null) return;

client/src/main/java/dev/ultreon/quantum/client/ServerInfo.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public MapType save() {
3535
MapType data = new MapType();
3636
data.putString("name", this.name);
3737
data.putString("address", this.address);
38+
data.putBoolean("secure", this.secure);
3839
return data;
3940
}
4041

@@ -66,9 +67,11 @@ public int hashCode() {
6667

6768
@Override
6869
public String toString() {
69-
return "ServerInfo[" +
70-
"name=" + name + ", " +
71-
"address=" + address + ']';
70+
if (this.secure) {
71+
return String.format("wss://%s", this.address);
72+
} else {
73+
return String.format("ws://%s", this.address);
74+
}
7275
}
7376

7477
}

client/src/main/java/dev/ultreon/quantum/client/gui/screens/MultiplayerScreen.java

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.ultreon.quantum.client.gui.screens;
22

33
import com.badlogic.gdx.graphics.Color;
4+
import dev.ultreon.quantum.CommonConstants;
45
import dev.ultreon.quantum.client.QuantumClient;
56
import dev.ultreon.quantum.client.ServerInfo;
67
import dev.ultreon.quantum.client.gui.DialogBuilder;
@@ -40,12 +41,8 @@ protected void init() {
4041
super.init();
4142

4243
listPlatform = add(Platform.create());
43-
listPlatform.setPos(0, 0);
44-
listPlatform.setSize(200, size.height - 27);
4544

4645
listButtonPlatform = add(Platform.create());
47-
listButtonPlatform.setPos(0, size.height - 327);
48-
listButtonPlatform.setSize(200, 30);
4946

5047
selectionList = add(new SelectionList<>());
5148
selectionList.setPos(2, 0);
@@ -72,33 +69,30 @@ protected void init() {
7269
client.localData.servers.forEach(info -> selectionList.entry(new ServerEntry(info)));
7370

7471
platform = add(Platform.create());
75-
platform.setPos(200 + (this.size.width - 200) / 2 - 55, this.size.height / 2 - 61);
76-
platform.setSize(110, 122);
7772

7873
joinButton = add(TextButton.of(TextObject.translation("quantum.screen.multiplayer.join"), 98));
79-
joinButton.setPos(platform.getPos().x + 5, platform.getPos().y + 5);
8074
joinButton.withType(Button.Type.DARK_EMBED);
8175
joinButton.withCallback(this::joinServer);
8276
joinButton.disable();
8377

8478
removeButton = add(TextButton.of(TextObject.translation("quantum.screen.multiplayer.remove"), 98));
85-
removeButton.setPos(platform.getPos().x + 5, platform.getPos().y + 35);
8679
removeButton.withType(Button.Type.DARK_EMBED);
8780
removeButton.withCallback(this::removeServer);
8881

8982
editButton = add(TextButton.of(TextObject.translation("quantum.screen.multiplayer.edit"), 98));
90-
editButton.setPos(platform.getPos().x + 5, platform.getPos().y + 65);
9183
editButton.withType(Button.Type.DARK_EMBED);
9284
editButton.withCallback(this::editServer);
9385

9486
backButton = add(TextButton.of(UITranslations.BACK, 98));
95-
backButton.setPos(platform.getPos().x + 5, platform.getPos().y + 95);
9687
backButton.withType(Button.Type.DARK_EMBED);
9788
backButton.withCallback(this::back);
9889
}
9990

10091
private void editServer(TextButton textButton) {
101-
client.showScreen(new EditServerScreen(this, selectionList.getSelected(), server));
92+
ServerEntry selected = selectionList.getSelected();
93+
ServerInfo server = this.server;
94+
if (selected == null || server == null) return;
95+
client.showScreen(new EditServerScreen(this, selected, server));
10296
}
10397

10498
private void removeServer(TextButton textButton) {
@@ -133,23 +127,24 @@ private void selectServer(ServerEntry serverEntry) {
133127
public void resized(int width, int height) {
134128
super.resized(width, height);
135129

136-
listPlatform.setPos(0, 0);
130+
listPlatform.setPos(getX(), getY());
137131
listPlatform.setSize(200, size.height - 30);
138132

139-
listButtonPlatform.setPos(0, size.height - 30);
140-
listButtonPlatform.setSize(200, 30);
133+
listButtonPlatform.setPos(0, size.height - 60);
134+
listButtonPlatform.setSize(200, 60);
141135

142-
selectionList.setPos(2, 0);
136+
selectionList.setPos(getX(), getY());
143137
selectionList.setSize(196, size.height - 30);
144138

145139
addButton.setPos(5, this.size.height - 26);
146140

147141
platform.setPos(200 + (this.size.width - 200) / 2 - 55, this.size.height / 2 - 47);
148-
platform.setSize(110, 92);
142+
platform.setSize(110, 127);
149143

150144
joinButton.setPos(platform.getPos().x + 5, platform.getPos().y + 5);
151-
removeButton.setPos(platform.getPos().x + 5, platform.getPos().y + 35);
152-
backButton.setPos(platform.getPos().x + 5, platform.getPos().y + 65);
145+
editButton.setPos(platform.getPos().x + 5, platform.getPos().y + 35);
146+
removeButton.setPos(platform.getPos().x + 5, platform.getPos().y + 65);
147+
backButton.setPos(platform.getPos().x + 5, platform.getPos().y + 95);
153148
}
154149

155150
private void back(TextButton textButton) {
@@ -170,7 +165,9 @@ private void joinServer(TextButton caller) {
170165

171166
try {
172167
this.client.serverInfo = selected.info;
173-
this.client.connectToServer(selected.info.address());
168+
String location = selected.info + "/quantum-server";
169+
CommonConstants.LOGGER.info("Connecting to server: " + location);
170+
this.client.connectToServer(location);
174171
} catch (Exception e) {
175172
QuantumClient.LOGGER.error("Can't connect to server", e);
176173
}
@@ -226,14 +223,19 @@ public void revalidate() {
226223

227224
private void validateServerIp(TextEntry caller) {
228225
var text = caller.getValue();
229-
boolean matches = text.matches("[^:]+:\\d{1,5}(/[^@:]+)?");
226+
boolean matches = text.matches("[^:]+(:\\d{1,5})?(/[^@:]+)?");
230227
if (!matches) {
231228
this.addButton.isEnabled = false;
232229
return;
233230
}
234231
var hostSplitOff = text.split(":", 2);
235-
String[] portSplitOff = hostSplitOff[1].split("/", 2);
236-
var port = Integer.parseInt(portSplitOff[0]);
232+
int port;
233+
if (hostSplitOff.length < 2) {
234+
port = 443;
235+
} else {
236+
String[] portSplitOff = hostSplitOff[1].split("/", 2);
237+
port = Integer.parseInt(portSplitOff[0]);
238+
}
237239

238240
if (port != 80 && port != 443 && !(port >= 1000 && port <= 65535)) {
239241
this.addButton.isEnabled = false;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package dev.ultreon.quantum.dedicated;
2+
3+
import com.badlogic.gdx.files.FileHandle;
4+
import dev.ultreon.quantum.CommonConstants;
5+
import dev.ultreon.quantum.Mod;
6+
import dev.ultreon.quantum.ModOrigin;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Nullable;
9+
10+
import java.util.Collection;
11+
import java.util.List;
12+
13+
public class GameMod implements Mod {
14+
public static final GameMod INSTANCE = new GameMod();
15+
16+
@Override
17+
public @NotNull String getId() {
18+
return CommonConstants.NAMESPACE;
19+
}
20+
21+
@Override
22+
public @NotNull String getName() {
23+
return "Quantum Voxel";
24+
}
25+
26+
@Override
27+
public @NotNull String getVersion() {
28+
return "0.2.0-alpha.2";
29+
}
30+
31+
@Override
32+
public @Nullable String getDescription() {
33+
return "Yay";
34+
}
35+
36+
@Override
37+
public @NotNull Collection<String> getAuthors() {
38+
return List.of("Ultreon Studios");
39+
}
40+
41+
@Override
42+
public @NotNull ModOrigin getOrigin() {
43+
return ModOrigin.ACTUAL_PATH;
44+
}
45+
46+
@Override
47+
public @Nullable Iterable<FileHandle> getRootPaths() {
48+
return null;
49+
}
50+
}

dedicated/src/main/java/dev/ultreon/quantum/dedicated/JavaWebSocketServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.Map;
1616
import java.util.concurrent.ConcurrentHashMap;
1717

18-
@ServerEndpoint("/server")
18+
@ServerEndpoint("/quantum-server")
1919
public class JavaWebSocketServer implements Networker {
2020
private final DedicatedServer server;
2121
private final Map<Session, ServerConnection> connections = new ConcurrentHashMap<>();

dedicated/src/main/java/dev/ultreon/quantum/dedicated/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static void main(String[] args) throws IOException, InterruptedException
5959

6060
}, createConfig());
6161

62-
ModLoadingContext.withinContext(GamePlatform.get().getMod(CommonConstants.NAMESPACE).orElseThrow(), Main::initConfig);
62+
ModLoadingContext.withinContext(GamePlatform.get().getGameMod(), Main::initConfig);
6363

6464
setupMods();
6565

dedicated/src/main/java/dev/ultreon/quantum/dedicated/ServerPlatform.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ public UUID constructUuid(long msb, long lsb) {
110110
return new UUID(msb, lsb);
111111
}
112112

113+
@Override
114+
public Mod getGameMod() {
115+
if (IXeoxLoader.get() == null) return GameMod.INSTANCE;
116+
return new XeoxMod(IXeoxLoader.get().getMod(CommonConstants.NAMESPACE));
117+
}
118+
113119
@Override
114120
public boolean isFeatureSupported(PlatformFeature platformFeature) {
115121
return false;
@@ -173,6 +179,10 @@ public Logger getLogger(String name) {
173179

174180
@Override
175181
public Optional<Mod> getMod(String id) {
182+
if (this.mods.containsKey(id)) {
183+
return Optional.of(this.mods.get(id));
184+
}
185+
if (IXeoxLoader.get() == null) return Optional.empty();
176186
IMod mod = IXeoxLoader.get().getMod(id);
177187
if (mod != null) {
178188
XeoxMod value = new XeoxMod(mod);
@@ -199,12 +209,15 @@ public Collection<? extends Mod> getMods() {
199209
public void initMods() {
200210
CommonConstants.LOGGER.info("Initializing mods...");
201211

212+
if (IXeoxLoader.get() == null) return;
213+
202214
IXeoxLoader.get().invokeEntrypoints("main", ModInitializer.class, ModInitializer::onInitialize);
203215
IXeoxLoader.get().invokeEntrypoints("server", DedicatedServerModInitializer.class, DedicatedServerModInitializer::onInitializeServer);
204216
}
205217

206218
@Override
207219
public boolean isDevEnvironment() {
220+
if (IXeoxLoader.get() == null) return false;
208221
return IXeoxLoader.get().isDevEnvironment();
209222
}
210223

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package dev.ultreon.quantum.dedicated;
2+
3+
import dev.ultreon.quantum.CommonConstants;
4+
5+
import java.io.IOException;
6+
7+
public class XeoxLauncher {
8+
public static void main(String[] args) {
9+
try {
10+
Main.main(args);
11+
} catch (IOException | InterruptedException e) {
12+
CommonConstants.LOGGER.error("Failed to start server: " + e.getMessage());
13+
Runtime.getRuntime().halt(1);
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)