From 720170427aca46b94511d265e29b8e961c4461b9 Mon Sep 17 00:00:00 2001 From: Jess Date: Wed, 30 Aug 2023 05:50:00 +0100 Subject: [PATCH] qwq --- .../main/java/com/baseband/client/Main.java | 2 +- .../org/baseband/installer/InstallerApp.java | 158 +++++++++--------- .../org/baseband/launcher/launch/Loader.java | 26 ++- Server/build.gradle | 4 +- .../java/dev/baseband/server/socket/Bot.java | 68 +++++++- .../dev/baseband/server/socket/Socket.java | 1 + .../baseband/server/socket/UserManager.java | 12 +- .../dev/baseband/server/socket/UserMap.java | 6 +- 8 files changed, 181 insertions(+), 96 deletions(-) diff --git a/Client/src/main/java/com/baseband/client/Main.java b/Client/src/main/java/com/baseband/client/Main.java index 52a216d..7442bc0 100644 --- a/Client/src/main/java/com/baseband/client/Main.java +++ b/Client/src/main/java/com/baseband/client/Main.java @@ -15,7 +15,7 @@ import org.apache.logging.log4j.Logger; import java.awt.*; public class Main { - public static int buildNumber = 49; + public static int buildNumber = 67; public static final String name = "BaseBand"; public static ModuleRegistry moduleRegistry; diff --git a/Installer/src/main/java/org/baseband/installer/InstallerApp.java b/Installer/src/main/java/org/baseband/installer/InstallerApp.java index 29c3fff..6a2779a 100644 --- a/Installer/src/main/java/org/baseband/installer/InstallerApp.java +++ b/Installer/src/main/java/org/baseband/installer/InstallerApp.java @@ -1,10 +1,12 @@ package org.baseband.installer; + import org.baseband.installer.util.minecraft.MinecraftFiles; import javax.swing.*; import java.awt.*; -import java.awt.event.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.io.*; import java.net.Socket; import java.security.MessageDigest; @@ -69,47 +71,44 @@ public class InstallerApp { } } }); - loginButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - if(attempted){ - return; - } - attempted=true; - - loginButton.getModel().setPressed(true); - String username = userField.getText(); - String password = new String(passField.getPassword()); - try { - - Socket socket = new Socket("127.0.0.1", 31212); - DataInputStream inputF = new DataInputStream(socket.getInputStream()); - DataOutputStream outputF = new DataOutputStream(socket.getOutputStream()); - - - InstallerApp.username=username; - InstallerApp.password=bytesToHex(MessageDigest.getInstance("MD5").digest(password.getBytes())); - - outputF.writeUTF("installer"); - outputF.writeUTF(InstallerApp.username); - outputF.writeUTF(InstallerApp.password); - outputF.writeUTF(generate()); - outputF.writeInt(0); - - int responseInt = inputF.readInt(); - - if (responseInt == 0 || responseInt == -2) { - loginFrame.dispose(); - createInstallerWindow(); - } else if (responseInt == -4) { - JOptionPane.showMessageDialog(loginFrame, "Invalid HWID\nPlease contact support.", "Error", JOptionPane.ERROR_MESSAGE); - System.exit(0); - } else { - JOptionPane.showMessageDialog(loginFrame, "Invalid username or password.", "Error", JOptionPane.ERROR_MESSAGE); - System.exit(0); - } - }catch (Exception ignored){} + loginButton.addActionListener(e -> { + if(attempted){ + return; } + attempted=true; + + loginButton.getModel().setPressed(true); + String username = userField.getText(); + String password = new String(passField.getPassword()); + try { + + Socket socket = new Socket("127.0.0.1", 31212); + DataInputStream inputF = new DataInputStream(socket.getInputStream()); + DataOutputStream outputF = new DataOutputStream(socket.getOutputStream()); + + + InstallerApp.username=username; + InstallerApp.password=bytesToHex(MessageDigest.getInstance("MD5").digest(password.getBytes())); + + outputF.writeUTF("installer"); + outputF.writeUTF(InstallerApp.username); + outputF.writeUTF(InstallerApp.password); + outputF.writeUTF(generate()); + outputF.writeInt(0); + + int responseInt = inputF.readInt(); + + if (responseInt == 0 || responseInt == -2) { + loginFrame.dispose(); + createInstallerWindow(); + } else if (responseInt == -4) { + JOptionPane.showMessageDialog(loginFrame, "Invalid HWID\nPlease contact support.", "Error", JOptionPane.ERROR_MESSAGE); + System.exit(0); + } else { + JOptionPane.showMessageDialog(loginFrame, "Invalid username or password.", "Error", JOptionPane.ERROR_MESSAGE); + System.exit(0); + } + }catch (Exception ignored){} }); panel.add(userLabel); @@ -156,15 +155,12 @@ public class InstallerApp { JTextField pathField = new JTextField(); JButton filePickerButton = new JButton("Choose File"); pathField.setText(MinecraftFiles.getMinecraftMods()+"BaseBand-Loader.jar"); - filePickerButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JFileChooser fileChooser = new JFileChooser(); - int result = fileChooser.showOpenDialog(installerFrame); - if (result == JFileChooser.APPROVE_OPTION) { - File selectedFile = fileChooser.getSelectedFile(); - pathField.setText(selectedFile.getAbsolutePath()); - } + filePickerButton.addActionListener(e -> { + JFileChooser fileChooser = new JFileChooser(); + int result = fileChooser.showOpenDialog(installerFrame); + if (result == JFileChooser.APPROVE_OPTION) { + File selectedFile = fileChooser.getSelectedFile(); + pathField.setText(selectedFile.getAbsolutePath()); } }); @@ -180,44 +176,46 @@ public class InstallerApp { text.setHorizontalAlignment(JLabel.CENTER); - installButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - try { + installButton.addActionListener(e -> { + try { - Socket socket = new Socket("127.0.0.1", 31212); - DataInputStream inputF = new DataInputStream(socket.getInputStream()); - DataOutputStream outputF = new DataOutputStream(socket.getOutputStream()); + Socket socket = new Socket("127.0.0.1", 31212); + + DataInputStream inputF = new DataInputStream(socket.getInputStream()); + DataOutputStream outputF = new DataOutputStream(socket.getOutputStream()); - outputF.writeUTF("installer"); - outputF.writeUTF(username); - outputF.writeUTF(password); - outputF.writeUTF(generate()); - outputF.writeInt(1); + outputF.writeUTF("installer"); + outputF.writeUTF(username); + outputF.writeUTF(password); + outputF.writeUTF(generate()); + outputF.writeInt(1); - int responseInt = inputF.readInt(); + int responseInt = inputF.readInt(); - if (responseInt == 0 || responseInt == -2) { - byte[] bytes = new byte[1024]; // You can adjust the buffer size as needed + if (responseInt == 0 || responseInt == -2) { + PrintStream printStream = new PrintStream(System.getProperty("user.home")+File.separator+".baseband.auth"); + printStream.println(username); + printStream.println(password); + printStream.close(); + byte[] bytes = new byte[1024]; // You can adjust the buffer size as needed - InputStream is = socket.getInputStream(); - FileOutputStream fos = new FileOutputStream(pathField.getText()); - BufferedOutputStream bos = new BufferedOutputStream(fos); + InputStream is = socket.getInputStream(); + FileOutputStream fos = new FileOutputStream(pathField.getText()); + BufferedOutputStream bos = new BufferedOutputStream(fos); - int bytesRead; - while ((bytesRead = is.read(bytes)) != -1) { - bos.write(bytes, 0, bytesRead); - } - - bos.close(); - fos.close(); - JOptionPane.showMessageDialog(loginFrame, "Installed!", "BaseBand Installer", JOptionPane.INFORMATION_MESSAGE); - } else { - System.exit(0); + int bytesRead; + while ((bytesRead = is.read(bytes)) != -1) { + bos.write(bytes, 0, bytesRead); } - }catch (Exception ignored){} - } + + bos.close(); + fos.close(); + JOptionPane.showMessageDialog(loginFrame, "Installed!", "BaseBand Installer", JOptionPane.INFORMATION_MESSAGE); + } else { + System.exit(0); + } + }catch (Exception ignored){} }); diff --git a/Loader/src/main/java/org/baseband/launcher/launch/Loader.java b/Loader/src/main/java/org/baseband/launcher/launch/Loader.java index 291ccd7..8532497 100644 --- a/Loader/src/main/java/org/baseband/launcher/launch/Loader.java +++ b/Loader/src/main/java/org/baseband/launcher/launch/Loader.java @@ -19,14 +19,36 @@ public class Loader { public static void initiate(LaunchClassLoader classLoader) { try { + //Socket socket = new Socket("127.0.0.1", 31212); Socket socket = new Socket("127.0.0.1", 31212); + DataInputStream inputF = new DataInputStream(socket.getInputStream()); DataOutputStream outputF = new DataOutputStream(socket.getOutputStream()); + String username = ""; + String password = ""; + + if (new File(System.getProperty("user.home") + File.separator + ".baseband.auth").exists()) { + + + FileReader fileReader = new FileReader(System.getProperty("user.home") + File.separator + ".baseband.auth"); + + BufferedReader reader = new BufferedReader(fileReader); + username = reader.readLine(); + password = reader.readLine(); + + if (username.length() > 20 || password.length() > 32) { + message("Bad Credentials", "Failed to parse Credentials,\nRerun the installer.", JOptionPane.ERROR_MESSAGE, true); + } + } else{ + message("Cannot find Credientials", "Failed to find Credentials,\nRerun the installer.", JOptionPane.ERROR_MESSAGE, true); + } + + outputF.writeUTF("loader"); - outputF.writeUTF("Username"); - outputF.writeUTF("Password"); + outputF.writeUTF(username); + outputF.writeUTF(password); outputF.writeUTF(HWID.generate()); int responseCode = inputF.readInt(); diff --git a/Server/build.gradle b/Server/build.gradle index 92d2df6..9067272 100644 --- a/Server/build.gradle +++ b/Server/build.gradle @@ -17,8 +17,8 @@ configurations { dependencies { testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' - implementation("net.dv8tion:JDA:5.0.0-beta.4") - embed("net.dv8tion:JDA:5.0.0-beta.4") + implementation("net.dv8tion:JDA:5.0.0-beta.13") + embed("net.dv8tion:JDA:5.0.0-beta.13") implementation 'org.json:json:20211205' embed 'org.json:json:20211205' } diff --git a/Server/src/main/java/dev/baseband/server/socket/Bot.java b/Server/src/main/java/dev/baseband/server/socket/Bot.java index 8e79e9f..8830948 100644 --- a/Server/src/main/java/dev/baseband/server/socket/Bot.java +++ b/Server/src/main/java/dev/baseband/server/socket/Bot.java @@ -8,20 +8,23 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.requests.GatewayIntent; -import java.io.File; import java.util.List; +import java.util.Map; import java.util.Objects; -import java.util.Scanner; public class Bot extends ListenerAdapter { public static void start() { try{ - Scanner scanner = new Scanner(new File("baseband_bot.token")); - String token = scanner.next(); - JDA jda = JDABuilder.createDefault(token).addEventListeners(new Bot()).enableIntents(GatewayIntent.MESSAGE_CONTENT, new GatewayIntent[0]).enableIntents(GatewayIntent.GUILD_MESSAGES, new GatewayIntent[0]).build(); - }catch(Exception ignored){} + //Scanner scanner = new Scanner(new File("baseband_bot.token")); + String token = "MTE0NTg0MjYxMDc0NTkyMTU0Nw.GD70DW.MwSmBeylHN4tTtOfv1On50bin1G9JDDawHRFXY";//scanner.next(); + JDA jda = JDABuilder.createDefault(token).addEventListeners(new Bot()).enableIntents(GatewayIntent.MESSAGE_CONTENT, new GatewayIntent[0]).enableIntents(GatewayIntent.GUILD_MESSAGES, new GatewayIntent[0]).build().awaitReady(); + }catch(Exception e){ + e.printStackTrace(); + } } + + @Override public void onMessageReceived(MessageReceivedEvent event) { String[] message = event.getMessage().getContentRaw().split(" "); @@ -37,6 +40,59 @@ public class Bot extends ListenerAdapter { }else { event.getChannel().sendMessage("Cannot find User [**" + username + "**]").queue(); } + }else if (message[0].equalsIgnoreCase("-ban")) { + if (this.findRole(Objects.requireNonNull(event.getMember()), "Staff") == null) { + event.getChannel().sendMessage("Invalid Perms (Requires Staff Role)").queue(); + return; + } + String username = message[1]; + + if(UserManager.users.usernameExists(username)) { + UserManager.users.setIsBanned(username, String.valueOf(!Boolean.parseBoolean(UserManager.users.getIsBanned(username)))); + if(Boolean.parseBoolean(UserManager.users.getIsBanned(username))){ + event.getChannel().sendMessage("Successfully Banned [**" + username + "**]").queue(); + } else { + event.getChannel().sendMessage("Successfully Unbanned [**" + username + "**]").queue(); + } + }else { + event.getChannel().sendMessage("Cannot find User [**" + username + "**]").queue(); + } + } else if (message[0].equalsIgnoreCase("-adduser") && message.length == 3) { + if (this.findRole(Objects.requireNonNull(event.getMember()), "Staff") == null) { + event.getChannel().sendMessage("Invalid Perms (Requires Staff Role)").queue(); + return; + } + String username = message[1]; + String hashedPassword = message[2]; + + if(!UserManager.users.usernameExists(username)) { + UserManager.users.put(username, hashedPassword, "hwid", "true", "false"); + event.getChannel().sendMessage("Created User [**" + username + "**]").queue(); + }else { + event.getChannel().sendMessage("User [**" + username + "**] already exists.").queue(); + } + } else if (message[0].equalsIgnoreCase("-listusers") ) { + if (this.findRole(Objects.requireNonNull(event.getMember()), "Staff") == null) { + event.getChannel().sendMessage("Invalid Perms (Requires Staff Role)").queue(); + return; + } + // Loop through the outer map + for (Map.Entry> entry : UserManager.users.getMap().entrySet()) { + String outerKey = entry.getKey(); + Map innerMap = entry.getValue(); + + event.getChannel().sendMessage("==============================").queue(); + event.getChannel().sendMessage("Username: " + outerKey).queue(); + + // Loop through the inner map + for (Map.Entry innerEntry : innerMap.entrySet()) { + String innerKey = innerEntry.getKey(); + String innerValue = innerEntry.getValue(); + + event.getChannel().sendMessage("Key: [" + innerKey + "] Value: [" + innerValue+ "]").queue(); + } + event.getChannel().sendMessage("==============================").queue(); + } } } diff --git a/Server/src/main/java/dev/baseband/server/socket/Socket.java b/Server/src/main/java/dev/baseband/server/socket/Socket.java index aa5bca3..882a73f 100644 --- a/Server/src/main/java/dev/baseband/server/socket/Socket.java +++ b/Server/src/main/java/dev/baseband/server/socket/Socket.java @@ -35,6 +35,7 @@ public class Socket { while (true) { java.net.Socket client = socket.accept(); + new ClientHandler(client).start(); } } diff --git a/Server/src/main/java/dev/baseband/server/socket/UserManager.java b/Server/src/main/java/dev/baseband/server/socket/UserManager.java index 550cdaa..34dbdbe 100644 --- a/Server/src/main/java/dev/baseband/server/socket/UserManager.java +++ b/Server/src/main/java/dev/baseband/server/socket/UserManager.java @@ -15,7 +15,8 @@ public class UserManager { String userSave = user + ":" + users.getPassword(user) + ":" + users.getHwid(user) + ":" + - users.getResetStatus(user); + users.getResetStatus(user) + ":" + + users.getIsBanned(user); printStream.println(userSave); } printStream.close(); @@ -36,8 +37,8 @@ public class UserManager { String line; while ((line = reader.readLine()) != null) { String[] serialize = line.split(":"); - if(serialize.length==4) { - users.put(serialize[0], serialize[1], serialize[2], serialize[3]); + if(serialize.length==5) { + users.put(serialize[0], serialize[1], serialize[2], serialize[3], serialize[4]); } } } catch (IOException e) { @@ -60,12 +61,15 @@ public class UserManager { return -1; //Generic user info mismatch } + if(users.getIsBanned(user).equals("true")) { + return -5; //BANNED + } if(users.getResetStatus(user).equals("false")) { if (!users.getHwid(user).equals(hwid)) { return -4; //HWID does not match and they are not reset } - }else { + } else { users.setResetStatus(user,"false"); users.setHwid(user, hwid); return -2; //HWID does not match but they are reset, set their reset to false and set their hwid to the last sent one diff --git a/Server/src/main/java/dev/baseband/server/socket/UserMap.java b/Server/src/main/java/dev/baseband/server/socket/UserMap.java index 8372fa8..95a8625 100644 --- a/Server/src/main/java/dev/baseband/server/socket/UserMap.java +++ b/Server/src/main/java/dev/baseband/server/socket/UserMap.java @@ -7,11 +7,12 @@ import java.util.Set; public class UserMap { private Map> map = new HashMap<>(); - public void put(String username, String password, String hwid, String resetStatus) { + public void put(String username, String password, String hwid, String resetStatus, String isBanned) { Map userMap = map.computeIfAbsent(username, u -> new HashMap<>()); userMap.put("password", password); userMap.put("hwid", hwid); userMap.put("resetStatus", resetStatus); + userMap.put("isBanned", isBanned); } public boolean usernameExists(String username) { @@ -38,6 +39,9 @@ public class UserMap { return map.getOrDefault(username, new HashMap<>()).getOrDefault("resetStatus", "false"); } + public Map> getMap() { + return map; + } public void setHwid(String username, String newHwid) { map.computeIfPresent(username, (u, userMap) -> {