Archiviert
1
0

Checkpoint support

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2024-01-16 15:45:46 +01:00
Ursprung 9567bd4c3f
Commit f0e85c21ce
7 geänderte Dateien mit 45 neuen und 67 gelöschten Zeilen

Datei anzeigen

@ -54,7 +54,7 @@ public class EventStarter implements Runnable {
@Override @Override
public void run() { public void run() {
eventServer.entrySet().removeIf(entry -> !Subserver.getServerList().contains(entry.getValue())); eventServer.entrySet().removeIf(entry -> Subserver.getSubserver(entry.getValue().getServer()) == null);
Queue<EventFight> fights = EventFight.getFights(); Queue<EventFight> fights = EventFight.getFights();
EventFight next; EventFight next;
@ -70,10 +70,11 @@ public class EventStarter implements Runnable {
if(leiter != null) if(leiter != null)
starter.send(leiter); starter.send(leiter);
Subserver subserver = starter.start(); starter.callback(subserver -> {
eventServer.put(blue.getTeamId(), subserver); eventServer.put(blue.getTeamId(), subserver);
eventServer.put(red.getTeamId(), subserver); eventServer.put(red.getTeamId(), subserver);
}).start();
Message.broadcast("EVENT_FIGHT_BROADCAST", "EVENT_FIGHT_BROADCAST_HOVER", Message.broadcast("EVENT_FIGHT_BROADCAST", "EVENT_FIGHT_BROADCAST_HOVER",
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/event " + blue.getTeamKuerzel()), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName()); new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/event " + blue.getTeamKuerzel()), blue.getTeamColor(), blue.getTeamName(), red.getTeamColor(), red.getTeamName());
} else { } else {

Datei anzeigen

@ -23,6 +23,7 @@ import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import java.io.*; import java.io.*;
import java.nio.file.Files;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -30,7 +31,12 @@ import java.util.logging.Level;
public abstract class Node { public abstract class Node {
private static final List<String> OPENJ9_ARGS = Arrays.asList("-Xgc:excessiveGCratio=80", "-Xsyslog:none", "-Xtrace:none", "-Xdisableexplicitgc", "-XX:+AlwaysPreTouch", "-XX:+CompactStrings", "-XX:-HeapDumpOnOutOfMemory", "-XX:+ExitOnOutOfMemoryError", "-Dlog4j.configurationFile=log4j2.xml", "-Dio.netty.allocator.numHeapArenas=1", "-Xnoclassgc", "-Xmos128M", "-Xmns48M"); // initial heap half values of memory observed by 1.19 spectate server private static final List<String> OPENJ9_ARGS = Arrays.asList(
"-XX:+EnableCRIUSupport", "-XX:-CRIURestoreNonPortableMode",
"-Xgc:excessiveGCratio=80", "-Xdisableexplicitgc", "-Xnoclassgc", "-Xmos128M", "-Xmns48M", "-XX:+ExitOnOutOfMemoryError", // initial heap half values of memory observed by 1.19 spectate server
"-Xsyslog:none", "-Xtrace:none", "-Xverify:none",
"-Dlog4j.configurationFile=log4j2.xml"
);
private static final Set<String> JAVA_8 = new HashSet<>(); private static final Set<String> JAVA_8 = new HashSet<>();
static { static {
JAVA_8.add("paper-1.8.8.jar"); JAVA_8.add("paper-1.8.8.jar");
@ -41,7 +47,6 @@ public abstract class Node {
} }
private static final long MIN_FREE_MEM = 4 * 1024 * 1024L; // 4 GiB private static final long MIN_FREE_MEM = 4 * 1024 * 1024L; // 4 GiB
private static final double MAX_LOAD = 0.8;
private static final List<Node> nodes = new ArrayList<>(); private static final List<Node> nodes = new ArrayList<>();
@ -65,9 +70,6 @@ public abstract class Node {
protected final String hostname; protected final String hostname;
protected volatile boolean belowLoadLimit = true; protected volatile boolean belowLoadLimit = true;
private long previousCpuLoaded = 0;
private long previousCpuTotal = 0;
protected Node(String hostname) { protected Node(String hostname) {
this.hostname = hostname; this.hostname = hostname;
nodes.add(this); nodes.add(this);
@ -101,12 +103,13 @@ public abstract class Node {
for(String param : dParams){ for(String param : dParams){
cmd.add("-D" + param); cmd.add("-D" + param);
} }
cmd.add("-Xmx" + xmx);
cmd.add("-Xshareclasses:nonfatal,name=" + directory.getName()); cmd.add("-Xshareclasses:nonfatal,name=" + directory.getName());
cmd.add("-Xmx" + xmx);
cmd.addAll(OPENJ9_ARGS); cmd.addAll(OPENJ9_ARGS);
if (!JAVA_8.contains(serverJar)) { if (!JAVA_8.contains(serverJar)) {
cmd.add("--add-opens"); cmd.add("--add-opens");
cmd.add("java.base/jdk.internal.misc=ALL-UNNAMED"); cmd.add("java.base/jdk.internal.misc=ALL-UNNAMED");
cmd.add("-XX:-CRIUSecProvider");
} }
cmd.add("-jar"); cmd.add("-jar");
cmd.add("/binarys/" + serverJar); cmd.add("/binarys/" + serverJar);
@ -120,28 +123,18 @@ public abstract class Node {
cmd.add("nogui"); cmd.add("nogui");
} }
protected void calcLoadLimit(BufferedReader stat, BufferedReader meminfo) throws IOException { protected void calcLoadLimit(BufferedReader meminfo) throws IOException {
String[] cpuline = stat.readLine().split(" "); // 0-1: prefix, 2: user, 3: nice, 4: system, 5: idle, 6: iowait, 7: irq, 8: softirq, 9: steal, 10: guest, 11: guest_nice
long cpuLoaded = Long.parseLong(cpuline[2]) + Long.parseLong(cpuline[4]) + Long.parseLong(cpuline[6]) + Long.parseLong(cpuline[7]) + Long.parseLong(cpuline[8]) + Long.parseLong(cpuline[9]) + Long.parseLong(cpuline[10]) + Long.parseLong(cpuline[11]);
long cpuTotal = cpuLoaded + Long.parseLong(cpuline[3]) + Long.parseLong(cpuline[5]);
cpuLoaded -= previousCpuLoaded;
cpuTotal -= previousCpuTotal;
previousCpuLoaded += cpuLoaded;
previousCpuTotal += cpuTotal;
String line = meminfo.readLine(); String line = meminfo.readLine();
while(!line.startsWith("MemAvailable")) { while(!line.startsWith("MemAvailable")) {
line = meminfo.readLine(); line = meminfo.readLine();
} }
long availableMem = Long.parseLong(line.replaceAll(" +", " ").split(" ")[1]); long availableMem = Long.parseLong(line.replaceAll(" +", " ").split(" ")[1]);
belowLoadLimit = cpuLoaded / (double)cpuTotal <= MAX_LOAD && availableMem >= MIN_FREE_MEM; belowLoadLimit = availableMem >= MIN_FREE_MEM;
} }
public static class LocalNode extends Node { public static class LocalNode extends Node {
private static final File MEMINFO = new File("/proc/meminfo"); private static final File MEMINFO = new File("/proc/meminfo");
private static final File STAT = new File("/proc/stat");
public LocalNode() { public LocalNode() {
super("sw"); super("sw");
@ -158,10 +151,8 @@ public abstract class Node {
@Override @Override
protected void calcLoadLimit() { protected void calcLoadLimit() {
try (BufferedReader loadavg = new BufferedReader(new InputStreamReader(new FileInputStream(STAT)))) { try (BufferedReader meminfo = new BufferedReader(new InputStreamReader(Files.newInputStream(MEMINFO.toPath())))) {
try (BufferedReader meminfo = new BufferedReader(new InputStreamReader(new FileInputStream(MEMINFO)))) { calcLoadLimit(meminfo);
calcLoadLimit(loadavg, meminfo);
}
} catch (IOException e) { } catch (IOException e) {
BungeeCore.get().getLogger().log(Level.SEVERE, "Could not read local load", e); BungeeCore.get().getLogger().log(Level.SEVERE, "Could not read local load", e);
belowLoadLimit = false; belowLoadLimit = false;
@ -207,13 +198,11 @@ public abstract class Node {
@Override @Override
protected void calcLoadLimit() { protected void calcLoadLimit() {
try { try {
Process process = prepareExecution("cat /proc/stat /proc/meminfo").start(); Process process = prepareExecution("cat /proc/meminfo").start();
if(!process.waitFor(1, TimeUnit.SECONDS)) if(!process.waitFor(1, TimeUnit.SECONDS))
throw new IOException(hostname + " timeout"); throw new IOException(hostname + " timeout");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
if(reader == null) calcLoadLimit(reader);
throw new IOException("Why reader null? " + process.getInputStream());
calcLoadLimit(reader, reader);
} }
} catch (IOException e) { } catch (IOException e) {
if(belowLoadLimit) if(belowLoadLimit)

Datei anzeigen

@ -68,17 +68,17 @@ public class BauCommand extends SWCommand {
Map<String, ServerStarter.Version> versionMap = new HashMap<>(); Map<String, ServerStarter.Version> versionMap = new HashMap<>();
versionMap.put("20", ServerStarter.Version.PAPER_20); versionMap.put("20", ServerStarter.Version.PAPER_20);
versionMap.put("1.20", ServerStarter.Version.PAPER_20); versionMap.put("1.20", ServerStarter.Version.PAPER_20);
versionMap.put("as", ServerStarter.Version.PAPER_20);
versionMap.put("airship", ServerStarter.Version.PAPER_20);
versionMap.put("wg", ServerStarter.Version.PAPER_20);
versionMap.put("wargear", ServerStarter.Version.PAPER_20);
versionMap.put("ws", ServerStarter.Version.PAPER_20);
versionMap.put("warship", ServerStarter.Version.PAPER_20);
versionMap.put("19", ServerStarter.Version.PAPER_19); versionMap.put("19", ServerStarter.Version.PAPER_19);
versionMap.put("1.19", ServerStarter.Version.PAPER_19); versionMap.put("1.19", ServerStarter.Version.PAPER_19);
versionMap.put("mwg", ServerStarter.Version.PAPER_19); versionMap.put("mwg", ServerStarter.Version.PAPER_19);
versionMap.put("miniwargear", ServerStarter.Version.PAPER_19); versionMap.put("miniwargear", ServerStarter.Version.PAPER_19);
versionMap.put("wg", ServerStarter.Version.PAPER_19);
versionMap.put("wargear", ServerStarter.Version.PAPER_19);
versionMap.put("ws", ServerStarter.Version.PAPER_19);
versionMap.put("warship", ServerStarter.Version.PAPER_19);
versionMap.put("as", ServerStarter.Version.PAPER_19);
versionMap.put("airship", ServerStarter.Version.PAPER_19);
versionMap.put("15", ServerStarter.Version.SPIGOT_15); versionMap.put("15", ServerStarter.Version.SPIGOT_15);
versionMap.put("1.15", ServerStarter.Version.SPIGOT_15); versionMap.put("1.15", ServerStarter.Version.SPIGOT_15);
@ -294,12 +294,10 @@ public class BauCommand extends SWCommand {
private static void deleteWorld(ProxiedPlayer player, String world) { private static void deleteWorld(ProxiedPlayer player, String world) {
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
for (Subserver subserver : Subserver.getServerList()) { Bauserver subserver = Bauserver.get(player.getUniqueId());
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(player.getUniqueId())) { if(subserver != null)
subserver.stop(); subserver.stop();
break;
}
}
SubserverSystem.deleteFolder(BungeeCore.local, world); SubserverSystem.deleteFolder(BungeeCore.local, world);
Message.send("BAU_DELETE_DELETED", player); Message.send("BAU_DELETE_DELETED", player);
}); });

Datei anzeigen

@ -43,11 +43,9 @@ public class ChallengeCommand extends SWCommand {
challenges.remove(target); challenges.remove(target);
challenges.remove(p); challenges.remove(p);
Subserver arena = new ServerStarter().arena(mode, map).blueLeader(player).redLeader(target).start(); new ServerStarter().arena(mode, map).blueLeader(player).redLeader(target).callback(
if(arena != null) { arena -> Message.broadcast("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName(), target.getName())
Message.broadcast("CHALLENGE_BROADCAST", "CHALLENGE_BROADCAST_HOVER", ).start();
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName(), target.getName());
}
}else{ }else{
if(!challenges.containsKey(p)){ if(!challenges.containsKey(p)){
challenges.put(p, new LinkedList<>()); challenges.put(p, new LinkedList<>());

Datei anzeigen

@ -222,7 +222,7 @@ public class CheckCommand extends SWCommand {
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
ArenaMode mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype())); ArenaMode mode = ArenaMode.getBySchemType(fightTypes.get(schematic.getSchemtype()));
if(new ServerStarter().test(mode, mode.getRandomMap(), checker).check(schematic.getId()).start() == null) { if(!new ServerStarter().test(mode, mode.getRandomMap(), checker).check(schematic.getId()).start()) {
remove(); remove();
return; return;
} }
@ -318,12 +318,9 @@ public class CheckCommand extends SWCommand {
currentCheckers.remove(checker.getUniqueId()); currentCheckers.remove(checker.getUniqueId());
currentSchems.remove(schematic.getId()); currentSchems.remove(schematic.getId());
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> { ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
for (Subserver subserver : Subserver.getServerList()) { Bauserver subserver = Bauserver.get(checker.getUniqueId());
if (subserver.getType() == Servertype.BAUSERVER && ((Bauserver) subserver).getOwner().equals(checker.getUniqueId())) { if(subserver != null)
subserver.stop(); subserver.stop();
break;
}
}
}); });
} }

Datei anzeigen

@ -159,13 +159,11 @@ public class FightCommand extends SWCommand {
@Register @Register
public void fight(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { public void fight(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("nonHistoricArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
createArena(player, "/fight ", true, arenaMode, map, false, (p, mode, m) -> { createArena(player, "/fight ", true, arenaMode, map, false,
Subserver arena = new ServerStarter().arena(mode, m).blueLeader(p).start(); (p, mode, m) -> new ServerStarter().arena(mode, m).blueLeader(p).callback(
if(arena != null) { arena -> Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName())
Message.broadcast("FIGHT_BROADCAST", "FIGHT_BROADCAST_HOVER" ).start()
, new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName()); );
}
});
} }
/** /**

Datei anzeigen

@ -22,7 +22,6 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.ArenaMode; import de.steamwar.bungeecore.ArenaMode;
import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.ServerStarter; import de.steamwar.bungeecore.ServerStarter;
import de.steamwar.bungeecore.Subserver;
import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommand;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -35,11 +34,9 @@ public class HistoricCommand extends SWCommand {
@Register @Register
public void historic(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) { public void historic(@Validator("arenaPlayer") ProxiedPlayer player, @Mapper("historicArenaMode") @OptionalValue("") @AllowNull ArenaMode arenaMode, @Mapper("arenaMap") @OptionalValue("") @AllowNull String map) {
FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> { FightCommand.createArena(player, "/historic ", true, arenaMode, map, true, (p, mode, m) -> {
Subserver arena = new ServerStarter().arena(mode, m).blueLeader(p).start(); new ServerStarter().arena(mode, m).blueLeader(p).callback(
if(arena != null) { arena -> Message.broadcast("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName())
Message.broadcast("HISTORIC_BROADCAST", "HISTORIC_BROADCAST_HOVER", ).start();
new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/arena " + arena.getServer().getName()), mode.getDisplayName(), p.getName());
}
}); });
} }
} }