add web services and update notifications
Some checks failed
/ Build BaseBand DSM & Broadway (push) Successful in 2m1s
/ Build BaseBand Loader (push) Failing after 1m22s
/ Build BaseBand Server (push) Successful in 1m56s

This commit is contained in:
Daniella / Tove 2024-06-13 13:39:43 +02:00
parent c3331d899a
commit 38d29a8efd
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
12 changed files with 200 additions and 34 deletions

View file

@ -52,7 +52,6 @@ jobs:
BB_PORT: ${{ vars.BB_PORT }} BB_PORT: ${{ vars.BB_PORT }}
BB_PATH: ${{ vars.BB_PATH }} BB_PATH: ${{ vars.BB_PATH }}
run: | run: |
bash scripts/push_file.sh loader.version
bash scripts/push_file.sh Loader/build/proguard/BaseBand-Loader.jar bash scripts/push_file.sh Loader/build/proguard/BaseBand-Loader.jar
- name: Notify Action Completion - name: Notify Action Completion
if: always() if: always()

1
.gitignore vendored
View file

@ -14,3 +14,4 @@ valid_hashes.txt
Obf.tar Obf.tar
/Server/run/ /Server/run/
mobf.jar mobf.jar
resources/commit

View file

@ -12,6 +12,7 @@ import de.com.baseband.client.feature.render.HUD;
import de.com.baseband.client.registry.Configuration; import de.com.baseband.client.registry.Configuration;
import de.com.baseband.client.registry.Updater; import de.com.baseband.client.registry.Updater;
import de.com.baseband.client.util.interact.Chat; import de.com.baseband.client.util.interact.Chat;
import de.com.baseband.client.util.net.WebServiceClient;
import de.com.baseband.prod.LoadHandler; import de.com.baseband.prod.LoadHandler;
import de.tudbut.tools.Lock; import de.tudbut.tools.Lock;
import hint.Mobf; import hint.Mobf;
@ -74,6 +75,7 @@ public class BaseBand {
Lock lock = new Lock(); Lock lock = new Lock();
while (enabled) { while (enabled) {
lock.lock(1000); lock.lock(1000);
WebServiceClient.connect();
for (Updater updater : Configuration.updaters) { for (Updater updater : Configuration.updaters) {
updater.poll(); updater.poll();
} }

View file

@ -23,10 +23,13 @@ import java.util.Map;
public class DevStub implements IFMLLoadingPlugin { public class DevStub implements IFMLLoadingPlugin {
public static final String ID = "baseband_testing"; public static final String ID = "baseband_testing";
Logger LOGGER = LogManager.getLogger("BaseBand [dev]");
@Mod.EventHandler @Mod.EventHandler
public void onInit(FMLPostInitializationEvent event) { public void onInit(FMLPostInitializationEvent event) {
LoadHandler.data.set("release-branch", false); LoadHandler.data.set("release-branch", false);
LoadHandler.data.set("branch", "[dev]");
LoadHandler.data.set("username", "root");
} }
@Override @Override
@ -48,15 +51,11 @@ public class DevStub implements IFMLLoadingPlugin {
public void injectData(Map<String, Object> dataMap) { public void injectData(Map<String, Object> dataMap) {
MixinBootstrap.init(); MixinBootstrap.init();
Mixins.addConfiguration("mixins.baseband.json"); Mixins.addConfiguration("mixins.baseband.json");
DevLogger.LOGGER.info("loaded mixins"); LOGGER.info("loaded mixins");
} }
@Override @Override
public String getAccessTransformerClass() { public String getAccessTransformerClass() {
return null; return null;
} }
public interface DevLogger {
Logger LOGGER = LogManager.getLogger("baeban dev stub");
}
} }

View file

@ -1,6 +1,24 @@
package de.com.baseband.client.util.data; package de.com.baseband.client.util.data;
import de.tudbut.io.StreamReader;
import java.io.IOException;
import java.io.InputStream;
public class GitHash { public class GitHash {
public static final String GIT_HASH = "[dev]"; public static final String GIT_HASH;
static {
InputStream stream = GitHash.class.getResourceAsStream("commit");
if(stream != null) {
try {
GIT_HASH = new StreamReader(stream).readAllAsString().trim();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
else {
GIT_HASH = "[dev]";
}
}
} }

View file

@ -1,24 +1,84 @@
package de.com.baseband.client.util.net; package de.com.baseband.client.util.net;
import de.com.baseband.client.BaseBand; import de.com.baseband.client.BaseBand;
import de.tudbut.net.ws.Client; import de.com.baseband.client.util.data.GitHash;
import de.tudbut.net.ws.ConnectionHandler; import de.com.baseband.prod.LoadHandler;
import de.tudbut.io.TypedInputStream;
import de.tudbut.io.TypedOutputStream;
import de.tudbut.parsing.JSON;
import de.tudbut.parsing.TCN;
import java.io.IOException; import java.io.IOException;
import java.net.Socket;
public class WebServiceClient { public class WebServiceClient {
@SuppressWarnings("FieldCanBeLocal") // not finished yet
private static Client client; private static boolean wasEverConnected = false;
private static TypedInputStream inputStream;
private static TypedOutputStream outputStream;
public static void connect() { public static void connect() {
if(inputStream != null || outputStream != null)
return;
try { try {
client = new Client("azidoazideazi.de", 30000); try(Socket client = new Socket("baseband.com.de", 40000)) {
//client.addReceiveHook(READER); client.setSoTimeout(15000);
client.getOutputStream().write(1); // client mode
inputStream = new TypedInputStream(client.getInputStream());
outputStream = new TypedOutputStream(client.getOutputStream());
TCN init = new TCN();
init.set("username", LoadHandler.data.getString("username"));
init.set("type", "init");
init.set("branch", LoadHandler.data.getString("branch"));
outputStream.writeString(JSON.write(init));
int fails = 0;
while (fails < 3) {
try {
String string = inputStream.readString();
if(string.equals("SHUTDOWN."))
BaseBand.shutdown();
TCN packet = JSON.read(string);
fails = 0;
wasEverConnected = true;
handlePacket(packet);
} catch (Exception e) {
fails++;
TCN keepAlive = new TCN();
keepAlive.set("type", "c-keepalive");
try {
outputStream.writeString(JSON.write(keepAlive));
} catch (Exception e1) {
inputStream = null;
outputStream = null;
return;
}
}
}
}
} catch (IOException e) { } catch (IOException e) {
if(!wasEverConnected) {
BaseBand.LOGGER.fatal(e); BaseBand.LOGGER.fatal(e);
BaseBand.shutdown(); BaseBand.shutdown();
} }
} }
}
public static ConnectionHandler READER = connection -> connection.send("");
public static boolean outdated = false;
private static void handlePacket(TCN packet) throws IOException {
String type = packet.getString("type");
if(type.equals("keepalive")) {
outputStream.writeString(JSON.write(packet));
return;
}
if(type.equals("info")) {
if(!packet.getString("commit").equals(GitHash.GIT_HASH) && !outdated) {
outdated = true;
BaseBand.notify("§d§lBaseBand has updated. You will receive the update automatically when you next restart your game.");
}
}
}
} }

View file

@ -57,6 +57,7 @@ public class Loader implements Util {
public static void run() { public static void run() {
try(Socket client = new Socket("baseband.com.de", 40000)) { try(Socket client = new Socket("baseband.com.de", 40000)) {
client.setSoTimeout(15000); client.setSoTimeout(15000);
client.getOutputStream().write(0);
TypedInputStream inputStream = new TypedInputStream(client.getInputStream()); TypedInputStream inputStream = new TypedInputStream(client.getInputStream());
TypedOutputStream outputStream = new TypedOutputStream(client.getOutputStream()); TypedOutputStream outputStream = new TypedOutputStream(client.getOutputStream());
@ -78,8 +79,8 @@ public class Loader implements Util {
out.closeEntry(); out.closeEntry();
} }
out.close(); out.close();
LOGGER.info("BaseBand has downloaded an update. Minecraft will exit."); LOGGER.info("BaseBand has downloaded a significant update. Minecraft will exit.");
JOptionPane.showMessageDialog(null, "BaseBand has downloaded an update. Please restart Minecraft."); JOptionPane.showMessageDialog(null, "BaseBand has downloaded a significant update. Please restart Minecraft.");
exit(); exit();
} }
else if(status == Response.OK) { else if(status == Response.OK) {

View file

@ -1,6 +1,24 @@
package de.com.baseband.launcher.util; package de.com.baseband.launcher.util;
import de.tudbut.io.StreamReader;
import java.io.IOException;
import java.io.InputStream;
public class GitHash { public class GitHash {
public static final String GIT_HASH = "[dev]"; public static final String GIT_HASH;
static {
InputStream stream = GitHash.class.getResourceAsStream("commit");
if(stream != null) {
try {
GIT_HASH = new StreamReader(stream).readAllAsString().trim();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
else {
GIT_HASH = "[dev]";
}
}
} }

View file

@ -0,0 +1,69 @@
package de.com.baseband.server;
import de.tudbut.io.TypedInputStream;
import de.tudbut.io.TypedOutputStream;
import de.tudbut.parsing.JSON;
import de.tudbut.parsing.TCN;
import java.io.IOException;
import java.net.Socket;
public class ClientHandler {
public TypedInputStream inputStream;
public TypedOutputStream outputStream;
public void handle(Socket socket) throws IOException {
socket.setSoTimeout(15000);
inputStream = new TypedInputStream(socket.getInputStream());
outputStream = new TypedOutputStream(socket.getOutputStream());
int fails = 0;
while (fails < 3) {
try {
TCN packet = JSON.read(inputStream.readString());
fails = 0;
handlePacket(packet);
} catch (Exception e) {
fails++;
TCN keepAlive = new TCN();
keepAlive.set("type", "keepalive");
try {
outputStream.writeString(JSON.write(keepAlive));
} catch (Exception e1) {
return;
}
}
}
}
private void handlePacket(TCN packet) throws IOException {
String type = packet.getString("type");
if(type.equals("c-keepalive")) {
packet.set("type", "keepalive");
outputStream.writeString(JSON.write(packet));
return;
}
if(type.equals("init")) {
String branchHash = null;
String branch = packet.getString("branch");
if(branch.equals("main"))
branchHash = Main.clientDebugHash;
if(branch.equals("release"))
branchHash = Main.clientHash;
if(branch.equals("[dev]"))
branchHash = "[dev]";
TCN initResponse = new TCN();
initResponse.set("type", "info");
if(branchHash == null) {
outputStream.writeString("SHUTDOWN.");
return;
}
initResponse.set("commit", branchHash);
outputStream.writeString(JSON.write(initResponse));
}
}
}

View file

@ -31,6 +31,8 @@ public class LoaderHandler {
if(response.o == UserHandler.Response.OK.ordinal()) { if(response.o == UserHandler.Response.OK.ordinal()) {
TCN data = new TCN(); TCN data = new TCN();
data.set("release-branch", "release".equals(response.t.getString("branch"))); data.set("release-branch", "release".equals(response.t.getString("branch")));
data.set("branch", response.t.getString("branch"));
data.set("username", userData.getString("username"));
outputStream.writeString(key.encryptString(Tools.mapToString(data.toMap()))); outputStream.writeString(key.encryptString(Tools.mapToString(data.toMap())));
Map<String, byte[]> classes = null; Map<String, byte[]> classes = null;

View file

@ -21,6 +21,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.security.KeyPair; import java.security.KeyPair;
import java.util.HashMap; import java.util.HashMap;
@ -35,9 +36,9 @@ public class Main {
public static RSAKey rsaKey; public static RSAKey rsaKey;
public static boolean denyAll = false; public static boolean denyAll = false;
public static String clientHash, clientDebugHash, loaderHash;
public static Map<String, byte[]> classes = new HashMap<>(); public static Map<String, byte[]> classes = new HashMap<>();
public static Map<String, byte[]> classesDebug = new HashMap<>(); public static Map<String, byte[]> classesDebug = new HashMap<>();
public static String loaderHash;
public static Map<String, byte[]> classesLoader = new HashMap<>(); public static Map<String, byte[]> classesLoader = new HashMap<>();
public static void save() { public static void save() {
@ -98,7 +99,10 @@ public class Main {
indexJar(classes, "Broadway"); indexJar(classes, "Broadway");
indexJar(classesDebug, "DSM"); indexJar(classesDebug, "DSM");
indexJar(classesLoader, "Loader"); indexJar(classesLoader, "Loader");
loaderHash = new StreamReader(new FileInputStream("loader.version")).readAllAsString().trim(); clientHash = new String(classes.get("commit"), StandardCharsets.ISO_8859_1);
loaderHash = new String(classesLoader.getOrDefault("commit", "[dev]".getBytes(StandardCharsets.ISO_8859_1)), StandardCharsets.ISO_8859_1);
clientDebugHash = new String(classesDebug.getOrDefault("commit", "[dev]".getBytes(StandardCharsets.ISO_8859_1)), StandardCharsets.ISO_8859_1);
for (String s : classesDebug.keySet().toArray(new String[0])) { for (String s : classesDebug.keySet().toArray(new String[0])) {
if(s.startsWith("org/spongepowered")) if(s.startsWith("org/spongepowered"))
@ -123,7 +127,11 @@ public class Main {
Socket thisClient = client; Socket thisClient = client;
new Thread(() -> { new Thread(() -> {
try { try {
int type = thisClient.getInputStream().read();
if(type == 0)
LoaderHandler.handle(thisClient); LoaderHandler.handle(thisClient);
if(type == 1)
new ClientHandler().handle(thisClient);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -2,15 +2,4 @@
COMMIT="$(git describe --always)" COMMIT="$(git describe --always)"
echo "package de.com.baseband.client.util.data;" > Client/src/main/java/de/com/baseband/client/util/data/GitHash.java echo -n "$COMMIT" | tee Client/src/main/resources/commit Loader/src/main/resources/commit
echo "package de.com.baseband.launcher.util;" > Loader/src/main/java/de/com/baseband/launcher/util/GitHash.java
(cat | tee -a Client/src/main/java/de/com/baseband/client/util/data/GitHash.java Loader/src/main/java/de/com/baseband/launcher/util/GitHash.java) << EOF
public class GitHash {
public static final String GIT_HASH = "$COMMIT";
}
EOF
echo "$COMMIT" > loader.version