diff --git a/Discord/build.gradle b/Discord/build.gradle new file mode 100644 index 0000000..6c1f692 --- /dev/null +++ b/Discord/build.gradle @@ -0,0 +1,46 @@ +plugins { + id 'java' +} + +group = 'com.baseband.bot' +version = '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + +configurations { + jarLibs +} + +dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0' + testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.0' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.0' + + jarLibs("net.dv8tion:JDA:5.0.0-beta.24") + jarLibs(files('libs/TuddyLIB.jar')) + + implementation configurations.jarLibs +} + + +jar { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + + from { + configurations.jarLibs.collect { + it.isDirectory() ? it : zipTree(it) + } + } { + exclude "LICENSE.txt", "META-INF/MANIFSET.MF", "META-INF/maven/**", "META-INF/*.RSA", "META-INF/*.SF" + } + + manifest.attributes( + 'Main-Class': 'com.baseband.bot.Main', + ) +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/Discord/build/classes/java/main/com/baseband/bot/Main.class b/Discord/build/classes/java/main/com/baseband/bot/Main.class new file mode 100644 index 0000000..e919a35 Binary files /dev/null and b/Discord/build/classes/java/main/com/baseband/bot/Main.class differ diff --git a/Discord/build/tmp/compileJava/previous-compilation-data.bin b/Discord/build/tmp/compileJava/previous-compilation-data.bin new file mode 100644 index 0000000..756b3d2 Binary files /dev/null and b/Discord/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/Discord/libs/TuddyLIB-javadoc.zip b/Discord/libs/TuddyLIB-javadoc.zip new file mode 100644 index 0000000..f9bcbd1 Binary files /dev/null and b/Discord/libs/TuddyLIB-javadoc.zip differ diff --git a/Discord/libs/TuddyLIB.jar b/Discord/libs/TuddyLIB.jar new file mode 100644 index 0000000..8beca52 Binary files /dev/null and b/Discord/libs/TuddyLIB.jar differ diff --git a/Discord/src/main/java/com/baseband/bot/Main.java b/Discord/src/main/java/com/baseband/bot/Main.java new file mode 100644 index 0000000..a9e06ad --- /dev/null +++ b/Discord/src/main/java/com/baseband/bot/Main.java @@ -0,0 +1,163 @@ +package com.baseband.bot; + +//TIP To Run code, press or +// click the icon in the gutter. + +import de.tudbut.net.ws.Client; +import de.tudbut.parsing.TCN; +import de.tudbut.tools.Hasher; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.JDABuilder; +import net.dv8tion.jda.api.entities.Activity; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions; +import net.dv8tion.jda.api.interactions.commands.build.Commands; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import net.dv8tion.jda.api.requests.GatewayIntent; +import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction; + +import java.io.IOException; + +import static de.tudbut.net.http.HTTPContentType.TCN; +import static net.dv8tion.jda.api.interactions.commands.OptionType.STRING; +import static net.dv8tion.jda.api.interactions.commands.OptionType.USER; + +public class Main extends ListenerAdapter { + public static void main(String[] args) { + JDA jda = JDABuilder.createLight("MTI0OTU0Nzg4Mzc1ODM1NDQ2Nw.GKWKLI.QeS4zbIn2q3Yl9KSZ-8z_8izFsspHiLYlIMIpY", GatewayIntent.GUILD_MESSAGES, GatewayIntent.DIRECT_MESSAGES) + .addEventListeners(new Main()) + .build(); + + jda.getPresence().setActivity(Activity.customStatus("Amazing, Kamerad!")); + CommandListUpdateAction commands = jda.updateCommands(); + + commands.addCommands( + Commands.slash("test", "Test command.") + .setGuildOnly(true) + .setDefaultPermissions(DefaultMemberPermissions.DISABLED) + ); + + commands.addCommands( + Commands.slash("reset", "Reset HWID of a given user.") + .addOptions(new OptionData(USER, "user", "The user who's HWID we should reset.") + .setRequired(true)).setGuildOnly(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.") + .setRequired(true)).setGuildOnly(true) + .addOptions(new OptionData(STRING, "password", "The admin password.") + .setRequired(true)).setGuildOnly(true) + .addOptions(new OptionData(STRING, "username", "The username of the user to create.") + .setRequired(true)).setGuildOnly(true) + .setDefaultPermissions(DefaultMemberPermissions.DISABLED) + ); + + + commands.queue(); + } + + @Override + public void onSlashCommandInteraction(SlashCommandInteractionEvent event) { + if (event.getGuild() == null) + return; + switch (event.getName()) { + case "reset" : { + User user = event.getOption("user").getAsUser(); + String password = event.getOption("password").getAsString(); + + try { + Client client = new Client("127.0.0.1", 40001); + TCN tcn = new TCN(); + tcn.set("action", "reset"); + tcn.set("authorisation", Hasher.sha512hex(password)); + tcn.set("discord-id", user.getIdLong()); + client.send(tcn.toString()); + + switch (client.receive()) { + case "200": { + event.reply("`Reset the HWID of "+user.getName()+".`").queue(); + break; + } + + case "403": { + event.reply("`Incorrect Admin Password.`").setEphemeral(true).queue(); + } + + case "503": { + event.reply("`Error! TCN Exception.`").setEphemeral(true).queue(); + break; + } + + case "404": { + event.reply("`User Not Found, Do they have BaseBand?`").setEphemeral(true).queue(); + break; + } + + default: { + 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(); + String username = event.getOption("username").getAsString(); + + try { + Client client = new Client("127.0.0.1", 40001); + TCN tcn = new TCN(); + tcn.set("action", "create"); + tcn.set("authorisation", Hasher.sha512hex(password)); + tcn.set("discord-id", user.getIdLong()); + client.send(tcn.toString()); + + switch (client.receive()) { + case "200": { + event.reply("`Created user with username "+username+". ("+ user.getName() +")`").queue(); + break; + } + + case "403": { + event.reply("`Incorrect Admin Password.`").setEphemeral(true).queue(); + } + + case "400": { + event.reply("`User already exists!`").setEphemeral(true).queue(); + } + + case "503": { + event.reply("`Error! TCN Exception.`").setEphemeral(true).queue(); + break; + } + + default: { + break; + } + } + } catch (IOException e) { + e.printStackTrace(); + event.reply("Exception occurred pushing data to server.").setEphemeral(true).queue(); + } + } + default: + event.reply("I can't handle that command right now :(").setEphemeral(true).queue(); + } + } + + public void say(SlashCommandInteractionEvent event, String content) { + event.reply(content).queue(); // This requires no permissions! + } +} \ No newline at end of file diff --git a/Server/src/main/java/com/baseband/server/BotServiceHandler.java b/Server/src/main/java/com/baseband/server/BotServiceHandler.java new file mode 100644 index 0000000..9cf0dc6 --- /dev/null +++ b/Server/src/main/java/com/baseband/server/BotServiceHandler.java @@ -0,0 +1,80 @@ +package com.baseband.server; + +import at.favre.lib.crypto.bcrypt.BCrypt; +import de.tudbut.net.ws.Connection; +import de.tudbut.net.ws.ConnectionHandler; +import de.tudbut.parsing.TCN; +import de.tudbut.tools.Hasher; +import de.tudbut.tools.StringTools; +import de.tudbut.tools.encryption.Key; + +import java.io.IOException; +import java.security.SecureRandom; + +public class BotServiceHandler implements ConnectionHandler { + + @Override + public void run(Connection connection) throws IOException { + try { + TCN tcn = TCN.read(connection.receive()); + + String password = "1ee7a143df6e0d2f3d2b86b3e5c098c06a07d7c8eb01d629f51712b6bba3a468dc96ef9729d586007ca71383b1c203f6f996bdce3972772d0e5351364eba0d1e"; + + if(!tcn.getString("authorisation").equals(password)) { + connection.send("403"); + return; + } + + String action = tcn.getString("action"); + + switch (action) { + case "reset" : { + 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("hardware-id-reset", true); + connection.send("200"); + } else { + connection.send("404"); + } + break; + } + + case "add" : { + long discord_id = tcn.getLong("discord-id"); + String username = tcn.getString("username"); + + + TCN userToAdd = new TCN(); + + tcn.set("username", username); + tcn.set("password", BCrypt.withDefaults().hashToString(4, new String(SecureRandom.getSeed(64)).toCharArray())); + tcn.set("hardware-id", Hasher.sha512hex(new String(SecureRandom.getSeed(512)))); + tcn.set("hardware-id-reset", true); + tcn.set("disabled", false); + tcn.set("discord-id", discord_id); + + TCN user = (TCN) UserHandler.users.stream() //checking if it already exists LOL + .filter( + a -> ((TCN) a).getLong("discord-id").equals(tcn.getLong("discord-id")) + ).findFirst().orElse(null); + + if(user == null) { + UserHandler.users.add(userToAdd); + connection.send("200"); + } else { + connection.send("400"); + } + break; + } + } + + + } catch (TCN.TCNException e) { + connection.send("503"); + } + } +} diff --git a/Server/src/main/java/com/baseband/server/Main.java b/Server/src/main/java/com/baseband/server/Main.java index e57e0ab..8637974 100644 --- a/Server/src/main/java/com/baseband/server/Main.java +++ b/Server/src/main/java/com/baseband/server/Main.java @@ -14,6 +14,7 @@ import de.tudbut.parsing.JSON; import de.tudbut.parsing.TCN; import de.tudbut.parsing.TCNArray; import de.tudbut.tools.Hasher; +import de.tudbut.net.ws.Server; import java.io.File; import java.io.FileInputStream; @@ -65,6 +66,7 @@ public class Main { tcn.set("hardware-id", Hasher.sha512hex("hardware-id")); tcn.set("hardware-id-reset", true); tcn.set("disabled", false); + tcn.set("discord_id", 631459372576407593L); UserHandler.users.add(tcn); } @@ -82,7 +84,7 @@ public class Main { })); - System.out.println("Indexing..."); + System.out.println("Indexing Jar..."); classes = new HashMap<>(); ZipInputStream jar = new ZipInputStream(new FileInputStream("BaseBand-Broadway.jar")); ZipEntry entry; @@ -92,6 +94,12 @@ public class Main { System.out.println(entry.getName() + ": " + bytes.length); jar.closeEntry(); } + + + System.out.println("Enabling Service Handler for Remote Actioning..."); + Server botServiceServer = new Server(40001); + botServiceServer.addHandler(new BotServiceHandler()); + botServiceServer.run(); System.out.println("Listening!"); ServerSocket server = new ServerSocket(40000); @@ -109,9 +117,7 @@ public class Main { } //WebServices - //Server webServiceServer = new Server(40001); - //webServiceServer.addHandler(new WebServiceHandler()); - //webServiceServer.run(); + } diff --git a/Server/src/main/java/com/baseband/server/WebServiceHandler.java b/Server/src/main/java/com/baseband/server/WebServiceHandler.java deleted file mode 100644 index 9a731b0..0000000 --- a/Server/src/main/java/com/baseband/server/WebServiceHandler.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baseband.server; - -import de.tudbut.net.ws.Connection; -import de.tudbut.net.ws.ConnectionHandler; - -public class WebServiceHandler implements ConnectionHandler { - - @Override - public void run(Connection connection) { - - } -} diff --git a/settings.gradle b/settings.gradle index 3740384..e9c0d37 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,4 +3,5 @@ include 'Loader' include 'Installer' include 'Client' include 'Server' +include 'Discord'