From ade3fe43116cdd92e17e3dc066f0977687e7684d Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 22 Jan 2013 10:39:21 +1100 Subject: [PATCH] Just need to add default permissions and we are ready for release. --- .../main/java/net/md_5/bungee/BungeeCord.java | 7 +++++- .../java/net/md_5/bungee/InitialHandler.java | 1 + .../java/net/md_5/bungee/UserConnection.java | 23 +++++++++++++++---- .../net/md_5/bungee/YamlReconnectHandler.java | 8 +++++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java index c0f038db..bc0f83ec 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -89,7 +89,7 @@ public class BungeeCord extends ProxyServer public final PluginManager pluginManager = new PluginManager(); @Getter @Setter - private ReconnectHandler reconnectHandler = new YamlReconnectHandler(); + private ReconnectHandler reconnectHandler; @Getter @Setter private ConfigurationAdapter configurationAdapter = new YamlConfig(); @@ -104,6 +104,10 @@ public class BungeeCord extends ProxyServer getPluginManager().registerCommand(new CommandIP()); getPluginManager().registerCommand(new CommandAlert()); getPluginManager().registerCommand(new CommandBungee()); + + registerChannel("BungeeCord::Disconnect"); + registerChannel("BungeeCord::Connect"); + registerChannel("BungeeCord::Forward"); } public static BungeeCord getInstance() @@ -148,6 +152,7 @@ public class BungeeCord extends ProxyServer public void start() throws IOException { config.load(); + reconnectHandler = new YamlReconnectHandler(); isRunning = true; File plugins = new File("plugins"); diff --git a/proxy/src/main/java/net/md_5/bungee/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/InitialHandler.java index 611cc1c6..d09f9dfa 100644 --- a/proxy/src/main/java/net/md_5/bungee/InitialHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/InitialHandler.java @@ -118,6 +118,7 @@ public class InitialHandler implements Runnable, PendingConnection } catch (Exception ex) { disconnect("[Proxy Error] " + Util.exception(ex)); + ex.printStackTrace(); } } 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 a5405896..5b893456 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -18,10 +18,10 @@ import java.util.concurrent.ConcurrentLinkedQueue; import lombok.Getter; import lombok.Synchronized; import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.config.ListenerInfo; import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.ServerConnectEvent; @@ -77,7 +77,7 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer if (server == null) { // First join - ProxyServer.getInstance().getPlayers().add(this); + BungeeCord.getInstance().connections.put(name, this); ProxyServer.getInstance().getTabListHandler().onConnect(this); } @@ -118,6 +118,7 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer } server.disconnect("Quitting"); + server.getInfo().removePlayer(this); Packet1Login login = newServer.loginPacket; serverEntityId = login.entityId; @@ -127,8 +128,6 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer // Reconnect process has finished, lets get the player moving again reconnecting = false; - // Remove from the old by server list - server.getInfo().removePlayer(this); // Add to new target.addPlayer(this); @@ -141,8 +140,8 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer destroySelf(ex.getMessage()); } catch (Exception ex) { - destroySelf("Could not connect to server - " + ex.getClass().getSimpleName()); ex.printStackTrace(); // TODO: Remove + destroySelf("Could not connect to server - " + ex.getClass().getSimpleName()); } } @@ -377,6 +376,20 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer short len = in.readShort(); byte[] data = new byte[len]; in.readFully(data); + + if (target.equals("ALL")) + { + for (String s : BungeeCord.getInstance().getServers().keySet()) + { + Server server = BungeeCord.getInstance().getServer(s); + server.sendData(channel, data); + } + } else + { + Server server = BungeeCord.getInstance().getServer(target); + server.sendData(channel, data); + } + break; case "BungeeCord::Connect": ServerInfo server = BungeeCord.getInstance().config.getServers().get(in.readUTF()); diff --git a/proxy/src/main/java/net/md_5/bungee/YamlReconnectHandler.java b/proxy/src/main/java/net/md_5/bungee/YamlReconnectHandler.java index 50c60d71..cd9e227a 100644 --- a/proxy/src/main/java/net/md_5/bungee/YamlReconnectHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/YamlReconnectHandler.java @@ -25,9 +25,13 @@ public class YamlReconnectHandler implements ReconnectHandler @SuppressWarnings("unchecked") public YamlReconnectHandler() { - try (FileReader rd = new FileReader(file)) + try { - data = yaml.loadAs(rd, Map.class); + file.createNewFile(); + try (FileReader rd = new FileReader(file)) + { + data = yaml.loadAs(rd, Map.class); + } } catch (IOException ex) { ProxyServer.getInstance().getLogger().log(Level.WARNING, "Could not load reconnect locations", ex);