Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-19 14:30:17 +01:00
Ensure proper Geyser starting/disabling when Geyser is used on a client (#4621)
* Ensure proper Geyser starting/disabling when Geyser is used on a client * also set correct remote port * only use direct connection on server, not client, actually override remote port
Dieser Commit ist enthalten in:
Ursprung
9cb9a1450e
Commit
1291b89e64
@ -28,14 +28,15 @@ package org.geysermc.geyser.platform.fabric;
|
|||||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.geysermc.geyser.platform.mod.GeyserModBootstrap;
|
import org.geysermc.geyser.platform.mod.GeyserModBootstrap;
|
||||||
import org.geysermc.geyser.platform.mod.GeyserModUpdateListener;
|
import org.geysermc.geyser.platform.mod.GeyserModUpdateListener;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
|
|
||||||
public class GeyserFabricBootstrap extends GeyserModBootstrap implements ModInitializer {
|
public class GeyserFabricBootstrap extends GeyserModBootstrap implements ModInitializer {
|
||||||
|
|
||||||
@ -45,21 +46,37 @@ public class GeyserFabricBootstrap extends GeyserModBootstrap implements ModInit
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.SERVER) {
|
if (isServer()) {
|
||||||
// Set as an event, so we can get the proper IP and port if needed
|
// Set as an event, so we can get the proper IP and port if needed
|
||||||
ServerLifecycleEvents.SERVER_STARTED.register((server) -> {
|
ServerLifecycleEvents.SERVER_STARTED.register((server) -> {
|
||||||
this.setServer(server);
|
this.setServer(server);
|
||||||
onGeyserEnable();
|
onGeyserEnable();
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
ClientLifecycleEvents.CLIENT_STOPPING.register(($)-> {
|
||||||
|
onGeyserShutdown();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are only registered once
|
// These are only registered once
|
||||||
ServerLifecycleEvents.SERVER_STOPPING.register((server) -> onGeyserShutdown());
|
ServerLifecycleEvents.SERVER_STOPPING.register((server) -> {
|
||||||
|
if (isServer()) {
|
||||||
|
onGeyserShutdown();
|
||||||
|
} else {
|
||||||
|
onGeyserDisable();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ServerPlayConnectionEvents.JOIN.register((handler, $, $$) -> GeyserModUpdateListener.onPlayReady(handler.getPlayer()));
|
ServerPlayConnectionEvents.JOIN.register((handler, $, $$) -> GeyserModUpdateListener.onPlayReady(handler.getPlayer()));
|
||||||
|
|
||||||
this.onGeyserInitialize();
|
this.onGeyserInitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isServer() {
|
||||||
|
return FabricLoader.getInstance().getEnvironmentType().equals(EnvType.SERVER);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(@NonNull Player source, @NonNull String permissionNode) {
|
public boolean hasPermission(@NonNull Player source, @NonNull String permissionNode) {
|
||||||
return Permissions.check(source, permissionNode);
|
return Permissions.check(source, permissionNode);
|
||||||
|
@ -27,10 +27,10 @@ package org.geysermc.geyser.platform.neoforge;
|
|||||||
|
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.neoforged.api.distmarker.Dist;
|
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.fml.loading.FMLLoader;
|
import net.neoforged.fml.loading.FMLLoader;
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
|
import net.neoforged.neoforge.event.GameShuttingDownEvent;
|
||||||
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||||
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
||||||
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
|
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
|
||||||
@ -46,9 +46,11 @@ public class GeyserNeoForgeBootstrap extends GeyserModBootstrap {
|
|||||||
public GeyserNeoForgeBootstrap() {
|
public GeyserNeoForgeBootstrap() {
|
||||||
super(new GeyserNeoForgePlatform());
|
super(new GeyserNeoForgePlatform());
|
||||||
|
|
||||||
if (FMLLoader.getDist() == Dist.DEDICATED_SERVER) {
|
if (isServer()) {
|
||||||
// Set as an event so we can get the proper IP and port if needed
|
// Set as an event so we can get the proper IP and port if needed
|
||||||
NeoForge.EVENT_BUS.addListener(this::onServerStarted);
|
NeoForge.EVENT_BUS.addListener(this::onServerStarted);
|
||||||
|
} else {
|
||||||
|
NeoForge.EVENT_BUS.addListener(this::onClientStopping);
|
||||||
}
|
}
|
||||||
|
|
||||||
NeoForge.EVENT_BUS.addListener(this::onServerStopping);
|
NeoForge.EVENT_BUS.addListener(this::onServerStopping);
|
||||||
@ -64,6 +66,14 @@ public class GeyserNeoForgeBootstrap extends GeyserModBootstrap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onServerStopping(ServerStoppingEvent event) {
|
private void onServerStopping(ServerStoppingEvent event) {
|
||||||
|
if (isServer()) {
|
||||||
|
this.onGeyserShutdown();
|
||||||
|
} else {
|
||||||
|
this.onGeyserDisable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onClientStopping(GameShuttingDownEvent ignored) {
|
||||||
this.onGeyserShutdown();
|
this.onGeyserShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +81,11 @@ public class GeyserNeoForgeBootstrap extends GeyserModBootstrap {
|
|||||||
GeyserModUpdateListener.onPlayReady(event.getEntity());
|
GeyserModUpdateListener.onPlayReady(event.getEntity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isServer() {
|
||||||
|
return FMLLoader.getDist().isDedicatedServer();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(@NonNull Player source, @NonNull String permissionNode) {
|
public boolean hasPermission(@NonNull Player source, @NonNull String permissionNode) {
|
||||||
return this.permissionHandler.hasPermission(source, permissionNode);
|
return this.permissionHandler.hasPermission(source, permissionNode);
|
||||||
|
@ -58,6 +58,7 @@ import org.geysermc.geyser.util.FileUtils;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.SocketAddress;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -127,7 +128,9 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
|
|||||||
// We want to do this late in the server startup process to allow other mods
|
// We want to do this late in the server startup process to allow other mods
|
||||||
// To do their job injecting, then connect into *that*
|
// To do their job injecting, then connect into *that*
|
||||||
this.geyserInjector = new GeyserModInjector(server, this.platform);
|
this.geyserInjector = new GeyserModInjector(server, this.platform);
|
||||||
|
if (isServer()) {
|
||||||
this.geyserInjector.initializeLocalChannel(this);
|
this.geyserInjector.initializeLocalChannel(this);
|
||||||
|
}
|
||||||
|
|
||||||
// Start command building
|
// Start command building
|
||||||
// Set just "geyser" as the help command
|
// Set just "geyser" as the help command
|
||||||
@ -242,7 +245,19 @@ public abstract class GeyserModBootstrap implements GeyserBootstrap {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getServerPort() {
|
public int getServerPort() {
|
||||||
|
if (isServer()) {
|
||||||
return ((GeyserServerPortGetter) server).geyser$getServerPort();
|
return ((GeyserServerPortGetter) server).geyser$getServerPort();
|
||||||
|
} else {
|
||||||
|
// Set in the IntegratedServerMixin
|
||||||
|
return geyserConfig.getRemote().port();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean isServer();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable SocketAddress getSocketAddress() {
|
||||||
|
return this.geyserInjector.getServerSocketAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,8 +54,10 @@ public class IntegratedServerMixin implements GeyserServerPortGetter {
|
|||||||
private void onOpenToLan(GameType gameType, boolean cheatsAllowed, int port, CallbackInfoReturnable<Boolean> cir) {
|
private void onOpenToLan(GameType gameType, boolean cheatsAllowed, int port, CallbackInfoReturnable<Boolean> cir) {
|
||||||
if (cir.getReturnValueZ()) {
|
if (cir.getReturnValueZ()) {
|
||||||
// If the LAN is opened, starts Geyser.
|
// If the LAN is opened, starts Geyser.
|
||||||
GeyserModBootstrap.getInstance().setServer((MinecraftServer) (Object) this);
|
GeyserModBootstrap instance = GeyserModBootstrap.getInstance();
|
||||||
GeyserModBootstrap.getInstance().onGeyserEnable();
|
instance.setServer((MinecraftServer) (Object) this);
|
||||||
|
instance.getGeyserConfig().getRemote().setPort(port);
|
||||||
|
instance.onGeyserEnable();
|
||||||
// Ensure player locale has been loaded, in case it's different from Java system language
|
// Ensure player locale has been loaded, in case it's different from Java system language
|
||||||
GeyserLocale.loadGeyserLocale(this.minecraft.options.languageCode);
|
GeyserLocale.loadGeyserLocale(this.minecraft.options.languageCode);
|
||||||
// Give indication that Geyser is loaded
|
// Give indication that Geyser is loaded
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren