Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ikos3k committed May 28, 2021
1 parent 1aeff6b commit 01c9dd0
Show file tree
Hide file tree
Showing 24 changed files with 91 additions and 88 deletions.
14 changes: 6 additions & 8 deletions src/main/java/me/ANONIMUS/proxy/BetterProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import me.ANONIMUS.proxy.utils.FileUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;

@Getter
Expand All @@ -24,10 +24,9 @@ public class BetterProxy {
private final ConfigManager configManager;
private final PlayerManager playerManager;
private static BetterProxy instance;
private final List<Account> accounts;
private final Map<String, Account> accounts;
private final ProxyServer server;
private final File dirFolder;
private final String icon;

public BetterProxy() {
instance = this;
Expand All @@ -36,10 +35,9 @@ public BetterProxy() {
packetRegistry = new PacketRegistry();
exploitManager = new ExploitManager();
configManager = new ConfigManager(new File(dirFolder + "/config.json"));
icon = FileUtil.loadIconFile(configManager.getConfig().icon);
playerManager = new PlayerManager();
accounts = new ArrayList<>();
server = new ProxyServer();
accounts = new HashMap<>();
server = new ProxyServer(FileUtil.getIconFile(configManager.getConfig().icon));
}

public void run() {
Expand All @@ -60,7 +58,7 @@ public void run() {
System.out.println("> Loading accounts...");
FileUtil.loadAccounts();
System.out.println("> Starting the server...");
server.bind();
server.bind(playerManager);
System.out.println();

final Timer timer = new Timer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onCommand(Player sender, String[] args) {
return;
}

if (sender.getAccount().getUsername().equals(args[1])) {
if (sender.getUsername().equals(args[1])) {
ChatUtil.sendChatMessage("&cYou can't kick yourself out!", sender, true);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void onCommand(Player sender, String[] args) {
} else {
Bot b = null;
for (Bot bot : sender.getBots()) {
if (bot.getSession().getUsername().equals(args[1])) {
if (bot.getUsername().equals(args[1])) {
b = bot;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void onCommand(Player sender, String[] args) {
final String player = args[1];

if (player.equalsIgnoreCase("default")) {
sender.setSkin(SkinUtil.getSkin(sender.getAccount().getUsername(), null));
sender.setSkin(SkinUtil.getSkin(sender.getUsername(), null));
ChatUtil.sendChatMessage("&7Skin has been successfully reset", sender, true);
ChatUtil.sendChatMessage("&cYou need to reconnect to the proxy!", sender, true);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void onCommand(Player sender, String[] args) {
sender.getRemoteSession().getChannel().pipeline().replace("handler", "handler", new SimpleChannelInboundHandler<Packet>() {
@Override
public void channelInactive(ChannelHandlerContext ctx) {
ChatUtil.sendChatMessage(sender.getThemeType().getColor(1) + ">> &8Bot &c" + bot.getSession().getUsername() + " &8disconnected from the server &fcause: &c" + ctx.getClass(), bot.getOwner(), true);
ChatUtil.sendChatMessage(sender.getThemeType().getColor(1) + ">> &8Bot &c" + bot.getUsername() + " &8disconnected from the server &fcause: &c" + ctx.getClass(), bot.getOwner(), true);
disconnect(bot, sender);
}

Expand All @@ -51,16 +51,16 @@ protected void channelRead0(ChannelHandlerContext channelHandlerContext, Packet
} else if (packet instanceof ServerKeepAlivePacket) {
bot.getSession().sendPacket(new ClientKeepAlivePacket(((ServerKeepAlivePacket) packet).getKeepaliveId()));
} else if (packet instanceof ServerJoinGamePacket) {
ChatUtil.sendChatMessage(sender.getThemeType().getColor(1) + ">> &8Bot &a" + bot.getSession().getUsername() + " &8connected to the server", bot.getOwner(), true);
ChatUtil.sendChatMessage(sender.getThemeType().getColor(1) + ">> &8Bot &a" + bot.getUsername() + " &8connected to the server", bot.getOwner(), true);
bot.getOwner().getBots().add(bot);
bot.getSession().sendPacket(new ClientCustomPayloadPacket("MC|Brand", "vanilla".getBytes()));
bot.getSession().sendPacket(new ClientSettingsPacket("pl_PL", (byte) 32, (byte) 0, false, (byte) 1));
} else if (packet instanceof ServerDisconnectPacket) {
ChatUtil.sendChatMessage(sender.getThemeType().getColor(1) + ">> &8Bot &c" + bot.getSession().getUsername() + " &8disconnected from the server &fcause: &c" + ChatColor.stripColor(BaseComponent.toLegacyText(((ServerDisconnectPacket) packet).getReason())), bot.getOwner(), true);
ChatUtil.sendChatMessage(sender.getThemeType().getColor(1) + ">> &8Bot &c" + bot.getUsername() + " &8disconnected from the server &fcause: &c" + ChatColor.stripColor(BaseComponent.toLegacyText(((ServerDisconnectPacket) packet).getReason())), bot.getOwner(), true);
disconnect(bot, sender);

} else if (packet instanceof ServerLoginDisconnectPacket) {
ChatUtil.sendChatMessage(sender.getThemeType().getColor(1) + ">> &8Bot &c" + bot.getSession().getUsername() + " &8disconnected from the server &fause: &c" + ChatColor.stripColor(BaseComponent.toLegacyText(((ServerLoginDisconnectPacket) packet).getReason())), bot.getOwner(), true);
ChatUtil.sendChatMessage(sender.getThemeType().getColor(1) + ">> &8Bot &c" + bot.getUsername() + " &8disconnected from the server &fause: &c" + ChatColor.stripColor(BaseComponent.toLegacyText(((ServerLoginDisconnectPacket) packet).getReason())), bot.getOwner(), true);
disconnect(bot, sender);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/ANONIMUS/proxy/enums/GroupType.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public int getDelayCMD() {
}

public static GroupType getByPermission(int permission) {
return Arrays.stream(GroupType.values()).filter(gp -> gp.permission == permission).findFirst().orElse(GroupType.USER);
return Arrays.stream(values()).filter(gp -> gp.permission == permission).findFirst().orElse(GroupType.USER);
}
}
10 changes: 5 additions & 5 deletions src/main/java/me/ANONIMUS/proxy/exploits/ShitExploit.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ public void execute(Player sender, Object... objects) {
ChatUtil.sendChatMessage(sender.getThemeType().getColor(1) + ">> &8Crashing complete &7(" + sender.getThemeType().getColor(2) + time2 + "ms&7)", sender, false);
}

private String getCrashCommand(final int mode, final boolean fullCMD, final boolean bypass) {
private String getCrashCommand(final int mode, final boolean full, final boolean bypass) {
switch (mode) {
case 1: {
return (bypass ? "/worldedit:/" : "//") + "solve";
}
case 2: {
return (bypass ? "/worldedit:/" : "//") + (fullCMD ? "evaluate" : "eval");
return (bypass ? "/worldedit:/" : "//") + (full ? "evaluate" : "eval");
}
case 3: {
return (bypass ? "/worldedit:/" : "//") + (fullCMD ? "calculate" : "calc");
return (bypass ? "/worldedit:/" : "//") + (full ? "calculate" : "calc");
}
case 4: {
return (fullCMD ? (bypass ? "/permissionsex:pex " : "/pex ") : "/") + "demote a a";
return (full ? (bypass ? "/permissionsex:pex " : "/pex ") : "/") + "demote a a";
}
case 5: {
return (fullCMD ? (bypass ? "/permissionsex:pex " : "/pex ") : "/") + "promote a a";
return (full ? (bypass ? "/permissionsex:pex " : "/pex ") : "/") + "promote a a";
}
default:
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/ANONIMUS/proxy/handler/ServerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public abstract class ServerHandler {
public final Player player;

public abstract void disconnected();
public abstract void disconnect();

public abstract void handlePacket(final Packet packet);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import me.kbrewster.mojangapi.MojangAPI;

import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;
Expand All @@ -27,27 +28,27 @@ public ServerLoginHandler(Player player) {
}

@Override
public void disconnected() {
if (player != null && player.getAccount() != null) {
System.out.println("[" + player.getAccount().getUsername() + "] Disconnected during login sequence!");
}
public void disconnect() {
System.out.println("[" + player.getUsername() + "] Disconnected during login sequence!");
}

@SneakyThrows
@Override
public void handlePacket(Packet packet) {
if (packet instanceof ClientLoginStartPacket) {
final String playerName = ((ClientLoginStartPacket) packet).getUsername();
player.getSession().setUsername(playerName);
if (BetterProxy.getInstance().getPlayerManager().getPlayers().size() > 1) {
for (Player p : BetterProxy.getInstance().getPlayerManager().getPlayers()) {
if (p.getAccount() != null && p.getAccount().getUsername().equals(playerName)) {
if (p.getAccount() != null && p.getUsername().equals(playerName)) {
player.getSession().sendPacket(new ServerLoginDisconnectPacket(ChatUtil.fixColor("&4The player with this nickname is already on the proxy!")));
return;
}
}
}
for (Account account : BetterProxy.getInstance().getAccounts()) {
if (account.getUsername().equals(playerName)) {

for(Map.Entry<String, Account> account : BetterProxy.getInstance().getAccounts().entrySet()) {
if (account.getKey().equals(playerName)) {
UUID uuid;
try {
uuid = MojangAPI.getUUID(playerName);
Expand All @@ -60,13 +61,13 @@ public void handlePacket(Packet packet) {
player.getSession().sendPacket(new ServerLoginSuccessPacket(uuid, playerName));
player.getSession().setConnectionState(ConnectionState.PLAY);
player.getSession().setPacketHandler(new ServerPlayHandler(player));
player.setAccount(account);
player.setAccount(account.getValue());
player.loadOptions();

SkinUtil.showSkin(player.getSession(), uuid, player.getSkin());

WorldUtil.emptyWorld(player);
System.out.println("[" + account.getUsername() + "] Connected!");
System.out.println("[" + playerName + "] Connected!");
ChatUtil.clearChat(100, player);

ScoreboardUtil.sendScoreboard(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public ServerPlayHandler(Player player) {
}

@Override
public void disconnected() {
System.out.println("[" + player.getAccount().getUsername() + "] Disconnected.");
ChatUtil.sendBroadcastMessage(player.getThemeType().getColor(1) + ">> &8The player " + player.getThemeType().getColor(1) + player.getAccount().getUsername() + " &8has disconnected from the " + player.getThemeType().getColor(1) + "BetterProxy&8!", false);
public void disconnect() {
System.out.println("[" + player.getUsername() + "] Disconnected.");
ChatUtil.sendBroadcastMessage(player.getThemeType().getColor(1) + ">> &8The player " + player.getThemeType().getColor(1) + player.getUsername() + " &8has disconnected from the " + player.getThemeType().getColor(1) + "BetterProxy&8!", false);
}

@SneakyThrows
Expand Down Expand Up @@ -111,7 +111,7 @@ public void handlePacket(Packet packet) {
}
}
if (packet instanceof ClientPlayerPositionPacket) {
if (((ClientPlayerPositionPacket) packet).getY() < 60 && !player.isConnected()) {
if (((ClientPlayerPositionPacket) packet).getY() < 65 && !player.isConnected()) {
PacketUtil.lobbyPosTeleport(player);
}
}
Expand All @@ -121,7 +121,7 @@ public void handlePacket(Packet packet) {
if (message.startsWith(player.getPrefixCMD())) {
BetterProxy.getInstance().getCommandManager().onCommand(message, player);
} else if (player.isLogged() && message.startsWith("@")) {
ChatUtil.sendBroadcastMessage("&8(&f" + ProtocolType.getByProtocolID(player.getSession().getProtocolID()).getPrefix() + "&8) &8[" + player.getAccount().getGroup().getPrefix() + "&8] " + player.getThemeType().getColor(1) + player.getAccount().getUsername() + " &8>> &7" + message.substring(1), false);
ChatUtil.sendBroadcastMessage("&8(&f" + ProtocolType.getByProtocolID(player.getSession().getProtocolID()).getPrefix() + "&8) &8[" + player.getAccount().getGroup().getPrefix() + "&8] " + player.getThemeType().getColor(1) + player.getUsername() + " &8>> &7" + message.substring(1), false);
} else {
forwardPacket(packet);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ServerStatusHandler(Player player) {
}

@Override
public void disconnected() { }
public void disconnect() { }

@Override
public void handlePacket(Packet packet) {
Expand All @@ -45,7 +45,7 @@ public void handlePacket(Packet packet) {
final PlayerInfo playerInfo = new PlayerInfo(0, 0, gp);
final BaseComponent[] desc = new ComponentBuilder(ChatUtil.fixColor(BetterProxy.getInstance().getConfigManager().getConfig().line1 + "&r\n" + BetterProxy.getInstance().getConfigManager().getConfig().line2)).create();

player.getSession().sendPacket(new ServerStatusResponsePacket(new ServerStatusInfo(versionInfo, playerInfo, desc, BetterProxy.getInstance().getIcon())));
player.getSession().sendPacket(new ServerStatusResponsePacket(new ServerStatusInfo(versionInfo, playerInfo, desc, BetterProxy.getInstance().getServer().getIcon())));
player.getSession().sendPacket(new ServerStatusPongPacket(0));

player.getSession().getChannel().close();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/ANONIMUS/proxy/managers/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public void onCommand(final String message, final Player sender) {
}

try {
if (!(command instanceof CommandHelp) && cooldown.containsKey(sender.getAccount().getUsername())) {
final long secondsLeft = cooldown.get(sender.getAccount().getUsername()) / 1000L + sender.getAccount().getGroup().getDelayCMD() - System.currentTimeMillis() / 1000L;
if (!(command instanceof CommandHelp) && cooldown.containsKey(sender.getUsername())) {
final long secondsLeft = cooldown.get(sender.getUsername()) / 1000L + sender.getAccount().getGroup().getDelayCMD() - System.currentTimeMillis() / 1000L;
if (secondsLeft > 0L) {
ChatUtil.sendChatMessage("&7The next command can be used in " + sender.getThemeType().getColor(1) + secondsLeft + "s&7!", sender, true);
return;
}
cooldown.put(sender.getAccount().getUsername(), System.currentTimeMillis());
cooldown.put(sender.getUsername(), System.currentTimeMillis());
}

command.onCommand(sender, args);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/ANONIMUS/proxy/managers/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public ConfigManager(File file) {
this.file = file;

if(!file.exists()) {
create();
write();
}

read();
}

public void create() {
public void write() {
JSONObject jsonObj = new JSONObject();

jsonObj.put("port", 1337);
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/me/ANONIMUS/proxy/managers/ExploitManager.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package me.ANONIMUS.proxy.managers;

import lombok.Getter;
import me.ANONIMUS.proxy.objects.Exploit;
import org.reflections.Reflections;

import java.util.ArrayList;
import java.util.List;

@Getter
public class ExploitManager {
private final List<Exploit> exploits = new ArrayList<>();

public ExploitManager() {
new Reflections("me.ANONIMUS.proxy.exploits").getSubTypesOf(Exploit.class).forEach(exploit -> {
try {
Expand All @@ -17,16 +21,6 @@ public ExploitManager() {
});
}

private final List<Exploit> exploits = new ArrayList<>();

public void addExploit(Exploit exploit) {
this.exploits.add(exploit);
}

public List<Exploit> getExploits() {
return this.exploits;
}

public Exploit findExploit(String name) {
return this.exploits.stream().filter(exploit -> exploit.getName().equalsIgnoreCase(name)).findFirst().orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public List<Player> getPlayers() {

public Player getPlayer(String name) {
for (Player p : players) {
if (p.getAccount().getUsername().equals(name)) {
if (p.getUsername().equals(name)) {
return p;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/me/ANONIMUS/proxy/objects/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

@Data
public class Account {
private final String username;
private final String password;
private final GroupType group;
}
17 changes: 12 additions & 5 deletions src/main/java/me/ANONIMUS/proxy/protocol/ProxyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.netty.handler.timeout.ReadTimeoutHandler;
import lombok.Data;
import me.ANONIMUS.proxy.BetterProxy;
import me.ANONIMUS.proxy.managers.PlayerManager;
import me.ANONIMUS.proxy.protocol.data.ConnectionState;
import me.ANONIMUS.proxy.protocol.handlers.PacketCodec;
import me.ANONIMUS.proxy.protocol.handlers.VarInt21FrameCodec;
Expand All @@ -23,7 +24,9 @@
public class ProxyServer {
EventLoopGroup worker = new NioEventLoopGroup();

public void bind() {
private final String icon;

public void bind(PlayerManager playerManager) {
new ServerBootstrap()
.group(worker)
.channel(NioServerSocketChannel.class)
Expand All @@ -39,21 +42,25 @@ protected void initChannel(SocketChannel socketChannel) {
pipeline.addLast(new SimpleChannelInboundHandler<Packet>() {
@Override
public void channelActive(ChannelHandlerContext ctx) {
BetterProxy.getInstance().getPlayerManager().createPlayer(new Session(ctx.channel()));
playerManager.createPlayer(new Session(ctx.channel()));
}

@Override
public void channelInactive(ChannelHandlerContext ctx) {
BetterProxy.getInstance().getPlayerManager().getPlayer(ctx.channel()).disconnect();
playerManager.getPlayer(ctx.channel()).disconnect();
}

@Override
protected void channelRead0(ChannelHandlerContext ctx, Packet packet) {
BetterProxy.getInstance().getPlayerManager().getPlayer(ctx.channel()).packetReceived(packet);
playerManager.getPlayer(ctx.channel()).packetReceived(packet);
}
});
}
}).bind(BetterProxy.getInstance().getConfigManager().getConfig().port);
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> BetterProxy.getInstance().getPlayerManager().getPlayers().stream().filter(p -> p.getSession().getConnectionState() == ConnectionState.PLAY).forEach(p -> p.getSession().sendPacket(new ServerKeepAlivePacket(System.currentTimeMillis()))), 3, 3, TimeUnit.SECONDS);
Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> playerManager.getPlayers().stream().filter(p -> p.getSession().getConnectionState() == ConnectionState.PLAY).forEach(p -> p.getSession().sendPacket(new ServerKeepAlivePacket(System.currentTimeMillis()))), 3, 3, TimeUnit.SECONDS);
}

public String getIcon() {
return icon;
}
}
Loading

0 comments on commit 01c9dd0

Please sign in to comment.