Skip to content

Commit

Permalink
lots of fixes, changes, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikos3k committed Aug 23, 2021
1 parent 01c9dd0 commit b74c110
Show file tree
Hide file tree
Showing 109 changed files with 783 additions and 807 deletions.
27 changes: 13 additions & 14 deletions BetterProxy/config.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
{
"port": 1337,
"motd": {
"versionInfo": "&4BetterProxy",
"line1": " &f✖ &l&m\\-\\-\\-\\-&r&f&l>> &6BetterProxy &f&l<<&m-/-/-/-/&r&f ✖&r",
"line2": " &c----&e/ &6✯ &eProxy by ANONIMUS &6✯ &e\\&c----",
"playerList": [
"&f---------------------------------------------------",
" &8Supported versions:",
" &e%supported_versions%",
"&f---------------------------------------------------"
],
"icon": "icon.png",
"protocol": 0
"motd" : {
"protocol" : 0,
"playerList" : [ "&f---------------------------------------------------", " &8Supported versions:", " &e%supported_versions%", "&f---------------------------------------------------" ],
"icon" : "icon.png",
"versionInfo" : "&4BetterProxy",
"line2" : " &c----&e/ &6✯ &eProxy by ANONIMUS &6✯ &e\\&c----",
"line1" : " &f✖ &l&m\\-\\-\\-\\-&r&f&l>> &6BetterProxy &f&l<<&m-/-/-/-/&r&f ✖&r"
},
"packet_debugger": true
"debug" : {
"debugType" : "LEGIBLE",
"debugger" : true,
"showCustomPackets" : false
},
"port" : 1337
}
5 changes: 3 additions & 2 deletions BetterProxy/exploits/dream.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions BetterProxy/exploits/good.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions BetterProxy/exploits/killer.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions BetterProxy/exploits/light.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions BetterProxy/exploits/moon.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions BetterProxy/exploits/power.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.45.Final</version>
<version>4.1.67.Final</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<version>2.8.7</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand All @@ -45,7 +45,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
Expand All @@ -55,7 +55,7 @@
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1</version>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
Expand All @@ -75,9 +75,10 @@
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-xc</artifactId>
<version>1.9.12</version>
<version>1.9.13</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/ANONIMUS/proxy/BetterProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
public class BetterProxy {
private final CommandManager commandManager;
private final PacketRegistry packetRegistry;
private final Map<String, Account> accounts;
private final ExploitManager exploitManager;
private final ConfigManager configManager;
private final PlayerManager playerManager;
private static BetterProxy instance;
private final Map<String, Account> accounts;
private final ProxyServer server;
private final File dirFolder;

Expand Down
14 changes: 8 additions & 6 deletions src/main/java/me/ANONIMUS/proxy/commands/CommandHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public CommandHelp() {

@Override
public void onCommand(Player sender, String[] args) {
List<Command> list = BetterProxy.getInstance().getCommandManager().getCommands();
List<Command> list = BetterProxy.getInstance().getCommandManager().elements;
list.sort(Comparator.comparingInt(s -> StringUtil.getStringWidth(s.getPrefix())));

int i = 1;
Expand All @@ -32,19 +32,20 @@ public void onCommand(Player sender, String[] args) {
int k = i - 1;
int l = Math.min((k + 1) * 10, list.size());
int j = (list.size() - 1) / 10;
int f = j + 1;

if (i < 1) {
ChatUtil.sendChatMessage("&cThe given number (" + i + ") is too small, must be at least 1", sender, false);
return;
}

if (i > (j + 1)) {
ChatUtil.sendChatMessage("&cThe given number (" + i + ") is too high, cannot exceed " + (j + 1), sender, false);
if (i > f) {
ChatUtil.sendChatMessage("&cThe given number (" + i + ") is too high, cannot exceed " + f, sender, false);
return;
}

ChatUtil.clearChat(1, sender);
ChatUtil.sendChatMessage(" &8 --- Showing help page: " + sender.getThemeType().getColor(1) + i + " &8of " + sender.getThemeType().getColor(1) + (j + 1) + " &8---", sender, false);
ChatUtil.sendChatMessage(" &8 --- Showing help page: " + sender.getThemeType().getColor(1) + i + " &8of " + sender.getThemeType().getColor(1) + f + " &8---", sender, false);
for (int i1 = k * 10; i1 < l; ++i1) {
final Command command = list.get(i1);
ChatUtil.sendHoverMessage(sender, "&8>> &f" + sender.getPrefixCMD() + command.getPrefix() + " &7" + command.getUsage(), sender.getThemeType().getColor(1) + command.getDesc());
Expand All @@ -56,11 +57,12 @@ public void onCommand(Player sender, String[] args) {
msg.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, sender.getPrefixCMD() + "help " + (i - 1)));
}

TextComponent msg2 = new TextComponent(ChatUtil.fixColor((i != (j + 1) ? "&a" : "&7") + "[NEXT]"));
if (i != (j + 1)) {
TextComponent msg2 = new TextComponent(ChatUtil.fixColor((i != f ? "&a" : "&7") + "[NEXT]"));
if (i != f) {
msg2.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent(ChatUtil.fixColor(sender.getThemeType().getColor(2) + "Click to go to the next page!"))));
msg2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, sender.getPrefixCMD() + "help " + (i + 1)));
}

sender.getSession().sendPacket(new ServerChatPacket(msg, new TextComponent(" "), msg2));
}
}
2 changes: 2 additions & 0 deletions src/main/java/me/ANONIMUS/proxy/commands/CommandLogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public void onCommand(Player sender, String[] args) {
ChatUtil.sendChatMessage("&4You are already logged!", sender, true);
return;
}

