Waterfall/BungeeCord-Patches/0027-Add-timeout-variant-to-connect-methods.patch

114 lines
5.7 KiB
Diff
Raw Normal View History

From c7e03fafe03c044f0da356ac97c3b08d7b3d16c1 Mon Sep 17 00:00:00 2001
2016-07-03 10:07:00 +02:00
From: Ichbinjoe <joe@ibj.io>
Date: Sat, 16 Jul 2016 20:44:01 -0400
2016-07-03 22:53:51 +02:00
Subject: [PATCH] Add timeout variant to connect methods
2016-07-03 10:07:00 +02:00
2016-07-03 22:53:51 +02:00
Also added more connect methods to ProxiedPlayer, in addition to the new method
2016-07-03 10:07:00 +02:00
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
2023-09-21 12:33:23 +02:00
index c3848b3c..a441a424 100644
2016-07-03 10:07:00 +02:00
--- 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
@@ -126,6 +126,38 @@ public interface ProxiedPlayer extends Connection, CommandSender
2016-07-03 10:07:00 +02:00
*/
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
2018-04-02 11:21:24 +02:00
+
/**
* Connects / transfers this user to the specified connection, gracefully
* closing the current one. Depending on the implementation, this method
@@ -139,6 +171,25 @@ public interface ProxiedPlayer extends Connection, CommandSender
2018-04-02 11:21:24 +02:00
*/
void connect(ServerInfo target, Callback<Boolean> callback, ServerConnectEvent.Reason reason);
+ // 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.
+ * @param reason the reason for connecting to the new server
+ * @param timeout timeout in milliseconds of the connection created to the
+ * target server
+ */
+ void connect(ServerInfo target, Callback<Boolean> callback, boolean retry, ServerConnectEvent.Reason reason, int timeout);
+ // Waterfall end
2016-07-03 10:07:00 +02:00
+
/**
2018-07-30 13:54:15 +02:00
* Connects / transfers this user to the specified connection, gracefully
* closing the current one. Depending on the implementation, this method
2016-07-03 10:07:00 +02:00
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 00c88e4d..242b693e 100644
2016-07-03 10:07:00 +02:00
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
@@ -281,9 +281,20 @@ public final class UserConnection implements ProxiedPlayer
2016-07-03 10:07:00 +02:00
2018-04-02 11:21:24 +02:00
public void connect(ServerInfo info, final Callback<Boolean> callback, final boolean retry, ServerConnectEvent.Reason reason)
2016-07-03 10:07:00 +02:00
{
+ // Waterfall start
+ connect(info, callback, retry, reason, bungee.getConfig().getServerConnectTimeout());
2016-07-03 10:07:00 +02:00
+ }
2018-04-02 11:21:24 +02:00
+ public void connect(ServerInfo info, final Callback<Boolean> callback, final boolean retry, int timeout) {
+ connect(info, callback, retry, ServerConnectEvent.Reason.PLUGIN, timeout);
+ }
+
+ public void connect(ServerInfo info, final Callback<Boolean> callback, final boolean retry, ServerConnectEvent.Reason reason, final int timeout)
2016-07-03 10:07:00 +02:00
+ {
+ // Waterfall end
Preconditions.checkNotNull( info, "info" );
2018-07-30 13:54:15 +02:00
ServerConnectRequest.Builder builder = ServerConnectRequest.builder().retry( retry ).reason( reason ).target( info );
+ builder.connectTimeout(timeout); // Waterfall
if ( callback != null )
{
// Convert the Callback<Boolean> to be compatible with Callback<Result> from ServerConnectRequest.
@@ -377,7 +388,7 @@ public final class UserConnection implements ProxiedPlayer
2018-07-30 13:54:15 +02:00
if ( request.isRetry() && def != null && ( getServer() == null || def != getServer().getInfo() ) )
2016-07-03 10:07:00 +02:00
{
sendMessage( bungee.getTranslation( "fallback_lobby" ) );
2018-04-02 11:21:24 +02:00
- connect( def, null, true, ServerConnectEvent.Reason.LOBBY_FALLBACK );
2018-07-30 13:54:15 +02:00
+ connect( def, null, true, ServerConnectEvent.Reason.LOBBY_FALLBACK, request.getConnectTimeout() ); // Waterfall
} else if ( dimensionChange )
2016-07-03 10:07:00 +02:00
{
disconnect( bungee.getTranslation( "fallback_kick", connectionFailMessage( future.cause() ) ) );
2016-07-03 10:07:00 +02:00
--
2023-09-21 12:33:23 +02:00
2.42.0
2016-07-03 10:07:00 +02:00