This commit is contained in:
Jess 2023-08-30 05:50:00 +01:00
parent faa880659d
commit 720170427a
8 changed files with 181 additions and 96 deletions

View file

@ -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;

View file

@ -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){}
});

View file

@ -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();

View file

@ -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'
}

View file

@ -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<String, Map<String, String>> entry : UserManager.users.getMap().entrySet()) {
String outerKey = entry.getKey();
Map<String, String> innerMap = entry.getValue();
event.getChannel().sendMessage("==============================").queue();
event.getChannel().sendMessage("Username: " + outerKey).queue();
// Loop through the inner map
for (Map.Entry<String, String> innerEntry : innerMap.entrySet()) {
String innerKey = innerEntry.getKey();
String innerValue = innerEntry.getValue();
event.getChannel().sendMessage("Key: [" + innerKey + "] Value: [" + innerValue+ "]").queue();
}
event.getChannel().sendMessage("==============================").queue();
}
}
}

View file

@ -35,6 +35,7 @@ public class Socket {
while (true) {
java.net.Socket client = socket.accept();
new ClientHandler(client).start();
}
}

View file

@ -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

View file

@ -7,11 +7,12 @@ import java.util.Set;
public class UserMap {
private Map<String, Map<String, String>> 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<String, String> 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<String, Map<String, String>> getMap() {
return map;
}
public void setHwid(String username, String newHwid) {
map.computeIfPresent(username, (u, userMap) -> {