    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.io.File;
    006    import java.net.SocketAddress;
    007    import java.text.SimpleDateFormat;
    008    import java.util.ArrayList;
    009    import java.util.Collections;
    010    import java.util.HashSet;
    011    import java.util.Iterator;
    012    import java.util.List;
    013    import java.util.Set;
    014    import java.util.logging.Logger;
    015
    016    import cpw.mods.fml.common.network.FMLNetworkHandler;
    017    import cpw.mods.fml.common.network.NetworkRegistry;
    018    import cpw.mods.fml.common.registry.GameRegistry;
    019    import net.minecraft.server.MinecraftServer;
    020    import net.minecraftforge.common.DimensionManager;
    021
    022    public abstract class ServerConfigurationManager
    023    {
    024        private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
    025
    026        /** Reference to the logger. */
    027        public static final Logger logger = Logger.getLogger("Minecraft");
    028
    029        /** Reference to the MinecraftServer object. */
    030        private final MinecraftServer mcServer;
    031
    032        /** A list of player entities that exist on this server. */
    033        public final List playerEntityList = new ArrayList();
    034        private final BanList bannedPlayers = new BanList(new File("banned-players.txt"));
    035        private final BanList bannedIPs = new BanList(new File("banned-ips.txt"));
    036
    037        /** A set containing the OPs. */
    038        private Set ops = new HashSet();
    039
    040        /** The Set of all whitelisted players. */
    041        private Set whiteListedPlayers = new HashSet();
    042
    043        /** Reference to the PlayerNBTManager object. */
    044        private IPlayerFileData playerNBTManagerObj;
    045
    046        /**
    047         * Server setting to only allow OPs and whitelisted players to join the server.
    048         */
    049        private boolean whiteListEnforced;
    050
    051        /** The maximum number of players that can be connected at a time. */
    052        protected int maxPlayers;
    053        protected int viewDistance;
    054        private EnumGameType gameType;
    055
    056        /** True if all players are allowed to use commands (cheats). */
    057        private boolean commandsAllowedForAll;
    058
    059        /**
    060         * index into playerEntities of player to ping, updated every tick; currently hardcoded to max at 200 players
    061         */
    062        private int playerPingIndex = 0;
    063
    064        public ServerConfigurationManager(MinecraftServer par1MinecraftServer)
    065        {
    066            this.mcServer = par1MinecraftServer;
    067            this.bannedPlayers.setListActive(false);
    068            this.bannedIPs.setListActive(false);
    069            this.maxPlayers = 8;
    070        }
    071
    072        public void initializeConnectionToPlayer(INetworkManager par1INetworkManager, EntityPlayerMP par2EntityPlayerMP)
    073        {
    074            this.readPlayerDataFromFile(par2EntityPlayerMP);
    075            par2EntityPlayerMP.setWorld(this.mcServer.worldServerForDimension(par2EntityPlayerMP.dimension));
    076            par2EntityPlayerMP.theItemInWorldManager.setWorld((WorldServer)par2EntityPlayerMP.worldObj);
    077            String var3 = "local";
    078
    079            if (par1INetworkManager.getSocketAddress() != null)
    080            {
    081                var3 = par1INetworkManager.getSocketAddress().toString();
    082            }
    083
    084            logger.info(par2EntityPlayerMP.username + "[" + var3 + "] logged in with entity id " + par2EntityPlayerMP.entityId + " at (" + par2EntityPlayerMP.posX + ", " + par2EntityPlayerMP.posY + ", " + par2EntityPlayerMP.posZ + ")");
    085            WorldServer var4 = this.mcServer.worldServerForDimension(par2EntityPlayerMP.dimension);
    086            ChunkCoordinates var5 = var4.getSpawnPoint();
    087            this.func_72381_a(par2EntityPlayerMP, (EntityPlayerMP)null, var4);
    088            NetServerHandler var6 = new NetServerHandler(this.mcServer, par1INetworkManager, par2EntityPlayerMP);
    089            var6.sendPacketToPlayer(new Packet1Login(par2EntityPlayerMP.entityId, var4.getWorldInfo().getTerrainType(), par2EntityPlayerMP.theItemInWorldManager.getGameType(), var4.getWorldInfo().isHardcoreModeEnabled(), var4.provider.dimensionId, var4.difficultySetting, var4.getHeight(), this.getMaxPlayers()));
    090            var6.sendPacketToPlayer(new Packet6SpawnPosition(var5.posX, var5.posY, var5.posZ));
    091            var6.sendPacketToPlayer(new Packet202PlayerAbilities(par2EntityPlayerMP.capabilities));
    092            this.updateTimeAndWeatherForPlayer(par2EntityPlayerMP, var4);
    093            this.sendPacketToAllPlayers(new Packet3Chat("\u00a7e" + par2EntityPlayerMP.username + " joined the game."));
    094            this.playerLoggedIn(par2EntityPlayerMP);
    095            var6.setPlayerLocation(par2EntityPlayerMP.posX, par2EntityPlayerMP.posY, par2EntityPlayerMP.posZ, par2EntityPlayerMP.rotationYaw, par2EntityPlayerMP.rotationPitch);
    096            this.mcServer.getNetworkThread().addPlayer(var6);
    097            var6.sendPacketToPlayer(new Packet4UpdateTime(var4.func_82737_E(), var4.getWorldTime()));
    098
    099            if (this.mcServer.getTexturePack().length() > 0)
    100            {
    101                par2EntityPlayerMP.requestTexturePackLoad(this.mcServer.getTexturePack(), this.mcServer.textureSize());
    102            }
    103
    104            Iterator var7 = par2EntityPlayerMP.getActivePotionEffects().iterator();
    105
    106            while (var7.hasNext())
    107            {
    108                PotionEffect var8 = (PotionEffect)var7.next();
    109                var6.sendPacketToPlayer(new Packet41EntityEffect(par2EntityPlayerMP.entityId, var8));
    110            }
    111
    112            par2EntityPlayerMP.addSelfToInternalCraftingInventory();
    113            FMLNetworkHandler.handlePlayerLogin(par2EntityPlayerMP, var6, par1INetworkManager);
    114        }
    115
    116        /**
    117         * Sets the NBT manager to the one for the WorldServer given.
    118         */
    119        public void setPlayerManager(WorldServer[] par1ArrayOfWorldServer)
    120        {
    121            this.playerNBTManagerObj = par1ArrayOfWorldServer[0].getSaveHandler().getSaveHandler();
    122        }
    123
    124        public void func_72375_a(EntityPlayerMP par1EntityPlayerMP, WorldServer par2WorldServer)
    125        {
    126            WorldServer var3 = par1EntityPlayerMP.getServerForPlayer();
    127
    128            if (par2WorldServer != null)
    129            {
    130                par2WorldServer.getPlayerManager().removePlayer(par1EntityPlayerMP);
    131            }
    132
    133            var3.getPlayerManager().addPlayer(par1EntityPlayerMP);
    134            var3.theChunkProviderServer.loadChunk((int)par1EntityPlayerMP.posX >> 4, (int)par1EntityPlayerMP.posZ >> 4);
    135        }
    136
    137        public int getEntityViewDistance()
    138        {
    139            return PlayerManager.func_72686_a(this.getViewDistance());
    140        }
    141
    142        /**
    143         * called during player login. reads the player information from disk.
    144         */
    145        public void readPlayerDataFromFile(EntityPlayerMP par1EntityPlayerMP)
    146        {
    147            NBTTagCompound var2 = this.mcServer.worldServers[0].getWorldInfo().getPlayerNBTTagCompound();
    148
    149            if (par1EntityPlayerMP.getCommandSenderName().equals(this.mcServer.getServerOwner()) && var2 != null)
    150            {
    151                par1EntityPlayerMP.readFromNBT(var2);
    152            }
    153            else
    154            {
    155                this.playerNBTManagerObj.readPlayerData(par1EntityPlayerMP);
    156            }
    157        }
    158
    159        /**
    160         * also stores the NBTTags if this is an intergratedPlayerList
    161         */
    162        protected void writePlayerData(EntityPlayerMP par1EntityPlayerMP)
    163        {
    164            this.playerNBTManagerObj.writePlayerData(par1EntityPlayerMP);
    165        }
    166
    167        /**
    168         * Called when a player successfully logs in. Reads player data from disk and inserts the player into the world.
    169         */
    170        public void playerLoggedIn(EntityPlayerMP par1EntityPlayerMP)
    171        {
    172            this.sendPacketToAllPlayers(new Packet201PlayerInfo(par1EntityPlayerMP.username, true, 1000));
    173            this.playerEntityList.add(par1EntityPlayerMP);
    174            WorldServer var2 = this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension);
    175
    176            while (!var2.getCollidingBoundingBoxes(par1EntityPlayerMP, par1EntityPlayerMP.boundingBox).isEmpty())
    177            {
    178                par1EntityPlayerMP.setPosition(par1EntityPlayerMP.posX, par1EntityPlayerMP.posY + 1.0D, par1EntityPlayerMP.posZ);
    179            }
    180
    181            var2.spawnEntityInWorld(par1EntityPlayerMP);
    182            this.func_72375_a(par1EntityPlayerMP, (WorldServer)null);
    183            Iterator var3 = this.playerEntityList.iterator();
    184
    185            while (var3.hasNext())
    186            {
    187                EntityPlayerMP var4 = (EntityPlayerMP)var3.next();
    188                par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet201PlayerInfo(var4.username, true, var4.ping));
    189            }
    190        }
    191
    192        /**
    193         * using player's dimension, update their movement when in a vehicle (e.g. cart, boat)
    194         */
    195        public void serverUpdateMountedMovingPlayer(EntityPlayerMP par1EntityPlayerMP)
    196        {
    197            par1EntityPlayerMP.getServerForPlayer().getPlayerManager().updateMountedMovingPlayer(par1EntityPlayerMP);
    198        }
    199
    200        /**
    201         * Called when a player disconnects from the game. Writes player data to disk and removes them from the world.
    202         */
    203        public void playerLoggedOut(EntityPlayerMP par1EntityPlayerMP)
    204        {
    205            GameRegistry.onPlayerLogout(par1EntityPlayerMP);
    206            this.writePlayerData(par1EntityPlayerMP);
    207            WorldServer var2 = par1EntityPlayerMP.getServerForPlayer();
    208            var2.setEntityDead(par1EntityPlayerMP);
    209            var2.getPlayerManager().removePlayer(par1EntityPlayerMP);
    210            this.playerEntityList.remove(par1EntityPlayerMP);
    211            this.sendPacketToAllPlayers(new Packet201PlayerInfo(par1EntityPlayerMP.username, false, 9999));
    212        }
    213
    214        /**
    215         * checks ban-lists, then white-lists, then space for the server. Returns null on success, or an error message
    216         */
    217        public String allowUserToConnect(SocketAddress par1SocketAddress, String par2Str)
    218        {
    219            if (this.bannedPlayers.isBanned(par2Str))
    220            {
    221                BanEntry var6 = (BanEntry)this.bannedPlayers.getBannedList().get(par2Str);
    222                String var7 = "You are banned from this server!\nReason: " + var6.getBanReason();
    223
    224                if (var6.getBanEndDate() != null)
    225                {
    226                    var7 = var7 + "\nYour ban will be removed on " + dateFormat.format(var6.getBanEndDate());
    227                }
    228
    229                return var7;
    230            }
    231            else if (!this.isAllowedToLogin(par2Str))
    232            {
    233                return "You are not white-listed on this server!";
    234            }
    235            else
    236            {
    237                String var3 = par1SocketAddress.toString();
    238                var3 = var3.substring(var3.indexOf("/") + 1);
    239                var3 = var3.substring(0, var3.indexOf(":"));
    240
    241                if (this.bannedIPs.isBanned(var3))
    242                {
    243                    BanEntry var4 = (BanEntry)this.bannedIPs.getBannedList().get(var3);
    244                    String var5 = "Your IP address is banned from this server!\nReason: " + var4.getBanReason();
    245
    246                    if (var4.getBanEndDate() != null)
    247                    {
    248                        var5 = var5 + "\nYour ban will be removed on " + dateFormat.format(var4.getBanEndDate());
    249                    }
    250
    251                    return var5;
    252                }
    253                else
    254                {
    255                    return this.playerEntityList.size() >= this.maxPlayers ? "The server is full!" : null;
    256                }
    257            }
    258        }
    259
    260        /**
    261         * also checks for multiple logins
    262         */
    263        public EntityPlayerMP createPlayerForUser(String par1Str)
    264        {
    265            ArrayList var2 = new ArrayList();
    266            Iterator var3 = this.playerEntityList.iterator();
    267            EntityPlayerMP var4;
    268
    269            while (var3.hasNext())
    270            {
    271                var4 = (EntityPlayerMP)var3.next();
    272
    273                if (var4.username.equalsIgnoreCase(par1Str))
    274                {
    275                    var2.add(var4);
    276                }
    277            }
    278
    279            var3 = var2.iterator();
    280
    281            while (var3.hasNext())
    282            {
    283                var4 = (EntityPlayerMP)var3.next();
    284                var4.playerNetServerHandler.kickPlayerFromServer("You logged in from another location");
    285            }
    286
    287            Object var5;
    288
    289            if (this.mcServer.isDemo())
    290            {
    291                var5 = new DemoWorldManager(this.mcServer.worldServerForDimension(0));
    292            }
    293            else
    294            {
    295                var5 = new ItemInWorldManager(this.mcServer.worldServerForDimension(0));
    296            }
    297
    298            return new EntityPlayerMP(this.mcServer, this.mcServer.worldServerForDimension(0), par1Str, (ItemInWorldManager)var5);
    299        }
    300
    301        /**
    302         * creates and returns a respawned player based on the provided PlayerEntity. Args are the PlayerEntityMP to
    303         * respawn, an INT for the dimension to respawn into (usually 0), and a boolean value that is true if the player
    304         * beat the game rather than dying
    305         */
    306        public EntityPlayerMP respawnPlayer(EntityPlayerMP par1EntityPlayerMP, int par2, boolean par3)
    307        {
    308            World world = mcServer.worldServerForDimension(par2);
    309            if (world == null || !world.provider.canRespawnHere())
    310            {
    311                par2 = 0;
    312            }
    313
    314            par1EntityPlayerMP.getServerForPlayer().getEntityTracker().removeAllTrackingPlayers(par1EntityPlayerMP);
    315            par1EntityPlayerMP.getServerForPlayer().getEntityTracker().removeEntityFromAllTrackingPlayers(par1EntityPlayerMP);
    316            par1EntityPlayerMP.getServerForPlayer().getPlayerManager().removePlayer(par1EntityPlayerMP);
    317            this.playerEntityList.remove(par1EntityPlayerMP);
    318            this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension).removeEntity(par1EntityPlayerMP);
    319            ChunkCoordinates var4 = par1EntityPlayerMP.getSpawnChunk();
    320            boolean var5 = par1EntityPlayerMP.func_82245_bX();
    321            par1EntityPlayerMP.dimension = par2;
    322            Object var6;
    323
    324            if (this.mcServer.isDemo())
    325            {
    326                var6 = new DemoWorldManager(this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension));
    327            }
    328            else
    329            {
    330                var6 = new ItemInWorldManager(this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension));
    331            }
    332
    333            EntityPlayerMP var7 = new EntityPlayerMP(this.mcServer, this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension), par1EntityPlayerMP.username, (ItemInWorldManager)var6);
    334            var7.playerNetServerHandler = par1EntityPlayerMP.playerNetServerHandler;
    335            var7.clonePlayer(par1EntityPlayerMP, par3);
    336            var7.dimension = par2;
    337            var7.entityId = par1EntityPlayerMP.entityId;
    338            WorldServer var8 = this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension);
    339            this.func_72381_a(var7, par1EntityPlayerMP, var8);
    340            ChunkCoordinates var9;
    341
    342            if (var4 != null)
    343            {
    344                var9 = EntityPlayer.verifyRespawnCoordinates(this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension), var4, var5);
    345
    346                if (var9 != null)
    347                {
    348                    var7.setLocationAndAngles((double)((float)var9.posX + 0.5F), (double)((float)var9.posY + 0.1F), (double)((float)var9.posZ + 0.5F), 0.0F, 0.0F);
    349                    var7.setSpawnChunk(var4, var5);
    350                }
    351                else
    352                {
    353                    var7.playerNetServerHandler.sendPacketToPlayer(new Packet70GameEvent(0, 0));
    354                }
    355            }
    356
    357            var8.theChunkProviderServer.loadChunk((int)var7.posX >> 4, (int)var7.posZ >> 4);
    358
    359            while (!var8.getCollidingBoundingBoxes(var7, var7.boundingBox).isEmpty())
    360            {
    361                var7.setPosition(var7.posX, var7.posY + 1.0D, var7.posZ);
    362            }
    363
    364            var7.playerNetServerHandler.sendPacketToPlayer(new Packet9Respawn(var7.dimension, (byte)var7.worldObj.difficultySetting, var7.worldObj.getWorldInfo().getTerrainType(), var7.worldObj.getHeight(), var7.theItemInWorldManager.getGameType()));
    365            var9 = var8.getSpawnPoint();
    366            var7.playerNetServerHandler.setPlayerLocation(var7.posX, var7.posY, var7.posZ, var7.rotationYaw, var7.rotationPitch);
    367            var7.playerNetServerHandler.sendPacketToPlayer(new Packet6SpawnPosition(var9.posX, var9.posY, var9.posZ));
    368            var7.playerNetServerHandler.sendPacketToPlayer(new Packet43Experience(var7.experience, var7.experienceTotal, var7.experienceLevel));
    369            this.updateTimeAndWeatherForPlayer(var7, var8);
    370            var8.getPlayerManager().addPlayer(var7);
    371            var8.spawnEntityInWorld(var7);
    372            this.playerEntityList.add(var7);
    373            var7.addSelfToInternalCraftingInventory();
    374            GameRegistry.onPlayerRespawn(var7);
    375            return var7;
    376        }
    377
    378        public void transferPlayerToDimension(EntityPlayerMP par1EntityPlayerMP, int par2)
    379        {
    380            transferPlayerToDimension(par1EntityPlayerMP, par2, new Teleporter());
    381        }
    382
    383        public void transferPlayerToDimension(EntityPlayerMP par1EntityPlayerMP, int par2, Teleporter teleporter)
    384        {
    385            int var3 = par1EntityPlayerMP.dimension;
    386            WorldServer var4 = this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension);
    387            par1EntityPlayerMP.dimension = par2;
    388            WorldServer var5 = this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension);
    389            par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet9Respawn(par1EntityPlayerMP.dimension, (byte)par1EntityPlayerMP.worldObj.difficultySetting, var5.getWorldInfo().getTerrainType(), var5.getHeight(), par1EntityPlayerMP.theItemInWorldManager.getGameType()));
    390            var4.removeEntity(par1EntityPlayerMP);
    391            par1EntityPlayerMP.isDead = false;
    392            this.func_82448_a(par1EntityPlayerMP, var3, var4, var5, teleporter);
    393            this.func_72375_a(par1EntityPlayerMP, var4);
    394            par1EntityPlayerMP.playerNetServerHandler.setPlayerLocation(par1EntityPlayerMP.posX, par1EntityPlayerMP.posY, par1EntityPlayerMP.posZ, par1EntityPlayerMP.rotationYaw, par1EntityPlayerMP.rotationPitch);
    395            par1EntityPlayerMP.theItemInWorldManager.setWorld(var5);
    396            this.updateTimeAndWeatherForPlayer(par1EntityPlayerMP, var5);
    397            this.syncPlayerInventory(par1EntityPlayerMP);
    398            Iterator var6 = par1EntityPlayerMP.getActivePotionEffects().iterator();
    399
    400            while (var6.hasNext())
    401            {
    402                PotionEffect var7 = (PotionEffect)var6.next();
    403                par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet41EntityEffect(par1EntityPlayerMP.entityId, var7));
    404            }
    405            GameRegistry.onPlayerChangedDimension(par1EntityPlayerMP);
    406        }
    407
    408        public void func_82448_a(Entity par1Entity, int par2, WorldServer par3WorldServer, WorldServer par4WorldServer)
    409        {
    410            func_82448_a(par1Entity, par2, par3WorldServer, par4WorldServer, new Teleporter());
    411        }
    412
    413        public void func_82448_a(Entity par1Entity, int par2, WorldServer par3WorldServer, WorldServer par4WorldServer, Teleporter teleporter)
    414        {
    415            WorldProvider pOld = par3WorldServer.provider;
    416            WorldProvider pNew = par4WorldServer.provider;
    417            double moveFactor = pOld.getMovementFactor() / pNew.getMovementFactor();
    418            double var5 = par1Entity.posX * moveFactor;
    419            double var7 = par1Entity.posZ * moveFactor;
    420            double var11 = par1Entity.posX;
    421            double var13 = par1Entity.posY;
    422            double var15 = par1Entity.posZ;
    423            float var17 = par1Entity.rotationYaw;
    424
    425            if (par1Entity.dimension == 1)
    426            {
    427                ChunkCoordinates var18;
    428
    429                if (par2 == 1)
    430                {
    431                    var18 = par4WorldServer.getSpawnPoint();
    432                }
    433                else
    434                {
    435                    var18 = par4WorldServer.getEntrancePortalLocation();
    436                }
    437
    438                var5 = (double)var18.posX;
    439                par1Entity.posY = (double)var18.posY;
    440                var7 = (double)var18.posZ;
    441                par1Entity.setLocationAndAngles(var5, par1Entity.posY, var7, 90.0F, 0.0F);
    442
    443                if (par1Entity.isEntityAlive())
    444                {
    445                    par3WorldServer.updateEntityWithOptionalForce(par1Entity, false);
    446                }
    447            }
    448
    449            if (par2 != 1)
    450            {
    451                var5 = (double)MathHelper.clamp_int((int)var5, -29999872, 29999872);
    452                var7 = (double)MathHelper.clamp_int((int)var7, -29999872, 29999872);
    453
    454                if (par1Entity.isEntityAlive())
    455                {
    456                    par4WorldServer.spawnEntityInWorld(par1Entity);
    457                    par1Entity.setLocationAndAngles(var5, par1Entity.posY, var7, par1Entity.rotationYaw, par1Entity.rotationPitch);
    458                    par4WorldServer.updateEntityWithOptionalForce(par1Entity, false);
    459                    teleporter.placeInPortal(par4WorldServer, par1Entity, var11, var13, var15, var17);
    460                }
    461            }
    462
    463            par1Entity.setWorld(par4WorldServer);
    464        }
    465
    466        /**
    467         * sends 1 player per tick, but only sends a player once every 600 ticks
    468         */
    469        public void sendPlayerInfoToAllPlayers()
    470        {
    471            if (++this.playerPingIndex > 600)
    472            {
    473                this.playerPingIndex = 0;
    474            }
    475
    476            if (this.playerPingIndex < this.playerEntityList.size())
    477            {
    478                EntityPlayerMP var1 = (EntityPlayerMP)this.playerEntityList.get(this.playerPingIndex);
    479                this.sendPacketToAllPlayers(new Packet201PlayerInfo(var1.username, true, var1.ping));
    480            }
    481        }
    482
    483        /**
    484         * sends a packet to all players
    485         */
    486        public void sendPacketToAllPlayers(Packet par1Packet)
    487        {
    488            for (int var2 = 0; var2 < this.playerEntityList.size(); ++var2)
    489            {
    490                ((EntityPlayerMP)this.playerEntityList.get(var2)).playerNetServerHandler.sendPacketToPlayer(par1Packet);
    491            }
    492        }
    493
    494        /**
    495         * Sends a packet to all players in the specified Dimension
    496         */
    497        public void sendPacketToAllPlayersInDimension(Packet par1Packet, int par2)
    498        {
    499            Iterator var3 = this.playerEntityList.iterator();
    500
    501            while (var3.hasNext())
    502            {
    503                EntityPlayerMP var4 = (EntityPlayerMP)var3.next();
    504
    505                if (var4.dimension == par2)
    506                {
    507                    var4.playerNetServerHandler.sendPacketToPlayer(par1Packet);
    508                }
    509            }
    510        }
    511
    512        /**
    513         * returns a string containing a comma-seperated list of player names
    514         */
    515        public String getPlayerListAsString()
    516        {
    517            String var1 = "";
    518
    519            for (int var2 = 0; var2 < this.playerEntityList.size(); ++var2)
    520            {
    521                if (var2 > 0)
    522                {
    523                    var1 = var1 + ", ";
    524                }
    525
    526                var1 = var1 + ((EntityPlayerMP)this.playerEntityList.get(var2)).username;
    527            }
    528
    529            return var1;
    530        }
    531
    532        /**
    533         * Returns an array of the usernames of all the connected players.
    534         */
    535        public String[] getAllUsernames()
    536        {
    537            String[] var1 = new String[this.playerEntityList.size()];
    538
    539            for (int var2 = 0; var2 < this.playerEntityList.size(); ++var2)
    540            {
    541                var1[var2] = ((EntityPlayerMP)this.playerEntityList.get(var2)).username;
    542            }
    543
    544            return var1;
    545        }
    546
    547        public BanList getBannedPlayers()
    548        {
    549            return this.bannedPlayers;
    550        }
    551
    552        public BanList getBannedIPs()
    553        {
    554            return this.bannedIPs;
    555        }
    556
    557        /**
    558         * This adds a username to the ops list, then saves the op list
    559         */
    560        public void addOp(String par1Str)
    561        {
    562            this.ops.add(par1Str.toLowerCase());
    563        }
    564
    565        /**
    566         * This removes a username from the ops list, then saves the op list
    567         */
    568        public void removeOp(String par1Str)
    569        {
    570            this.ops.remove(par1Str.toLowerCase());
    571        }
    572
    573        /**
    574         * Determine if the player is allowed to connect based on current server settings.
    575         */
    576        public boolean isAllowedToLogin(String par1Str)
    577        {
    578            par1Str = par1Str.trim().toLowerCase();
    579            return !this.whiteListEnforced || this.ops.contains(par1Str) || this.whiteListedPlayers.contains(par1Str);
    580        }
    581
    582        /**
    583         * Returns true if the specific player is allowed to use commands.
    584         */
    585        public boolean areCommandsAllowed(String par1Str)
    586        {
    587            return this.ops.contains(par1Str.trim().toLowerCase()) || this.mcServer.isSinglePlayer() && this.mcServer.worldServers[0].getWorldInfo().areCommandsAllowed() && this.mcServer.getServerOwner().equalsIgnoreCase(par1Str) || this.commandsAllowedForAll;
    588        }
    589
    590        public EntityPlayerMP getPlayerForUsername(String par1Str)
    591        {
    592            Iterator var2 = this.playerEntityList.iterator();
    593            EntityPlayerMP var3;
    594
    595            do
    596            {
    597                if (!var2.hasNext())
    598                {
    599                    return null;
    600                }
    601
    602                var3 = (EntityPlayerMP)var2.next();
    603            }
    604            while (!var3.username.equalsIgnoreCase(par1Str));
    605
    606            return var3;
    607        }
    608
    609        public List func_82449_a(ChunkCoordinates par1ChunkCoordinates, int par2, int par3, int par4, int par5, int par6, int par7)
    610        {
    611            if (this.playerEntityList.isEmpty())
    612            {
    613                return null;
    614            }
    615            else
    616            {
    617                Object var8 = new ArrayList();
    618                boolean var9 = par4 < 0;
    619                int var10 = par2 * par2;
    620                int var11 = par3 * par3;
    621                par4 = MathHelper.abs_int(par4);
    622
    623                for (int var12 = 0; var12 < this.playerEntityList.size(); ++var12)
    624                {
    625                    EntityPlayerMP var13 = (EntityPlayerMP)this.playerEntityList.get(var12);
    626
    627                    if (par1ChunkCoordinates != null && (par2 > 0 || par3 > 0))
    628                    {
    629                        float var14 = par1ChunkCoordinates.func_82371_e(var13.func_82114_b());
    630
    631                        if (par2 > 0 && var14 < (float)var10 || par3 > 0 && var14 > (float)var11)
    632                        {
    633                            continue;
    634                        }
    635                    }
    636
    637                    if ((par5 == EnumGameType.NOT_SET.getID() || par5 == var13.theItemInWorldManager.getGameType().getID()) && (par6 <= 0 || var13.experienceLevel >= par6) && var13.experienceLevel <= par7)
    638                    {
    639                        ((List)var8).add(var13);
    640                    }
    641                }
    642
    643                if (par1ChunkCoordinates != null)
    644                {
    645                    Collections.sort((List)var8, new PlayerPositionComparator(par1ChunkCoordinates));
    646                }
    647
    648                if (var9)
    649                {
    650                    Collections.reverse((List)var8);
    651                }
    652
    653                if (par4 > 0)
    654                {
    655                    var8 = ((List)var8).subList(0, Math.min(par4, ((List)var8).size()));
    656                }
    657
    658                return (List)var8;
    659            }
    660        }
    661
    662        /**
    663         * params: x,y,z,d,dimension. The packet is sent to all players within d distance of x,y,z (d^2<x^2+y^2+z^2)
    664         */
    665        public void sendToAllNear(double par1, double par3, double par5, double par7, int par9, Packet par10Packet)
    666        {
    667            this.sendToAllNearExcept((EntityPlayer)null, par1, par3, par5, par7, par9, par10Packet);
    668        }
    669
    670        /**
    671         * params: srcPlayer,x,y,z,d,dimension. The packet is not sent to the srcPlayer, but all other players where
    672         * dx*dx+dy*dy+dz*dz<d*d
    673         */
    674        public void sendToAllNearExcept(EntityPlayer par1EntityPlayer, double par2, double par4, double par6, double par8, int par10, Packet par11Packet)
    675        {
    676            Iterator var12 = this.playerEntityList.iterator();
    677
    678            while (var12.hasNext())
    679            {
    680                EntityPlayerMP var13 = (EntityPlayerMP)var12.next();
    681
    682                if (var13 != par1EntityPlayer && var13.dimension == par10)
    683                {
    684                    double var14 = par2 - var13.posX;
    685                    double var16 = par4 - var13.posY;
    686                    double var18 = par6 - var13.posZ;
    687
    688                    if (var14 * var14 + var16 * var16 + var18 * var18 < par8 * par8)
    689                    {
    690                        var13.playerNetServerHandler.sendPacketToPlayer(par11Packet);
    691                    }
    692                }
    693            }
    694        }
    695
    696        /**
    697         * Saves all of the players' current states.
    698         */
    699        public void saveAllPlayerData()
    700        {
    701            Iterator var1 = this.playerEntityList.iterator();
    702
    703            while (var1.hasNext())
    704            {
    705                EntityPlayerMP var2 = (EntityPlayerMP)var1.next();
    706                this.writePlayerData(var2);
    707            }
    708        }
    709
    710        /**
    711         * Add the specified player to the white list.
    712         */
    713        public void addToWhiteList(String par1Str)
    714        {
    715            this.whiteListedPlayers.add(par1Str);
    716        }
    717
    718        /**
    719         * Remove the specified player from the whitelist.
    720         */
    721        public void removeFromWhitelist(String par1Str)
    722        {
    723            this.whiteListedPlayers.remove(par1Str);
    724        }
    725
    726        /**
    727         * Returns the whitelisted players.
    728         */
    729        public Set getWhiteListedPlayers()
    730        {
    731            return this.whiteListedPlayers;
    732        }
    733
    734        public Set getOps()
    735        {
    736            return this.ops;
    737        }
    738
    739        /**
    740         * Either does nothing, or calls readWhiteList.
    741         */
    742        public void loadWhiteList() {}
    743
    744        /**
    745         * Updates the time and weather for the given player to those of the given world
    746         */
    747        public void updateTimeAndWeatherForPlayer(EntityPlayerMP par1EntityPlayerMP, WorldServer par2WorldServer)
    748        {
    749            par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet4UpdateTime(par2WorldServer.func_82737_E(), par2WorldServer.getWorldTime()));
    750
    751            if (par2WorldServer.isRaining())
    752            {
    753                par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet70GameEvent(1, 0));
    754            }
    755        }
    756
    757        /**
    758         * sends the players inventory to himself
    759         */
    760        public void syncPlayerInventory(EntityPlayerMP par1EntityPlayerMP)
    761        {
    762            par1EntityPlayerMP.sendContainerToPlayer(par1EntityPlayerMP.inventorySlots);
    763            par1EntityPlayerMP.setPlayerHealthUpdated();
    764        }
    765
    766        /**
    767         * Returns the number of players currently on the server.
    768         */
    769        public int getCurrentPlayerCount()
    770        {
    771            return this.playerEntityList.size();
    772        }
    773
    774        /**
    775         * Returns the maximum number of players allowed on the server.
    776         */
    777        public int getMaxPlayers()
    778        {
    779            return this.maxPlayers;
    780        }
    781
    782        /**
    783         * Returns an array of usernames for which player.dat exists for.
    784         */
    785        public String[] getAvailablePlayerDat()
    786        {
    787            return this.mcServer.worldServers[0].getSaveHandler().getSaveHandler().getAvailablePlayerDat();
    788        }
    789
    790        public boolean isWhiteListEnabled()
    791        {
    792            return this.whiteListEnforced;
    793        }
    794
    795        public void setWhiteListEnabled(boolean par1)
    796        {
    797            this.whiteListEnforced = par1;
    798        }
    799
    800        public List getPlayerList(String par1Str)
    801        {
    802            ArrayList var2 = new ArrayList();
    803            Iterator var3 = this.playerEntityList.iterator();
    804
    805            while (var3.hasNext())
    806            {
    807                EntityPlayerMP var4 = (EntityPlayerMP)var3.next();
    808
    809                if (var4.func_71114_r().equals(par1Str))
    810                {
    811                    var2.add(var4);
    812                }
    813            }
    814
    815            return var2;
    816        }
    817
    818        /**
    819         * Gets the View Distance.
    820         */
    821        public int getViewDistance()
    822        {
    823            return this.viewDistance;
    824        }
    825
    826        public MinecraftServer getServerInstance()
    827        {
    828            return this.mcServer;
    829        }
    830
    831        /**
    832         * gets the tags created in the last writePlayerData call
    833         */
    834        public NBTTagCompound getTagsFromLastWrite()
    835        {
    836            return null;
    837        }
    838
    839        @SideOnly(Side.CLIENT)
    840        public void setGameType(EnumGameType par1EnumGameType)
    841        {
    842            this.gameType = par1EnumGameType;
    843        }
    844
    845        private void func_72381_a(EntityPlayerMP par1EntityPlayerMP, EntityPlayerMP par2EntityPlayerMP, World par3World)
    846        {
    847            if (par2EntityPlayerMP != null)
    848            {
    849                par1EntityPlayerMP.theItemInWorldManager.setGameType(par2EntityPlayerMP.theItemInWorldManager.getGameType());
    850            }
    851            else if (this.gameType != null)
    852            {
    853                par1EntityPlayerMP.theItemInWorldManager.setGameType(this.gameType);
    854            }
    855
    856            par1EntityPlayerMP.theItemInWorldManager.initializeGameType(par3World.getWorldInfo().getGameType());
    857        }
    858
    859        @SideOnly(Side.CLIENT)
    860
    861        /**
    862         * Sets whether all players are allowed to use commands (cheats) on the server.
    863         */
    864        public void setCommandsAllowedForAll(boolean par1)
    865        {
    866            this.commandsAllowedForAll = par1;
    867        }
    868
    869        /**
    870         * Kicks everyone with "Server closed" as reason.
    871         */
    872        public void removeAllPlayers()
    873        {
    874            while (!this.playerEntityList.isEmpty())
    875            {
    876                ((EntityPlayerMP)this.playerEntityList.get(0)).playerNetServerHandler.kickPlayerFromServer("Server closed");
    877            }
    878        }
    879    }