Skip to content

Commit 328714e

Browse files
authored
Merge pull request #7 from Minecraft-Java-Edition-Speedrunning/fix_no_internet_crash
fixes a no internet crash
2 parents d43a42b + c12cc58 commit 328714e

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

src/main/java/me/voidxwalker/serversiderng/RNGHandler.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.jetbrains.annotations.Nullable;
1010

1111
import java.io.IOException;
12+
import java.net.ConnectException;
13+
import java.net.UnknownHostException;
1214
import java.util.LinkedHashMap;
1315
import java.util.Map;
1416
import java.util.Random;
@@ -50,7 +52,12 @@ public void log(Level level,String message){
5052
public static RNGHandler createRNGHandlerOrNull(long runId) {
5153
try {
5254
return new RNGHandler(new Random(ServerSideRNG.getGetRandomToken(runId).get("random").getAsLong()).nextLong());
53-
} catch (IOException | NullPointerException e) {
55+
}
56+
catch (UnknownHostException | ConnectException e){
57+
ServerSideRNG.log(Level.WARN,"Failed to create new RNGHandler: Could not connect to the Server.");
58+
return null;
59+
}
60+
catch (IOException | NullPointerException e) {
5461
ServerSideRNG.log(Level.WARN,"Failed to create new RNGHandler: ");
5562
e.printStackTrace();
5663
return null;
@@ -207,7 +214,4 @@ public RandomMapEntry(Random random){
207214
useTimes=0;
208215
}
209216
}
210-
}
211-
212-
213-
217+
}

src/main/java/me/voidxwalker/serversiderng/RNGSession.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.jetbrains.annotations.Nullable;
66

77
import java.io.IOException;
8+
import java.net.ConnectException;
9+
import java.net.UnknownHostException;
810
import java.util.Optional;
911
import java.util.Random;
1012
import java.util.concurrent.CompletableFuture;
@@ -129,7 +131,12 @@ public static boolean inSession() {
129131
public static RNGSession createRNGSessionOrNull() {
130132
try {
131133
return new RNGSession(ServerSideRNG.getStartRunToken());
132-
} catch (IOException e) {
134+
}
135+
catch (UnknownHostException | ConnectException e){
136+
ServerSideRNG.log(Level.WARN,"Failed to create new RNGSession: Could not connect to the Server.");
137+
return null;
138+
}
139+
catch (IOException e) {
133140
ServerSideRNG.log(Level.WARN,"Failed to create new RNGSession: ");
134141
e.printStackTrace();
135142
return null;
@@ -208,8 +215,6 @@ boolean updateSessionState(){
208215
public void getRngHandlerFromFuture() {
209216
try {
210217
currentRNGHandler = rngHandlerCompletableFuture.get(1L, TimeUnit.SECONDS);
211-
currentRNGHandler.activate(handlerIndex++);
212-
currentRNGHandler.log(Level.INFO,"Successfully updated the current RNGHandler!");
213218
} catch (InterruptedException | ExecutionException | TimeoutException e) {
214219
e.printStackTrace();
215220
}
@@ -222,8 +227,15 @@ public void getRngHandlerFromFuture() {
222227
}
223228
else {
224229
this.log(Level.WARN,"Failed to update the current RNGHandler!");
230+
return;
225231
}
226232
}
233+
else {
234+
currentRNGHandler.activate(handlerIndex++);
235+
currentRNGHandler.log(Level.INFO,"Successfully updated the current RNGHandler!");
236+
}
237+
238+
227239
rngHandlerCompletableFuture = CompletableFuture.supplyAsync(()-> RNGHandler.createRNGHandlerOrNull(runId));
228240
}
229241
/**

0 commit comments

Comments
 (0)