some some more

no its still not fixed anyone please ehelp me mem , ,,.,.,.,.,.,.,.
healp
help
help
help
uwu
This commit is contained in:
Chayapak 2023-06-14 19:38:26 +07:00
parent 5c53842157
commit 3726f8311a
2 changed files with 11 additions and 10 deletions
src/main/java/land/chipmunk/chayapak/chomens_bot

View file

@ -4,6 +4,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundCu
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCustomPayloadPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCustomPayloadPacket;
import com.github.steveice10.packetlib.Session; import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import land.chipmunk.chayapak.chomens_bot.Bot; import land.chipmunk.chayapak.chomens_bot.Bot;
@ -68,16 +69,11 @@ public class VoiceChatPlugin extends Bot.Listener {
System.out.println(new String(_packet.getData())); System.out.println(new String(_packet.getData()));
*/ */
if (_packet.getChannel().equals("voicechat:secret")) { if (_packet.getChannel().equals("voicechat:secret")) {
System.out.println("got the secret packet");
final byte[] bytes = _packet.getData(); final byte[] bytes = _packet.getData();
final FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes)); final FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes));
final SecretPacket secretPacket = new SecretPacket().fromBytes(buf); final SecretPacket secretPacket = new SecretPacket().fromBytes(buf);
System.out.println(secretPacket.secret());
System.out.println(secretPacket.serverPort());
initializationData = new InitializationData(bot.options().host(), secretPacket); initializationData = new InitializationData(bot.options().host(), secretPacket);
try { try {
@ -87,8 +83,6 @@ public class VoiceChatPlugin extends Bot.Listener {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
System.out.println("address " + address.getHostName());
socket = new ClientVoiceChatSocket(); socket = new ClientVoiceChatSocket();
try { try {
socket.open(); socket.open();
@ -96,14 +90,12 @@ public class VoiceChatPlugin extends Bot.Listener {
e.printStackTrace(); e.printStackTrace();
} }
bot.executorService().submit(() -> { bot.executorService().execute(() -> {
while (true) { while (true) {
try { try {
if (socket.isClosed()) continue; if (socket.isClosed()) continue;
System.out.println("reading packet");
final NetworkMessage message = NetworkMessage.readPacket(socket.read(), initializationData); final NetworkMessage message = NetworkMessage.readPacket(socket.read(), initializationData);
System.out.println("DONE reading packet, this message will; prob nto woshow");
if (message == null) continue; if (message == null) continue;
@ -137,6 +129,7 @@ public class VoiceChatPlugin extends Bot.Listener {
private final byte[] BUFFER = new byte[4096]; private final byte[] BUFFER = new byte[4096];
public RawUdpPacket read (DatagramSocket socket) { public RawUdpPacket read (DatagramSocket socket) {
if (socket.isClosed()) return null;
try { try {
DatagramPacket packet = new DatagramPacket(BUFFER, BUFFER.length); DatagramPacket packet = new DatagramPacket(BUFFER, BUFFER.length);
@ -161,6 +154,11 @@ public class VoiceChatPlugin extends Bot.Listener {
} }
@Override
public void disconnected(DisconnectedEvent event) {
socket.close();
}
private static class ClientVoiceChatSocket extends VoiceChatSocketBase { private static class ClientVoiceChatSocket extends VoiceChatSocketBase {
private DatagramSocket socket; private DatagramSocket socket;
@ -185,6 +183,7 @@ public class VoiceChatPlugin extends Bot.Listener {
public void close() { public void close() {
if (socket != null) { if (socket != null) {
socket.close(); socket.close();
socket = null;
} }
} }

View file

@ -57,6 +57,8 @@ public class NetworkMessage {
} }
public static NetworkMessage readPacket (RawUdpPacket packet, InitializationData initializationData) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { public static NetworkMessage readPacket (RawUdpPacket packet, InitializationData initializationData) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
if (packet == null) return null;
final byte[] data = packet.data(); final byte[] data = packet.data();
final FriendlyByteBuf b = new FriendlyByteBuf(Unpooled.wrappedBuffer(data)); final FriendlyByteBuf b = new FriendlyByteBuf(Unpooled.wrappedBuffer(data));