You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			317 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Java
		
	
			
		
		
	
	
			317 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Java
		
	
package net.minecraft.server.integrated;
 | 
						|
 | 
						|
import cpw.mods.fml.common.FMLCommonHandler;
 | 
						|
import cpw.mods.fml.relauncher.Side;
 | 
						|
import cpw.mods.fml.relauncher.SideOnly;
 | 
						|
import java.io.File;
 | 
						|
import java.io.IOException;
 | 
						|
import java.net.InetAddress;
 | 
						|
import java.util.concurrent.Callable;
 | 
						|
import net.minecraft.client.ClientBrandRetriever;
 | 
						|
import net.minecraft.client.Minecraft;
 | 
						|
import net.minecraft.client.multiplayer.ThreadLanServerPing;
 | 
						|
import net.minecraft.crash.CrashReport;
 | 
						|
import net.minecraft.profiler.PlayerUsageSnooper;
 | 
						|
import net.minecraft.server.MinecraftServer;
 | 
						|
import net.minecraft.util.CryptManager;
 | 
						|
import net.minecraft.util.HttpUtil;
 | 
						|
import net.minecraft.world.EnumDifficulty;
 | 
						|
import net.minecraft.world.WorldManager;
 | 
						|
import net.minecraft.world.WorldServer;
 | 
						|
import net.minecraft.world.WorldServerMulti;
 | 
						|
import net.minecraft.world.WorldSettings;
 | 
						|
import net.minecraft.world.WorldType;
 | 
						|
import net.minecraft.world.demo.DemoWorldServer;
 | 
						|
import net.minecraft.world.storage.ISaveHandler;
 | 
						|
import net.minecraftforge.common.DimensionManager;
 | 
						|
import net.minecraftforge.common.MinecraftForge;
 | 
						|
import net.minecraftforge.event.world.WorldEvent;
 | 
						|
import org.apache.logging.log4j.LogManager;
 | 
						|
import org.apache.logging.log4j.Logger;
 | 
						|
 | 
						|
@SideOnly(Side.CLIENT)
 | 
						|
