implement branch switching

This commit is contained in:
Daniella / Tove 2024-06-12 13:50:15 +02:00
parent 960abca5cc
commit cd9d1b8095
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
10 changed files with 127 additions and 30 deletions

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.Updater;
import de.com.baseband.client.util.interact.Chat;
import de.com.baseband.prod.LoadHandler;
import de.tudbut.tools.Lock;
import hint.Mobf;
import net.minecraft.client.Minecraft;
@ -28,7 +29,7 @@ public class BaseBand {
public static final Logger LOGGER = LogManager.getLogger("BaseBand");
public static final SecureRandom RANDOM = new SecureRandom();
public static String buildString = "Broadway";
public static String buildString = LoadHandler.data.getBoolean("main-branch") ? "Dark Side of the Moon" : "Broadway";
public static final EventManager eventManager = new EventManager(LOGGER::error);
public static final RemoteEventManager remoteEventManager = new RemoteEventManager();
public static final FMLEventHandler fmlEventHandlerInstance = new FMLEventHandler();

View file

@ -1,5 +1,6 @@
package de.com.baseband.client;
import de.com.baseband.prod.LoadHandler;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
@ -25,8 +26,7 @@ public class DevStub implements IFMLLoadingPlugin {
@Mod.EventHandler
public void onInit(FMLPostInitializationEvent event) {
BaseBand.buildString = "Dark Side of the Moon";
BaseBand.onInit();
LoadHandler.data.set("main-branch", true);
}
@Override

View file

@ -1,10 +1,14 @@
package de.com.baseband.prod;
import de.com.baseband.client.BaseBand;
import de.tudbut.parsing.TCN;
public class LoadHandler {
public static void loaded() {
public static TCN data = new TCN();
public static void loaded(TCN data) {
LoadHandler.data = data;
try {
Class.forName("de.com.baseband.launcher.Tweaker").getDeclaredMethod("loaded", Class.class).invoke(null, BaseBand.class);
} catch (Exception e) {

View file

@ -48,6 +48,18 @@ public class Main extends ListenerAdapter {
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)
);
commands.addCommands(
Commands.slash("branch", "Set branch of a given user.")
.addOptions(new OptionData(USER, "user", "The user who's branch we should change.")
.setRequired(true))
.addOptions(new OptionData(STRING, "branch", "The branch.")
.setRequired(true))
.addOptions(new OptionData(STRING, "password", "The admin password.")
.setRequired(true))
.setGuildOnly(true)
.setDefaultPermissions(DefaultMemberPermissions.DISABLED)
);
commands.addCommands(
Commands.slash("add", "Add a user.")
.addOptions(new OptionData(USER, "user", "The user who's HWID we should reset.")
@ -133,6 +145,54 @@ public class Main extends ListenerAdapter {
break;
}
case "branch": {
User user = event.getOption("user").getAsUser();
String branch = event.getOption("branch").getAsString();
String password = event.getOption("password").getAsString();
try {
TCN tcn = new TCN();
tcn.set("action", "reset");
tcn.set("authorisation", Hasher.sha512hex(password));
tcn.set("discord-id", user.getIdLong());
tcn.set("branch", branch);
tos.writeString(tcn.toString());
switch (tis.readInt()) {
case 201: {
event.getChannel().sendMessage("Branch of **`" + user.getName() + "`** has been set.").queue();
event.reply("`Success.`").setEphemeral(true).queue();
break;
}
case 403: {
event.reply("`Incorrect Admin Password.`").setEphemeral(true).queue();
break;
}
case 400: {
event.reply("`Error! I sent malformed data somehow.`").setEphemeral(true).queue();
break;
}
case 404: {
event.reply("`User Not Found, Do they have BaseBand?`").setEphemeral(true).queue();
break;
}
default: {
event.reply("Error! I am out of sync with the server.").setEphemeral(true).queue();
break;
}
}
} catch (IOException e) {
e.printStackTrace();
event.reply("Exception occurred pushing data to server.").setEphemeral(true).queue();
}
break;
}
case "add": {
User user = event.getOption("user").getAsUser();
String password = event.getOption("password").getAsString();
@ -148,7 +208,8 @@ public class Main extends ListenerAdapter {
switch (tis.readInt()) {
case 201: {
event.reply("Created user with username **`" + username + "`**. (`" + user.getName() + "`)").setEphemeral(true).queue();
event.getChannel().sendMessage("Created user with username **`" + username + "`**. (`" + user.getName() + "`)").queue();
event.reply("`Success.`").setEphemeral(true).queue();
break;
}

View file

@ -66,6 +66,8 @@ public class Loader implements Util {
if(status == Response.OK) {
try {
TCN clientData = TCN.readMap(Tools.stringToMap(key.decryptString(inputStream.readString())));
HashMap<String, byte[]> data = new HashMap<>();
RawKey rk = new RawKey(key.toBytes());
int n = inputStream.readInt();
@ -75,7 +77,7 @@ public class Loader implements Util {
LOGGER.info("BaseBand downloaded: " + data.size() + " classes.");
classLoader = new CustomClassLoader(data);
classLoader.inject();
classLoader.informClient();
classLoader.informClient(clientData);
} catch (Exception e) {
LOGGER.fatal("BaseBand failed to (down)load.");
e.printStackTrace();

View file

@ -2,6 +2,7 @@ package de.com.baseband.launcher.classloader;
import de.com.baseband.launcher.url.URLWrapper;
import de.com.baseband.launcher.util.Util;
import de.tudbut.parsing.TCN;
import de.tudbut.security.*;
import de.tudbut.security.permissionmanager.CallClassRestriction;
import de.tudbut.security.permissionmanager.ClassLoaderRestriction;
@ -77,10 +78,10 @@ public class CustomClassLoader extends ClassLoader implements Util {
}
}
public void informClient() {
public void informClient(TCN clientData) {
LOGGER.info("Informing client that it has been loaded.");
try {
this.loadClass("de.com.baseband.prod.LoadHandler").getDeclaredMethod("loaded").invoke(null);
this.loadClass("de.com.baseband.prod.LoadHandler").getDeclaredMethod("loaded", TCN.class).invoke(null, clientData);
} catch (Exception e) {
throw new RuntimeException(e);
}

View file

@ -59,6 +59,21 @@ public class BotServiceHandler {
break;
}
case "branch": {
TCN user = (TCN) UserHandler.users.stream()
.filter(
a -> ((TCN) a).getLong("discord-id").equals(tcn.getLong("discord-id"))
).findFirst().orElse(null);
if(user != null) {
user.set("branch", tcn.getString("branch"));
tos.writeInt(201);
} else {
tos.writeInt(404);
}
break;
}
case "add": {
long discord_id = tcn.getLong("discord-id");
String username = tcn.getString("username");
@ -72,6 +87,7 @@ public class BotServiceHandler {
userToAdd.set("hardware-id-reset", true);
userToAdd.set("disabled", false);
userToAdd.set("discord-id", discord_id);
userToAdd.set("main-branch", false);
TCN user = (TCN) UserHandler.users.stream() //checking if it already exists LOL
.filter(

View file

@ -2,6 +2,7 @@ package de.com.baseband.server;
import de.tudbut.io.TypedInputStream;
import de.tudbut.io.TypedOutputStream;
import de.tudbut.obj.DoubleTypedObject;
import de.tudbut.parsing.TCN;
import de.tudbut.tools.Tools;
import de.tudbut.tools.encryption.Key;
@ -22,9 +23,12 @@ public class LoaderHandler {
TCN userData = TCN.readMap(Tools.stringToMap(key.decryptString(inputStream.readString())));
int response = UserHandler.isValid(userData);
outputStream.writeInt(response);
if(response == UserHandler.Response.OK.ordinal()) {
DoubleTypedObject<Integer, TCN> response = UserHandler.isValid(userData);
outputStream.writeInt(response.o);
if(response.o == UserHandler.Response.OK.ordinal()) {
TCN data = new TCN();
data.set("main-branch", "main".equals(response.t.getString("branch")));
RawKey rk = new RawKey(key.toBytes());
outputStream.writeInt(Main.classes.size());
for (Map.Entry<String, byte[]> entry : Main.classes.entrySet()) {

View file

@ -35,7 +35,8 @@ public class Main {
public static RSAKey rsaKey;
public static boolean denyAll = false;
public static Map<String, byte[]> classes;
public static Map<String, byte[]> classes = new HashMap<>();
public static Map<String, byte[]> classesDebug = new HashMap<>();
public static void save() {
try {
@ -82,6 +83,7 @@ public class Main {
tcn.set("hardware-id-reset", true);
tcn.set("disabled", false);
tcn.set("discord-id", 0);
tcn.set("main-branch", false);
UserHandler.users.add(tcn);
}
@ -91,15 +93,8 @@ public class Main {
System.out.println("Indexing Jar...");
classes = new HashMap<>();
ZipInputStream jar = new ZipInputStream(new FileInputStream("BaseBand-Broadway.jar"));
ZipEntry entry;
while ((entry = jar.getNextEntry()) != null) {
byte[] bytes = new StreamReader(jar).readAllAsBytes();
classes.put(entry.getName(), bytes);
System.out.println(entry.getName() + ": " + bytes.length);
jar.closeEntry();
}
indexJar(classes, "Broadway");
indexJar(classesDebug, "DSM");
System.out.println("Enabling Service Handler for Remote Actioning...");
@ -131,6 +126,18 @@ public class Main {
}
private static void indexJar(Map<String, byte[]> classes, String label) throws IOException {
classes.clear();
ZipInputStream jar = new ZipInputStream(new FileInputStream("BaseBand-" + label + ".jar"));
ZipEntry entry;
while ((entry = jar.getNextEntry()) != null) {
byte[] bytes = new StreamReader(jar).readAllAsBytes();
classes.put(entry.getName(), bytes);
jar.closeEntry();
}
jar.close();
}
private static void remoteActionHandler() throws IOException {
ServerSocket server = new ServerSocket(40001);
Socket client;

View file

@ -1,15 +1,16 @@
package de.com.baseband.server;
import at.favre.lib.crypto.bcrypt.BCrypt;
import de.tudbut.obj.DoubleTypedObject;
import de.tudbut.parsing.TCN;
import de.tudbut.parsing.TCNArray;
public class UserHandler {
public static TCNArray users = new TCNArray();
public static int isValid(TCN remoteTCN) {
public static DoubleTypedObject<Integer, TCN> isValid(TCN remoteTCN) {
if(CheckNull.isNull(remoteTCN.get("username"))) {
return Response.FORBIDDEN.ordinal();
return new DoubleTypedObject<>(Response.FORBIDDEN.ordinal(), null);
}
try {
@ -24,35 +25,35 @@ public class UserHandler {
boolean isDisabled = localTCN.getBoolean("disabled");
if(isDisabled) { //if they're banned we're not even looking at their TCN
return Response.BANNED.ordinal();
return new DoubleTypedObject<>(Response.BANNED.ordinal(), localTCN);
}
String remotePassword = remoteTCN.getString("password");
String remoteHardwareID = remoteTCN.getString("hardware-id");
if(CheckNull.isNull(remotePassword, remoteHardwareID)) {
return Response.SERVER_ERROR.ordinal();
return new DoubleTypedObject<>(Response.SERVER_ERROR.ordinal(), localTCN);
}
if (isReset) {
localTCN.set("hardware-id-reset", false);
localTCN.set("hardware-id", remoteHardwareID);
return Response.RESET.ordinal();
return new DoubleTypedObject<>(Response.RESET.ordinal(), localTCN);
}
if(!localHardwareID.equals(remoteTCN.getString("hardware-id"))) {
return Response.HWID_INVALID.ordinal();
return new DoubleTypedObject<>(Response.HWID_INVALID.ordinal(), localTCN);
}
if(BCrypt.verifyer().verify(remotePassword.toCharArray(), localPassword.toCharArray()).verified) {
return Response.OK.ordinal();
return new DoubleTypedObject<>(Response.OK.ordinal(), localTCN);
}
}
//LOL
return Response.FORBIDDEN.ordinal();
return new DoubleTypedObject<>(Response.FORBIDDEN.ordinal(), localTCN);
} catch(Exception e) {
return Response.SERVER_ERROR.ordinal();
return new DoubleTypedObject<>(Response.SERVER_ERROR.ordinal(), null);
}
}