2020-05-23 21:50:04 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2020-05-23 21:50:04 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* 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:
|
2020-05-23 21:50:04 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2020-05-23 21:50:04 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* 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.
|
2020-05-23 21:50:04 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
2020-05-23 21:50:04 +00:00
|
|
|
*/
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
package org.geysermc.geyser.platform.bungeecord;
|
2020-05-23 21:50:04 +00:00
|
|
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import net.md_5.bungee.api.ProxyServer;
|
|
|
|
import net.md_5.bungee.api.ServerPing;
|
|
|
|
import net.md_5.bungee.api.chat.BaseComponent;
|
2021-12-23 04:05:56 +00:00
|
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
2020-05-23 21:50:04 +00:00
|
|
|
import net.md_5.bungee.api.config.ListenerInfo;
|
|
|
|
import net.md_5.bungee.api.connection.PendingConnection;
|
|
|
|
import net.md_5.bungee.api.event.ProxyPingEvent;
|
|
|
|
import net.md_5.bungee.api.plugin.Listener;
|
|
|
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.ping.GeyserPingInfo;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
|
2020-05-23 21:50:04 +00:00
|
|
|
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.net.SocketAddress;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, Listener {
|
|
|
|
|
|
|
|
private final ProxyServer proxyServer;
|
|
|
|
|
|
|
|
@Override
|
2020-12-07 19:04:50 +00:00
|
|
|
public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
|
2020-05-23 21:50:04 +00:00
|
|
|
CompletableFuture<ProxyPingEvent> future = new CompletableFuture<>();
|
2020-12-07 19:04:50 +00:00
|
|
|
proxyServer.getPluginManager().callEvent(new ProxyPingEvent(new GeyserPendingConnection(inetSocketAddress), getPingInfo(), (event, throwable) -> {
|
2021-12-23 04:05:56 +00:00
|
|
|
if (throwable != null) {
|
|
|
|
future.completeExceptionally(throwable);
|
|
|
|
} else {
|
|
|
|
future.complete(event);
|
|
|
|
}
|
2020-05-23 21:50:04 +00:00
|
|
|
}));
|
|
|
|
ProxyPingEvent event = future.join();
|
2020-07-04 21:35:48 +00:00
|
|
|
ServerPing response = event.getResponse();
|
2023-11-13 23:17:40 +00:00
|
|
|
return new GeyserPingInfo(
|
2020-07-04 21:35:48 +00:00
|
|
|
response.getDescriptionComponent().toLegacyText(),
|
2023-11-13 23:17:40 +00:00
|
|
|
response.getPlayers().getMax(),
|
|
|
|
response.getPlayers().getOnline()
|
2020-05-23 21:50:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is static so pending connection can use it
|
|
|
|
private static ListenerInfo getDefaultListener() {
|
|
|
|
return ProxyServer.getInstance().getConfig().getListeners().iterator().next();
|
|
|
|
}
|
|
|
|
|
|
|
|
private ServerPing getPingInfo() {
|
|
|
|
return new ServerPing(
|
2021-12-23 04:05:56 +00:00
|
|
|
new ServerPing.Protocol(
|
|
|
|
proxyServer.getName() + " " + ProtocolConstants.SUPPORTED_VERSIONS.get(0) + "-" + ProtocolConstants.SUPPORTED_VERSIONS.get(ProtocolConstants.SUPPORTED_VERSIONS.size() - 1),
|
|
|
|
ProtocolConstants.SUPPORTED_VERSION_IDS.get(ProtocolConstants.SUPPORTED_VERSION_IDS.size() - 1)),
|
2020-05-23 21:50:04 +00:00
|
|
|
new ServerPing.Players(getDefaultListener().getMaxPlayers(), proxyServer.getOnlineCount(), null),
|
2021-12-23 04:05:56 +00:00
|
|
|
TextComponent.fromLegacyText(getDefaultListener().getMotd())[0],
|
|
|
|
proxyServer.getConfig().getFaviconObject()
|
2020-05-23 21:50:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class GeyserPendingConnection implements PendingConnection {
|
|
|
|
|
|
|
|
private static final UUID FAKE_UUID = UUID.nameUUIDFromBytes("geyser!internal".getBytes());
|
2020-12-07 19:04:50 +00:00
|
|
|
|
|
|
|
private final InetSocketAddress remote;
|
|
|
|
|
|
|
|
public GeyserPendingConnection(InetSocketAddress remote) {
|
|
|
|
this.remote = remote;
|
|
|
|
}
|
2020-05-23 21:50:04 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getVersion() {
|
|
|
|
return ProtocolConstants.SUPPORTED_VERSION_IDS.get(ProtocolConstants.SUPPORTED_VERSION_IDS.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public InetSocketAddress getVirtualHost() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ListenerInfo getListener() {
|
|
|
|
return getDefaultListener();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getUUID() {
|
|
|
|
return FAKE_UUID.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public UUID getUniqueId() {
|
|
|
|
return FAKE_UUID;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setUniqueId(UUID uuid) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOnlineMode() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setOnlineMode(boolean b) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isLegacy() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public InetSocketAddress getAddress() {
|
2020-12-07 19:04:50 +00:00
|
|
|
return remote;
|
2020-05-23 21:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public SocketAddress getSocketAddress() {
|
|
|
|
return getAddress();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void disconnect(String s) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void disconnect(BaseComponent... baseComponents) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void disconnect(BaseComponent baseComponent) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isConnected() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Unsafe unsafe() {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|