    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
    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.transferEntityToWorld(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        /**
    409         * Transfers an entity from a world to another world.
    410         */
    411        public void transferEntityToWorld(Entity par1Entity, int par2, WorldServer par3WorldServer, WorldServer par4WorldServer)
    412        {
    413            transferEntityToWorld(par1Entity, par2, par3WorldServer, par4WorldServer, new Teleporter());
    414        }
    415
    416        public void transferEntityToWorld(Entity par1Entity, int par2, WorldServer par3WorldServer, WorldServer par4WorldServer, Teleporter teleporter)
    417        {
    418            WorldProvider pOld = par3WorldServer.provider;
    419            WorldProvider pNew = par4WorldServer.provider;
    420            double moveFactor = pOld.getMovementFactor() / pNew.getMovementFactor();
    421            double var5 = par1Entity.posX * moveFactor;
    422            double var7 = par1Entity.posZ * moveFactor;
    423            double var11 = par1Entity.posX;
    424            double var13 = par1Entity.posY;
    425            double var15 = par1Entity.posZ;
    426            float var17 = par1Entity.rotationYaw;
    427
    428            if (par1Entity.dimension == 1)
    429            {
    430                ChunkCoordinates var18;
    431
    432                if (par2 == 1)
    433                {
    434                    var18 = par4WorldServer.getSpawnPoint();
    435                }
    436                else
    437                {
    438                    var18 = par4WorldServer.getEntrancePortalLocation();
    439                }
    440
    441                var5 = (double)var18.posX;
    442                par1Entity.posY = (double)var18.posY;
    443                var7 = (double)var18.posZ;
    444                par1Entity.setLocationAndAngles(var5, par1Entity.posY, var7, 90.0F, 0.0F);
    445
    446                if (par1Entity.isEntityAlive())
    447                {
    448                    par3WorldServer.updateEntityWithOptionalForce(par1Entity, false);
    449                }
    450            }
    451
    452            if (par2 != 1)
    453            {
    454                var5 = (double)MathHelper.clamp_int((int)var5, -29999872, 29999872);
    455                var7 = (double)MathHelper.clamp_int((int)var7, -29999872, 29999872);
    456
    457                if (par1Entity.isEntityAlive())
    458                {
    459                    par4WorldServer.spawnEntityInWorld(par1Entity);
    460                    par1Entity.setLocationAndAngles(var5, par1Entity.posY, var7, par1Entity.rotationYaw, par1Entity.rotationPitch);
    461                    par4WorldServer.updateEntityWithOptionalForce(par1Entity, false);
    462                    teleporter.placeInPortal(par4WorldServer, par1Entity, var11, var13, var15, var17);
    463                }
    464            }
    465
    466            par1Entity.setWorld(par4WorldServer);
    467        }
    468
    469        /**
    470         * sends 1 player per tick, but only sends a player once every 600 ticks
    471         */
    472        public void sendPlayerInfoToAllPlayers()
    473        {
    474            if (++this.playerPingIndex > 600)
    475            {
    476                this.playerPingIndex = 0;
    477            }
    478
    479            if (this.playerPingIndex < this.playerEntityList.size())
    480            {
    481                EntityPlayerMP var1 = (EntityPlayerMP)this.playerEntityList.get(this.playerPingIndex);
    482                this.sendPacketToAllPlayers(new Packet201PlayerInfo(var1.username, true, var1.ping));
    483            }
    484        }
    485
    486        /**
    487         * sends a packet to all players
    488         */
    489        public void sendPacketToAllPlayers(Packet par1Packet)
    490        {
    491            for (int var2 = 0; var2 < this.playerEntityList.size(); ++var2)
    492            {
    493                ((EntityPlayerMP)this.playerEntityList.get(var2)).playerNetServerHandler.sendPacketToPlayer(par1Packet);
    494            }
    495        }
    496
    497        /**
    498         * Sends a packet to all players in the specified Dimension
    499         */
    500        public void sendPacketToAllPlayersInDimension(Packet par1Packet, int par2)
    501        {
    502            Iterator var3 = this.playerEntityList.iterator();
    503
    504            while (var3.hasNext())
    505            {
    506                EntityPlayerMP var4 = (EntityPlayerMP)var3.next();
    507
    508                if (var4.dimension == par2)
    509                {
    510                    var4.playerNetServerHandler.sendPacketToPlayer(par1Packet);
    511                }
    512            }
    513        }
    514
    515        /**
    516         * returns a string containing a comma-seperated list of player names
    517         */
    518        public String getPlayerListAsString()
    519        {
    520            String var1 = "";
    521
    522            for (int var2 = 0; var2 < this.playerEntityList.size(); ++var2)
    523            {
    524                if (var2 > 0)
    525                {
    526                    var1 = var1 + ", ";
    527                }
    528
    529                var1 = var1 + ((EntityPlayerMP)this.playerEntityList.get(var2)).username;
    530            }
    531
    532            return var1;
    533        }
    534
    535        /**
    536         * Returns an array of the usernames of all the connected players.
    537         */
    538        public String[] getAllUsernames()
    539        {
    540            String[] var1 = new String[this.playerEntityList.size()];
    541
    542            for (int var2 = 0; var2 < this.playerEntityList.size(); ++var2)
    543            {
    544                var1[var2] = ((EntityPlayerMP)this.playerEntityList.get(var2)).username;
    545            }
    546
    547            return var1;
    548        }
    549
    550        public BanList getBannedPlayers()
    551        {
    552            return this.bannedPlayers;
    553        }
    554
    555        public BanList getBannedIPs()
    556        {
    557            return this.bannedIPs;
    558        }
    559
    560        /**
    561         * This adds a username to the ops list, then saves the op list
    562         */
    563        public void addOp(String par1Str)
    564        {
    565            this.ops.add(par1Str.toLowerCase());
    566        }
    567
    568        /**
    569         * This removes a username from the ops list, then saves the op list
    570         */
    571        public void removeOp(String par1Str)
    572        {
    573            this.ops.remove(par1Str.toLowerCase());
    574        }
    575
    576        /**
    577         * Determine if the player is allowed to connect based on current server settings.
    578         */
    579        public boolean isAllowedToLogin(String par1Str)
    580        {
    581            par1Str = par1Str.trim().toLowerCase();
    582            return !this.whiteListEnforced || this.ops.contains(par1Str) || this.whiteListedPlayers.contains(par1Str);
    583        }
    584
    585        /**
    586         * Returns true if the specific player is allowed to use commands.
    587         */
    588        public boolean areCommandsAllowed(String par1Str)
    589        {
    590            return this.ops.contains(par1Str.trim().toLowerCase()) || this.mcServer.isSinglePlayer() && this.mcServer.worldServers[0].getWorldInfo().areCommandsAllowed() && this.mcServer.getServerOwner().equalsIgnoreCase(par1Str) || this.commandsAllowedForAll;
    591        }
    592
    593        public EntityPlayerMP getPlayerForUsername(String par1Str)
    594        {
    595            Iterator var2 = this.playerEntityList.iterator();
    596            EntityPlayerMP var3;
    597
    598            do
    599            {
    600                if (!var2.hasNext())
    601                {
    602                    return null;
    603                }
    604
    605                var3 = (EntityPlayerMP)var2.next();
    606            }
    607            while (!var3.username.equalsIgnoreCase(par1Str));
    608
    609            return var3;
    610        }
    611
    612        /**
    613         * Find all players in a specified range and narrowing down by other parameters
    614         */
    615        public List findPlayers(ChunkCoordinates par1ChunkCoordinates, int par2, int par3, int par4, int par5, int par6, int par7)
    616        {
    617            if (this.playerEntityList.isEmpty())
    618            {
    619                return null;
    620            }
    621            else
    622            {
    623                Object var8 = new ArrayList();
    624                boolean var9 = par4 < 0;
    625                int var10 = par2 * par2;
    626                int var11 = par3 * par3;
    627                par4 = MathHelper.abs_int(par4);
    628
    629                for (int var12 = 0; var12 < this.playerEntityList.size(); ++var12)
    630                {
    631                    EntityPlayerMP var13 = (EntityPlayerMP)this.playerEntityList.get(var12);
    632
    633                    if (par1ChunkCoordinates != null && (par2 > 0 || par3 > 0))
    634                    {
    635                        float var14 = par1ChunkCoordinates.getDistanceSquaredToChunkCoordinates(var13.getPlayerCoordinates());
    636
    637                        if (par2 > 0 && var14 < (float)var10 || par3 > 0 && var14 > (float)var11)
    638                        {
    639                            continue;
    640                        }
    641                    }
    642
    643                    if ((par5 == EnumGameType.NOT_SET.getID() || par5 == var13.theItemInWorldManager.getGameType().getID()) && (par6 <= 0 || var13.experienceLevel >= par6) && var13.experienceLevel <= par7)
    644                    {
    645                        ((List)var8).add(var13);
    646                    }
    647                }
    648
    649                if (par1ChunkCoordinates != null)
    650                {
    651                    Collections.sort((List)var8, new PlayerPositionComparator(par1ChunkCoordinates));
    652                }
    653
    654                if (var9)
    655                {
    656                    Collections.reverse((List)var8);
    657                }
    658
    659                if (par4 > 0)
    660                {
    661                    var8 = ((List)var8).subList(0, Math.min(par4, ((List)var8).size()));
    662                }
    663
    664                return (List)var8;
    665            }
    666        }
    667
    668        /**
    669         * 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)
    670         */
    671        public void sendToAllNear(double par1, double par3, double par5, double par7, int par9, Packet par10Packet)
    672        {
    673            this.sendToAllNearExcept((EntityPlayer)null, par1, par3, par5, par7, par9, par10Packet);
    674        }
    675
    676        /**
    677         * params: srcPlayer,x,y,z,d,dimension. The packet is not sent to the srcPlayer, but all other players where
    678         * dx*dx+dy*dy+dz*dz<d*d
    679         */
    680        public void sendToAllNearExcept(EntityPlayer par1EntityPlayer, double par2, double par4, double par6, double par8, int par10, Packet par11Packet)
    681        {
    682            Iterator var12 = this.playerEntityList.iterator();
    683
    684            while (var12.hasNext())
    685            {
    686                EntityPlayerMP var13 = (EntityPlayerMP)var12.next();
    687
    688                if (var13 != par1EntityPlayer && var13.dimension == par10)
    689                {
    690                    double var14 = par2 - var13.posX;
    691                    double var16 = par4 - var13.posY;
    692                    double var18 = par6 - var13.posZ;
    693
    694                    if (var14 * var14 + var16 * var16 + var18 * var18 < par8 * par8)
    695                    {
    696                        var13.playerNetServerHandler.sendPacketToPlayer(par11Packet);
    697                    }
    698                }
    699            }
    700        }
    701
    702        /**
    703         * Saves all of the players' current states.
    704         */
    705        public void saveAllPlayerData()
    706        {
    707            Iterator var1 = this.playerEntityList.iterator();
    708
    709            while (var1.hasNext())
    710            {
    711                EntityPlayerMP var2 = (EntityPlayerMP)var1.next();
    712                this.writePlayerData(var2);
    713            }
    714        }
    715
    716        /**
    717         * Add the specified player to the white list.
    718         */
    719        public void addToWhiteList(String par1Str)
    720        {
    721            this.whiteListedPlayers.add(par1Str);
    722        }
    723
    724        /**
    725         * Remove the specified player from the whitelist.
    726         */
    727        public void removeFromWhitelist(String par1Str)
    728        {
    729            this.whiteListedPlayers.remove(par1Str);
    730        }
    731
    732        /**
    733         * Returns the whitelisted players.
    734         */
    735        public Set getWhiteListedPlayers()
    736        {
    737            return this.whiteListedPlayers;
    738        }
    739
    740        public Set getOps()
    741        {
    742            return this.ops;
    743        }
    744
    745        /**
    746         * Either does nothing, or calls readWhiteList.
    747         */
    748        public void loadWhiteList() {}
    749
    750        /**
    751         * Updates the time and weather for the given player to those of the given world
    752         */
    753        public void updateTimeAndWeatherForPlayer(EntityPlayerMP par1EntityPlayerMP, WorldServer par2WorldServer)
    754        {
    755            par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet4UpdateTime(par2WorldServer.getTotalWorldTime(), par2WorldServer.getWorldTime()));
    756
    757            if (par2WorldServer.isRaining())
    758            {
    759                par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(new Packet70GameEvent(1, 0));
    760            }
    761        }
    762
    763        /**
    764         * sends the players inventory to himself
    765         */
    766        public void syncPlayerInventory(EntityPlayerMP par1EntityPlayerMP)
    767        {
    768            par1EntityPlayerMP.sendContainerToPlayer(par1EntityPlayerMP.inventorySlots);
    769            par1EntityPlayerMP.setPlayerHealthUpdated();
    770        }
    771
    772        /**
    773         * Returns the number of players currently on the server.
    774         */
    775        public int getCurrentPlayerCount()
    776        {
    777            return this.playerEntityList.size();
    778        }
    779
    780        /**
    781         * Returns the maximum number of players allowed on the server.
    782         */
    783        public int getMaxPlayers()
    784        {
    785            return this.maxPlayers;
    786        }
    787
    788        /**
    789         * Returns an array of usernames for which player.dat exists for.
    790         */
    791        public String[] getAvailablePlayerDat()
    792        {
    793            return this.mcServer.worldServers[0].getSaveHandler().getSaveHandler().getAvailablePlayerDat();
    794        }
    795
    796        public boolean isWhiteListEnabled()
    797        {
    798            return this.whiteListEnforced;
    799        }
    800
    801        public void setWhiteListEnabled(boolean par1)
    802        {
    803            this.whiteListEnforced = par1;
    804        }
    805
    806        public List getPlayerList(String par1Str)
    807        {
    808            ArrayList var2 = new ArrayList();
    809            Iterator var3 = this.playerEntityList.iterator();
    810
    811            while (var3.hasNext())
    812            {
    813                EntityPlayerMP var4 = (EntityPlayerMP)var3.next();
    814
    815                if (var4.func_71114_r().equals(par1Str))
    816                {
    817                    var2.add(var4);
    818                }
    819            }
    820
    821            return var2;
    822        }
    823
    824        /**
    825         * Gets the View Distance.
    826         */
    827        public int getViewDistance()
    828        {
    829            return this.viewDistance;
    830        }
    831
    832        public MinecraftServer getServerInstance()
    833        {
    834            return this.mcServer;
    835        }
    836
    837        /**
    838         * gets the tags created in the last writePlayerData call
    839         */
    840        public NBTTagCompound getTagsFromLastWrite()
    841        {
    842            return null;
    843        }
    844
    845        @SideOnly(Side.CLIENT)
    846        public void setGameType(EnumGameType par1EnumGameType)
    847        {
    848            this.gameType = par1EnumGameType;
    849        }
    850
    851        private void func_72381_a(EntityPlayerMP par1EntityPlayerMP, EntityPlayerMP par2EntityPlayerMP, World par3World)
    852        {
    853            if (par2EntityPlayerMP != null)
    854            {
    855                par1EntityPlayerMP.theItemInWorldManager.setGameType(par2EntityPlayerMP.theItemInWorldManager.getGameType());
    856            }
    857            else if (this.gameType != null)
    858            {
    859                par1EntityPlayerMP.theItemInWorldManager.setGameType(this.gameType);
    860            }
    861
    862            par1EntityPlayerMP.theItemInWorldManager.initializeGameType(par3World.getWorldInfo().getGameType());
    863        }
    864
    865        @SideOnly(Side.CLIENT)
    866
    867        /**
    868         * Sets whether all players are allowed to use commands (cheats) on the server.
    869         */
    870        public void setCommandsAllowedForAll(boolean par1)
    871        {
    872            this.commandsAllowedForAll = par1;
    873        }
    874
    875        /**
    876         * Kicks everyone with "Server closed" as reason.
    877         */
    878        public void removeAllPlayers()
    879        {
    880            while (!this.playerEntityList.isEmpty())
    881            {
    882                ((EntityPlayerMP)this.playerEntityList.get(0)).playerNetServerHandler.kickPlayerFromServer("Server closed");
    883            }
    884        }
    885    }