mirror of
https://github.com/barkeser2002/CatServer.git
synced 2026-09-25 02:20:01 +03:00
374 lines
18 KiB
Diff
374 lines
18 KiB
Diff
--- ../src-base/minecraft/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ ../src-work/minecraft/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -8,6 +8,7 @@
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
+import java.io.PrintStream;
|
|
import java.net.InetAddress;
|
|
import java.net.Proxy;
|
|
import java.nio.charset.StandardCharsets;
|
|
@@ -43,29 +44,40 @@
|
|
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.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.util.Waitable;
|
|
+import org.bukkit.event.server.RemoteServerCommandEvent;
|
|
+import org.bukkit.event.server.ServerCommandEvent;
|
|
+import org.spigotmc.SpigotConfig;
|
|
|
|
@SideOnly(Side.SERVER)
|
|
public class DedicatedServer extends MinecraftServer implements IServer
|
|
{
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
|
private static final Pattern RESOURCE_PACK_SHA1_PATTERN = Pattern.compile("^[a-fA-F0-9]{40}$");
|
|
- public final List<PendingCommand> pendingCommandList = Collections.<PendingCommand>synchronizedList(Lists.newArrayList());
|
|
+ public final List<PendingCommand> field_71341_l = Collections.<PendingCommand>synchronizedList(Lists.newArrayList()); // CatServer - keep srg field
|
|
private RConThreadQuery rconQueryThread;
|
|
- private final RConConsoleSource rconConsoleSource = new RConConsoleSource(this);
|
|
+ public final RConConsoleSource rconConsoleSource = new RConConsoleSource(this);
|
|
private RConThreadMain rconThread;
|
|
- private PropertyManager settings;
|
|
+ public PropertyManager settings;
|
|
private ServerEula eula;
|
|
private boolean canSpawnStructures;
|
|
private GameType gameType;
|
|
private boolean guiIsEnabled;
|
|
+ public static boolean allowPlayerLogins = false;
|
|
+ public final java.util.Queue<PendingCommand> pendingCommandList = new java.util.concurrent.ConcurrentLinkedQueue<>(); // Paper - use a proper queue
|
|
|
|
- public DedicatedServer(File anvilFileIn, DataFixer dataFixerIn, YggdrasilAuthenticationService authServiceIn, MinecraftSessionService sessionServiceIn, GameProfileRepository profileRepoIn, PlayerProfileCache profileCacheIn)
|
|
+ // CraftBukkit start - Signature changed
|
|
+ public DedicatedServer(joptsimple.OptionSet options, 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")
|
|
{
|
|
{
|
|
@@ -95,6 +107,11 @@
|
|
{
|
|
public void run()
|
|
{
|
|
+ if (!org.bukkit.craftbukkit.Main.useConsole) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ if (net.minecraftforge.server.console.TerminalHandler.handleCommands(DedicatedServer.this)) return;
|
|
BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
|
|
String s4;
|
|
|
|
@@ -111,6 +128,35 @@
|
|
}
|
|
}
|
|
};
|
|
+
|
|
+ // 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());
|
|
+
|
|
+ // Paper start - Not needed with TerminalConsoleAppender
|
|
+ final org.apache.logging.log4j.Logger logger = LogManager.getRootLogger();
|
|
+ /*
|
|
+ final org.apache.logging.log4j.core.Logger logger = ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger());
|
|
+ for (org.apache.logging.log4j.core.Appender appender : logger.getAppenders().values()) {
|
|
+ if (appender instanceof org.apache.logging.log4j.core.appender.ConsoleAppender) {
|
|
+ logger.removeAppender(appender);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ new Thread(new org.bukkit.craftbukkit.util.TerminalConsoleWriterThread(System.out, this.reader)).start();
|
|
+ */
|
|
+ // Paper end
|
|
+
|
|
+ catserver.server.threads.ConsoleWriteThread.startThread(); // CatServer
|
|
+
|
|
+ System.setOut(new PrintStream(new LoggerOutputStream(logger, Level.INFO), true));
|
|
+ System.setErr(new PrintStream(new LoggerOutputStream(logger, Level.WARN), true));
|
|
+ // CraftBukkit end
|
|
+
|
|
thread.setDaemon(true);
|
|
thread.start();
|
|
LOGGER.info("Starting minecraft server version 1.12.2");
|
|
@@ -120,8 +166,10 @@
|
|
LOGGER.warn("To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\"");
|
|
}
|
|
|
|
+ net.minecraftforge.fml.common.FMLCommonHandler.instance().onServerStart(this);
|
|
+
|
|
LOGGER.info("Loading properties");
|
|
- this.settings = new PropertyManager(new File("server.properties"));
|
|
+ this.settings = new PropertyManager(this.options); // CraftBukkit - CLI argument support
|
|
this.eula = new ServerEula(new File("eula.txt"));
|
|
|
|
if (!this.eula.hasAcceptedEULA())
|
|
@@ -177,27 +225,42 @@
|
|
this.setServerPort(this.settings.getIntProperty("server-port", 25565));
|
|
}
|
|
|
|
+ // Spigot start
|
|
+ this.setPlayerList(new DedicatedPlayerList(this));
|
|
+ org.spigotmc.SpigotConfig.init((File) options.valueOf("spigot-settings"));
|
|
+ org.spigotmc.SpigotConfig.registerCommands();
|
|
+ // Spigot end
|
|
+
|
|
LOGGER.info("Generating keypair");
|
|
this.setKeyPair(CryptManager.generateKeyPair());
|
|
LOGGER.info("Starting Minecraft server on {}:{}", 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: {}", (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: {}", (Object)ioexception.toString());
|
|
- LOGGER.warn("Perhaps a server is already running on that port?");
|
|
- return false;
|
|
- }
|
|
+ // this.setPlayerList(new DedicatedPlayerList(this)); // Spigot - moved up
|
|
|
|
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.");
|
|
+ // Spigot start
|
|
+ if (org.spigotmc.SpigotConfig.bungee) {
|
|
+ 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.");
|
|
+ LOGGER.warn("Please see http://www.spigotmc.org/wiki/firewall-guide/ for further information.");
|
|
+ } else {
|
|
+ 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.");
|
|
+ }
|
|
+ // Spigot end
|
|
LOGGER.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file.");
|
|
}
|
|
|
|
@@ -212,7 +275,9 @@
|
|
}
|
|
else
|
|
{
|
|
- this.setPlayerList(new DedicatedPlayerList(this));
|
|
+ net.minecraftforge.fml.common.FMLCommonHandler.instance().onServerStarted();
|
|
+ this.anvilConverterForAnvilFile = new AnvilSaveConverter(server.getWorldContainer(), this.dataFixer); // CraftBukkit - moved from MinecraftServer constructor
|
|
+// this.setPlayerList(new DedicatedPlayerList(this));
|
|
long j = System.nanoTime();
|
|
|
|
if (this.getFolderName() == null)
|
|
@@ -260,6 +325,7 @@
|
|
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 \"{}\"", (Object)this.getFolderName());
|
|
this.loadAllWorlds(this.getFolderName(), this.getFolderName(), k, worldtype, s2);
|
|
long i1 = System.nanoTime() - j;
|
|
@@ -268,7 +334,7 @@
|
|
|
|
if (this.settings.hasProperty("announce-player-achievements"))
|
|
{
|
|
- this.worlds[0].getGameRules().setOrCreateGameRule("announceAdvancements", this.settings.getBooleanProperty("announce-player-achievements", true) ? "true" : "false");
|
|
+ this.worldServerList.get(0).getGameRules().setOrCreateGameRule("announceAdvancements", this.settings.getBooleanProperty("announce-player-achievements", true) ? "true" : "false");
|
|
this.settings.removeProperty("announce-player-achievements");
|
|
this.settings.saveProperties();
|
|
}
|
|
@@ -280,14 +346,33 @@
|
|
this.rconQueryThread.startThread();
|
|
}
|
|
|
|
- if (this.settings.getBooleanProperty("enable-rcon", false))
|
|
- {
|
|
+ if (this.settings.getBooleanProperty("enable-rcon", false)) {
|
|
LOGGER.info("Starting remote control listener");
|
|
this.rconThread = new RConThreadMain(this);
|
|
this.rconThread.startThread();
|
|
+ this.remoteConsole = new org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender(this.rconConsoleSource);
|
|
}
|
|
|
|
- if (this.getMaxTickTime() > 0L)
|
|
+ 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();
|
|
+ }
|
|
+
|
|
+ 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: {}", (Object)ioexception.toString());
|
|
+ LOGGER.warn("Perhaps a server is already running on that port?");
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (this.getMaxTickTime() > 0L && false) // CatServer - disable WatchDog
|
|
{
|
|
Thread thread1 = new Thread(new ServerHangWatchdog(this));
|
|
thread1.setName("Server Watchdog");
|
|
@@ -296,7 +381,8 @@
|
|
}
|
|
|
|
Items.AIR.getSubItems(CreativeTabs.SEARCH, NonNullList.create());
|
|
- return true;
|
|
+ // <3 you Grum for this, saves us ~30 patch files! --^
|
|
+ return net.minecraftforge.fml.common.FMLCommonHandler.instance().handleServerStarting(this);
|
|
}
|
|
}
|
|
}
|
|
@@ -419,11 +505,32 @@
|
|
|
|
public void executePendingCommands()
|
|
{
|
|
- while (!this.pendingCommandList.isEmpty())
|
|
+ SpigotTimings.serverCommandTimer.startTiming(); // Spigot
|
|
+ PendingCommand pendingcommand;
|
|
+ while ((pendingcommand = this.pendingCommandList.poll()) != null) { // Paper - use proper queue
|
|
+ // 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);
|
|
+
|
|
+ // this.getCommandManager().executeCommand(pendingcommand.sender, pendingcommand.command); // Called in dispatchServerCommand
|
|
+ server.dispatchServerCommand(console, pendingcommand);
|
|
+ // CraftBukkit end
|
|
+ }
|
|
+ // CatServer start
|
|
+ while (!this.field_71341_l.isEmpty())
|
|
{
|
|
- PendingCommand pendingcommand = this.pendingCommandList.remove(0);
|
|
- this.getCommandManager().executeCommand(pendingcommand.sender, pendingcommand.command);
|
|
+ pendingcommand = this.field_71341_l.remove(0);
|
|
+ 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);
|
|
}
|
|
+ // CatServer end
|
|
+ SpigotTimings.serverCommandTimer.stopTiming(); // Spigot
|
|
}
|
|
|
|
public boolean isDedicatedServer()
|
|
@@ -515,7 +622,7 @@
|
|
|
|
public boolean isBlockProtected(World worldIn, BlockPos pos, EntityPlayer playerIn)
|
|
{
|
|
- if (worldIn.provider.getDimensionType().getId() != 0)
|
|
+ if (worldIn.provider.getDimension() != 0)
|
|
{
|
|
return false;
|
|
}
|
|
@@ -584,6 +691,9 @@
|
|
return this.settings.getIntProperty("network-compression-threshold", super.getNetworkCompressionThreshold());
|
|
}
|
|
|
|
+ //Forge: Enable formated text for colors in console.
|
|
+ @Override public void sendMessage(net.minecraft.util.text.ITextComponent message) { LOGGER.info(message.getFormattedText()); }
|
|
+
|
|
protected boolean convertFiles() throws IOException
|
|
{
|
|
boolean flag = false;
|
|
@@ -673,13 +783,66 @@
|
|
|
|
public String getPlugins()
|
|
{
|
|
- 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)
|
|
+ // CraftBukkit start - fire RemoteServerCommandEvent
|
|
+ public String handleRConCommand(final String command)
|
|
{
|
|
- 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
|
|
+
|
|
+ // TODO: Check if it's useless
|
|
+ @Override
|
|
+ public PropertyManager getPropertyManager() {
|
|
+ return this.settings;
|
|
+ }
|
|
}
|