MC running through HTTP Proxy

Discussion in 'Plugin Development' started by blockade08, Dec 4, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    blockade08

    Hello,

    I've been looking around for a while on how to get minecraft multiplayer to work through a proxy. The environment i get internet through most often has an HTTP proxy set up that requires programs wanting to access the internet to be configured to go through the forced proxy. I've tried multiple solutions, including changing the java network settings in the control panel, port tunneling, and trying to run minecraft with arguments that would require it to go through the specific proxy through a batch file. (I realize there are some third party programs that do this but I can't use those). I resorted to modifying the code, specifically GuiMultiplayer.jar, which i tracked the polling and packet sending down to.

    The contents of the file are below (and stuff I changed highlighted)

    Code:
    // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
    // Jad home page: http://www.kpdus.com/jad.html
    // Decompiler options: packimports(3) braces deadcode fieldsfirst 
    
    package net.minecraft.src;
    
    
    import java.io.*;
    import java.net.InetSocketAddress;
    import java.net.Socket;
    import java.util.ArrayList;
    import java.util.List;
    import net.minecraft.client.Minecraft;
    import org.lwjgl.input.Keyboard;
    
    
    import java.net.Proxy; //ADDED
    
    
    //SKIPPING METHODS THAT HAVEN'T BEEN CHANGED
    
     private void pollServer(ServerNBTStorage servernbtstorage)
            throws IOException
        {
            String s = servernbtstorage.host;
            String as[] = s.split(":");
            if(s.startsWith("["))
            {
                int i = s.indexOf("]");
                if(i > 0)
                {
                    String s2 = s.substring(1, i);
                    String s3 = s.substring(i + 1).trim();
                    if(s3.startsWith(":") && s3.length() > 0)
                    {
                        s3 = s3.substring(1);
                        as = new String[2];
                        as[0] = s2;
                        as[1] = s3;
                    } else
                    {
                        as = new String[1];
                        as[0] = s2;
                    }
                }
            }
            if(as.length > 2)
            {
                as = new String[1];
                as[0] = s;
            }
            String s1 = as[0];
            int j = as.length <= 1 ? 25565 : parseIntWithDefault(as[1], 25565);
    
        //ADDITIONS CHANGES START HERE
    
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("web-proxy", 8080));
    
        //ADDITIONS END HERE
    
    
            Socket socket = null;
            DataInputStream datainputstream = null;
            DataOutputStream dataoutputstream = null;
            try
            {
    
        //CHANGES START HERE
    
            socket = new Socket(proxy); //CHANGE FROM : socket = new Socket();
    
        //CHANGES END HERE
    
                socket.setSoTimeout(3000);
                socket.setTcpNoDelay(true);
                socket.setTrafficClass(18);
                socket.connect(new InetSocketAddress(s1, j), 3000);
                datainputstream = new DataInputStream(socket.getInputStream());
                dataoutputstream = new DataOutputStream(socket.getOutputStream());
                dataoutputstream.write(254);
                if(datainputstream.read() != 255)
                {
                    throw new IOException("Bad message");
                }
                String s4 = Packet.readString(datainputstream, 64);
                char ac[] = s4.toCharArray();
                for(int k = 0; k < ac.length; k++)
                {
                    if(ac[k] != '\247' && ChatAllowedCharacters.allowedCharacters.indexOf(ac[k]) < 0)
                    {
                        ac[k] = '?';
                    }
                }
    
                s4 = new String(ac);
                String as1[] = s4.split("\247");
                s4 = as1[0];
                int l = -1;
                int i1 = -1;
                try
                {
                    l = Integer.parseInt(as1[1]);
                    i1 = Integer.parseInt(as1[2]);
                }
                catch(Exception exception) { }
                servernbtstorage.motd = (new StringBuilder()).append("\2477").append(s4).toString();
                if(l >= 0 && i1 > 0)
                {
                    servernbtstorage.playerCount = (new StringBuilder()).append("\2477").append(l).append("\2478/\2477").append
    
    (i1).toString();
                } else
                {
                    servernbtstorage.playerCount = "\2478???";
                }
            }
            finally
            {
                try
                {
                    if(datainputstream != null)
                    {
                        datainputstream.close();
                    }
                }
                catch(Throwable throwable) { }
                try
                {
                    if(dataoutputstream != null)
                    {
                        dataoutputstream.close();
                    }
                }
                catch(Throwable throwable1) { }
                try
                {
                    if(socket != null)
                    {
                        socket.close();
                    }
                }
                catch(Throwable throwable2) { }
            }
        }
    
    After going through some changes to get it to recompile, i ended up with this dissatisfying result:

    [​IMG]

    Any ideas on how to fix this?

    Thanks so much for your help in advance :)

    EDIT:
    Here is the command line output if that helps:
    Show Spoiler
    Code:
    == MCP v5.0 ==
    [15:41] 27 achievements
    [15:41] 174 recipes
    [15:42] WARNING: Found unknown Windows version: Windows 7
    [15:42] Attempting to use default windows plug-in.
    [15:42] Loading: net.java.games.input.DirectAndRawInputEnvironmentPlugin
    [15:42]
    [15:42] Starting up SoundSystem...
    [15:42] Initializing LWJGL OpenAL
    [15:42] (The LWJGL binding of OpenAL.  For more information, see http://www.lwjg
    l.org)
    [15:42] OpenAL initialized.
    [15:42]
    [15:43] java.net.ConnectException: Connection timed out: connect
    [15:43] at java.net.DualStackPlainSocketImpl.connect0(Native Method)
    [15:43] at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketI
    mpl.java:69)
    [15:43] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.ja
    va:337)
    [15:43] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocket
    Impl.java:198)
    [15:43] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java
    :180)
    [15:43] at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    [15:43] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    [15:43] at java.net.Socket.connect(Socket.java:579)
    [15:43] at java.net.Socket.connect(Socket.java:528)
    [15:43] at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    [15:43] at sun.net.www.http.HttpClient.openServer(HttpClient.java:388)
    [15:43] at sun.net.www.http.HttpClient.openServer(HttpClient.java:483)
    [15:43] at sun.net.www.http.HttpClient.<init>(HttpClient.java:213)
    [15:43] at sun.net.www.http.HttpClient.New(HttpClient.java:300)
    [15:43] at sun.net.www.http.HttpClient.New(HttpClient.java:316)
    [15:43] at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLC
    onnection.java:992)
    [15:43] at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConne
    ction.java:928)
    [15:43] at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection
    .java:846)
    [15:43] at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
    nection.java:1296)
    [15:43] at java.net.URL.openStream(URL.java:1035)
    [15:43] at net.minecraft.src.ThreadDownloadResources.run(ThreadDownloadResources
    .java:44)
    [15:44] Stopping!
    [15:44]
    [15:44] SoundSystem shutting down...
    [15:44] Author: Paul Lamb, www.paulscode.com
    [15:44]
    Press any key to continue . . .
    
     
  2. Offline

    Evangon

    Um....
    line 1 says waffles plus cows should equals ducks. it's always equals a holy cow in the batmobile.
    Anyways, why is "servernbtstorage.playerCount = "\2478???";" the way it is? It seems weird that it says /2478???
     
  3. It's just like a color code (\247<colorcode>)
     
  4. Offline

    MikeA

    If you're using a proxy (HTTP), localhost won't work.
     
  5. Offline

    blockade08


    I see, thats why that doesn't work. Any Ideas why the other server doesn't work though? Im assuming the "ERROR: class java.lang.IllegalArgumentException" has something to do with it, but i don't see where I have an illegal argument :S

    Thanks for the replies by the way
     
  6. Offline

    cheese5505

    Look at the class ThreadDownloadResources on line 44
     
  7. Offline

    blockade08

    Didn't catch that in the cmd output, thanks!

    Okay, this is what the code there does:

    Code:
    public void run()
        {
            try
            {
                URL url = new URL("http://s3.amazonaws.com/MinecraftResources/");
                DocumentBuilderFactory documentbuilderfactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder documentbuilder = documentbuilderfactory.newDocumentBuilder();
                Document document = documentbuilder.parse(url.openStream());  //LINE 44
    
    url.openConnection has the parameter 'Proxy' which I can use to get it through the forced HTTP proxy, but the openStream() returns an input stream while the URL returns a URL connection. Any ideas on how to get the proxy to work with the input stream?

    Also the address "http://s3.amazonaws.com/MinecraftResources/" seems to hold the music files..
     
Thread Status:
Not open for further replies.

Share This Page