if (sender.getAccount().getPassword().equals(args[1])) {
ChatUtil.clearChat(1, sender);
PacketUtil.clearBossBar(sender);
Expand All @@ -27,6 +28,7 @@ public void onCommand(Player sender, String[] args) {
WorldUtil.lobby(sender, false);
return;
}

ChatUtil.sendChatMessage("&cThe given password is not correct!", sender, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public void onCommand(Player sender, String[] args) {
}

String finalOut = out;
BetterProxy.getInstance().getPlayerManager().getPlayers().forEach(player -> PacketUtil.sendTitle(player, "&8[&4ALERT&8]", "&n" + finalOut, 13, 18, 13));
BetterProxy.getInstance().getPlayerManager().elements.forEach(player -> PacketUtil.sendTitle(player, "&8[&4ALERT&8]", "&n" + finalOut, 13, 18, 13));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void onCommand(Player sender, String[] args) {
return;
}

if (player.getAccount().getGroup().getPermissionLevel() >= sender.getAccount().getGroup().getPermissionLevel()) {
if (player.getAccount().getGroup().getPermission() >= sender.getAccount().getGroup().getPermission()) {
ChatUtil.sendChatMessage("&cYou cannot kick this player!", sender, true);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void onCommand(Player sender, String[] args) throws Exception {
} else if (args[1].equals("save")) {
sender.setListenChunks(false);

if (sender.getListenedChunks().size() == 0) {
if (sender.getListenedChunks().isEmpty()) {
ChatUtil.sendChatMessage("&cThe list is empty", sender, false);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ public void onCommand(Player sender, String[] args) throws Exception {
long maxMemory = Runtime.getRuntime().maxMemory();
long inUseMemory = totalMemory - freeMemory;
int inUse = (int) (inUseMemory * 100L / maxMemory);
double cpu = 0.0;
try {
cpu = getProcessCpuLoad();
} catch (Exception e) {
e.printStackTrace();
}
double cpu = getProcessCpuLoad();
ChatUtil.sendChatMessage("", sender, false);
ChatUtil.sendChatMessage("----------------------------------", sender, false);
ChatUtil.sendChatMessage("Available memory: " + sender.getThemeType().getColor(2) + humanReadableByteCount(totalMemory), sender, true);
ChatUtil.sendChatMessage("Assigned memory: &a" + humanReadableByteCount(maxMemory), sender, true);
ChatUtil.sendChatMessage("Used Memory: &4" + humanReadableByteCount(inUseMemory) + " &8(" + "&f" + inUse + "%&8)", sender, true);
ChatUtil.sendChatMessage("Used CPU: " + sender.getThemeType().getColor(1) + cpu + "%", sender, true);
ChatUtil.sendChatMessage("", sender, true);
ChatUtil.sendChatMessage(sender.getPrefixCMD() + "free - clean memory", sender, true);
ChatUtil.sendChatMessage("----------------------------------", sender, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@ public void onCommand(Player sender, String[] args) {
ChatUtil.sendChatMessage("&7Successfully kicked out &4" + sender.getBots().size() + " &7bots", sender, true);
sender.getBots().clear();
} else {
Bot b = null;
for (Bot bot : sender.getBots()) {
if (bot.getUsername().equals(args[1])) {
b = bot;
}
}
Bot b = sender.getBots().stream().filter(bot -> bot.getUsername().equals(args[1])).findFirst().orElse(null);

if (b == null) {
ChatUtil.sendChatMessage("&cThe bot with a nickname &4" + args[1] + " &cdoes not exist", sender, true);
return;
}

b.getSession().getChannel().close();
b.setSession(null);
sender.getBots().remove(b);

ChatUtil.sendChatMessage("&7A bot with a nickname &4" + args[1] + " &7was successfully thrown out", sender, true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void onCommand(Player sender, String[] args) throws Exception {
ChatUtil.sendChatMessage("&cYou need to download players first " + sender.getThemeType().getColor(1) + sender.getPrefixCMD() + "players", sender, true);
return;
}

sendMSG(sender, delay, text);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ public CommandOptions() {
public void onCommand(Player sender, String[] args) {
if (args[1].equals("list") && sender.getSession().getProtocolID() == 47) {
List<ItemStack> items = new ArrayList<>();
sender.getOptionsManager().getOptions().forEach(option -> items.add(ItemUtil.option(option)));
sender.getOptionsManager().elements.forEach(option -> items.add(ItemUtil.option(option)));
sender.getSession().sendPacket(new ServerOpenWindowPacket(234, WindowType.CHEST, "SETTINGS", 9));
sender.getSession().sendPacket(new ServerWindowItemsPacket(234, items));
return;
}

if (args[1].equals("set")) {
Option option = sender.getOptionsManager().getOptionByName(args[2]);

if (option == null) {
ChatUtil.sendChatMessage("&cThe specified option was not found!", sender, true);
return;
}
option.setEnabled(sender, Boolean.parseBoolean(args[3]));

option.setEnabled(Boolean.parseBoolean(args[3]));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void onCommand(Player sender, String[] args) throws Exception {
ChatUtil.sendChatMessage("&cThere is no one on the list &c:[", sender, true);
return;
}
ChatUtil.sendChatMessage(sender.getThemeType().getColor(1) + "The list with players was cleared successfully &8(" + sender.getThemeType().getColor(2) + sender.getPlayers().size() + ")", sender, true);
ChatUtil.sendChatMessage(sender.getThemeType().getColor(1) + "The list with players was cleared successfully &8(" + sender.getThemeType().getColor(2) + sender.getPlayers().size() + "&8)", sender, true);
sender.getPlayers().clear();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,5 @@ public void onCommand(Player sender, String[] args) {
ChatUtil.sendChatMessage("&7Open ports: " + sender.getThemeType().getColor(1) + ports, sender, true);
ports.clear();
});
ChatUtil.sendChatMessage("&7Scanning is complete &8(" + sender.getThemeType().getColor(2) + ports.size() + "&8)", sender, true);
ChatUtil.sendChatMessage("&7Open ports: " + sender.getThemeType().getColor(1) + ports, sender, true);
ports.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public void onCommand(Player sender, String[] args) {
final String player = args[1];

if (player.equalsIgnoreCase("default")) {
sender.setSkin(SkinUtil.getSkin(sender.getUsername(), null));
sender.setSkin(SkinUtil.getSkin(sender.getUsername()));
ChatUtil.sendChatMessage("&7Skin has been successfully reset", sender, true);
ChatUtil.sendChatMessage("&cYou need to reconnect to the proxy!", sender, true);
return;
}

Skin skin = SkinUtil.getSkin(player, null);
Skin skin = SkinUtil.getSkin(player);
if (skin == null) {
ChatUtil.sendChatMessage("&7The player does not have a premium account", sender, true);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ public void onCommand(Player sender, String[] args) {
ChatUtil.sendChatMessage("Current theme: " + sender.getThemeType().getColor(1) + sender.getThemeType(), sender, true);
ChatUtil.sendChatMessage("Themes: " + Arrays.stream(ThemeType.values()).map(themeType -> themeType.getColor(1) + themeType.name()).collect(Collectors.joining(", ")), sender, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public CommandCrash() {
@Override
public void onCommand(Player sender, String[] args) {
if (args[1].equals("list") && args.length == 2) {
ChatUtil.sendChatMessage("&8>> " + sender.getThemeType().getColor(1) + BetterProxy.getInstance().getExploitManager().getExploits().stream().map(Exploit::getName).collect(Collectors.joining(", ")), sender, false);
ChatUtil.sendChatMessage("&8>> " + sender.getThemeType().getColor(1) + BetterProxy.getInstance().getExploitManager().elements.stream().map(exploit -> exploit.getName() + (exploit.isCompressed() ? sender.getThemeType().getColor(2) + "(compressed)" + sender.getThemeType().getColor(1) : "")).collect(Collectors.joining(", ")), sender, false);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public CommandJoin() {
public void onCommand(Player sender, String[] args) {
String ip = args[1];
int port = 25565;

if (ip.contains(":")) {
final String[] sp = ip.split(":", 2);
ip = sp[0];
Expand All @@ -45,6 +46,7 @@ public void onCommand(Player sender, String[] args) {
if (Boolean.parseBoolean(args[4])) {
new ServerPinger(sender, true).connect(ip, port, Proxy.NO_PROXY);
}

new PlayerConnection(sender, args[2]).connect(ip, port, Proxy.NO_PROXY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ public CommandQuit() {
@Override
public void onCommand(Player sender, String[] args) {
ChatUtil.sendChatMessage(sender.getThemeType().getColor(1) + ">> &cDisconnected!", sender, false);
sender.setServerData(null);
sender.setConnected(false);
sender.getRemoteSession().getChannel().close();
sender.setRemoteSession(null);
sender.setConnectedType(ConnectedType.DISCONNECTED);
WorldUtil.lobby(sender, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public CommandStay() {
super("stay", "detach", null, null, ConnectedType.CONNECTED);
}

EventLoopGroup group = new NioEventLoopGroup();
private final EventLoopGroup group = new NioEventLoopGroup();

@Override
public void onCommand(Player sender, String[] args) {
Expand Down Expand Up @@ -71,9 +71,8 @@ protected void channelRead0(ChannelHandlerContext channelHandlerContext, Packet

sender.getBots().add(bot);

sender.setRemoteSession(null);
sender.setConnected(false);
sender.setServerData(null);
sender.getRemoteSession().getChannel().close();
sender.setConnectedType(ConnectedType.DISCONNECTED);
WorldUtil.lobby(sender, true);
}

Expand Down
Loading

0 comments on commit b74c110

Please sign in to comment.