    001package net.minecraft.client.gui;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.io.IOException;
    006import net.minecraft.client.mco.ExceptionMcoService;
    007import net.minecraft.client.mco.ExceptionRetryCall;
    008import net.minecraft.client.mco.McoClient;
    009import net.minecraft.client.mco.McoServer;
    010import net.minecraft.client.mco.McoServerAddress;
    011import net.minecraft.client.multiplayer.NetClientHandler;
    012import net.minecraft.client.multiplayer.ServerAddress;
    013import net.minecraft.util.StringTranslate;
    014
    015@SideOnly(Side.CLIENT)
    016public class TaskOnlineConnect extends TaskLongRunning
    017{
    018    private NetClientHandler field_96586_a;
    019    private final McoServer field_96585_c;
    020    private final GuiScreen field_96584_d;
    021
    022    public TaskOnlineConnect(GuiScreen par1GuiScreen, McoServer par2McoServer)
    023    {
    024        this.field_96584_d = par1GuiScreen;
    025        this.field_96585_c = par2McoServer;
    026    }
    027
    028    public void run()
    029    {
    030        this.func_96576_b(StringTranslate.getInstance().translateKey("mco.connect.connecting"));
    031        McoClient mcoclient = new McoClient(this.func_96578_b().session);
    032        boolean flag = false;
    033        boolean flag1 = false;
    034        McoServerAddress mcoserveraddress = null;
    035
    036        for (int i = 0; i < 10 && !this.func_96577_c(); ++i)
    037        {
    038            try
    039            {
    040                mcoserveraddress = mcoclient.func_96374_a(this.field_96585_c.field_96408_a);
    041                flag = true;
    042            }
    043            catch (ExceptionRetryCall exceptionretrycall)
    044            {
    045                ;
    046            }
    047            catch (ExceptionMcoService exceptionmcoservice)
    048            {
    049                flag1 = true;
    050                this.func_96575_a(exceptionmcoservice.getLocalizedMessage());
    051                break;
    052            }
    053            catch (IOException ioexception)
    054            {
    055                ;
    056            }
    057            catch (Exception exception)
    058            {
    059                flag1 = true;
    060                this.func_96575_a(exception.getLocalizedMessage());
    061            }
    062
    063            if (flag)
    064            {
    065                break;
    066            }
    067
    068            this.func_96581_e();
    069        }
    070
    071        if (!this.func_96577_c() && !flag1)
    072        {
    073            if (flag)
    074            {
    075                ServerAddress serveraddress = ServerAddress.func_78860_a(mcoserveraddress.field_96417_a);
    076                this.func_96582_a(serveraddress.getIP(), serveraddress.getPort());
    077            }
    078            else
    079            {
    080                this.func_96578_b().displayGuiScreen(this.field_96584_d);
    081            }
    082        }
    083    }
    084
    085    private void func_96581_e()
    086    {
    087        try
    088        {
    089            Thread.sleep(5000L);
    090        }
    091        catch (InterruptedException interruptedexception)
    092        {
    093            System.err.println(interruptedexception);
    094        }
    095    }
    096
    097    private void func_96582_a(String par1Str, int par2)
    098    {
    099        (new ThreadOnlineConnect(this, par1Str, par2)).start();
    100    }
    101
    102    public void func_96573_a()
    103    {
    104        if (this.field_96586_a != null)
    105        {
    106            this.field_96586_a.processReadPackets();
    107        }
    108    }
    109
    110    static NetClientHandler func_96583_a(TaskOnlineConnect par0TaskOnlineConnect, NetClientHandler par1NetClientHandler)
    111    {
    112        return par0TaskOnlineConnect.field_96586_a = par1NetClientHandler;
    113    }
    114
    115    static GuiScreen func_98172_a(TaskOnlineConnect par0TaskOnlineConnect)
    116    {
    117        return par0TaskOnlineConnect.field_96584_d;
    118    }
    119
    120    static NetClientHandler func_96580_a(TaskOnlineConnect par0TaskOnlineConnect)
    121    {
    122        return par0TaskOnlineConnect.field_96586_a;
    123    }
    124}