mirror of
https://github.com/barkeser2002/CatServer.git
synced 2026-09-25 15:06:01 +03:00
340 lines
17 KiB
Diff
340 lines
17 KiB
Diff
--- ../src-base/minecraft/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ ../src-work/minecraft/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -1,13 +1,9 @@
|
|
package net.minecraft.server.dedicated;
|
|
|
|
-import com.google.common.collect.Lists;
|
|
-import com.mojang.authlib.GameProfileRepository;
|
|
-import com.mojang.authlib.minecraft.MinecraftSessionService;
|
|
-import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
|
|
-import java.io.BufferedReader;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
-import java.io.InputStreamReader;
|
|
+//CraftBukkit start
|
|
+import java.io.PrintStream;
|
|
import java.net.InetAddress;
|
|
import java.net.Proxy;
|
|
import java.util.Collections;
|
|
@@ -15,6 +11,25 @@
|
|
import java.util.Random;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.regex.Pattern;
|
|
+
|
|
+import org.apache.logging.log4j.Level;
|
|
+import org.apache.logging.log4j.LogManager;
|
|
+import org.apache.logging.log4j.Logger;
|
|
+import org.bukkit.craftbukkit.LoggerOutputStream;
|
|
+import org.bukkit.craftbukkit.SpigotTimings;
|
|
+import org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender;
|
|
+import org.bukkit.craftbukkit.util.Waitable;
|
|
+import org.bukkit.event.server.RemoteServerCommandEvent;
|
|
+import org.bukkit.event.server.ServerCommandEvent;
|
|
+import org.spigotmc.SpigotConfig;
|
|
+// CraftBukkit end
|
|
+
|
|
+import com.google.common.collect.Lists;
|
|
+import com.mojang.authlib.GameProfileRepository;
|
|
+import com.mojang.authlib.minecraft.MinecraftSessionService;
|
|
+import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
|
|
+
|
|
+import jline.console.ConsoleReader;
|
|
import net.minecraft.command.ICommandSender;
|
|
import net.minecraft.crash.CrashReport;
|
|
import net.minecraft.crash.ICrashReportDetail;
|
|
@@ -39,10 +54,9 @@
|
|
import net.minecraft.world.World;
|
|
import net.minecraft.world.WorldSettings;
|
|
import net.minecraft.world.WorldType;
|
|
+import net.minecraft.world.chunk.storage.AnvilSaveConverter;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
-import org.apache.logging.log4j.LogManager;
|
|
-import org.apache.logging.log4j.Logger;
|
|
|
|
@SideOnly(Side.SERVER)
|
|
public class DedicatedServer extends MinecraftServer implements IServer
|
|
@@ -51,18 +65,18 @@
|
|
private static final Pattern RESOURCE_PACK_SHA1_PATTERN = Pattern.compile("^[a-fA-F0-9]{40}$");
|
|
public final List<PendingCommand> pendingCommandList = Collections.<PendingCommand>synchronizedList(Lists.<PendingCommand>newArrayList());
|
|
private RConThreadQuery theRConThreadQuery;
|
|
- private final RConConsoleSource rconConsoleSource = new RConConsoleSource(this);
|
|
+ public final RConConsoleSource rconConsoleSource = new RConConsoleSource(this);
|
|
private RConThreadMain theRConThreadMain;
|
|
- private PropertyManager settings;
|
|
+ public PropertyManager settings;
|
|
private ServerEula eula;
|
|
private boolean canSpawnStructures;
|
|
private GameType gameType;
|
|
private boolean guiIsEnabled;
|
|
public static boolean allowPlayerLogins = false;
|
|
|
|
- public DedicatedServer(File anvilFileIn, DataFixer dataFixerIn, YggdrasilAuthenticationService authServiceIn, MinecraftSessionService sessionServiceIn, GameProfileRepository profileRepoIn, PlayerProfileCache profileCacheIn)
|
|
+ public DedicatedServer(joptsimple.OptionSet options/*, File anvilFileIn*/, DataFixer dataFixerIn, YggdrasilAuthenticationService authServiceIn, MinecraftSessionService sessionServiceIn, GameProfileRepository profileRepoIn, PlayerProfileCache profileCacheIn)
|
|
{
|
|
- super(anvilFileIn, Proxy.NO_PROXY, dataFixerIn, authServiceIn, sessionServiceIn, profileRepoIn, profileCacheIn);
|
|
+ super(options, Proxy.NO_PROXY, dataFixerIn, authServiceIn, sessionServiceIn, profileRepoIn, profileCacheIn);
|
|
Thread thread = new Thread("Server Infinisleeper")
|
|
{
|
|
{
|
|
@@ -92,8 +106,12 @@
|
|
{
|
|
public void run()
|
|
{
|
|
- if (net.minecraftforge.server.console.TerminalHandler.handleCommands(DedicatedServer.this)) return;
|
|
- BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));
|
|
+ // CraftBukkit start
|
|
+ if (!org.bukkit.craftbukkit.Main.useConsole) {
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+ ConsoleReader bufferedreader = DedicatedServer.this.reader;
|
|
String s4;
|
|
|
|
try
|
|
@@ -111,6 +129,21 @@
|
|
};
|
|
thread.setDaemon(true);
|
|
thread.start();
|
|
+ // CraftBukkit start - TODO: handle command-line logging arguments
|
|
+ java.util.logging.Logger global = java.util.logging.Logger.getLogger("");
|
|
+ global.setUseParentHandlers(false);
|
|
+
|
|
+ for (java.util.logging.Handler handler : global.getHandlers())
|
|
+ {
|
|
+ global.removeHandler(handler);
|
|
+ }
|
|
+
|
|
+ global.addHandler(new org.bukkit.craftbukkit.util.ForwardLogHandler());
|
|
+ final org.apache.logging.log4j.core.Logger logger = ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger());
|
|
+ new Thread(new org.bukkit.craftbukkit.util.TerminalConsoleWriterThread(System.out, this.reader)).start();
|
|
+ System.setOut(new PrintStream(new LoggerOutputStream(logger, Level.INFO), true));
|
|
+ System.setErr(new PrintStream(new LoggerOutputStream(logger, Level.WARN), true));
|
|
+ // CraftBukkit end
|
|
LOGGER.info("Starting minecraft server version 1.10.2");
|
|
|
|
if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L)
|
|
@@ -121,8 +154,9 @@
|
|
net.minecraftforge.fml.common.FMLCommonHandler.instance().onServerStart(this);
|
|
|
|
LOGGER.info("Loading properties");
|
|
- this.settings = new PropertyManager(new File("server.properties"));
|
|
- this.eula = new ServerEula(new File("eula.txt"));
|
|
+ //this.settings = new PropertyManager(new File("server.properties"));
|
|
+ this.settings = new PropertyManager(this.options); // CraftBukkit - CLI argument support
|
|
+ this.eula = new ServerEula(new File(MinecraftServer.serverConfigDir,"eula.txt"));
|
|
|
|
if (!this.eula.hasAcceptedEULA())
|
|
{
|
|
@@ -176,27 +210,37 @@
|
|
this.setServerPort(this.settings.getIntProperty("server-port", 25565));
|
|
}
|
|
|
|
+ this.setPlayerList(new DedicatedPlayerList(this));
|
|
+ //org.spigotmc.SpigotConfig.init((File) options.valueOf("spigot-settings"));
|
|
+ //org.spigotmc.SpigotConfig.registerCommands();
|
|
+
|
|
LOGGER.info("Generating keypair");
|
|
this.setKeyPair(CryptManager.generateKeyPair());
|
|
LOGGER.info("Starting Minecraft server on {}:{}", new Object[] {this.getServerHostname().isEmpty() ? "*" : this.getServerHostname(), Integer.valueOf(this.getServerPort())});
|
|
-
|
|
- try
|
|
- {
|
|
- this.getNetworkSystem().addLanEndpoint(inetaddress, this.getServerPort());
|
|
+ if(!SpigotConfig.lateBind){
|
|
+ try
|
|
+ {
|
|
+ this.getNetworkSystem().addLanEndpoint(inetaddress, this.getServerPort());
|
|
+ }
|
|
+ catch (IOException ioexception)
|
|
+ {
|
|
+ LOGGER.warn("**** FAILED TO BIND TO PORT!");
|
|
+ LOGGER.warn("The exception was: {}", new Object[] {ioexception.toString()});
|
|
+ LOGGER.warn("Perhaps a server is already running on that port?");
|
|
+ return false;
|
|
+ }
|
|
}
|
|
- catch (IOException ioexception)
|
|
- {
|
|
- LOGGER.warn("**** FAILED TO BIND TO PORT!");
|
|
- LOGGER.warn("The exception was: {}", new Object[] {ioexception.toString()});
|
|
- LOGGER.warn("Perhaps a server is already running on that port?");
|
|
- return false;
|
|
- }
|
|
-
|
|
if (!this.isServerInOnlineMode())
|
|
{
|
|
LOGGER.warn("**** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!");
|
|
LOGGER.warn("The server will make no attempt to authenticate usernames. Beware.");
|
|
LOGGER.warn("While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.");
|
|
+ if (org.spigotmc.SpigotConfig.bungee) {
|
|
+ DedicatedServer.LOGGER.warn("Whilst this makes it possible to use BungeeCord, unless access to your server is properly restricted, it also opens up the ability for hackers to connect with any username they choose.");
|
|
+ DedicatedServer.LOGGER.warn("Please see http://www.spigotmc.org/wiki/firewall-guide/ for further information.");
|
|
+ } else {
|
|
+ DedicatedServer.LOGGER.warn("While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.");
|
|
+ }
|
|
LOGGER.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file.");
|
|
}
|
|
|
|
@@ -212,7 +256,8 @@
|
|
else
|
|
{
|
|
net.minecraftforge.fml.common.FMLCommonHandler.instance().onServerStarted();
|
|
- this.setPlayerList(new DedicatedPlayerList(this));
|
|
+ //this.setPlayerList(new DedicatedPlayerList(this)); // CB - ^
|
|
+ this.anvilConverterForAnvilFile = new AnvilSaveConverter(this.server.getWorldContainer(), this.getDataFixer());
|
|
long j = System.nanoTime();
|
|
|
|
if (this.getFolderName() == null)
|
|
@@ -254,16 +299,16 @@
|
|
this.getOpPermissionLevel();
|
|
this.isSnooperEnabled();
|
|
this.getNetworkCompressionThreshold();
|
|
- this.setBuildLimit(this.settings.getIntProperty("max-build-height", 256));
|
|
+ this.setBuildLimit(this.settings.getIntProperty("max-build1-height", 256));
|
|
this.setBuildLimit((this.getBuildLimit() + 8) / 16 * 16);
|
|
this.setBuildLimit(MathHelper.clamp_int(this.getBuildLimit(), 64, 256));
|
|
- this.settings.setProperty("max-build-height", Integer.valueOf(this.getBuildLimit()));
|
|
+ this.settings.setProperty("max-build1-height", Integer.valueOf(this.getBuildLimit()));
|
|
TileEntitySkull.setProfileCache(this.getPlayerProfileCache());
|
|
TileEntitySkull.setSessionService(this.getMinecraftSessionService());
|
|
PlayerProfileCache.setOnlineMode(this.isServerInOnlineMode());
|
|
if (!net.minecraftforge.fml.common.FMLCommonHandler.instance().handleServerAboutToStart(this)) return false;
|
|
LOGGER.info("Preparing level \"{}\"", new Object[] {this.getFolderName()});
|
|
- this.loadAllWorlds(this.getFolderName(), this.getFolderName(), k, worldtype, s2);
|
|
+ this.loadAllWorlds(this.getFolderName(), this.getFolderName(), k, worldtype, s2);
|
|
long i1 = System.nanoTime() - j;
|
|
String s3 = String.format("%.3fs", new Object[] {Double.valueOf((double)i1 / 1.0E9D)});
|
|
LOGGER.info("Done ({})! For help, type \"help\" or \"?\"", new Object[] {s3});
|
|
@@ -280,9 +325,30 @@
|
|
LOGGER.info("Starting remote control listener");
|
|
this.theRConThreadMain = new RConThreadMain(this);
|
|
this.theRConThreadMain.startThread();
|
|
+ this.remoteConsole = new CraftRemoteConsoleCommandSender(this.rconConsoleSource); // CB
|
|
}
|
|
+ // CraftBukkit start
|
|
+ if (this.server.getBukkitSpawnRadius() > -1) {
|
|
+ DedicatedServer.LOGGER.info("'settings.spawn-radius' in bukkit.yml has been moved to 'spawn-protection' in server.properties. I will move your config for you.");
|
|
+ this.settings.serverProperties.remove("spawn-protection");
|
|
+ this.settings.getIntProperty("spawn-protection", this.server.getBukkitSpawnRadius());
|
|
+ this.server.removeBukkitSpawnRadius();
|
|
+ this.settings.saveProperties();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
|
|
- if (this.getMaxTickTime() > 0L)
|
|
+ if (SpigotConfig.lateBind) {
|
|
+ try {
|
|
+ this.getNetworkSystem().addLanEndpoint(inetaddress, this.getServerPort());
|
|
+ } catch (IOException ioexception) {
|
|
+ DedicatedServer.LOGGER.warn("**** FAILED TO BIND TO PORT!");
|
|
+ DedicatedServer.LOGGER.warn("The exception was: {}", new Object[] { ioexception.toString()});
|
|
+ DedicatedServer.LOGGER.warn("Perhaps a server is already running on that port?");
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (false && this.getMaxTickTime() > 0L) // Spigot - disable
|
|
{
|
|
Thread thread1 = new Thread(new ServerHangWatchdog(this));
|
|
thread1.setName("Server Watchdog");
|
|
@@ -417,11 +483,20 @@
|
|
|
|
public void executePendingCommands()
|
|
{
|
|
+ SpigotTimings.serverCommandTimer.startTiming();
|
|
while (!this.pendingCommandList.isEmpty())
|
|
{
|
|
PendingCommand pendingcommand = (PendingCommand)this.pendingCommandList.remove(0);
|
|
- this.getCommandManager().executeCommand(pendingcommand.sender, pendingcommand.command);
|
|
+ //this.getCommandManager().executeCommand(pendingcommand.sender, pendingcommand.command);
|
|
+ // CraftBukkit start - ServerCommand for preprocessing
|
|
+ ServerCommandEvent event = new ServerCommandEvent(console, pendingcommand.command);
|
|
+ server.getPluginManager().callEvent(event);
|
|
+ if (event.isCancelled()) continue;
|
|
+ pendingcommand = new PendingCommand(event.getCommand(), pendingcommand.sender);
|
|
+ server.dispatchServerCommand(console, pendingcommand);
|
|
+ // CraftBukkit end
|
|
}
|
|
+ SpigotTimings.serverCommandTimer.stopTiming();
|
|
}
|
|
|
|
public boolean isDedicatedServer()
|
|
@@ -674,18 +749,70 @@
|
|
|
|
public long getMaxTickTime()
|
|
{
|
|
- return this.settings.getLongProperty("max-tick-time", TimeUnit.MINUTES.toMillis(1L));
|
|
+ return this.settings.getLongProperty("max-tick-time", TimeUnit.MINUTES.toMillis(100L));
|
|
}
|
|
|
|
public String getPlugins()
|
|
{
|
|
- return "";
|
|
+ //return "";
|
|
+ // CraftBukkit start - Whole method
|
|
+ StringBuilder result = new StringBuilder();
|
|
+ org.bukkit.plugin.Plugin[] plugins = server.getPluginManager().getPlugins();
|
|
+ result.append(server.getName());
|
|
+ result.append(" on Bukkit ");
|
|
+ result.append(server.getBukkitVersion());
|
|
+ if (plugins.length > 0 && server.getQueryPlugins()) {
|
|
+ result.append(": ");
|
|
+ for (int i = 0; i < plugins.length; i++) {
|
|
+ if (i > 0) {
|
|
+ result.append("; ");
|
|
+ }
|
|
+ result.append(plugins[i].getDescription().getName());
|
|
+ result.append(" ");
|
|
+ result.append(plugins[i].getDescription().getVersion().replaceAll(";", ","));
|
|
+ }
|
|
+ }
|
|
+ return result.toString();
|
|
+ // CraftBukkit end
|
|
}
|
|
|
|
- public String handleRConCommand(String command)
|
|
+ public String handleRConCommand(final String command)
|
|
{
|
|
- this.rconConsoleSource.resetLog();
|
|
- this.commandManager.executeCommand(this.rconConsoleSource, command);
|
|
- return this.rconConsoleSource.getLogContents();
|
|
+ //this.rconConsoleSource.resetLog();
|
|
+ //this.commandManager.executeCommand(this.rconConsoleSource, command);
|
|
+ //return this.rconConsoleSource.getLogContents();
|
|
+ Waitable<String> waitable = new Waitable<String>() {
|
|
+ @Override
|
|
+ protected String evaluate() {
|
|
+ rconConsoleSource.resetLog();
|
|
+ // Event changes start
|
|
+ RemoteServerCommandEvent event = new RemoteServerCommandEvent(remoteConsole, command);
|
|
+ server.getPluginManager().callEvent(event);
|
|
+ if (event.isCancelled()) {
|
|
+ return "";
|
|
+ }
|
|
+ // Event change end
|
|
+ PendingCommand serverCommand = new PendingCommand(event.getCommand(), rconConsoleSource);
|
|
+ server.dispatchServerCommand(remoteConsole, serverCommand);
|
|
+ return rconConsoleSource.getLogContents();
|
|
+ }
|
|
+ };
|
|
+ processQueue.add(waitable);
|
|
+ try {
|
|
+ return waitable.get();
|
|
+ } catch (java.util.concurrent.ExecutionException e) {
|
|
+ throw new RuntimeException("Exception processing rcon command " + command, e.getCause());
|
|
+ } catch (InterruptedException e) {
|
|
+ Thread.currentThread().interrupt(); // Maintain interrupted state
|
|
+ throw new RuntimeException("Interrupted processing rcon command " + command, e);
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|
|
+
|
|
+ // CraftBukkit start
|
|
+ @Override
|
|
+ public PropertyManager getPropertyManager() {
|
|
+ return this.settings;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
}
|