?
This commit is contained in:
parent
84d782c18b
commit
3ee0497260
20 changed files with 123 additions and 256 deletions
2
.idea/modules/Client/BaseBand.Client.main.iml
generated
2
.idea/modules/Client/BaseBand.Client.main.iml
generated
|
@ -9,7 +9,9 @@
|
|||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>FORGE</platformType>
|
||||
<platformType>MIXIN</platformType>
|
||||
<platformType>MCP</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
|
|
2
.idea/modules/Client/BaseBand.Client.test.iml
generated
2
.idea/modules/Client/BaseBand.Client.test.iml
generated
|
@ -4,7 +4,9 @@
|
|||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>FORGE</platformType>
|
||||
<platformType>MIXIN</platformType>
|
||||
<platformType>MCP</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
|
|
|
@ -2,25 +2,28 @@ package com.baseband.client;
|
|||
|
||||
|
||||
import com.baseband.client.command.CommandManager;
|
||||
import com.baseband.client.event.EventManager;
|
||||
import com.baseband.client.event.events.SafeTickEvent;
|
||||
import com.baseband.client.module.ModuleRegistry;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class Main {
|
||||
public static int buildNumber = 11;
|
||||
public static EventManager EVENT_MANAGER;
|
||||
public static int buildNumber = 14;
|
||||
|
||||
public static final String name = "BaseBand";
|
||||
public static ModuleRegistry moduleRegistry;
|
||||
public static CommandManager commandRegistry;
|
||||
public static final Logger log = LogManager.getLogger("BaseBand");
|
||||
public static boolean authed = true; //TODO: make this update along with whatever protection Daniella's figuring out
|
||||
|
||||
public static void onInit() {
|
||||
EVENT_MANAGER = new EventManager();
|
||||
moduleRegistry = new ModuleRegistry();
|
||||
commandRegistry = new CommandManager();
|
||||
|
||||
|
@ -30,7 +33,24 @@ public class Main {
|
|||
@SubscribeEvent
|
||||
public void tick(TickEvent.ClientTickEvent e) {
|
||||
if(isIngame()) {
|
||||
EVENT_MANAGER.publish(new SafeTickEvent());
|
||||
//EVENT_MANAGER.publish(new SafeTickEvent());
|
||||
//TODO: implement better event manager
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderText(RenderGameOverlayEvent r) {
|
||||
if (r.getType().equals(RenderGameOverlayEvent.ElementType.TEXT) && isIngame() && !authed) {
|
||||
Minecraft.getMinecraft().gameSettings.limitFramerate = 5;
|
||||
ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
for (int h = 0; h < sr.getScaledHeight(); h += fr.FONT_HEIGHT) {
|
||||
for (int i = 0; i < sr.getScaledWidth(); i = i + fr.getStringWidth("!!UNLICENSED!!")) {
|
||||
if (Minecraft.getMinecraft().world != null && Minecraft.getMinecraft().player != null) {
|
||||
Minecraft.getMinecraft().fontRenderer.drawStringWithShadow("!!UNLICENSED!!", i, h, new Color(100, 255, 100).getRGB());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.baseband.client.command.commands;
|
|||
import com.baseband.client.Main;
|
||||
import com.baseband.client.command.Command;
|
||||
import com.baseband.client.module.Module;
|
||||
import com.baseband.client.module.ModuleRegistry;
|
||||
|
||||
public class ToggleCommand extends Command {
|
||||
public ToggleCommand() {
|
||||
|
@ -14,7 +15,7 @@ public class ToggleCommand extends Command {
|
|||
if (args.length != 1) {
|
||||
return "Please specify a module name.";
|
||||
}
|
||||
Module module = Main.moduleRegistry.getModule(args[0]);
|
||||
Module module = ModuleRegistry.getModule(args[0]);
|
||||
if (module == null) {
|
||||
return "Cannot find module.";
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package com.baseband.client.event;
|
||||
|
||||
public class Event {
|
||||
boolean isCancelled = false;
|
||||
|
||||
public void setCancelled(boolean cancelled) {
|
||||
isCancelled = cancelled;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return isCancelled;
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
package com.baseband.client.event;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class EventManager {
|
||||
private final Map<Class<? extends Event>, List<SubscriberMethod>> subscribers;
|
||||
private final Object lock;
|
||||
|
||||
public EventManager() {
|
||||
subscribers = new HashMap<>();
|
||||
lock = new Object();
|
||||
}
|
||||
|
||||
public void subscribe(Object subscriber) {
|
||||
Class<?> subscriberClass = subscriber.getClass();
|
||||
Method[] methods = subscriberClass.getDeclaredMethods();
|
||||
|
||||
for (Method method : methods) {
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
if (parameterTypes.length == 1 && Event.class.isAssignableFrom(parameterTypes[0])) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Event> eventType = (Class<? extends Event>) parameterTypes[0];
|
||||
SubscriberMethod subscriberMethod = new SubscriberMethod(subscriber, method);
|
||||
|
||||
synchronized (lock) {
|
||||
List<SubscriberMethod> eventSubscribers = subscribers.getOrDefault(eventType, new ArrayList<>());
|
||||
eventSubscribers.add(subscriberMethod);
|
||||
subscribers.put(eventType, eventSubscribers);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unsubscribe(Object subscriber) {
|
||||
synchronized (lock) {
|
||||
for (List<SubscriberMethod> eventSubscribers : subscribers.values()) {
|
||||
eventSubscribers.removeIf(subscriberMethod -> subscriberMethod.subscriber == subscriber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void publish(Event event) {
|
||||
Class<? extends Event> eventType = event.getClass();
|
||||
List<SubscriberMethod> eventSubscribers;
|
||||
synchronized (lock) {
|
||||
eventSubscribers = new ArrayList<>(subscribers.getOrDefault(eventType, new ArrayList<>()));
|
||||
}
|
||||
for (SubscriberMethod subscriberMethod : eventSubscribers) {
|
||||
subscriberMethod.invoke(event);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SubscriberMethod {
|
||||
private final Object subscriber;
|
||||
private final Method method;
|
||||
|
||||
private SubscriberMethod(Object subscriber, Method method) {
|
||||
this.subscriber = subscriber;
|
||||
this.method = method;
|
||||
this.method.setAccessible(true);
|
||||
}
|
||||
|
||||
private void invoke(Event event) {
|
||||
try {
|
||||
method.invoke(subscriber, event);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package com.baseband.client.event.events;
|
||||
|
||||
import com.baseband.client.event.Event;
|
||||
|
||||
|
||||
|
||||
public class SafeTickEvent extends Event {
|
||||
//Stub
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
package com.baseband.client.gui;
|
||||
|
||||
public abstract class Button {
|
||||
|
||||
private int x, y, width, height;
|
||||
private boolean hovered;
|
||||
|
||||
public Button(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public abstract void drawButton(int mouseX, int mouseY, float partialTicks);
|
||||
|
||||
public void onClick(int mouseX, int mouseY) {}
|
||||
|
||||
public boolean isMouseOver(int mouseX, int mouseY) {
|
||||
return mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
|
||||
}
|
||||
|
||||
public void setHovered(boolean hovered) {
|
||||
this.hovered = hovered;
|
||||
}
|
||||
|
||||
public boolean isHovered() {
|
||||
return hovered;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package com.baseband.client.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ButtonList {
|
||||
|
||||
private List<Button> buttons = new ArrayList<>();
|
||||
|
||||
public void addButton(Button button) {
|
||||
buttons.add(button);
|
||||
}
|
||||
|
||||
public void removeButton(Button button) {
|
||||
buttons.remove(button);
|
||||
}
|
||||
|
||||
public void drawButtons(int mouseX, int mouseY, float partialTicks) {
|
||||
for (Button button : buttons) {
|
||||
button.setHovered(button.isMouseOver(mouseX, mouseY));
|
||||
button.drawButton(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
}
|
||||
|
||||
public void onClick(int mouseX, int mouseY) {
|
||||
for (Button button : buttons) {
|
||||
if (button.isMouseOver(mouseX, mouseY)) {
|
||||
button.onClick(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package com.baseband.client.gui;
|
||||
|
||||
import com.baseband.client.Main;
|
||||
import com.baseband.client.module.Module;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ClickGui extends GuiScreen {
|
||||
|
||||
private ButtonList buttonList = new ButtonList();
|
||||
|
||||
public ClickGui() {
|
||||
int y=10;
|
||||
int x=10;
|
||||
|
||||
for (Module m : Main.moduleRegistry.getModuleList()) {
|
||||
Button moduleButton = new Button(x, y, 120, 15) {
|
||||
@Override
|
||||
public void drawButton(int mouseX, int mouseY, float partialTicks) {
|
||||
Gui.drawRect(getX(), getY(), getX() + getWidth(), getY() + getHeight(), Color.GREEN.getRGB());
|
||||
Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(m.getName()+":"+m.isEnabled(), getX() + 3, getY() + 3, 0xffffffff);
|
||||
}
|
||||
@Override
|
||||
public void onClick(int mouseX, int mouseY) {
|
||||
m.setEnabled(!m.isEnabled());
|
||||
|
||||
}
|
||||
};
|
||||
addButton(moduleButton);
|
||||
y+=moduleButton.getHeight();
|
||||
}
|
||||
}
|
||||
|
||||
public void addButton(Button button) {
|
||||
buttonList.addButton(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawDefaultBackground();
|
||||
buttonList.drawButtons(mouseX, mouseY, partialTicks);
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
buttonList.onClick(mouseX, mouseY);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package com.baseband.client.module;
|
||||
|
||||
import com.baseband.client.Main;
|
||||
|
||||
public class Module {
|
||||
String name;
|
||||
boolean isEnabled = false;
|
||||
|
@ -19,10 +17,10 @@ public class Module {
|
|||
isEnabled=enabled;
|
||||
if(isEnabled) {
|
||||
enable();
|
||||
Main.EVENT_MANAGER.subscribe(this);
|
||||
//Main.EVENT_MANAGER.subscribe(this);
|
||||
}else {
|
||||
disable();
|
||||
Main.EVENT_MANAGER.unsubscribe(this);
|
||||
//Main.EVENT_MANAGER.unsubscribe(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,11 +36,7 @@ public class Module {
|
|||
return isEnabled;
|
||||
}
|
||||
|
||||
public void enable(){
|
||||
public void enable(){}
|
||||
|
||||
}
|
||||
|
||||
public void disable(){
|
||||
|
||||
}
|
||||
public void disable(){}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package com.baseband.client.module.modules;
|
||||
|
||||
import com.baseband.client.event.events.SafeTickEvent;
|
||||
import com.baseband.client.gui.ClickGui;
|
||||
import com.baseband.client.module.Module;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class ClickGUI extends Module {
|
||||
|
@ -12,8 +9,10 @@ public class ClickGUI extends Module {
|
|||
this.setKey(Keyboard.KEY_PERIOD);
|
||||
}
|
||||
|
||||
public void tick(SafeTickEvent e){
|
||||
Minecraft.getMinecraft().displayGuiScreen(new ClickGui());
|
||||
|
||||
public void enable() {
|
||||
//Minecraft.getMinecraft().displayGuiScreen(new ClickGui());
|
||||
//TODO: this existed but it was just the old V/Line gui, *do me proud tud!* :3
|
||||
this.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.baseband.client.module.modules;
|
||||
|
||||
import com.baseband.client.event.events.SafeTickEvent;
|
||||
import com.baseband.client.module.Module;
|
||||
|
||||
public class Test extends Module {
|
||||
|
@ -9,9 +8,6 @@ public class Test extends Module {
|
|||
}
|
||||
|
||||
|
||||
public void tick(SafeTickEvent event) {
|
||||
|
||||
}
|
||||
|
||||
public void enable() {
|
||||
super.enable();
|
||||
|
|
|
@ -9,7 +9,26 @@ repositories {
|
|||
mavenCentral()
|
||||
}
|
||||
|
||||
configurations {
|
||||
embed
|
||||
compile.extendsFrom(embed)
|
||||
}
|
||||
|
||||
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 'org.json:json:20211205'
|
||||
embed 'org.json:json:20211205'
|
||||
}
|
||||
|
||||
jar {
|
||||
from {
|
||||
configurations.embed.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': 'dev.baseband.server.Main'
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package dev.baseband.server;
|
||||
|
||||
import dev.baseband.server.socket.Bot;
|
||||
import dev.baseband.server.socket.Socket;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws IOException {
|
||||
Bot.start();
|
||||
Socket.launch(args);
|
||||
}
|
||||
}
|
||||
|
|
48
Server/src/main/java/dev/baseband/server/socket/Bot.java
Normal file
48
Server/src/main/java/dev/baseband/server/socket/Bot.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
package dev.baseband.server.socket;
|
||||
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
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.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){}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
String[] message = event.getMessage().getContentRaw().split(" ");
|
||||
if (message[0].equalsIgnoreCase("-reset")) {
|
||||
if (this.findRole(Objects.requireNonNull(event.getMember()), "Staff") == null) {
|
||||
event.getChannel().sendMessage("Invalid Perms (Requires Staff Role)").queue();
|
||||
return;
|
||||
}
|
||||
String username = message[1];
|
||||
event.getChannel().sendMessage("Resetting HWID of username [**" + username + "**]").queue();
|
||||
if(UserManager.users.usernameExists(username)) {
|
||||
UserManager.users.setResetStatus(username, "true");
|
||||
event.getChannel().sendMessage("HWID of username [**" + username + "**] reset.").queue();
|
||||
}else {
|
||||
event.getChannel().sendMessage("Cannot find User [**" + username + "**]").queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Role findRole(Member member, String name) {
|
||||
List<Role> roles = member.getRoles();
|
||||
return roles.stream().filter(role -> role.getName().equals(name)).findFirst().orElse(null);
|
||||
}
|
||||
}
|
|
@ -15,6 +15,8 @@ public class ClientHandler extends Thread {
|
|||
DataOutputStream dos = new DataOutputStream(client.getOutputStream());
|
||||
DataInputStream dis = new DataInputStream(client.getInputStream());
|
||||
|
||||
|
||||
|
||||
String username = dis.readUTF();
|
||||
String hashedPassword = dis.readUTF();
|
||||
String hwid = dis.readUTF();
|
||||
|
|
|
@ -27,7 +27,6 @@ public class Socket {
|
|||
while (true) {
|
||||
java.net.Socket client = socket.accept();
|
||||
|
||||
|
||||
new ClientHandler(client).start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ public class UserManager {
|
|||
return -1; //Generic user info mismatch
|
||||
}
|
||||
|
||||
|
||||
if(users.getResetStatus(user).equals("false")) {
|
||||
if (!users.getHwid(user).equals(hwid)) {
|
||||
return -4; //HWID does not match and they are not reset
|
||||
|
|
|
@ -26,6 +26,10 @@ public class UserMap {
|
|||
return map.getOrDefault(username, new HashMap<>()).get("password");
|
||||
}
|
||||
|
||||
public String getIsBanned(String username) {
|
||||
return map.getOrDefault(username, new HashMap<>()).get("isBanned");
|
||||
}
|
||||
|
||||
public String getHwid(String username) {
|
||||
return map.getOrDefault(username, new HashMap<>()).get("hwid");
|
||||
}
|
||||
|
@ -49,6 +53,13 @@ public class UserMap {
|
|||
});
|
||||
}
|
||||
|
||||
public void setIsBanned(String username, String newPassword) {
|
||||
map.computeIfPresent(username, (u, userMap) -> {
|
||||
userMap.put("isBanned", newPassword);
|
||||
return userMap;
|
||||
});
|
||||
}
|
||||
|
||||
public void setResetStatus(String username, String resetStatus) {
|
||||
map.computeIfPresent(username, (u, userMap) -> {
|
||||
userMap.put("resetStatus", resetStatus);
|
||||
|
|
Loading…
Add table
Reference in a new issue