    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.getTotalWorldTime(), 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            var2.spawnEntityInWorld(par1EntityPlayerMP);
    176            this.func_72375_a(par1EntityPlayerMP, (WorldServer)null);
    177
    178            for (int var3 = 0; var3 < this.playerEntityList.size(); ++var3)
    179            {
    180                EntityPlayerMP var4 = (EntityPlayerMP)this.playerEntityList.get(var3);
    181                par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet201PlayerInfo(var4.username, true, var4.ping));
    182            }
    183        }
    184
    185        /**
    186         * using player's dimension, update their movement when in a vehicle (e.g. cart, boat)
    187         */
    188        public void serverUpdateMountedMovingPlayer(EntityPlayerMP par1EntityPlayerMP)
    189        {
    190            par1EntityPlayerMP.getServerForPlayer().getPlayerManager().updateMountedMovingPlayer(par1EntityPlayerMP);
    191        }
    192
    193        /**
    194         * Called when a player disconnects from the game. Writes player data to disk and removes them from the world.
    195         */
    196        public void playerLoggedOut(EntityPlayerMP par1EntityPlayerMP)
    197        {
    198            GameRegistry.onPlayerLogout(par1EntityPlayerMP);
    199            this.writePlayerData(par1EntityPlayerMP);
    200            WorldServer var2 = par1EntityPlayerMP.getServerForPlayer();
    201            var2.setEntityDead(par1EntityPlayerMP);
    202            var2.getPlayerManager().removePlayer(par1EntityPlayerMP);
    203            this.playerEntityList.remove(par1EntityPlayerMP);
    204            this.sendPacketToAllPlayers(new Packet201PlayerInfo(par1EntityPlayerMP.username, false, 9999));
    205        }
    206
    207        /**
    208         * checks ban-lists, then white-lists, then space for the server. Returns null on success, or an error message
    209         */
    210        public String allowUserToConnect(SocketAddress par1SocketAddress, String par2Str)
    211        {
    212            if (this.bannedPlayers.isBanned(par2Str))
    213            {
    214                BanEntry var6 = (BanEntry)this.bannedPlayers.getBannedList().get(par2Str);
    215                String var7 = "You are banned from this server!\nReason: " + var6.getBanReason();
    216
    217                if (var6.getBanEndDate() != null)
    218                {
    219                    var7 = var7 + "\nYour ban will be removed on " + dateFormat.format(var6.getBanEndDate());
    220                }
    221
    222                return var7;
    223            }
    224            else if (!this.isAllowedToLogin(par2Str))
    225            {
    226                return "You are not white-listed on this server!";
    227            }
    228            else
    229            {
    230                String var3 = par1SocketAddress.toString();
    231                var3 = var3.substring(var3.indexOf("/") + 1);
    232                var3 = var3.substring(0, var3.indexOf(":"));
    233
    234                if (this.bannedIPs.isBanned(var3))
    235                {
    236                    BanEntry var4 = (BanEntry)this.bannedIPs.getBannedList().get(var3);
    237                    String var5 = "Your IP address is banned from this server!\nReason: " + var4.getBanReason();
    238
    239                    if (var4.getBanEndDate() != null)
    240                    {
    241                        var5 = var5 + "\nYour ban will be removed on " + dateFormat.format(var4.getBanEndDate());
    242                    }
    243
    244                    return var5;
    245                }
    246                else
    247                {
    248                    return this.playerEntityList.size() >= this.maxPlayers ? "The server is full!" : null;
    249                }
    250            }
    251        }
    252
    253        /**
    254         * also checks for multiple logins
    255         */
    256        public EntityPlayerMP createPlayerForUser(String par1Str)
    257        {
    258            ArrayList var2 = new ArrayList();
    259            EntityPlayerMP var4;
    260
    261            for (int var3 = 0; var3 < this.playerEntityList.size(); ++var3)
    262            {
    263                var4 = (EntityPlayerMP)this.playerEntityList.get(var3);
    264
    265                if (var4.username.equalsIgnoreCase(par1Str))
    266                {
    267                    var2.add(var4);
    268                }
    269            }
    270
    271            Iterator var5 = var2.iterator();
    272
    273            while (var5.hasNext())
    274            {
    275                var4 = (EntityPlayerMP)var5.next();
    276                var4.playerNetServerHandler.kickPlayerFromServer("You logged in from another location");
    277            }
    278
    279            Object var6;
    280
    281            if (this.mcServer.isDemo())
    282            {
    283                var6 = new DemoWorldManager(this.mcServer.worldServerForDimension(0));
    284            }
    285            else
    286            {
    287                var6 = new ItemInWorldManager(this.mcServer.worldServerForDimension(0));
    288            }
    289
    290            return new EntityPlayerMP(this.mcServer, this.mcServer.worldServerForDimension(0), par1Str, (ItemInWorldManager)var6);
    291        }
    292
    293        /**
    294         * creates and returns a respawned player based on the provided PlayerEntity. Args are the PlayerEntityMP to
    295         * respawn, an INT for the dimension to respawn into (usually 0), and a boolean value that is true if the player
    296         * beat the game rather than dying
    297         */
    298        public EntityPlayerMP respawnPlayer(EntityPlayerMP par1EntityPlayerMP, int par2, boolean par3)
    299        {
    300            World world = mcServer.worldServerForDimension(par2);
    301            if (world == null || !world.provider.canRespawnHere())
    302            {
    303                par2 = 0;
    304            }
    305
    306            par1EntityPlayerMP.getServerForPlayer().getEntityTracker().removeAllTrackingPlayers(par1EntityPlayerMP);
    307            par1EntityPlayerMP.getServerForPlayer().getEntityTracker().removeEntityFromAllTrackingPlayers(par1EntityPlayerMP);
    308            par1EntityPlayerMP.getServerForPlayer().getPlayerManager().removePlayer(par1EntityPlayerMP);
    309            this.playerEntityList.remove(par1EntityPlayerMP);
    310            this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension).removeEntity(par1EntityPlayerMP);
    311            ChunkCoordinates var4 = par1EntityPlayerMP.getSpawnChunk();
    312            boolean var5 = par1EntityPlayerMP.func_82245_bX();
    313            par1EntityPlayerMP.dimension = par2;
    314            Object var6;
    315
    316            if (this.mcServer.isDemo())
    317            {
    318                var6 = new DemoWorldManager(this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension));
    319            }
    320            else
    321            {
    322                var6 = new ItemInWorldManager(this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension));
    323            }
    324
    325            EntityPlayerMP var7 = new EntityPlayerMP(this.mcServer, this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension), par1EntityPlayerMP.username, (ItemInWorldManager)var6);
    326            var7.playerNetServerHandler = par1EntityPlayerMP.playerNetServerHandler;
    327            var7.clonePlayer(par1EntityPlayerMP, par3);
    328            var7.dimension = par2;
    329            var7.entityId = par1EntityPlayerMP.entityId;
    330            WorldServer var8 = this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension);
    331            this.func_72381_a(var7, par1EntityPlayerMP, var8);
    332            ChunkCoordinates var9;
    333
    334            if (var4 != null)
    335            {
    336                var9 = EntityPlayer.verifyRespawnCoordinates(this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension), var4, var5);
    337
    338                if (var9 != null)
    339                {
    340                    var7.setLocationAndAngles((double)((float)var9.posX + 0.5F), (double)((float)var9.posY + 0.1F), (double)((float)var9.posZ + 0.5F), 0.0F, 0.0F);
    341                    var7.setSpawnChunk(var4, var5);
    342                }
    343                else
    344                {
    345                    var7.playerNetServerHandler.sendPacketToPlayer(new Packet70GameEvent(0, 0));
    346                }
    347            }
    348
    349            var8.theChunkProviderServer.loadChunk((int)var7.posX >> 4, (int)var7.posZ >> 4);
    350
    351            while (!var8.getCollidingBoundingBoxes(var7, var7.boundingBox).isEmpty())
    352            {
    353                var7.setPosition(var7.posX, var7.posY + 1.0D, var7.posZ);
    354            }
    355
    356            var7.playerNetServerHandler.sendPacketToPlayer(new Packet9Respawn(var7.dimension, (byte)var7.worldObj.difficultySetting, var7.worldObj.getWorldInfo().getTerrainType(), var7.worldObj.getHeight(), var7.theItemInWorldManager.getGameType()));
    357            var9 = var8.getSpawnPoint();
    358            var7.playerNetServerHandler.setPlayerLocation(var7.posX, var7.posY, var7.posZ, var7.rotationYaw, var7.rotationPitch);
    359            var7.playerNetServerHandler.sendPacketToPlayer(new Packet6SpawnPosition(var9.posX, var9.posY, var9.posZ));
    360            var7.playerNetServerHandler.sendPacketToPlayer(new Packet43Experience(var7.experience, var7.experienceTotal, var7.experienceLevel));
    361            this.updateTimeAndWeatherForPlayer(var7, var8);
    362            var8.getPlayerManager().addPlayer(var7);
    363            var8.spawnEntityInWorld(var7);
    364            this.playerEntityList.add(var7);
    365            var7.addSelfToInternalCraftingInventory();
    366            GameRegistry.onPlayerRespawn(var7);
    367            return var7;
    368        }
    369
    370        public void transferPlayerToDimension(EntityPlayerMP par1EntityPlayerMP, int par2)
    371        {
    372            transferPlayerToDimension(par1EntityPlayerMP, par2, mcServer.worldServerForDimension(par2).func_85176_s());
    373        }
    374
    375        public void transferPlayerToDimension(EntityPlayerMP par1EntityPlayerMP, int par2, Teleporter teleporter)
    376        {
    377            int var3 = par1EntityPlayerMP.dimension;
    378            WorldServer var4 = this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension);
    379            par1EntityPlayerMP.dimension = par2;
    380            WorldServer var5 = this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension);
    381
    382            par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet9Respawn(par1EntityPlayerMP.dimension, (byte)par1EntityPlayerMP.worldObj.difficultySetting, var5.getWorldInfo().getTerrainType(), var5.getHeight(), par1EntityPlayerMP.theItemInWorldManager.getGameType()));
    383            var4.removeEntity(par1EntityPlayerMP);
    384            par1EntityPlayerMP.isDead = false;
    385            this.transferEntityToWorld(par1EntityPlayerMP, var3, var4, var5, teleporter);
    386            this.func_72375_a(par1EntityPlayerMP, var4);
    387            par1EntityPlayerMP.playerNetServerHandler.setPlayerLocation(par1EntityPlayerMP.posX, par1EntityPlayerMP.posY, par1EntityPlayerMP.posZ, par1EntityPlayerMP.rotationYaw, par1EntityPlayerMP.rotationPitch);
    388            par1EntityPlayerMP.theItemInWorldManager.setWorld(var5);
    389            this.updateTimeAndWeatherForPlayer(par1EntityPlayerMP, var5);
    390            this.syncPlayerInventory(par1EntityPlayerMP);
    391            Iterator var6 = par1EntityPlayerMP.getActivePotionEffects().iterator();
    392
    393            while (var6.hasNext())
    394            {
    395                PotionEffect var7 = (PotionEffect)var6.next();
    396                par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet41EntityEffect(par1EntityPlayerMP.entityId, var7));
    397            }
    398            GameRegistry.onPlayerChangedDimension(par1EntityPlayerMP);
    399        }
    400
    401        /**
    402         * Transfers an entity from a world to another world.
    403         */
    404        public void transferEntityToWorld(Entity par1Entity, int par2, WorldServer par3WorldServer, WorldServer par4WorldServer)
    405        {
    406            transferEntityToWorld(par1Entity, par2, par3WorldServer, par4WorldServer, par4WorldServer.func_85176_s());
    407        }
    408
    409        public void transferEntityToWorld(Entity par1Entity, int par2, WorldServer par3WorldServer, WorldServer par4WorldServer, Teleporter teleporter)
    410        {
    411            WorldProvider pOld = par3WorldServer.provider;
    412            WorldProvider pNew = par4WorldServer.provider;
    413            double moveFactor = pOld.getMovementFactor() / pNew.getMovementFactor();
    414            double var5 = par1Entity.posX * moveFactor;
    415            double var7 = par1Entity.posZ * moveFactor;
    416            double var11 = par1Entity.posX;
    417            double var13 = par1Entity.posY;
    418            double var15 = par1Entity.posZ;
    419            float var17 = par1Entity.rotationYaw;
    420            par3WorldServer.theProfiler.startSection("moving");
    421
    422            if (par1Entity.dimension == 1)
    423            {
    424                ChunkCoordinates var18;
    425
    426                if (par2 == 1)
    427                {
    428                    var18 = par4WorldServer.getSpawnPoint();
    429                }
    430                else
    431                {
    432                    var18 = par4WorldServer.getEntrancePortalLocation();
    433                }
    434
    435                var5 = (double)var18.posX;
    436                par1Entity.posY = (double)var18.posY;
    437                var7 = (double)var18.posZ;
    438                par1Entity.setLocationAndAngles(var5, par1Entity.posY, var7, 90.0F, 0.0F);
    439
    440                if (par1Entity.isEntityAlive())
    441                {
    442                    par3WorldServer.updateEntityWithOptionalForce(par1Entity, false);
    443                }
    444            }
    445
    446            par3WorldServer.theProfiler.endSection();
    447
    448            if (par2 != 1)
    449            {
    450                par3WorldServer.theProfiler.startSection("placing");
    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(par1Entity, var11, var13, var15, var17);
    460                }
    461
    462                par3WorldServer.theProfiler.endSection();
    463            }
    464
    465            par1Entity.setWorld(par4WorldServer);
    466        }
    467
    468        /**
    469         * sends 1 player per tick, but only sends a player once every 600 ticks
    470         */
    471        public void sendPlayerInfoToAllPlayers()
    472        {
    473            if (++this.playerPingIndex > 600)
    474            {
    475                this.playerPingIndex = 0;
    476            }
    477
    478            if (this.playerPingIndex < this.playerEntityList.size())
    479            {
    480                EntityPlayerMP var1 = (EntityPlayerMP)this.playerEntityList.get(this.playerPingIndex);
    481                this.sendPacketToAllPlayers(new Packet201PlayerInfo(var1.username, true, var1.ping));
    482            }
    483        }
    484
    485        /**
    486         * sends a packet to all players
    487         */
    488        public void sendPacketToAllPlayers(Packet par1Packet)
    489        {
    490            for (int var2 = 0; var2 < this.playerEntityList.size(); ++var2)
    491            {
    492                ((EntityPlayerMP)this.playerEntityList.get(var2)).playerNetServerHandler.sendPacketToPlayer(par1Packet);
    493            }
    494        }
    495
    496        /**
    497         * Sends a packet to all players in the specified Dimension
    498         */
    499        public void sendPacketToAllPlayersInDimension(Packet par1Packet, int par2)
    500        {
    501            for (int var3 = 0; var3 < this.playerEntityList.size(); ++var3)
    502            {
    503                EntityPlayerMP var4 = (EntityPlayerMP)this.playerEntityList.get(var3);
    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        /**
    610         * Find all players in a specified range and narrowing down by other parameters
    611         */
    612        public List findPlayers(ChunkCoordinates par1ChunkCoordinates, int par2, int par3, int par4, int par5, int par6, int par7)
    613        {
    614            if (this.playerEntityList.isEmpty())
    615            {
    616                return null;
    617            }
    618            else
    619            {
    620                Object var8 = new ArrayList();
    621                boolean var9 = par4 < 0;
    622                int var10 = par2 * par2;
    623                int var11 = par3 * par3;
    624                par4 = MathHelper.abs_int(par4);
    625
    626                for (int var12 = 0; var12 < this.playerEntityList.size(); ++var12)
    627                {
    628                    EntityPlayerMP var13 = (EntityPlayerMP)this.playerEntityList.get(var12);
    629
    630                    if (par1ChunkCoordinates != null && (par2 > 0 || par3 > 0))
    631                    {
    632                        float var14 = par1ChunkCoordinates.getDistanceSquaredToChunkCoordinates(var13.getPlayerCoordinates());
    633
    634                        if (par2 > 0 && var14 < (float)var10 || par3 > 0 && var14 > (float)var11)
    635                        {
    636                            continue;
    637                        }
    638                    }
    639
    640                    if ((par5 == EnumGameType.NOT_SET.getID() || par5 == var13.theItemInWorldManager.getGameType().getID()) && (par6 <= 0 || var13.experienceLevel >= par6) && var13.experienceLevel <= par7)
    641                    {
    642                        ((List)var8).add(var13);
    643                    }
    644                }
    645
    646                if (par1ChunkCoordinates != null)
    647                {
    648                    Collections.sort((List)var8, new PlayerPositionComparator(par1ChunkCoordinates));
    649                }
    650
    651                if (var9)
    652                {
    653                    Collections.reverse((List)var8);
    654                }
    655
    656                if (par4 > 0)
    657                {
    658                    var8 = ((List)var8).subList(0, Math.min(par4, ((List)var8).size()));
    659                }
    660
    661                return (List)var8;
    662            }
    663        }
    664
    665        /**
    666         * 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)
    667         */
    668        public void sendToAllNear(double par1, double par3, double par5, double par7, int par9, Packet par10Packet)
    669        {
    670            this.sendToAllNearExcept((EntityPlayer)null, par1, par3, par5, par7, par9, par10Packet);
    671        }
    672
    673        /**
    674         * params: srcPlayer,x,y,z,d,dimension. The packet is not sent to the srcPlayer, but all other players where
    675         * dx*dx+dy*dy+dz*dz<d*d
    676         */
    677        public void sendToAllNearExcept(EntityPlayer par1EntityPlayer, double par2, double par4, double par6, double par8, int par10, Packet par11Packet)
    678        {
    679            for (int var12 = 0; var12 < this.playerEntityList.size(); ++var12)
    680            {
    681                EntityPlayerMP var13 = (EntityPlayerMP)this.playerEntityList.get(var12);
    682
    683                if (var13 != par1EntityPlayer && var13.dimension == par10)
    684                {
    685                    double var14 = par2 - var13.posX;
    686                    double var16 = par4 - var13.posY;
    687                    double var18 = par6 - var13.posZ;
    688
    689                    if (var14 * var14 + var16 * var16 + var18 * var18 < par8 * par8)
    690                    {
    691                        var13.playerNetServerHandler.sendPacketToPlayer(par11Packet);
    692                    }
    693                }
    694            }
    695        }
    696
    697        /**
    698         * Saves all of the players' current states.
    699         */
    700        public void saveAllPlayerData()
    701        {
    702            for (int var1 = 0; var1 < this.playerEntityList.size(); ++var1)
    703            {
    704                this.writePlayerData((EntityPlayerMP)this.playerEntityList.get(var1));
    705            }
    706        }
    707
    708        /**
    709         * Add the specified player to the white list.
    710         */
    711        public void addToWhiteList(String par1Str)
    712        {
    713            this.whiteListedPlayers.add(par1Str);
    714        }
    715
    716        /**
    717         * Remove the specified player from the whitelist.
    718         */
    719        public void removeFromWhitelist(String par1Str)
    720        {
    721            this.whiteListedPlayers.remove(par1Str);
    722        }
    723
    724        /**
    725         * Returns the whitelisted players.
    726         */
    727        public Set getWhiteListedPlayers()
    728        {
    729            return this.whiteListedPlayers;
    730        }
    731
    732        public Set getOps()
    733        {
    734            return this.ops;
    735        }
    736
    737        /**
    738         * Either does nothing, or calls readWhiteList.
    739         */
    740        public void loadWhiteList() {}
    741
    742        /**
    743         * Updates the time and weather for the given player to those of the given world
    744         */
    745        public void updateTimeAndWeatherForPlayer(EntityPlayerMP par1EntityPlayerMP, WorldServer par2WorldServer)
    746        {
    747            par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet4UpdateTime(par2WorldServer.getTotalWorldTime(), par2WorldServer.getWorldTime()));
    748
    749            if (par2WorldServer.isRaining())
    750            {
    751                par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet70GameEvent(1, 0));
    752            }
    753        }
    754
    755        /**
    756         * sends the players inventory to himself
    757         */
    758        public void syncPlayerInventory(EntityPlayerMP par1EntityPlayerMP)
    759        {
    760            par1EntityPlayerMP.sendContainerToPlayer(par1EntityPlayerMP.inventorySlots);
    761            par1EntityPlayerMP.setPlayerHealthUpdated();
    762        }
    763
    764        /**
    765         * Returns the number of players currently on the server.
    766         */
    767        public int getCurrentPlayerCount()
    768        {
    769            return this.playerEntityList.size();
    770        }
    771
    772        /**
    773         * Returns the maximum number of players allowed on the server.
    774         */
    775        public int getMaxPlayers()
    776        {
    777            return this.maxPlayers;
    778        }
    779
    780        /**
    781         * Returns an array of usernames for which player.dat exists for.
    782         */
    783        public String[] getAvailablePlayerDat()
    784        {
    785            return this.mcServer.worldServers[0].getSaveHandler().getSaveHandler().getAvailablePlayerDat();
    786        }
    787
    788        public boolean isWhiteListEnabled()
    789        {
    790            return this.whiteListEnforced;
    791        }
    792
    793        public void setWhiteListEnabled(boolean par1)
    794        {
    795            this.whiteListEnforced = par1;
    796        }
    797
    798        public List getPlayerList(String par1Str)
    799        {
    800            ArrayList var2 = new ArrayList();
    801            Iterator var3 = this.playerEntityList.iterator();
    802
    803            while (var3.hasNext())
    804            {
    805                EntityPlayerMP var4 = (EntityPlayerMP)var3.next();
    806
    807                if (var4.func_71114_r().equals(par1Str))
    808                {
    809                    var2.add(var4);
    810                }
    811            }
    812
    813            return var2;
    814        }
    815
    816        /**
    817         * Gets the View Distance.
    818         */
    819        public int getViewDistance()
    820        {
    821            return this.viewDistance;
    822        }
    823
    824        public MinecraftServer getServerInstance()
    825        {
    826            return this.mcServer;
    827        }
    828
    829        /**
    830         * gets the tags created in the last writePlayerData call
    831         */
    832        public NBTTagCompound getTagsFromLastWrite()
    833        {
    834            return null;
    835        }
    836
    837        @SideOnly(Side.CLIENT)
    838        public void setGameType(EnumGameType par1EnumGameType)
    839        {
    840            this.gameType = par1EnumGameType;
    841        }
    842
    843        private void func_72381_a(EntityPlayerMP par1EntityPlayerMP, EntityPlayerMP par2EntityPlayerMP, World par3World)
    844        {
    845            if (par2EntityPlayerMP != null)
    846            {
    847                par1EntityPlayerMP.theItemInWorldManager.setGameType(par2EntityPlayerMP.theItemInWorldManager.getGameType());
    848            }
    849            else if (this.gameType != null)
    850            {
    851                par1EntityPlayerMP.theItemInWorldManager.setGameType(this.gameType);
    852            }
    853
    854            par1EntityPlayerMP.theItemInWorldManager.initializeGameType(par3World.getWorldInfo().getGameType());
    855        }
    856
    857        @SideOnly(Side.CLIENT)
    858
    859        /**
    860         * Sets whether all players are allowed to use commands (cheats) on the server.
    861         */
    862        public void setCommandsAllowedForAll(boolean par1)
    863        {
    864            this.commandsAllowedForAll = par1;
    865        }
    866
    867        /**
    868         * Kicks everyone with "Server closed" as reason.
    869         */
    870        public void removeAllPlayers()
    871        {
    872            while (!this.playerEntityList.isEmpty())
    873            {
    874                ((EntityPlayerMP)this.playerEntityList.get(0)).playerNetServerHandler.kickPlayerFromServer("Server closed");
    875            }
    876        }
    877    }