Skip to content

Commit

Permalink
checkpoint before isolation
Browse files Browse the repository at this point in the history
  • Loading branch information
bundabrg committed Sep 17, 2020
1 parent c3bae9a commit 46ccf28
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 139 deletions.
14 changes: 2 additions & 12 deletions geyser-reversion/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,9 @@
</artifactSet>
<relocations>
<relocation>
<pattern>com.nukkitx.protocol.bedrock</pattern>
<shadedPattern>au.com.grieve.geyser.reversion.shaded.nukkitx.protocol.bedrock
<pattern>com.nukkitx.protocol</pattern>
<shadedPattern>au.com.grieve.geyser.reversion.shaded.nukkitx.protocol
</shadedPattern>
<excludes>
<!-- <exclude>com.nukkitx.protocol.bedrock.BedrockServer</exclude>-->
<!-- <exclude>com.nukkitx.protocol.bedrock.BedrockServerSession</exclude>-->
<!-- <exclude>com.nukkitx.protocol.bedrock.BedrockServerEventHandler</exclude>-->
<!-- <exclude>com.nukkitx.protocol.bedrock.BedrockPong</exclude>-->
<!-- <exclude>com.nukkitx.protocol.bedrock.BedrockWrapperSerializer</exclude>-->
<!-- <exclude>com.nukkitx.protocol.bedrock.BedrockPacketCodec$1</exclude>-->
<!-- <exclude>com.nukkitx.protocol.bedrock.BedrockPacketCodec$Builder</exclude>-->
<!-- <exclude>com.nukkitx.protocol.bedrock.BedrockPacketHelper</exclude>-->
</excludes>
</relocation>
</relocations>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class GeyserReversionExtension extends GeyserExtension {
private final Map<String, Edition> registeredEditions = new HashMap<>();
private final List<RegisteredTranslator> registeredTranslators = new ArrayList<>();

private ReversionServer server;

private Configuration config;

public GeyserReversionExtension(ExtensionManager extensionManager, ExtensionClassLoader extensionClassLoader) {
Expand Down Expand Up @@ -137,7 +139,7 @@ private void loadConfig() {
/**
* Replace Geyser BedrockServer with one provided by an edition
*/
@GeyserEventHandler(priority = EventHandler.PRIORITY.HIGH)
@GeyserEventHandler(priority = EventHandler.PRIORITY.LOW)
public void onGeyserStart(GeyserStartEvent event) {
Edition edition = registeredEditions.get(config.getEdition());

Expand All @@ -148,22 +150,23 @@ public void onGeyserStart(GeyserStartEvent event) {

InetSocketAddress address = GeyserConnector.getInstance().getBedrockServer().getBindAddress();

// Create a new server on the same address/port as the default server
server = edition.createReversionServer(GeyserConnector.getInstance().getBedrockServer().getBindAddress());

try {
Field bedrockServer = GeyserConnector.class.getDeclaredField("bedrockServer");
bedrockServer.setAccessible(true);

ReversionServer server = edition.createReversionServer(GeyserConnector.getInstance().getBedrockServer().getBindAddress());

GeyserConnector.getInstance().getBedrockServer().close();
bedrockServer.set(GeyserConnector.getInstance(), server);
// bedrockServer.set(GeyserConnector.getInstance(), server);

} catch (NoSuchFieldException | IllegalAccessException e) {
} catch (NoSuchFieldException e) {
getLogger().error(String.format("Unable to set Edition '%s'. Extension disabled.", config.getEdition()), e);
}

// Give the old BedrockServer time to close down
// Give the old BedrockServer time to close down then bind our default server
GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> {
GeyserConnector.getInstance().getBedrockServer().bind().whenComplete((avoid, throwable) -> {
server.bind().whenComplete((avoid, throwable) -> {
if (throwable != null) {
getLogger().severe(LanguageUtils.getLocaleStringLog("geyser.core.fail", address.getAddress().toString(), address.getPort()));
throwable.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
import au.com.grieve.reversion.api.RegisteredTranslator;
import au.com.grieve.reversion.api.ReversionServer;
import au.com.grieve.reversion.editions.bedrock.BedrockRegisteredTranslator;
import au.com.grieve.reversion.editions.bedrock.BedrockReversionServer;
import lombok.RequiredArgsConstructor;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.BedrockProtocol;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;

@RequiredArgsConstructor
Expand All @@ -40,16 +39,7 @@ public class BedrockEdition implements Edition {
public ReversionServer createReversionServer(InetSocketAddress address) {
extension.getLogger().info("BedrockServer listening on " + address.toString());

int version = 0;
try {
Object toCodec = BedrockProtocol.SUPPORTED_BEDROCK_CODECS.get(BedrockProtocol.SUPPORTED_BEDROCK_CODECS.size() - 1);
Method getProtocolVersion = toCodec.getClass().getMethod("getProtocolVersion");
version = (int) getProtocolVersion.invoke(toCodec);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}

GeyserReversionServer server = new GeyserReversionServer("bedrock", version, address);
BedrockReversionServer server = new BedrockReversionServer(BedrockProtocol.DEFAULT_BEDROCK_CODEC, address);
server.setHandler(new BedrockServerEventHandler(GeyserConnector.getInstance()));

for (RegisteredTranslator translator : extension.getRegisteredTranslators()) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void onGeyserStart(GeyserStartEvent event) {
@Override
public ReversionServer createReversionServer(InetSocketAddress address) {
extension.getLogger().info("EducationServer listening on " + address.toString());
EducationReversionServer server = new EducationReversionServer("geyser-bedrock", BedrockProtocol.DEFAULT_BEDROCK_CODEC, tokenManager, address);
EducationReversionServer server = new EducationReversionServer(BedrockProtocol.DEFAULT_BEDROCK_CODEC, tokenManager, address);
server.setHandler(new BedrockServerEventHandler(GeyserConnector.getInstance()));

for (RegisteredTranslator translator : extension.getRegisteredTranslators()) {
Expand Down

0 comments on commit 46ccf28

Please sign in to comment.