diff --git a/.forgejo/workflows/build-server.yml b/.forgejo/workflows/build-server.yml index 0aaab3e..83637ff 100644 --- a/.forgejo/workflows/build-server.yml +++ b/.forgejo/workflows/build-server.yml @@ -4,6 +4,7 @@ on: paths: - ".forgejo/workflows/build-server.yml" - "Server/**" + - "Discord/**" jobs: @@ -23,15 +24,17 @@ jobs: - name: Initialize Gradle uses: https://github.com/gradle/actions/setup-gradle@v3 - name: Build - run: | - cd Server - ../gradlew --no-daemon build - cd .. + run: ./gradlew --no-daemon Server:build Discord:build - name: Upload Server uses: forgejo/upload-artifact@v4 with: name: BaseBand-Server.jar path: Server/build/libs/BaseBand-Server.jar + - name: Upload Bot + uses: forgejo/upload-artifact@v4 + with: + name: BaseBand-Discord.jar + path: Discord/build/libs/BaseBand-Discord.jar - name: Release to server if: github.ref == 'refs/heads/release' env: @@ -40,4 +43,6 @@ jobs: BB_HOST: ${{ vars.BB_HOST }} BB_PORT: ${{ vars.BB_PORT }} BB_PATH: ${{ vars.BB_PATH }} - run: bash push_file.sh Server/build/libs/BaseBand-Server.jar 3847 + run: | + bash push_file.sh Server/build/libs/BaseBand-Server.jar + bash push_file.sh Discord/build/libs/BaseBand-Discord.jar diff --git a/Discord/build.gradle b/Discord/build.gradle index 6c1f692..5f8d9eb 100644 --- a/Discord/build.gradle +++ b/Discord/build.gradle @@ -39,6 +39,8 @@ jar { manifest.attributes( 'Main-Class': 'com.baseband.bot.Main', ) + + archiveFileName = "BaseBand-Discord.jar" } test { diff --git a/Discord/src/main/java/com/baseband/bot/Main.java b/Discord/src/main/java/com/baseband/bot/Main.java index a73e212..26d33ae 100644 --- a/Discord/src/main/java/com/baseband/bot/Main.java +++ b/Discord/src/main/java/com/baseband/bot/Main.java @@ -19,6 +19,7 @@ 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 org.jetbrains.annotations.NotNull; import java.io.IOException; import java.net.Socket; @@ -45,38 +46,39 @@ public class Main extends ListenerAdapter { 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) + .setRequired(true)) .addOptions(new OptionData(STRING, "password", "The admin password.") - .setRequired(true)).setGuildOnly(true) - .setDefaultPermissions(DefaultMemberPermissions.DISABLED) + .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) + .setRequired(true)) .addOptions(new OptionData(STRING, "password", "The admin password.") - .setRequired(true)).setGuildOnly(true) + .setRequired(true)) .addOptions(new OptionData(STRING, "username", "The username of the user to create.") - .setRequired(true)).setGuildOnly(true) + .setRequired(true)) + .setGuildOnly(true) .setDefaultPermissions(DefaultMemberPermissions.DISABLED) ); commands.addCommands( Commands.slash("password", "Set your password.") .addOptions(new OptionData(STRING, "password", "Your new password.") - .setRequired(true)).setGuildOnly(true) + .setRequired(true)) .setDefaultPermissions(DefaultMemberPermissions.ENABLED) ); - commands.queue(); + commands.complete(); + System.out.println("INIT COMPLETE"); } @Override - public void onSlashCommandInteraction(SlashCommandInteractionEvent event) { - if (event.getGuild() == null) - return; + public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) { TypedInputStream tis; TypedOutputStream tos; @@ -100,7 +102,6 @@ public class Main extends ListenerAdapter { tcn.set("action", "reset"); tcn.set("authorisation", Hasher.sha512hex(password)); tcn.set("discord-id", user.getIdLong()); - event.reply("Contacting server...").setEphemeral(true).queue(); tos.writeString(tcn.toString()); switch (tis.readInt()) { @@ -146,7 +147,6 @@ public class Main extends ListenerAdapter { tcn.set("action", "add"); tcn.set("authorisation", Hasher.sha512hex(password)); tcn.set("discord-id", user.getIdLong()); - event.reply("Contacting server...").setEphemeral(true).queue(); tos.writeString(tcn.toString()); switch (tis.readInt()) { @@ -192,7 +192,6 @@ public class Main extends ListenerAdapter { tcn.set("authorisation", "1ee7a143df6e0d2f3d2b86b3e5c098c06a07d7c8eb01d629f51712b6bba3a468dc96ef9729d586007ca71383b1c203f6f996bdce3972772d0e5351364eba0d1e"); tcn.set("password", password); tcn.set("discord-id", user.getIdLong()); - event.reply("Contacting server...").setEphemeral(true).queue(); tos.writeString(tcn.toString()); switch (tis.readInt()) { diff --git a/Server/src/main/java/com/baseband/server/BotServiceHandler.java b/Server/src/main/java/com/baseband/server/BotServiceHandler.java index 2658046..55f3960 100644 --- a/Server/src/main/java/com/baseband/server/BotServiceHandler.java +++ b/Server/src/main/java/com/baseband/server/BotServiceHandler.java @@ -16,6 +16,7 @@ public class BotServiceHandler { public static void handle(Socket connection) throws IOException { TypedInputStream tis = new TypedInputStream(connection.getInputStream()); TypedOutputStream tos = new TypedOutputStream(connection.getOutputStream()); + String action = "UNINIT"; try { TCN tcn = TCN.read(tis.readString()); @@ -26,7 +27,7 @@ public class BotServiceHandler { return; } - String action = tcn.getString("action"); + action = tcn.getString("action"); System.out.println("Bot processing " + action); @@ -68,12 +69,12 @@ public class BotServiceHandler { TCN userToAdd = new TCN(); - tcn.set("username", username); - tcn.set("password", BCrypt.withDefaults().hashToString(4, new String(SecureRandom.getSeed(32), StandardCharsets.ISO_8859_1).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); + userToAdd.set("username", username); + userToAdd.set("password", ""); + userToAdd.set("hardware-id", ""); + userToAdd.set("hardware-id-reset", true); + userToAdd.set("disabled", false); + userToAdd.set("discord-id", discord_id); TCN user = (TCN) UserHandler.users.stream() //checking if it already exists LOL .filter( @@ -90,13 +91,14 @@ public class BotServiceHandler { } } - System.out.println("Bot processed " + action); - Main.save(); } catch (Exception e) { + e.printStackTrace(); tos.writeInt(400); } finally { + + System.out.println("Bot processed " + action); tos.getStream().close(); } } diff --git a/Server/src/main/java/com/baseband/server/Main.java b/Server/src/main/java/com/baseband/server/Main.java index da61fb7..dbfcd23 100644 --- a/Server/src/main/java/com/baseband/server/Main.java +++ b/Server/src/main/java/com/baseband/server/Main.java @@ -81,7 +81,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); + tcn.set("discord-id", 0); UserHandler.users.add(tcn); }