From 9fb814003b7bf530373d9ea1d7a80056f92692d1 Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 11 Mar 2013 10:15:14 +1100 Subject: [PATCH] Handle kicks when trying to login to server. Now we have to be about done. --- .../main/java/net/md_5/bungee/KickException.java | 14 -------------- .../java/net/md_5/bungee/ServerConnection.java | 5 +++++ .../main/java/net/md_5/bungee/ServerConnector.java | 10 +++++++++- 3 files changed, 14 insertions(+), 15 deletions(-) delete mode 100644 proxy/src/main/java/net/md_5/bungee/KickException.java diff --git a/proxy/src/main/java/net/md_5/bungee/KickException.java b/proxy/src/main/java/net/md_5/bungee/KickException.java deleted file mode 100644 index 5b495e009..000000000 --- a/proxy/src/main/java/net/md_5/bungee/KickException.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.md_5.bungee; - -/** - * Exception, which when thrown will disconnect the player from the proxy with - * the specified message. - */ -public class KickException extends RuntimeException -{ - - public KickException(String message) - { - super( message ); - } -} diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java index 6a55e2c93..c74b124bb 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java @@ -34,6 +34,11 @@ public class ServerConnection implements Server @Override public synchronized void disconnect(String reason) + { + disconnect( ch, reason ); + } + + static void disconnect(final Channel ch, String reason) { if ( ch.isActive() ) { diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java index bc21a10f5..9c138201c 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -4,6 +4,7 @@ import com.google.common.base.Preconditions; import io.netty.channel.Channel; import java.util.Queue; import lombok.RequiredArgsConstructor; +import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.event.ServerConnectedEvent; @@ -125,7 +126,14 @@ public class ServerConnector extends PacketHandler @Override public void handle(PacketFFKick kick) throws Exception { - throw new KickException( kick.message ); + String message = ChatColor.RED + "Kicked whilst connecting to " + target.getName() + ": " + kick.message; + if ( user.getServer() == null ) + { + user.disconnect( message ); + } else + { + user.sendMessage( message ); + } } @Override