Вопрос Проблема с прокси в чите

  • Автор темы Автор темы Valzer
  • Дата начала Дата начала
Начинающий
Начинающий
Статус
Оффлайн
Регистрация
30 Июн 2023
Сообщения
46
Реакции
0
привет!!
я сделал прокси, и оно почему-то не меняет айпи, вот код



Код:
Expand Collapse Copy
package VilzRecode.proxy;

import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;
import com.mojang.blaze3d.matrix.MatrixStack;
import org.apache.commons.lang3.StringUtils;
import net.minecraft.client.gui.screen.MultiplayerScreen;
import net.minecraft.client.gui.screen.MainMenuScreen;

public class GuiProxy extends Screen {
    private boolean isSocks4 = false;
    private boolean isEnabled = false;
    private TextFieldWidget ipPort;
    private TextFieldWidget username;
    private TextFieldWidget password;
    private final Screen parentScreen;
    private String msg = "";
    private int[] positionY;
    private int positionX;

    public GuiProxy(Screen parentScreen) {
        super(new StringTextComponent("Proxy Settings"));
        this.parentScreen = parentScreen;
    }

            private static boolean isValidIpPort(String ipP) {
                String[] split = ipP.split(":");
                if (split.length > 1) {
                    if (!StringUtils.isNumeric(split[1])) return false;
                    int port = Integer.parseInt(split[1]);
                    return port >= 0 && port <= 0xFFFF;
                }
                return false;
            }

            private boolean checkProxy() {
                if (!isValidIpPort(ipPort.getText())) {
                    msg = TextFormatting.RED + "Неверный IP:PORT";
                    this.ipPort.setFocused(true);
                    return false;
                }
                return true;
            }

            private void centerButtons(int amount, int buttonLength, int gap) {
                positionX = (this.width / 2) - (buttonLength / 2);
                positionY = new int[amount];
                int center = (this.height + amount * gap) / 2;
                int buttonStarts = center - (amount * gap);
                for (int i = 0; i != amount; i++) {
                    positionY[i] = buttonStarts + (gap * i);
                }
            }

            @Override
            protected void init() {
                int buttonLength = 160;
                centerButtons(8, buttonLength, 26);

                isSocks4 = ProxyManager.proxy.type == Proxy.ProxyType.SOCKS4;
                isEnabled = ProxyManager.proxyEnabled;

                this.addButton(new Button(positionX, positionY[1], buttonLength, 20,
                        new StringTextComponent(isSocks4 ? "Socks 4" : "Socks 5"), button -> {
                    isSocks4 = !isSocks4;
                    button.setMessage(new StringTextComponent(isSocks4 ? "Socks 4" : "Socks 5"));
                }));

                this.ipPort = new TextFieldWidget(this.font, positionX, positionY[2], buttonLength, 20,
                        new StringTextComponent("IP:Port"));
                this.ipPort.setMaxStringLength(1024);
                this.ipPort.setText(ProxyManager.proxy.ipPort);
                this.ipPort.setFocused(true);
                this.addButton(this.ipPort);

                this.username = new TextFieldWidget(this.font, positionX, positionY[4], buttonLength, 20,
                        new StringTextComponent("Username"));
                this.username.setMaxStringLength(255);
                this.username.setText(ProxyManager.proxy.username);
                this.addButton(this.username);

                this.password = new TextFieldWidget(this.font, positionX, positionY[5], buttonLength, 20,
                        new StringTextComponent("Password"));
                this.password.setMaxStringLength(255);
                this.password.setText(ProxyManager.proxy.password);
                this.addButton(this.password);

                int posXButtons = (this.width / 2) - (((buttonLength / 2) * 3) / 2);

                this.addButton(new Button(posXButtons, positionY[7], buttonLength / 2 - 3, 20,
                        new StringTextComponent("Сохранить"), button -> {
                    if (checkProxy()) {
                        ProxyManager.proxy = new Proxy(isSocks4, ipPort.getText(), username.getText(), password.getText());
                        ProxyManager.proxyEnabled = isEnabled;
                        ProxyManager.save();
                        this.minecraft.displayGuiScreen(new MultiplayerScreen(new MainMenuScreen()));
                    }
                }));

                this.addButton(new Button(positionX, positionY[6], buttonLength, 20,
                        new StringTextComponent(isEnabled ? "Включен" : "Выключен"), button -> {
                    isEnabled = !isEnabled;
                    button.setMessage(new StringTextComponent(isEnabled ? "Включен" : "Выключен"));
                }));

                this.addButton(new Button(posXButtons + (buttonLength / 2 + 3) * 2, positionY[7], buttonLength / 2 - 3, 20,
                        new StringTextComponent("Назад"), button -> {
                    this.minecraft.displayGuiScreen(parentScreen);
                }));
            }