public class IntegratedServer extends MinecraftServer
 | 
						|
{
 | 
						|
    private static final Logger logger = LogManager.getLogger();
 | 
						|
    /** The Minecraft instance. */
 | 
						|
    private final Minecraft mc;
 | 
						|
    private final WorldSettings theWorldSettings;
 | 
						|
    private boolean isGamePaused;
 | 
						|
    private boolean isPublic;
 | 
						|
    private ThreadLanServerPing lanServerPing;
 | 
						|
    private static final String __OBFID = "CL_00001129";
 | 
						|
 | 
						|
    public IntegratedServer(Minecraft p_i1317_1_, String p_i1317_2_, String p_i1317_3_, WorldSettings p_i1317_4_)
 | 
						|
    {
 | 
						|
        super(new File(p_i1317_1_.mcDataDir, "saves"), p_i1317_1_.getProxy());
 | 
						|
        this.setServerOwner(p_i1317_1_.getSession().getUsername());
 | 
						|
        this.setFolderName(p_i1317_2_);
 | 
						|
        this.setWorldName(p_i1317_3_);
 | 
						|
        this.setDemo(p_i1317_1_.isDemo());
 | 
						|
        this.canCreateBonusChest(p_i1317_4_.isBonusChestEnabled());
 | 
						|
        this.setBuildLimit(256);
 | 
						|
        this.func_152361_a(new IntegratedPlayerList(this));
 | 
						|
        this.mc = p_i1317_1_;
 | 
						|
        this.theWorldSettings = p_i1317_4_;
 | 
						|
    }
 | 
						|
 | 
						|
    protected void loadAllWorlds(String p_71247_1_, String p_71247_2_, long p_71247_3_, WorldType p_71247_5_, String p_71247_6_)
 | 
						|
    {
 | 
						|
        this.convertMapIfNeeded(p_71247_1_);
 | 
						|
        ISaveHandler isavehandler = this.getActiveAnvilConverter().getSaveLoader(p_71247_1_, true);
 | 
						|
 | 
						|
        WorldServer overWorld = (isDemo() ? new DemoWorldServer(this, isavehandler, p_71247_2_, 0, theProfiler) : new WorldServer(this, isavehandler, p_71247_2_, 0, theWorldSettings, theProfiler));
 | 
						|
        for (int dim : DimensionManager.getStaticDimensionIDs())
 | 
						|
        {
 | 
						|
            WorldServer world = (dim == 0 ? overWorld : new WorldServerMulti(this, isavehandler, p_71247_2_, dim, theWorldSettings, overWorld, theProfiler));
 | 
						|
            world.addWorldAccess(new WorldManager(this, world));
 | 
						|
 | 
						|
            if (!this.isSinglePlayer())
 | 
						|
            {
 | 
						|
                world.getWorldInfo().setGameType(getGameType());
 | 
						|
            }
 | 
						|
 | 
						|
            MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(world));
 | 
						|
        }
 | 
						|
 | 
						|
        this.getConfigurationManager().setPlayerManager(new WorldServer[]{ overWorld });
 | 
						|
        this.func_147139_a(this.func_147135_j());
 | 
						|
        this.initialWorldChunkLoad();
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Initialises the server and starts it.
 | 
						|
     */
 | 
						|
    protected boolean startServer() throws IOException
 | 
						|
    {
 | 
						|
        logger.info("Starting integrated minecraft server version 1.7.10");
 | 
						|
        this.setOnlineMode(true);
 | 
						|
        this.setCanSpawnAnimals(true);
 | 
						|
        this.setCanSpawnNPCs(true);
 | 
						|
        this.setAllowPvp(true);
 | 
						|
        this.setAllowFlight(true);
 | 
						|
        logger.info("Generating keypair");
 | 
						|
        this.setKeyPair(CryptManager.createNewKeyPair());
 | 
						|
        if (!FMLCommonHandler.instance().handleServerAboutToStart(this)) { return false; }
 | 
						|
        this.loadAllWorlds(this.getFolderName(), this.getWorldName(), this.theWorldSettings.getSeed(), this.theWorldSettings.getTerrainType(), this.theWorldSettings.func_82749_j());
 | 
						|
        this.setMOTD(this.getServerOwner() + " - " + this.worldServers[0].getWorldInfo().getWorldName());
 | 
						|
        return FMLCommonHandler.instance().handleServerStarting(this);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Main function called by run() every loop.
 | 
						|
     */
 | 
						|
    public void tick()
 | 
						|
    {
 | 
						|
        boolean flag = this.isGamePaused;
 | 
						|
        this.isGamePaused = Minecraft.getMinecraft().getNetHandler() != null && Minecraft.getMinecraft().isGamePaused();
 | 
						|
 | 
						|
        if (!flag && this.isGamePaused)
 | 
						|
        {
 | 
						|
            logger.info("Saving and pausing game...");
 | 
						|
            this.getConfigurationManager().saveAllPlayerData();
 | 
						|
            this.saveAllWorlds(false);
 | 
						|
        }
 | 
						|
 | 
						|
        if (!this.isGamePaused)
 | 
						|
        {
 | 
						|
            super.tick();
 | 
						|
 | 
						|
            if (this.mc.gameSettings.renderDistanceChunks != this.getConfigurationManager().getViewDistance())
 | 
						|
            {
 | 
						|
                logger.info("Changing view distance to {}, from {}", new Object[] {Integer.valueOf(this.mc.gameSettings.renderDistanceChunks), Integer.valueOf(this.getConfigurationManager().getViewDistance())});
 | 
						|
                this.getConfigurationManager().func_152611_a(this.mc.gameSettings.renderDistanceChunks);
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public boolean canStructuresSpawn()
 | 
						|
    {
 | 
						|
        return false;
 | 
						|
    }
 | 
						|
 | 
						|
    public WorldSettings.GameType getGameType()
 | 
						|
    {
 | 
						|
        return this.theWorldSettings.getGameType();
 | 
						|
    }
 | 
						|
 | 
						|
    public EnumDifficulty func_147135_j()
 | 
						|
    {
 | 
						|
        return this.mc.gameSettings.difficulty;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Defaults to false.
 | 
						|
     */
 | 
						|
    public boolean isHardcore()
 | 
						|
    {
 | 
						|
        return this.theWorldSettings.getHardcoreEnabled();
 | 
						|
    }
 | 
						|
 | 
						|
    public boolean func_152363_m()
 | 
						|
    {
 | 
						|
        return false;
 | 
						|
    }
 | 
						|
 | 
						|
    protected File getDataDirectory()
 | 
						|
    {
 | 
						|
        return this.mc.mcDataDir;
 | 
						|
    }
 | 
						|
 | 
						|
    public boolean isDedicatedServer()
 | 
						|
    {
 | 
						|
        return false;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Called on exit from the main run() loop.
 | 
						|
     */
 | 
						|
    protected void finalTick(CrashReport report)
 | 
						|
    {
 | 
						|
        this.mc.crashed(report);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Adds the server info, including from theWorldServer, to the crash report.
 | 
						|
     */
 | 
						|
    public CrashReport addServerInfoToCrashReport(CrashReport report)
 | 
						|
    {
 | 
						|
        report = super.addServerInfoToCrashReport(report);
 | 
						|
        report.getCategory().addCrashSectionCallable("Type", new Callable()
 | 
						|
        {
 | 
						|
            private static final String __OBFID = "CL_00001130";
 | 
						|
            public String call()
 | 
						|
            {
 | 
						|
                return "Integrated Server (map_client.txt)";
 | 
						|
            }
 | 
						|
        });
 | 
						|
        report.getCategory().addCrashSectionCallable("Is Modded", new Callable()
 | 
						|
        {
 | 
						|
            private static final String __OBFID = "CL_00001131";
 | 
						|
            public String call()
 | 
						|
            {
 | 
						|
                String s = ClientBrandRetriever.getClientModName();
 | 
						|
 | 
						|
                if (!s.equals("vanilla"))
 | 
						|
                {
 | 
						|
                    return "Definitely; Client brand changed to \'" + s + "\'";
 | 
						|
                }
 | 
						|
                else
 | 
						|
                {
 | 
						|
                    s = IntegratedServer.this.getServerModName();
 | 
						|
                    return !s.equals("vanilla") ? "Definitely; Server brand changed to \'" + s + "\'" : (Minecraft.class.getSigners() == null ? "Very likely; Jar signature invalidated" : "Probably not. Jar signature remains and both client + server brands are untouched.");
 | 
						|
                }
 | 
						|
            }
 | 
						|
        });
 | 
						|
        return report;
 | 
						|
    }
 | 
						|
 | 
						|
    public void addServerStatsToSnooper(PlayerUsageSnooper playerSnooper)
 | 
						|
    {
 | 
						|
        super.addServerStatsToSnooper(playerSnooper);
 | 
						|
        playerSnooper.func_152768_a("snooper_partner", this.mc.getPlayerUsageSnooper().getUniqueID());
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Returns whether snooping is enabled or not.
 | 
						|
     */
 | 
						|
    public boolean isSnooperEnabled()
 | 
						|
    {
 | 
						|
        return Minecraft.getMinecraft().isSnooperEnabled();
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * On dedicated does nothing. On integrated, sets commandsAllowedForAll, gameType and allows external connections.
 | 
						|
     */
 | 
						|
    public String shareToLAN(WorldSettings.GameType type, boolean allowCheats)
 | 
						|
    {
 | 
						|
        try
 | 
						|
        {
 | 
						|
            int i = -1;
 | 
						|
 | 
						|
            try
 | 
						|
            {
 | 
						|
                i = HttpUtil.func_76181_a();
 | 
						|
            }
 | 
						|
            catch (IOException ioexception)
 | 
						|
            {
 | 
						|
                ;
 | 
						|
            }
 | 
						|
 | 
						|
            if (i <= 0)
 | 
						|
            {
 | 
						|
                i = 25564;
 | 
						|
            }
 | 
						|
 | 
						|
            this.func_147137_ag().addLanEndpoint((InetAddress)null, i);
 | 
						|
            logger.info("Started on " + i);
 | 
						|
            this.isPublic = true;
 | 
						|
            this.lanServerPing = new ThreadLanServerPing(this.getMOTD(), i + "");
 | 
						|
            this.lanServerPing.start();
 | 
						|
            this.getConfigurationManager().func_152604_a(type);
 | 
						|
            this.getConfigurationManager().setCommandsAllowedForAll(allowCheats);
 | 
						|
            return i + "";
 | 
						|
        }
 | 
						|
        catch (IOException ioexception1)
 | 
						|
        {
 | 
						|
            return null;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Saves all necessary data as preparation for stopping the server.
 | 
						|
     */
 | 
						|
    public void stopServer()
 | 
						|
    {
 | 
						|
        super.stopServer();
 | 
						|
 | 
						|
        if (this.lanServerPing != null)
 | 
						|
        {
 | 
						|
            this.lanServerPing.interrupt();
 | 
						|
            this.lanServerPing = null;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Sets the serverRunning variable to false, in order to get the server to shut down.
 | 
						|
     */
 | 
						|
    public void initiateShutdown()
 | 
						|
    {
 | 
						|
        super.initiateShutdown();
 | 
						|
 | 
						|
        if (this.lanServerPing != null)
 | 
						|
        {
 | 
						|
            this.lanServerPing.interrupt();
 | 
						|
            this.lanServerPing = null;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Returns true if this integrated server is open to LAN
 | 
						|
     */
 | 
						|
    public boolean getPublic()
 | 
						|
    {
 | 
						|
        return this.isPublic;
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Sets the game type for all worlds.
 | 
						|
     */
 | 
						|
    public void setGameType(WorldSettings.GameType gameMode)
 | 
						|
    {
 | 
						|
        this.getConfigurationManager().func_152604_a(gameMode);
 | 
						|
    }
 | 
						|
 | 
						|
    /**
 | 
						|
     * Return whether command blocks are enabled.
 | 
						|
     */
 | 
						|
    public boolean isCommandBlockEnabled()
 | 
						|
    {
 | 
						|
        return true;
 | 
						|
    }
 | 
						|
 | 
						|
    public int getOpPermissionLevel()
 | 
						|
    {
 | 
						|
        return 4;
 | 
						|
    }
 | 
						|
} |