mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-11-24 19:25:16 +01:00
Added more stuff from old Waterfall
This commit is contained in:
parent
2fc007f3e4
commit
1cf5557c48
@ -0,0 +1,89 @@
|
||||
From 22251b09127f2cebcb6853666cf391f6c07641dd Mon Sep 17 00:00:00 2001
|
||||
From: Ichbinjoe <joe@ibj.io>
|
||||
Date: Sun, 3 Jul 2016 03:54:14 -0400
|
||||
Subject: [PATCH] Add timeout variant to connect methods Also added more
|
||||
connect methods to ProxiedPlayer, in addition to the new method
|
||||
|
||||
|
||||
diff --git a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java
|
||||
index 375815c..c49e900 100644
|
||||
--- a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java
|
||||
+++ b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java
|
||||
@@ -69,6 +69,38 @@ public interface ProxiedPlayer extends Connection, CommandSender
|
||||
*/
|
||||
void connect(ServerInfo target, Callback<Boolean> callback);
|
||||
|
||||
+ // Waterfall start
|
||||
+ /**
|
||||
+ * Connects / transfers this user to the specified connection, gracefully
|
||||
+ * closing the current one. Depending on the implementation, this method
|
||||
+ * might return before the user has been connected.
|
||||
+ *
|
||||
+ * @param target the new server to connect to
|
||||
+ * @param callback the method called when the connection is complete, or
|
||||
+ * when an exception is encountered. The boolean parameter denotes success
|
||||
+ * or failure.
|
||||
+ * @param retry whether to retry the connection if the initial connection
|
||||
+ * fails.
|
||||
+ */
|
||||
+ void connect(ServerInfo target, Callback<Boolean> callback, boolean retry);
|
||||
+
|
||||
+ /**
|
||||
+ * Connects / transfers this user to the specified connection, gracefully
|
||||
+ * closing the current one. Depending on the implementation, this method
|
||||
+ * might return before the user has been connected.
|
||||
+ *
|
||||
+ * @param target the new server to connect to
|
||||
+ * @param callback the method called when the connection is complete, or
|
||||
+ * when an exception is encountered. The boolean parameter denotes success
|
||||
+ * or failure.
|
||||
+ * @param retry whether to retry the connection if the initial connection
|
||||
+ * fails.
|
||||
+ * @param timeout timeout in milliseconds of the connection created to the
|
||||
+ * target server
|
||||
+ */
|
||||
+ void connect(ServerInfo target, Callback<Boolean> callback, boolean retry, int timeout);
|
||||
+ // Waterfall end
|
||||
+
|
||||
/**
|
||||
* Gets the server this player is connected to.
|
||||
*
|
||||
diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
||||
index ff103bf..47b37c0 100644
|
||||
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
||||
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
|
||||
@@ -251,6 +251,13 @@ public final class UserConnection implements ProxiedPlayer
|
||||
|
||||
public void connect(ServerInfo info, final Callback<Boolean> callback, final boolean retry)
|
||||
{
|
||||
+ // Waterfall start
|
||||
+ connect(info, callback, retry, 5000); // todo: configurable
|
||||
+ }
|
||||
+
|
||||
+ public void connect(ServerInfo info, final Callback<Boolean> callback, final boolean retry, final int timeout)
|
||||
+ {
|
||||
+ // Waterfall end
|
||||
Preconditions.checkNotNull( info, "info" );
|
||||
|
||||
ServerConnectEvent event = new ServerConnectEvent( this, info );
|
||||
@@ -319,7 +326,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
if ( retry && def != null && ( getServer() == null || def != getServer().getInfo() ) )
|
||||
{
|
||||
sendMessage( bungee.getTranslation( "fallback_lobby" ) );
|
||||
- connect( def, null, false );
|
||||
+ connect( def, null, false, timeout ); // Waterfall
|
||||
} else
|
||||
{
|
||||
disconnect( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) );
|
||||
@@ -331,7 +338,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
.channel( PipelineUtils.getChannel() )
|
||||
.group( ch.getHandle().eventLoop() )
|
||||
.handler( initializer )
|
||||
- .option( ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000 ) // TODO: Configurable
|
||||
+ .option( ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout ) // Waterfall
|
||||
.remoteAddress( target.getAddress() );
|
||||
// Windows is bugged, multi homed users will just have to live with random connecting IPs
|
||||
if ( getPendingConnection().getListener().isSetLocalAddress() && !PlatformDependent.isWindows() )
|
||||
--
|
||||
2.7.4 (Apple Git-66)
|
||||
|
219
BungeeCord-Patches/0042-Proxy-query-event.patch
Normal file
219
BungeeCord-Patches/0042-Proxy-query-event.patch
Normal file
@ -0,0 +1,219 @@
|
||||
From 2df0089bfe96dcd1abf5a192a4f21b025867bfa8 Mon Sep 17 00:00:00 2001
|
||||
From: minecrafter <unknown@unknown>
|
||||
Date: Sun, 3 Jul 2016 04:03:21 -0400
|
||||
Subject: [PATCH] Proxy query event
|
||||
|
||||
|
||||
diff --git a/api/src/main/java/io/github/waterfallmc/waterfall/QueryResult.java b/api/src/main/java/io/github/waterfallmc/waterfall/QueryResult.java
|
||||
new file mode 100644
|
||||
index 0000000..1e33cd1
|
||||
--- /dev/null
|
||||
+++ b/api/src/main/java/io/github/waterfallmc/waterfall/QueryResult.java
|
||||
@@ -0,0 +1,62 @@
|
||||
+package io.github.waterfallmc.waterfall;
|
||||
+
|
||||
+import lombok.AllArgsConstructor;
|
||||
+import lombok.Data;
|
||||
+import lombok.NonNull;
|
||||
+
|
||||
+import java.util.List;
|
||||
+
|
||||
+@Data
|
||||
+@AllArgsConstructor
|
||||
+public class QueryResult {
|
||||
+ /**
|
||||
+ * The message of the day to return.
|
||||
+ */
|
||||
+ @NonNull
|
||||
+ private String motd;
|
||||
+ /**
|
||||
+ * The game type to return, usually SMP.
|
||||
+ */
|
||||
+ @NonNull
|
||||
+ private String gameType;
|
||||
+ /**
|
||||
+ * The world name to return.
|
||||
+ */
|
||||
+ @NonNull
|
||||
+ private String worldName;
|
||||
+ /**
|
||||
+ * The number of players currently online.
|
||||
+ */
|
||||
+ @NonNull
|
||||
+ private int onlinePlayers;
|
||||
+ /**
|
||||
+ * The maximum number of players that can be online.
|
||||
+ */
|
||||
+ @NonNull
|
||||
+ private int maxPlayers;
|
||||
+ /**
|
||||
+ * The port for this server.
|
||||
+ */
|
||||
+ @NonNull
|
||||
+ private int port;
|
||||
+ /**
|
||||
+ * The hostname for this server.
|
||||
+ */
|
||||
+ @NonNull
|
||||
+ private String address;
|
||||
+ /**
|
||||
+ * The game ID for this server, usually MINECRAFT.
|
||||
+ */
|
||||
+ @NonNull
|
||||
+ private String gameId;
|
||||
+ /**
|
||||
+ * The players currently online.
|
||||
+ */
|
||||
+ @NonNull
|
||||
+ private final List<String> players;
|
||||
+ /**
|
||||
+ * The version to return for this server.
|
||||
+ */
|
||||
+ @NonNull
|
||||
+ private String version;
|
||||
+}
|
||||
diff --git a/api/src/main/java/io/github/waterfallmc/waterfall/event/ProxyQueryEvent.java b/api/src/main/java/io/github/waterfallmc/waterfall/event/ProxyQueryEvent.java
|
||||
new file mode 100644
|
||||
index 0000000..220d59f
|
||||
--- /dev/null
|
||||
+++ b/api/src/main/java/io/github/waterfallmc/waterfall/event/ProxyQueryEvent.java
|
||||
@@ -0,0 +1,28 @@
|
||||
+package io.github.waterfallmc.waterfall.event;
|
||||
+
|
||||
+import io.github.waterfallmc.waterfall.QueryResult;
|
||||
+import lombok.AllArgsConstructor;
|
||||
+import lombok.Data;
|
||||
+import lombok.EqualsAndHashCode;
|
||||
+import lombok.NonNull;
|
||||
+import net.md_5.bungee.api.config.ListenerInfo;
|
||||
+import net.md_5.bungee.api.plugin.Event;
|
||||
+
|
||||
+/**
|
||||
+ * This event will be posted whenever a Query request is received.
|
||||
+ */
|
||||
+@AllArgsConstructor
|
||||
+@EqualsAndHashCode(callSuper = false)
|
||||
+@Data
|
||||
+public class ProxyQueryEvent extends Event {
|
||||
+ /**
|
||||
+ * The listener associated with this query.
|
||||
+ */
|
||||
+ @NonNull
|
||||
+ private final ListenerInfo listener;
|
||||
+ /**
|
||||
+ * The query to return.
|
||||
+ */
|
||||
+ @NonNull
|
||||
+ private QueryResult result;
|
||||
+}
|
||||
diff --git a/query/src/main/java/net/md_5/bungee/query/QueryHandler.java b/query/src/main/java/net/md_5/bungee/query/QueryHandler.java
|
||||
index 0be915c..e577b3f 100644
|
||||
--- a/query/src/main/java/net/md_5/bungee/query/QueryHandler.java
|
||||
+++ b/query/src/main/java/net/md_5/bungee/query/QueryHandler.java
|
||||
@@ -1,17 +1,18 @@
|
||||
package net.md_5.bungee.query;
|
||||
|
||||
+import io.github.waterfallmc.waterfall.QueryResult;
|
||||
+import io.github.waterfallmc.waterfall.event.ProxyQueryEvent;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.AddressedEnvelope;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.channel.socket.DatagramPacket;
|
||||
import java.nio.ByteOrder;
|
||||
-import java.util.HashMap;
|
||||
-import java.util.LinkedHashMap;
|
||||
-import java.util.Map;
|
||||
-import java.util.Random;
|
||||
+import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
+import java.util.stream.Collectors;
|
||||
+
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
@@ -82,19 +83,30 @@ public class QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
||||
throw new IllegalStateException( "No session!" );
|
||||
}
|
||||
|
||||
+ // Waterfall start
|
||||
+ List<String> players = bungee.getPlayers().stream().map(ProxiedPlayer::getName).collect(Collectors.toList());
|
||||
+
|
||||
+ ProxyQueryEvent event = new ProxyQueryEvent(listener, new QueryResult(listener.getMotd(), "SMP", "Waterfall_Proxy",
|
||||
+ bungee.getOnlineCount(), listener.getMaxPlayers(), listener.getHost().getPort(),
|
||||
+ listener.getHost().getHostString(), "MINECRAFT", players, bungee.getGameVersion()));
|
||||
+ QueryResult result = bungee.getPluginManager().callEvent(event).getResult();
|
||||
+ // Waterfall end
|
||||
+
|
||||
out.writeByte( 0x00 );
|
||||
out.writeInt( sessionId );
|
||||
|
||||
if ( in.readableBytes() == 0 )
|
||||
{
|
||||
// Short response
|
||||
- writeString( out, listener.getMotd() ); // MOTD
|
||||
- writeString( out, "SMP" ); // Game Type
|
||||
- writeString( out, "BungeeCord_Proxy" ); // World Name
|
||||
- writeNumber( out, bungee.getOnlineCount() ); // Online Count
|
||||
- writeNumber( out, listener.getMaxPlayers() ); // Max Players
|
||||
- writeShort( out, listener.getHost().getPort() ); // Port
|
||||
- writeString( out, listener.getHost().getHostString() ); // IP
|
||||
+ // Waterfall start
|
||||
+ writeString( out, result.getMotd() ); // MOTD
|
||||
+ writeString( out, result.getGameType() ); // Game Type
|
||||
+ writeString( out, result.getWorldName() ); // World Name
|
||||
+ writeNumber( out, result.getOnlinePlayers() ); // Online Count
|
||||
+ writeNumber( out, result.getMaxPlayers() ); // Max Players
|
||||
+ writeShort( out, result.getPort() ); // Port
|
||||
+ writeString( out, result.getAddress() ); // IP
|
||||
+ // Waterfall end
|
||||
} else if ( in.readableBytes() == 4 )
|
||||
{
|
||||
// Long Response
|
||||
@@ -104,18 +116,20 @@ public class QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
||||
} );
|
||||
Map<String, String> data = new LinkedHashMap<>();
|
||||
|
||||
- data.put( "hostname", listener.getMotd() );
|
||||
- data.put( "gametype", "SMP" );
|
||||
+ // Waterfall start
|
||||
+ data.put( "hostname", result.getMotd() );
|
||||
+ data.put( "gametype", result.getGameType() );
|
||||
// Start Extra Info
|
||||
- data.put( "game_id", "MINECRAFT" );
|
||||
- data.put( "version", bungee.getGameVersion() );
|
||||
- data.put( "plugins", "" );
|
||||
+ data.put( "game_id", result.getGameId() );
|
||||
+ data.put( "version", result.getVersion() );
|
||||
+ data.put( "plugins", "" ); // TODO: Allow population?
|
||||
// End Extra Info
|
||||
- data.put( "map", "BungeeCord_Proxy" );
|
||||
- data.put( "numplayers", Integer.toString( bungee.getOnlineCount() ) );
|
||||
- data.put( "maxplayers", Integer.toString( listener.getMaxPlayers() ) );
|
||||
- data.put( "hostport", Integer.toString( listener.getHost().getPort() ) );
|
||||
- data.put( "hostip", listener.getHost().getHostString() );
|
||||
+ data.put( "map", result.getWorldName() );
|
||||
+ data.put( "numplayers", Integer.toString( result.getOnlinePlayers() ) );
|
||||
+ data.put( "maxplayers", Integer.toString( result.getMaxPlayers() ) );
|
||||
+ data.put( "hostport", Integer.toString( result.getPort() ) );
|
||||
+ data.put( "hostip", result.getAddress() );
|
||||
+ // Waterfall end
|
||||
|
||||
for ( Map.Entry<String, String> entry : data.entrySet() )
|
||||
{
|
||||
@@ -127,10 +141,7 @@ public class QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
||||
// Padding
|
||||
writeString( out, "\01player_\00" );
|
||||
// Player List
|
||||
- for ( ProxiedPlayer p : bungee.getPlayers() )
|
||||
- {
|
||||
- writeString( out, p.getName() );
|
||||
- }
|
||||
+ result.getPlayers().stream().forEach(p -> writeString(out, p)); // Waterfall
|
||||
out.writeByte( 0x00 ); // Null
|
||||
} else
|
||||
{
|
||||
--
|
||||
2.7.4 (Apple Git-66)
|
||||
|
Loading…
Reference in New Issue
Block a user