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