            @Override
            public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
                this.renderBackground(matrixStack);

                this.font.drawString(matrixStack, "Тип", this.width / 2 - 150, positionY[1] + 5, 0xA0A0A0);
                this.font.drawStringWithShadow(matrixStack, "Настройки прокси", this.width / 2 -
                        this.font.getStringWidth("Настройки прокси") / 2, positionY[0] + 8, 0xFFFFFF);
                this.font.drawString(matrixStack, "IP:PORT: ", this.width / 2 - 150, positionY[2] + 5, 0xA0A0A0);
                this.font.drawString(matrixStack, "Статус", this.width / 2 - 150, positionY[6] + 5, 0xA0A0A0);

                this.ipPort.render(matrixStack, mouseX, mouseY, partialTicks);
                if (isSocks4) {
                    this.font.drawString(matrixStack, "User ID: ", this.width / 2 - 150, positionY[4] + 5, 0xA0A0A0);
                    this.username.render(matrixStack, mouseX, mouseY, partialTicks);
                } else {
                    this.font.drawString(matrixStack, "Логин", this.width / 2 - 150, positionY[4] + 5, 0xA0A0A0);
                    this.font.drawString(matrixStack, "Пароль", this.width / 2 - 150, positionY[5] + 5, 0xA0A0A0);
                    this.username.render(matrixStack, mouseX, mouseY, partialTicks);
                    this.password.render(matrixStack, mouseX, mouseY, partialTicks);
                }

                this.font.drawStringWithShadow(matrixStack, msg,
                        this.width / 2 - this.font.getStringWidth(msg) / 2,
                        positionY[7] + 5, 0xA0A0A0);

                super.render(matrixStack, mouseX, mouseY, partialTicks);
            }

            @Override
            public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
                msg = "";
                return super.keyPressed(keyCode, scanCode, modifiers);
            }

            @Override
            public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
                this.ipPort.mouseClicked(mouseX, mouseY, mouseButton);
                this.username.mouseClicked(mouseX, mouseY, mouseButton);
                this.password.mouseClicked(mouseX, mouseY, mouseButton);
                return super.mouseClicked(mouseX, mouseY, mouseButton);
            }
        }

Код:
Expand Collapse Copy
package VilzRecode.proxy;

public class Proxy {
    public String ipPort = "";
    public ProxyType type = ProxyType.SOCKS5;
    public String username = "";
    public String password = "";

    public Proxy() {}

    public Proxy(boolean isSocks4, String ipPort, String username, String password) {
        this.type = isSocks4 ? ProxyType.SOCKS4 : ProxyType.SOCKS5;
        this.ipPort = ipPort;
        this.username = username;
        this.password = password;
    }

    public int getPort() {
        try {
            return Integer.parseInt(ipPort.split(":")[1]);
        } catch (Exception e) {
            return 1080; // default proxy port
        }
    }

    public String getIp() {
        try {
            return ipPort.split(":")[0];
        } catch (Exception e) {
            return "";
        }
    }

    public boolean isValid() {
        return !ipPort.isEmpty() && getPort() > 0 && !getIp().isEmpty();
    }

    public enum ProxyType {
        SOCKS4,
        SOCKS5
    }
}



Код:
Expand Collapse Copy
package VilzRecode.proxy;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.proxy.*;
import io.netty.handler.timeout.ReadTimeoutHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.network.*;

import java.io.*;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.util.concurrent.atomic.AtomicReference;

public class ProxyManager {
    public static boolean proxyEnabled = false;
    public static Proxy proxy = new Proxy();
    private static final File proxyFile = new File(Minecraft.getInstance().gameDir, "config/proxy.vl");

    public static String getProxyIp() {
        return proxy.ipPort.isEmpty() ? "Нет" : proxyEnabled ? proxy.getIp() + ":" + proxy.getPort() : "Отключен";
    }

    public static void init() throws IOException {
        if (!proxyFile.exists()) {
            proxyFile.getParentFile().mkdirs();
            proxyFile.createNewFile();
            save();
        } else {
            load();
        }
    }

    public static NetworkManager createConnection(String ip, int port) throws Exception {
        return createNetworkManager(InetAddress.getByName(ip), port);
    }

