    001    package net.minecraft.src;
    002
    003    import java.io.IOException;
    004    import java.util.ArrayList;
    005    import java.util.Collections;
    006    import java.util.List;
    007    import java.util.logging.Level;
    008    import java.util.logging.Logger;
    009
    010    import cpw.mods.fml.common.FMLLog;
    011    import net.minecraft.server.MinecraftServer;
    012
    013    public abstract class NetworkListenThread
    014    {
    015        /** Reference to the logger. */
    016        public static Logger logger = Logger.getLogger("Minecraft");
    017
    018        /** Reference to the MinecraftServer object. */
    019        private final MinecraftServer mcServer;
    020        private final List connections = Collections.synchronizedList(new ArrayList());
    021
    022        /** Whether the network listener object is listening. */
    023        public volatile boolean isListening = false;
    024
    025        public NetworkListenThread(MinecraftServer par1MinecraftServer) throws IOException
    026        {
    027            this.mcServer = par1MinecraftServer;
    028            this.isListening = true;
    029        }
    030
    031        /**
    032         * adds this connection to the list of currently connected players
    033         */
    034        public void addPlayer(NetServerHandler par1NetServerHandler)
    035        {
    036            this.connections.add(par1NetServerHandler);
    037        }
    038
    039        public void stopListening()
    040        {
    041            this.isListening = false;
    042        }
    043
    044        /**
    045         * processes packets and pending connections
    046         */
    047        public void networkTick()
    048        {
    049            for (int var1 = 0; var1 < this.connections.size(); ++var1)
    050            {
    051                NetServerHandler var2 = (NetServerHandler)this.connections.get(var1);
    052
    053                try
    054                {
    055                    var2.networkTick();
    056                }
    057                catch (Exception var5)
    058                {
    059                    if (var2.netManager instanceof MemoryConnection)
    060                    {
    061                        CrashReport var4 = CrashReport.func_85055_a(var5, "Ticking memory connection");
    062                        throw new ReportedException(var4);
    063                    }
    064
    065                    FMLLog.log(Level.SEVERE, var5, "A critical server error occured handling a packet, kicking %s", var2.getPlayer().entityId);
    066                    logger.log(Level.WARNING, "Failed to handle packet for " + var2.playerEntity.getEntityName() + "/" + var2.playerEntity.func_71114_r() + ": " + var5, var5);
    067                    var2.kickPlayerFromServer("Internal server error");
    068                }
    069
    070                if (var2.connectionClosed)
    071                {
    072                    this.connections.remove(var1--);
    073                }
    074
    075                var2.netManager.wakeThreads();
    076            }
    077        }
    078
    079        public MinecraftServer getServer()
    080        {
    081            return this.mcServer;
    082        }
    083    }