    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 var4)
    058                {
    059                    FMLLog.log(Level.SEVERE, var4, "A critical server error occured handling a packet, kicking %s", var2.getPlayer().entityId);
    060                    logger.log(Level.WARNING, "Failed to handle packet: " + var4, var4);
    061                    var2.kickPlayerFromServer("Internal server error");
    062                }
    063
    064                if (var2.connectionClosed)
    065                {
    066                    this.connections.remove(var1--);
    067                }
    068
    069                var2.netManager.wakeThreads();
    070            }
    071        }
    072
    073        public MinecraftServer getServer()
    074        {
    075            return this.mcServer;
    076        }
    077    }