    public static NetworkManager createNetworkManager(InetAddress address, int port) throws Exception {
        final AtomicReference<NetworkManager> managerRef = new AtomicReference<>();
        final AtomicReference<Exception> errorRef = new AtomicReference<>();

        Bootstrap bootstrap = new Bootstrap()
                .group(NetworkManager.CLIENT_NIO_EVENTLOOP.getValue())
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<Channel>() {
                    @Override
                    protected void initChannel(Channel channel) {
                        try {
                            channel.config().setOption(ChannelOption.TCP_NODELAY, true);
                            channel.config().setOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000);

                            if (proxyEnabled && proxy.isValid()) {
                                InetSocketAddress proxyAddr = new InetSocketAddress(proxy.getIp(), proxy.getPort());
                                if (proxy.type == Proxy.ProxyType.SOCKS5) {
                                    channel.pipeline().addFirst(new Socks5ProxyHandler(
                                            proxyAddr,
                                            proxy.username.isEmpty() ? null : proxy.username,
                                            proxy.password.isEmpty() ? null : proxy.password
                                    ));
                                } else {
                                    channel.pipeline().addFirst(new Socks4ProxyHandler(
                                            proxyAddr,
                                            proxy.username.isEmpty() ? null : proxy.username
                                    ));
                                }
                            }

                            NetworkManager networkManager = new NetworkManager(PacketDirection.CLIENTBOUND);
                            managerRef.set(networkManager);

                            channel.pipeline()
                                    .addLast("timeout", new ReadTimeoutHandler(30))
                                    .addLast("splitter", new NettyVarint21FrameDecoder())
                                    .addLast("decoder", new NettyPacketDecoder(PacketDirection.CLIENTBOUND))
                                    .addLast("prepender", new NettyVarint21FrameEncoder())
                                    .addLast("encoder", new NettyPacketEncoder(PacketDirection.SERVERBOUND))
                                    .addLast("packet_handler", networkManager);
                        } catch (Exception e) {
                            errorRef.set(e);
                            channel.close();
                        }
                    }
                });

        ChannelFuture future = bootstrap.connect(address, port).syncUninterruptibly();
        if (!future.isSuccess()) {
            throw new Exception("Ошибка подключения: " + future.cause().getMessage());
        }
        if (errorRef.get() != null) {
            throw errorRef.get();
        }
        return managerRef.get();
    }

    private static void setupProxy(Channel channel) {
        InetSocketAddress proxyAddr = new InetSocketAddress(proxy.getIp(), proxy.getPort());
        if (proxy.type == Proxy.ProxyType.SOCKS5) {
            channel.pipeline().addFirst(new Socks5ProxyHandler(
                    proxyAddr,
                    proxy.username.isEmpty() ? null : proxy.username,
                    proxy.password.isEmpty() ? null : proxy.password));
        } else {
            channel.pipeline().addFirst(new Socks4ProxyHandler(
                    proxyAddr,
                    proxy.username.isEmpty() ? null : proxy.username));
        }
    }

    private static void setupPipeline(Channel channel, NetworkManager networkManager) {
        channel.pipeline()
                .addLast("timeout", new ReadTimeoutHandler(30))
                .addLast("splitter", new NettyVarint21FrameDecoder())
                .addLast("decoder", new NettyPacketDecoder(PacketDirection.CLIENTBOUND))
                .addLast("prepender", new NettyVarint21FrameEncoder())
                .addLast("encoder", new NettyPacketEncoder(PacketDirection.SERVERBOUND))
                .addLast("packet_handler", networkManager);
    }

    private static void load() {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(proxyFile)))) {
            String line = reader.readLine();
            if (line != null) {
                String[] parts = line.trim().split(";");
                if (parts.length >= 5) {
                    proxy = new Proxy(
                            parts[0].equals("SOCKS4"),
                            parts[1],
                            parts[2],
                            parts[3]
                    );
                    proxyEnabled = Boolean.parseBoolean(parts[4]);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static NetworkManager createProxyConnection(InetAddress address, int port) throws Exception {
        if (proxyEnabled && proxy.isValid()) {
            return createNetworkManager(address, port);
        } else {
            return NetworkManager.createNetworkManagerAndConnect(address, port, false);
        }
    }

    public static void save() {
        try {
            String data = String.join(";",
                    proxy.type.toString(),
                    proxy.ipPort,
                    proxy.username,
                    proxy.password,
                    String.valueOf(proxyEnabled)
            );
            Files.write(proxyFile.toPath(), data.getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}



Код:
Expand Collapse Copy
package VilzRecode.proxy;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.proxy.*;
import io.netty.handler.timeout.ReadTimeoutHandler;
import net.minecraft.network.*;
import net.minecraft.network.handshake.client.CHandshakePacket;
import net.minecraft.network.status.client.*;
import net.minecraft.network.status.server.*;
import net.minecraft.util.text.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.status.IClientStatusNetHandler;

import java.net.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;

public class TestPing {
    public String state = "";
    private long pingSentAt;
    private NetworkManager pingDestination = null;
    private Proxy proxy;
    private static final ThreadPoolExecutor EXECUTOR = new ScheduledThreadPoolExecutor(5,
            new ThreadFactoryBuilder().setNameFormat("Server Pinger #%d").setDaemon(true).build());

    public void run(String ip, int port, Proxy proxy) {
        this.proxy = proxy;
        EXECUTOR.submit(() -> {
            try {
                ping(ip, port);
            } catch (Exception e) {
                state = TextFormatting.RED + "Ошибка: " + e.getMessage();
                e.printStackTrace();
            }
        });
    }

    private void ping(String ip, int port) throws Exception {
        state = "Подключение к " + ip + " через прокси " + proxy.ipPort + "...";

        NetworkManager networkManager = createNetworkManager(InetAddress.getByName(ip), port);
        pingDestination = networkManager;

        networkManager.setNetHandler(new IClientStatusNetHandler() {
            private boolean successful = false;

            @Override
            public void onDisconnect(ITextComponent reason) {
                if (!successful) {
                    state = TextFormatting.RED + "Ошибка: " + (reason != null ? reason.getString() : "Неизвестная ошибка");
                }
                pingDestination = null;
            }

            @Override
            public void handleServerInfo(SServerInfoPacket packetIn) {
                pingSentAt = System.currentTimeMillis();
                networkManager.sendPacket(new CPingPacket(pingSentAt));
            }

            @Override
            public void handlePong(SPongPacket packetIn) {
                successful = true;
                pingDestination = null;
                long pingToServer = System.currentTimeMillis() - pingSentAt;
                state = "Успешно! Пинг: " + pingToServer + " мс";
                networkManager.closeChannel(new StringTextComponent("Finished"));
            }

            @Override
            public NetworkManager getNetworkManager() {
                return networkManager;
            }
        });

        networkManager.sendPacket(new CHandshakePacket(ip, port, ProtocolType.STATUS));
        networkManager.sendPacket(new CServerQueryPacket());
    }

    private NetworkManager createNetworkManager(InetAddress address, int port) throws Exception {
        final AtomicReference<NetworkManager> managerRef = new AtomicReference<>();
        final AtomicReference<Exception> errorRef = new AtomicReference<>();

        Bootstrap bootstrap = new Bootstrap()
                .group(NetworkManager.CLIENT_NIO_EVENTLOOP.getValue())
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<Channel>() {
                    @Override
                    protected void initChannel(Channel channel) {
                        try {
                            channel.config().setOption(ChannelOption.TCP_NODELAY, true);
                            channel.config().setOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000);

                            ChannelPipeline pipeline = channel.pipeline();

                            if (proxy != null && proxy.isValid()) {
                                InetSocketAddress proxyAddress = new InetSocketAddress(proxy.getIp(), proxy.getPort());

                                if (proxy.type == Proxy.ProxyType.SOCKS5) {
                                    pipeline.addFirst("socks5_proxy", new Socks5ProxyHandler(
                                            proxyAddress,
                                            proxy.username.isEmpty() ? null : proxy.username,
                                            proxy.password.isEmpty() ? null : proxy.password));
                                } else {
                                    pipeline.addFirst("socks4_proxy", new Socks4ProxyHandler(
                                            proxyAddress,
                                            proxy.username.isEmpty() ? null : proxy.username));
                                }
                            }

                            NetworkManager networkManager = new NetworkManager(PacketDirection.CLIENTBOUND);
                            managerRef.set(networkManager);

                            pipeline.addLast("timeout", new ReadTimeoutHandler(30))
                                    .addLast("splitter", new NettyVarint21FrameDecoder())
                                    .addLast("decoder", new NettyPacketDecoder(PacketDirection.CLIENTBOUND))
                                    .addLast("prepender", new NettyVarint21FrameEncoder())
                                    .addLast("encoder", new NettyPacketEncoder(PacketDirection.SERVERBOUND))
                                    .addLast("packet_handler", networkManager);
                        } catch (Exception e) {
                            errorRef.set(e);
                            channel.close();
                        }
                    }
                });

        ChannelFuture future = bootstrap.connect(address, port).syncUninterruptibly();

        if (!future.isSuccess()) {
            throw new Exception("Ошибка подключения: " + (future.cause() != null ? future.cause().getMessage() : "Неизвестная ошибка"));
        }

        if (errorRef.get() != null) {
            throw errorRef.get();
        }

        return managerRef.get();
    }

    public void pingPendingNetworks() {
        if (pingDestination != null) {
            try {
                pingDestination.tick();
                if (!pingDestination.isChannelOpen()) {
                    pingDestination.handleDisconnection();
                    pingDestination = null;
                }
            } catch (Exception e) {
                pingDestination = null;
            }
        }
    }
}
если еще что-то скинуть
то пишите
 
мб с конфигом что то
 
Назад
Сверху Снизу