Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require Connection to Router for Online Content #59

Draft
wants to merge 5 commits into
base: 1.20.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ultreon.devices.api.utils;

import com.ultreon.devices.core.Laptop;
import com.ultreon.devices.util.StreamUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
Expand Down Expand Up @@ -121,6 +122,10 @@ public void run() {

while (!requests.isEmpty()) {
RequestWrapper wrapper = requests.poll();
if (Laptop.isOffline()) {
wrapper.handler.handle(false, "Disconnected from the internet.");
return;
}
try {
URL url = new URL(wrapper.url);
checkURLForSuspicions(url);
Expand Down
17 changes: 17 additions & 0 deletions common/src/main/java/com/ultreon/devices/core/Laptop.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class Laptop extends Screen implements System {
private static Laptop instance;
private Double dragWindowFromX;
private Double dragWindowFromY;
@Nullable
private final LaptopBlockEntity blockEntity;

@PlatformOnly("fabric")
public static List<Application> getApplicationsForFabric() {
Expand Down Expand Up @@ -184,12 +186,27 @@ public boolean add(Window<?> window) {

// World-less flag.
Laptop.worldLess = worldLess;
this.blockEntity = laptop;
}

public static Laptop getInstance() {
return instance;
}

public static boolean isOffline() {
Laptop laptop = instance;
if (laptop == null) {
return false;
}

LaptopBlockEntity blockEntity = laptop.blockEntity;
if (blockEntity == null) {
return false;
}

return blockEntity.getConnection() == null;
}

public CompoundTag getModSystemTag(Mod mod) {
return getModSystemTag(mod.getModId());
}
Expand Down
Loading