forked from GeyserMC/Geyser
Rewrite Ping Passthrough (#468)
* Fix ping passthrough on BungeeCord * Initial implementation of direct ping passthrough * Finished implementation of direct ping passthrough * Remove test for something else entirely * Fix standalone * Add config option for ping passthrough interval * Use GeyserPingInfo to reduce methods * Add querying; modify ping passthrough * Add separate config options for passthrough MOTD and player counts * Convert all plugin bootstraps to use internal ping events to that other plugins can handle ping modifications * Small changes * Fix invalid packet spawm * Add legacy ping passthrough option * Fix BungeeCord * Proper UUID for BungeeCord, thanks @theminecoder * Update config version and messages * Merge master... again * Add missing javadocs and minor changes Co-authored-by: James Harrison <james@fasttortoise.co.uk> Co-authored-by: theminecoder <theminecoder.dev@gmail.com> Co-authored-by: Redned <redned235@gmail.com>
This commit is contained in:
parent
59da87a10f
commit
99f69b3a7d
26 changed files with 1108 additions and 106 deletions
|
@ -85,8 +85,23 @@ public class GeyserSpongeConfiguration implements GeyserConfiguration {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isPingPassthrough() {
|
||||
return node.getNode("ping-passthrough").getBoolean(false);
|
||||
public boolean isPassthroughMotd() {
|
||||
return node.getNode("passthrough-motd").getBoolean(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPassthroughPlayerCounts() {
|
||||
return node.getNode("passthrough-player-counts").getBoolean(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLegacyPingPassthrough() {
|
||||
return node.getNode("legacy-ping-passthrough").getBoolean(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPingPassthroughInterval() {
|
||||
return node.getNode("ping-passthrough-interval").getInt(3);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*
|
||||
*/
|
||||
|
||||
package org.geysermc.platform.sponge;
|
||||
|
||||
import org.geysermc.common.ping.GeyserPingInfo;
|
||||
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
||||
import org.spongepowered.api.MinecraftVersion;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.event.SpongeEventFactory;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.cause.EventContext;
|
||||
import org.spongepowered.api.event.server.ClientPingServerEvent;
|
||||
import org.spongepowered.api.network.status.StatusClient;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Optional;
|
||||
|
||||
public class GeyserSpongePingPassthrough implements IGeyserPingPassthrough {
|
||||
|
||||
private static final GeyserStatusClient STATUS_CLIENT = new GeyserStatusClient();
|
||||
private static final Cause CAUSE = Cause.of(EventContext.empty(), Sponge.getServer());
|
||||
|
||||
private static Method SpongeStatusResponse_create;
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public GeyserPingInfo getPingInformation() {
|
||||
// come on Sponge, this is in commons, why not expose it :(
|
||||
ClientPingServerEvent event;
|
||||
try {
|
||||
if(SpongeStatusResponse_create == null) {
|
||||
Class SpongeStatusResponse = Class.forName("org.spongepowered.common.network.status.SpongeStatusResponse");
|
||||
Class MinecraftServer = Class.forName("net.minecraft.server.MinecraftServer");
|
||||
SpongeStatusResponse_create = SpongeStatusResponse.getDeclaredMethod("create", MinecraftServer);
|
||||
}
|
||||
|
||||
Object response = SpongeStatusResponse_create.invoke(null, Sponge.getServer());
|
||||
event = SpongeEventFactory.createClientPingServerEvent(CAUSE, STATUS_CLIENT, (ClientPingServerEvent.Response) response);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Sponge.getEventManager().post(event);
|
||||
GeyserPingInfo geyserPingInfo = new GeyserPingInfo(
|
||||
event.getResponse().getDescription().toPlain(),
|
||||
event.getResponse().getPlayers().orElseThrow(IllegalStateException::new).getOnline(),
|
||||
event.getResponse().getPlayers().orElseThrow(IllegalStateException::new).getMax());
|
||||
event.getResponse().getPlayers().get().getProfiles().forEach(player -> {
|
||||
geyserPingInfo.addPlayer(player.getName().orElseThrow(IllegalStateException::new));
|
||||
});
|
||||
return geyserPingInfo;
|
||||
}
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
private static class GeyserStatusClient implements StatusClient {
|
||||
|
||||
private static final InetSocketAddress FAKE_REMOTE = new InetSocketAddress(Inet4Address.getLoopbackAddress(), 69);
|
||||
|
||||
@Override
|
||||
public InetSocketAddress getAddress() {
|
||||
return FAKE_REMOTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MinecraftVersion getVersion() {
|
||||
return Sponge.getPlatform().getMinecraftVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<InetSocketAddress> getVirtualHost() {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,6 +34,8 @@ import org.geysermc.connector.GeyserConfiguration;
|
|||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.bootstrap.GeyserBootstrap;
|
||||
import org.geysermc.connector.command.CommandManager;
|
||||
import org.geysermc.connector.ping.GeyserLegacyPingPassthrough;
|
||||
import org.geysermc.connector.ping.IGeyserPingPassthrough;
|
||||
import org.geysermc.connector.utils.FileUtils;
|
||||
import org.geysermc.platform.sponge.command.GeyserSpongeCommandExecutor;
|
||||
import org.geysermc.platform.sponge.command.GeyserSpongeCommandManager;
|
||||
|
@ -63,6 +65,7 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
|
|||
private GeyserSpongeCommandManager geyserCommandManager;
|
||||
private GeyserSpongeConfiguration geyserConfig;
|
||||
private GeyserSpongeLogger geyserLogger;
|
||||
private IGeyserPingPassthrough geyserSpongePingPassthrough;
|
||||
|
||||
private GeyserConnector connector;
|
||||
|
||||
|
@ -108,8 +111,14 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
|
|||
this.geyserLogger = new GeyserSpongeLogger(logger, geyserConfig.isDebugMode());
|
||||
GeyserConfiguration.checkGeyserConfiguration(geyserConfig, geyserLogger);
|
||||
this.connector = GeyserConnector.start(PlatformType.SPONGE, this);
|
||||
this.geyserCommandManager = new GeyserSpongeCommandManager(Sponge.getCommandManager(), connector);
|
||||
|
||||
if (geyserConfig.isLegacyPingPassthrough()) {
|
||||
this.geyserSpongePingPassthrough = GeyserLegacyPingPassthrough.init(connector);
|
||||
} else {
|
||||
this.geyserSpongePingPassthrough = new GeyserSpongePingPassthrough();
|
||||
}
|
||||
|
||||
this.geyserCommandManager = new GeyserSpongeCommandManager(Sponge.getCommandManager(), connector);
|
||||
Sponge.getCommandManager().register(this, new GeyserSpongeCommandExecutor(connector), "geyser");
|
||||
}
|
||||
|
||||
|
@ -133,6 +142,11 @@ public class GeyserSpongePlugin implements GeyserBootstrap {
|
|||
return this.geyserCommandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGeyserPingPassthrough getGeyserPingPassthrough() {
|
||||
return geyserSpongePingPassthrough;
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onServerStart(GameStartedServerEvent event) {
|
||||
onEnable();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue