001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    import cpw.mods.fml.common.network.FMLNetworkHandler;
006    
007    import java.io.IOException;
008    import java.net.InetAddress;
009    import java.net.NetworkInterface;
010    import java.util.Arrays;
011    import java.util.Collections;
012    import java.util.List;
013    
014    import com.google.common.collect.Iterators;
015    import com.google.common.collect.Lists;
016    
017    import net.minecraft.server.MinecraftServer;
018    
019    @SideOnly(Side.CLIENT)
020    public class IntegratedServerListenThread extends NetworkListenThread
021    {
022        private final MemoryConnection netMemoryConnection = new MemoryConnection((NetHandler)null);
023        private MemoryConnection theMemoryConnection;
024        private String field_71759_e;
025        private boolean field_71756_f = false;
026        private ServerListenThread myServerListenThread;
027    
028        public IntegratedServerListenThread(IntegratedServer par1IntegratedServer) throws IOException
029        {
030            super(par1IntegratedServer);
031        }
032    
033        public void func_71754_a(MemoryConnection par1MemoryConnection, String par2Str)
034        {
035            this.theMemoryConnection = par1MemoryConnection;
036            this.field_71759_e = par2Str;
037        }
038    
039        public String func_71755_c() throws IOException
040        {
041            if (this.myServerListenThread == null)
042            {
043                int var1 = -1;
044    
045                try
046                {
047                    var1 = HttpUtil.func_76181_a();
048                }
049                catch (IOException var4)
050                {
051                    ;
052                }
053    
054                if (var1 <= 0)
055                {
056                    var1 = 25564;
057                }
058    
059                try
060                {
061                    this.myServerListenThread = new ServerListenThread(this, (InetAddress)null, var1);
062                    this.myServerListenThread.start();
063                }
064                catch (IOException var3)
065                {
066                    throw var3;
067                }
068            }
069    
070            return FMLNetworkHandler.computeLocalHost().getHostAddress() + ":" + this.myServerListenThread.getMyPort();
071        }
072    
073        public void stopListening()
074        {
075            super.stopListening();
076    
077            if (this.myServerListenThread != null)
078            {
079                System.out.println("Stopping server connection");
080                this.myServerListenThread.func_71768_b();
081                this.myServerListenThread.interrupt();
082                this.myServerListenThread = null;
083            }
084        }
085    
086        /**
087         * processes packets and pending connections
088         */
089        public void networkTick()
090        {
091            if (this.theMemoryConnection != null)
092            {
093                EntityPlayerMP var1 = this.getIntergatedServerMinecraftServerInstance().getConfigurationManager().createPlayerForUser(this.field_71759_e);
094    
095                if (var1 != null)
096                {
097                    this.netMemoryConnection.pairWith(this.theMemoryConnection);
098                    this.field_71756_f = true;
099                    this.getIntergatedServerMinecraftServerInstance().getConfigurationManager().initializeConnectionToPlayer(this.netMemoryConnection, var1);
100                }
101    
102                this.theMemoryConnection = null;
103                this.field_71759_e = null;
104            }
105    
106            if (this.myServerListenThread != null)
107            {
108                this.myServerListenThread.processPendingConnections();
109            }
110    
111            super.networkTick();
112        }
113    
114        /**
115         * Gets MinecraftServer instance.
116         */
117        public IntegratedServer getIntergatedServerMinecraftServerInstance()
118        {
119            return (IntegratedServer)super.getServer();
120        }
121    
122        public boolean func_71752_f()
123        {
124            return this.field_71756_f && this.netMemoryConnection.getPairedConnection().isConnectionActive() && this.netMemoryConnection.getPairedConnection().isGamePaused();
125        }
126    
127        public MinecraftServer getServer()
128        {
129            return this.getIntergatedServerMinecraftServerInstance();
130        }
131    }