Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
f0e85c21ce
Commit
510fed73d3
@ -1,12 +1,14 @@
|
|||||||
package de.steamwar.bungeecore;
|
package de.steamwar.bungeecore;
|
||||||
|
|
||||||
|
import de.steamwar.messages.ChatSender;
|
||||||
import de.steamwar.sql.EventFight;
|
import de.steamwar.sql.EventFight;
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.sql.Team;
|
import de.steamwar.sql.Team;
|
||||||
import de.steamwar.sql.Tutorial;
|
import de.steamwar.sql.Tutorial;
|
||||||
import de.steamwar.messages.ChatSender;
|
import lombok.Getter;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
|
||||||
|
import java.io.DataOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -14,6 +16,7 @@ import java.nio.file.Files;
|
|||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -46,7 +49,9 @@ public class ServerStarter {
|
|||||||
private boolean allowMerge = false;
|
private boolean allowMerge = false;
|
||||||
private String fightMap = null;
|
private String fightMap = null;
|
||||||
private String gameMode = null;
|
private String gameMode = null;
|
||||||
private ServerConstructor constructor = (serverName, port, builder, shutdownCallback) -> new Arenaserver(serverName, gameMode, fightMap, allowMerge, port, builder, shutdownCallback);
|
private boolean checkpoint = false;
|
||||||
|
private ServerConstructor constructor = (serverName, port, builder, shutdownCallback, failureCallback) -> new Arenaserver(serverName, gameMode, fightMap, allowMerge, port, builder, shutdownCallback);
|
||||||
|
private Consumer<Subserver> callback = subserver -> {};
|
||||||
|
|
||||||
private final Set<ProxiedPlayer> playersToSend = new HashSet<>();
|
private final Set<ProxiedPlayer> playersToSend = new HashSet<>();
|
||||||
private final Map<String, String> arguments = new HashMap<>();
|
private final Map<String, String> arguments = new HashMap<>();
|
||||||
@ -117,6 +122,7 @@ public class ServerStarter {
|
|||||||
serverJar = version.getServerJar();
|
serverJar = version.getServerJar();
|
||||||
worldDir = version.getWorldFolder(WORLDS_BASE_PATH);
|
worldDir = version.getWorldFolder(WORLDS_BASE_PATH);
|
||||||
worldName = version != Version.SPIGOT_12 ? String.valueOf(SteamwarUser.get(owner).getId()) : owner.toString();
|
worldName = version != Version.SPIGOT_12 ? String.valueOf(SteamwarUser.get(owner).getId()) : owner.toString();
|
||||||
|
checkpoint = true;
|
||||||
|
|
||||||
build(owner);
|
build(owner);
|
||||||
|
|
||||||
@ -128,13 +134,12 @@ public class ServerStarter {
|
|||||||
|
|
||||||
// Send players to existing server
|
// Send players to existing server
|
||||||
startCondition = () -> {
|
startCondition = () -> {
|
||||||
for(Subserver subserver : Subserver.getServerList()) {
|
Bauserver subserver = Bauserver.get(owner);
|
||||||
if(subserver.getType() == Servertype.BAUSERVER && ((Bauserver)subserver).getOwner().equals(owner)) {
|
if(subserver != null) {
|
||||||
for(ProxiedPlayer p : playersToSend)
|
for(ProxiedPlayer p : playersToSend)
|
||||||
SubserverSystem.sendPlayer(subserver, p);
|
SubserverSystem.sendPlayer(subserver, p);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -163,19 +168,16 @@ public class ServerStarter {
|
|||||||
if(startingBau(owner))
|
if(startingBau(owner))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (Subserver subserver : Subserver.getServerList()) {
|
Bauserver subserver = Bauserver.get(owner.getUniqueId());
|
||||||
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(owner.getUniqueId()) && subserver.hasStarted()) {
|
if(subserver != null && subserver.isStarted())
|
||||||
subserver.stop();
|
subserver.stop();
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return !startingBau(owner);
|
return !startingBau(owner);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void build(UUID owner) {
|
private void build(UUID owner) {
|
||||||
constructor = (serverName, port, builder, shutdownCallback) -> new Bauserver(serverName, owner, port, builder, shutdownCallback);
|
constructor = (serverName, port, builder, shutdownCallback, failureCallback) -> new Bauserver(serverName, owner, port, builder, shutdownCallback, failureCallback);
|
||||||
serverNameProvider = port -> bauServerName(SteamwarUser.get(owner));
|
serverNameProvider = port -> bauServerName(SteamwarUser.get(owner));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,17 +187,17 @@ public class ServerStarter {
|
|||||||
worldDir = version.getWorldFolder(BUILDER_BASE_PATH);
|
worldDir = version.getWorldFolder(BUILDER_BASE_PATH);
|
||||||
worldName = map;
|
worldName = map;
|
||||||
serverNameProvider = port -> "⛏" + map;
|
serverNameProvider = port -> "⛏" + map;
|
||||||
constructor = (serverName, port, builder, shutdownCallback) -> new Builderserver(serverName, worldName, port, builder, shutdownCallback);
|
checkpoint = true;
|
||||||
|
constructor = (serverName, port, builder, shutdownCallback, failureCallback) -> new Builderserver(serverName, worldName, port, builder, shutdownCallback, failureCallback);
|
||||||
|
|
||||||
// Send players to existing server
|
// Send players to existing server
|
||||||
startCondition = () -> {
|
startCondition = () -> {
|
||||||
for(Subserver subserver : Subserver.getServerList()) {
|
Builderserver subserver = Builderserver.get(worldName);
|
||||||
if(subserver.getType() == Servertype.BUILDER && ((Builderserver)subserver).getMap().equals(worldName)) {
|
if(subserver != null) {
|
||||||
for(ProxiedPlayer p : playersToSend)
|
for(ProxiedPlayer p : playersToSend)
|
||||||
SubserverSystem.sendPlayer(subserver, p);
|
SubserverSystem.sendPlayer(subserver, p);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -218,9 +220,14 @@ public class ServerStarter {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Subserver start() {
|
public ServerStarter callback(Consumer<Subserver> callback) {
|
||||||
|
this.callback = callback;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean start() {
|
||||||
if(!startCondition.getAsBoolean())
|
if(!startCondition.getAsBoolean())
|
||||||
return null;
|
return false;
|
||||||
|
|
||||||
int port = portrange.freePort();
|
int port = portrange.freePort();
|
||||||
String serverName = serverNameProvider.apply(port);
|
String serverName = serverNameProvider.apply(port);
|
||||||
@ -231,7 +238,7 @@ public class ServerStarter {
|
|||||||
for (ProxiedPlayer p : playersToSend)
|
for (ProxiedPlayer p : playersToSend)
|
||||||
ChatSender.of(p).system("SERVER_START_OVERLOAD");
|
ChatSender.of(p).system("SERVER_START_OVERLOAD");
|
||||||
|
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(worldName == null)
|
if(worldName == null)
|
||||||
@ -240,23 +247,46 @@ public class ServerStarter {
|
|||||||
worldSetup.run();
|
worldSetup.run();
|
||||||
arguments.put("logPath", worldName);
|
arguments.put("logPath", worldName);
|
||||||
|
|
||||||
Subserver subserver = constructor.construct(serverName, port, node.startServer(
|
File checkpointDir = new File("/tmp/" + System.getProperty("user.name") + ".checkpoints/" + directory.getName() + "/" + worldName);
|
||||||
serverJar, directory, worldDir, worldName, port, xmx, arguments.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).toArray(String[]::new)
|
if(checkpoint)
|
||||||
), worldCleanup);
|
arguments.put("checkpoint", checkpointDir.getPath());
|
||||||
|
|
||||||
|
if(checkpoint && checkpointDir.exists()) {
|
||||||
|
try {
|
||||||
|
new DataOutputStream(Files.newOutputStream(new File(checkpointDir, "port").toPath())).writeInt(port);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new SecurityException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
postStart(constructor.construct(serverName, port, node.prepareExecution(
|
||||||
|
"criu", "restore", "-D", checkpointDir.getPath(), "--auto-dedup", "--shell-job", "-v"
|
||||||
|
), worldCleanup, e -> regularStart(serverName, port)));
|
||||||
|
} else {
|
||||||
|
regularStart(serverName, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void regularStart(String serverName, int port) {
|
||||||
|
postStart(constructor.construct(serverName, port, node.startServer(
|
||||||
|
serverJar, directory, worldDir, worldName, port, xmx, arguments.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).toArray(String[]::new)
|
||||||
|
), worldCleanup, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void postStart(Subserver subserver) {
|
||||||
for(ProxiedPlayer p : playersToSend)
|
for(ProxiedPlayer p : playersToSend)
|
||||||
SubserverSystem.sendPlayer(subserver, p);
|
SubserverSystem.sendPlayer(subserver, p);
|
||||||
|
|
||||||
return subserver;
|
callback.accept(subserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean startingBau(ProxiedPlayer p) {
|
private static boolean startingBau(ProxiedPlayer p) {
|
||||||
for (Subserver subserver : Subserver.getServerList()) {
|
Bauserver subserver = Bauserver.get(p.getUniqueId());
|
||||||
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(p.getUniqueId()) && !subserver.hasStarted()) {
|
if(subserver != null && !subserver.isStarted()) {
|
||||||
Message.send("BAU_START_ALREADY", p);
|
ChatSender.of(p).system("BAU_START_ALREADY");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +303,7 @@ public class ServerStarter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private interface ServerConstructor {
|
private interface ServerConstructor {
|
||||||
Subserver construct(String serverName, int port, ProcessBuilder builder, Runnable shutdownCallback);
|
Subserver construct(String serverName, int port, ProcessBuilder builder, Runnable shutdownCallback, Consumer<Exception> failureCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Portrange {
|
private static class Portrange {
|
||||||
@ -312,6 +342,7 @@ public class ServerStarter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
public enum Version {
|
public enum Version {
|
||||||
SPIGOT_12("spigot-1.12.2.jar", 12),
|
SPIGOT_12("spigot-1.12.2.jar", 12),
|
||||||
SPIGOT_15("spigot-1.15.2.jar", 15),
|
SPIGOT_15("spigot-1.15.2.jar", 15),
|
||||||
@ -326,14 +357,6 @@ public class ServerStarter {
|
|||||||
this.versionSuffix = versionSuffix;
|
this.versionSuffix = versionSuffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServerJar() {
|
|
||||||
return serverJar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getVersionSuffix() {
|
|
||||||
return versionSuffix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWorldFolder(String base) {
|
public String getWorldFolder(String base) {
|
||||||
return base + versionSuffix + "/";
|
return base + versionSuffix + "/";
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren