mirror of
https://github.com/GeyserMC/GeyserConnect.git
synced 2025-06-26 14:15:22 +02:00
Add automatic shutdown when proxy is empty
This commit is contained in:
parent
166006594b
commit
03979f2808
5 changed files with 40 additions and 4 deletions
|
@ -22,7 +22,7 @@ GeyserConnect is a server that Minecraft: Bedrock Edition clients can connect to
|
||||||
- [x] Add
|
- [x] Add
|
||||||
- [x] Remove
|
- [x] Remove
|
||||||
- [x] Edit
|
- [x] Edit
|
||||||
- [ ] Stop Geyser server after its idle for a while
|
- [x] Stop Geyser server after its idle for a while
|
||||||
- [x] Config file
|
- [x] Config file
|
||||||
- [x] Fix server images not loading straight away on Win10
|
- [x] Fix server images not loading straight away on Win10
|
||||||
- [x] Per server online/offline mode
|
- [x] Per server online/offline mode
|
||||||
|
|
|
@ -76,6 +76,9 @@ public class GeyserConnectConfig {
|
||||||
|
|
||||||
@JsonProperty("debug-mode")
|
@JsonProperty("debug-mode")
|
||||||
private boolean debugMode;
|
private boolean debugMode;
|
||||||
|
|
||||||
|
@JsonProperty("shutdown-time")
|
||||||
|
private int shutdownTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
|
|
@ -29,6 +29,7 @@ package org.geysermc.connect;
|
||||||
import com.nukkitx.protocol.bedrock.*;
|
import com.nukkitx.protocol.bedrock.*;
|
||||||
import com.nukkitx.protocol.bedrock.v390.Bedrock_v390;
|
import com.nukkitx.protocol.bedrock.v390.Bedrock_v390;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.geysermc.connect.utils.Server;
|
import org.geysermc.connect.utils.Server;
|
||||||
import org.geysermc.connector.utils.FileUtils;
|
import org.geysermc.connector.utils.FileUtils;
|
||||||
import org.geysermc.connect.proxy.GeyserProxyBootstrap;
|
import org.geysermc.connect.proxy.GeyserProxyBootstrap;
|
||||||
|
@ -78,6 +79,10 @@ public class MasterServer {
|
||||||
@Getter
|
@Getter
|
||||||
private AbstractStorageManager storageManager;
|
private AbstractStorageManager storageManager;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private long lastDisconnectTime = 0l;
|
||||||
|
|
||||||
public MasterServer() {
|
public MasterServer() {
|
||||||
this.instance = this;
|
this.instance = this;
|
||||||
|
|
||||||
|
@ -97,6 +102,8 @@ public class MasterServer {
|
||||||
|
|
||||||
this.generalThreadPool = Executors.newScheduledThreadPool(32);
|
this.generalThreadPool = Executors.newScheduledThreadPool(32);
|
||||||
|
|
||||||
|
boolean enableShutdownTimer = geyserConnectConfig.getGeyser().getShutdownTime() != -1;
|
||||||
|
|
||||||
// Start a timer to keep the thread running
|
// Start a timer to keep the thread running
|
||||||
timer = new Timer();
|
timer = new Timer();
|
||||||
TimerTask task = new TimerTask() { public void run() { } };
|
TimerTask task = new TimerTask() { public void run() { } };
|
||||||
|
@ -157,9 +164,7 @@ public class MasterServer {
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
shuttingDown = true;
|
shuttingDown = true;
|
||||||
|
|
||||||
if (geyserProxy != null) {
|
shutdownGeyserProxy();
|
||||||
geyserProxy.onDisable();
|
|
||||||
}
|
|
||||||
|
|
||||||
generalThreadPool.shutdown();
|
generalThreadPool.shutdown();
|
||||||
storageManager.closeStorage();
|
storageManager.closeStorage();
|
||||||
|
@ -172,4 +177,11 @@ public class MasterServer {
|
||||||
geyserProxy.onEnable();
|
geyserProxy.onEnable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void shutdownGeyserProxy() {
|
||||||
|
if (geyserProxy != null) {
|
||||||
|
geyserProxy.onDisable();
|
||||||
|
geyserProxy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ import org.geysermc.connector.network.ConnectorServerEventHandler;
|
||||||
import org.geysermc.connect.MasterServer;
|
import org.geysermc.connect.MasterServer;
|
||||||
import org.geysermc.connect.utils.Player;
|
import org.geysermc.connect.utils.Player;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ProxyConnectorServerEventHandler extends ConnectorServerEventHandler {
|
public class ProxyConnectorServerEventHandler extends ConnectorServerEventHandler {
|
||||||
|
|
||||||
private final GeyserConnector connector;
|
private final GeyserConnector connector;
|
||||||
|
@ -56,6 +58,21 @@ public class ProxyConnectorServerEventHandler extends ConnectorServerEventHandle
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
MasterServer.getInstance().getLogger().debug("Player disconnected from Geyser proxy: " + player.getDisplayName() + " (" + disconnectReason + ")");
|
MasterServer.getInstance().getLogger().debug("Player disconnected from Geyser proxy: " + player.getDisplayName() + " (" + disconnectReason + ")");
|
||||||
MasterServer.getInstance().getPlayers().remove(session.getAuthData().getXboxUUID());
|
MasterServer.getInstance().getPlayers().remove(session.getAuthData().getXboxUUID());
|
||||||
|
|
||||||
|
// Set the last disconnect time
|
||||||
|
MasterServer.getInstance().setLastDisconnectTime(System.currentTimeMillis());
|
||||||
|
|
||||||
|
int shutdownTime = MasterServer.getInstance().getGeyserConnectConfig().getGeyser().getShutdownTime();
|
||||||
|
|
||||||
|
if (shutdownTime != -1) {
|
||||||
|
MasterServer.getInstance().getGeneralThreadPool().schedule(() -> {
|
||||||
|
if (System.currentTimeMillis() - MasterServer.getInstance().getLastDisconnectTime() > shutdownTime * 1000
|
||||||
|
&& connector != null
|
||||||
|
&& connector.getPlayers().size() <= 0) {
|
||||||
|
MasterServer.getInstance().shutdownGeyserProxy();
|
||||||
|
}
|
||||||
|
}, shutdownTime, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,10 @@ geyser:
|
||||||
# If debug messages should be sent through console, has to be enabled in both places to work
|
# If debug messages should be sent through console, has to be enabled in both places to work
|
||||||
debug-mode: false
|
debug-mode: false
|
||||||
|
|
||||||
|
# The time to wait after the last player disconnects to shutdown the proxy
|
||||||
|
# In seconds, set to -1 to disable
|
||||||
|
shutdown-time: 300
|
||||||
|
|
||||||
# A global list of servers sent to all clients
|
# A global list of servers sent to all clients
|
||||||
servers:
|
servers:
|
||||||
- address: "play.cubecraft.net"
|
- address: "play.cubecraft.net"
|
||||||
|
|
Loading…
Add table
Reference in a new issue