Start work on making it compile again.

This commit is contained in:
md_5 2013-01-17 11:59:59 +11:00
parent 098ca5920e
commit 592a504e77
14 changed files with 168 additions and 114 deletions

View File

@ -105,6 +105,9 @@ public abstract class ProxyServer
/** /**
* Start this instance so that it may accept connections. * Start this instance so that it may accept connections.
*
* @throws Exception any exception thrown during startup causing the
* instance to fail to boot
*/ */
public abstract void start(); public abstract void start() throws Exception;
} }

View File

@ -3,6 +3,6 @@ package net.md_5.bungee.api.connection;
/** /**
* Represents a player physically connected to the world hosted on this server. * Represents a player physically connected to the world hosted on this server.
*/ */
public abstract class ConnectedPlayer extends ProxiedPlayer public interface ConnectedPlayer extends ProxiedPlayer
{ {
} }

View File

@ -8,15 +8,23 @@ import net.md_5.bungee.api.CommandSender;
* Represents a player who's connection is being connected to somewhere else, * Represents a player who's connection is being connected to somewhere else,
* whether it be a remote or embedded server. * whether it be a remote or embedded server.
*/ */
public abstract class ProxiedPlayer implements Connection, CommandSender public interface ProxiedPlayer extends Connection, CommandSender
{ {
/** /**
* Name displayed to other users in areas such as the tab list. * Gets this player's display name.
*
* @return the players current display name
*/ */
@Getter public String getDisplayName();
@Setter
private String displayName; /**
* Sets this players display name to be used as their nametag and tab list
* name.
*
* @param name the name to set
*/
public void setDisplayName(String name);
/** /**
* Connects / transfers this user to the specified connection, gracefully * Connects / transfers this user to the specified connection, gracefully
@ -25,21 +33,21 @@ public abstract class ProxiedPlayer implements Connection, CommandSender
* *
* @param server the new server to connect to * @param server the new server to connect to
*/ */
public abstract void connect(Server server); public void connect(Server server);
/** /**
* Gets the server this player is connected to. * Gets the server this player is connected to.
* *
* @return the server this player is connected to * @return the server this player is connected to
*/ */
public abstract Server getServer(); public Server getServer();
/** /**
* Gets the ping time between the proxy and this connection. * Gets the ping time between the proxy and this connection.
* *
* @return the current ping time * @return the current ping time
*/ */
public abstract int getPing(); public int getPing();
/** /**
* Completely kick this user from the proxy and all of its child * Completely kick this user from the proxy and all of its child
@ -47,7 +55,7 @@ public abstract class ProxiedPlayer implements Connection, CommandSender
* *
* @param reason the disconnect reason displayed to the player * @param reason the disconnect reason displayed to the player
*/ */
public abstract void disconnect(String reason); public void disconnect(String reason);
/** /**
* Send a plugin message to this player. * Send a plugin message to this player.
@ -55,5 +63,5 @@ public abstract class ProxiedPlayer implements Connection, CommandSender
* @param channel the channel to send this data via * @param channel the channel to send this data via
* @param data the data to send * @param data the data to send
*/ */
public abstract void sendData(String channel, byte[] data); public void sendData(String channel, byte[] data);
} }

View File

@ -11,22 +11,15 @@ import net.md_5.bungee.api.ServerPing;
/** /**
* Represents a destination which this proxy might connect to. * Represents a destination which this proxy might connect to.
*/ */
@RequiredArgsConstructor public interface Server extends Connection
public abstract class Server implements Connection
{ {
/** /**
* Information about the address, name and configuration regarding this * Returns the basic information about this server.
* server. *
* @return the {@link ServerInfo} for this server
*/ */
@Getter public ServerInfo getInfo();
private final ServerInfo info;
@Override
public InetSocketAddress getAddress()
{
return info.getAddress();
}
/** /**
* Send data by any available means to this server. * Send data by any available means to this server.

View File

@ -1,13 +1,12 @@
package net.md_5.bungee; package net.md_5.bungee;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
@ -16,12 +15,11 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import lombok.Getter; import lombok.Getter;
import static net.md_5.bungee.Logger.$; import static net.md_5.bungee.Logger.$;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.TabListHandler;
import net.md_5.bungee.api.config.ConfigurationAdapter; import net.md_5.bungee.api.config.ConfigurationAdapter;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server; import net.md_5.bungee.api.connection.Server;
@ -29,11 +27,9 @@ import net.md_5.bungee.api.plugin.PluginManager;
import net.md_5.bungee.command.*; import net.md_5.bungee.command.*;
import net.md_5.bungee.packet.DefinedPacket; import net.md_5.bungee.packet.DefinedPacket;
import net.md_5.bungee.packet.PacketFAPluginMessage; import net.md_5.bungee.packet.PacketFAPluginMessage;
import net.md_5.bungee.plugin.JavaPluginManager;
import net.md_5.bungee.tablist.GlobalPingTabList; import net.md_5.bungee.tablist.GlobalPingTabList;
import net.md_5.bungee.tablist.GlobalTabList; import net.md_5.bungee.tablist.GlobalTabList;
import net.md_5.bungee.tablist.ServerUniqueTabList; import net.md_5.bungee.tablist.ServerUniqueTabList;
import net.md_5.bungee.tablist.TabListHandler;
/** /**
* Main BungeeCord proxy class. * Main BungeeCord proxy class.
@ -78,10 +74,6 @@ public class BungeeCord extends ProxyServer
*/ */
public Map<String, UserConnection> connections = new ConcurrentHashMap<>(); public Map<String, UserConnection> connections = new ConcurrentHashMap<>();
public Map<String, List<UserConnection>> connectionsByServer = new ConcurrentHashMap<>(); public Map<String, List<UserConnection>> connectionsByServer = new ConcurrentHashMap<>();
/**
* Registered commands.
*/
public Map<String, Command> commandMap = new HashMap<>();
/** /**
* Tab list handler * Tab list handler
*/ */
@ -109,6 +101,11 @@ public class BungeeCord extends ProxyServer
getPluginManager().registerCommand(new CommandBungee()); getPluginManager().registerCommand(new CommandBungee());
} }
public static BungeeCord getInstance()
{
return (BungeeCord) ProxyServer.getInstance();
}
/** /**
* Starts a new instance of BungeeCord. * Starts a new instance of BungeeCord.
* *
@ -137,39 +134,6 @@ public class BungeeCord extends ProxyServer
} }
} }
/**
* Dispatch a command by formatting the arguments and then executing it.
*
* @param commandLine the entire command and arguments string
* @param sender which executed the command
* @return whether the command was handled or not.
*/
public boolean dispatchCommand(String commandLine, CommandSender sender)
{
String[] split = commandLine.trim().split(" ");
String commandName = split[0].toLowerCase();
Command command = commandMap.get(commandName);
if (config.disabledCommands != null && config.disabledCommands.contains(commandName))
{
return false;
} else if (command != null)
{
String[] args = Arrays.copyOfRange(split, 1, split.length);
try
{
command.execute(sender, args);
} catch (Exception ex)
{
sender.sendMessage(ChatColor.RED + "An error occurred while executing this command!");
$().severe("----------------------- [Start of command error] -----------------------");
$().log(Level.SEVERE, "", ex);
$().severe("----------------------- [End of command error] -----------------------");
}
}
return command != null;
}
/** /**
* Start this proxy instance by loading the configuration, plugins and * Start this proxy instance by loading the configuration, plugins and
* starting the connect thread. * starting the connect thread.
@ -181,7 +145,9 @@ public class BungeeCord extends ProxyServer
config.load(); config.load();
isRunning = true; isRunning = true;
pluginManager.loadPlugins(); File plugins = new File("plugins");
plugins.mkdir();
pluginManager.loadPlugins(plugins);
switch (config.tabList) switch (config.tabList)
{ {
@ -328,7 +294,7 @@ public class BungeeCord extends ProxyServer
*/ */
public void sendPluginMessage(String channel, String message, String targetServer) public void sendPluginMessage(String channel, String message, String targetServer)
{ {
List<UserConnection> conns = BungeeCord.instance.connectionsByServer.get(targetServer); List<UserConnection> conns = connectionsByServer.get(targetServer);
if (conns != null && conns.size() > 0) if (conns != null && conns.size() > 0)
{ {
UserConnection user = conns.get(0); UserConnection user = conns.get(0);

View File

@ -16,8 +16,6 @@ import java.util.Map;
import java.util.UUID; import java.util.UUID;
import static net.md_5.bungee.Logger.$; import static net.md_5.bungee.Logger.$;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.command.CommandSender;
import net.md_5.bungee.command.ConsoleCommandSender;
import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
@ -293,23 +291,4 @@ public class Configuration
save(reconnect, reconnectLocations); save(reconnect, reconnectLocations);
$().info("Saved reconnect locations to " + reconnect); $().info("Saved reconnect locations to " + reconnect);
} }
/**
* Get the highest permission a player has.
*
* @param sender to get permissions of
* @return their permission
*/
public Permission getPermission(CommandSender sender)
{
Permission permission = Permission.DEFAULT;
if (admins.contains(sender.getName()) || sender instanceof ConsoleCommandSender)
{
permission = Permission.ADMIN;
} else if (moderators.contains(sender.getName()))
{
permission = Permission.MODERATOR;
}
return permission;
}
} }

View File

@ -25,15 +25,15 @@ public class ListenThread extends Thread
@Override @Override
public void run() public void run()
{ {
while (BungeeCord.instance.isRunning) while (BungeeCord.getInstance().isRunning)
{ {
try try
{ {
Socket client = socket.accept(); Socket client = socket.accept();
BungeeCord.instance.setSocketOptions(client); BungeeCord.getInstance().setSocketOptions(client);
$().info(client.getInetAddress() + " has connected"); $().info(client.getInetAddress() + " has connected");
InitialHandler handler = new InitialHandler(client); InitialHandler handler = new InitialHandler(client);
BungeeCord.instance.threadPool.submit(handler); BungeeCord.getInstance().threadPool.submit(handler);
} catch (SocketException ex) } catch (SocketException ex)
{ {
} catch (IOException ex) } catch (IOException ex)

View File

@ -23,7 +23,7 @@ public class Logger extends java.util.logging.Logger
super("RubberBand", null); super("RubberBand", null);
try try
{ {
FileHandler handler = new FileHandler("proxy.log", BungeeCord.instance.config.logNumLines, 1, true); FileHandler handler = new FileHandler("proxy.log", BungeeCord.getInstance().config.logNumLines, 1, true);
handler.setFormatter(formatter); handler.setFormatter(formatter);
addHandler(handler); addHandler(handler);
} catch (IOException ex) } catch (IOException ex)

View File

@ -9,6 +9,7 @@ import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLEncoder; import java.net.URLEncoder;
import static net.md_5.bungee.Logger.$; import static net.md_5.bungee.Logger.$;
import net.md_5.bungee.api.ProxyServer;
public class Metrics extends Thread public class Metrics extends Thread
{ {
@ -73,10 +74,10 @@ public class Metrics extends Thread
{ {
// Construct the post data // Construct the post data
final StringBuilder data = new StringBuilder(); final StringBuilder data = new StringBuilder();
data.append(encode("guid")).append('=').append(encode(BungeeCord.instance.config.statsUuid)); data.append(encode("guid")).append('=').append(encode(BungeeCord.getInstance().config.statsUuid));
encodeDataPair(data, "version", BungeeCord.instance.version); encodeDataPair(data, "version", ProxyServer.getInstance().getVersion());
encodeDataPair(data, "server", "0"); encodeDataPair(data, "server", "0");
encodeDataPair(data, "players", Integer.toString(BungeeCord.instance.connections.size())); encodeDataPair(data, "players", Integer.toString(ProxyServer.getInstance().getPlayers().size()));
encodeDataPair(data, "revision", String.valueOf(REVISION)); encodeDataPair(data, "revision", String.valueOf(REVISION));
// If we're pinging, append it // If we're pinging, append it

View File

@ -4,9 +4,15 @@ import java.io.OutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.security.PublicKey; import java.security.PublicKey;
import java.util.Collection;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.packet.DefinedPacket; import net.md_5.bungee.packet.DefinedPacket;
import net.md_5.bungee.packet.Packet1Login; import net.md_5.bungee.packet.Packet1Login;
import net.md_5.bungee.packet.Packet2Handshake; import net.md_5.bungee.packet.Packet2Handshake;
@ -22,7 +28,7 @@ import org.bouncycastle.crypto.io.CipherOutputStream;
/** /**
* Class representing a connection from the proxy to the server; ie upstream. * Class representing a connection from the proxy to the server; ie upstream.
*/ */
public class ServerConnection extends GenericConnection public class ServerConnection extends GenericConnection implements Server
{ {
public final String name; public final String name;
@ -41,8 +47,8 @@ public class ServerConnection extends GenericConnection
try try
{ {
Socket socket = new Socket(); Socket socket = new Socket();
socket.connect(address, BungeeCord.instance.config.timeout); socket.connect(address, BungeeCord.getInstance().config.timeout);
BungeeCord.instance.setSocketOptions(socket); BungeeCord.getInstance().setSocketOptions(socket);
PacketInputStream in = new PacketInputStream(socket.getInputStream()); PacketInputStream in = new PacketInputStream(socket.getInputStream());
OutputStream out = socket.getOutputStream(); OutputStream out = socket.getOutputStream();
@ -80,7 +86,7 @@ public class ServerConnection extends GenericConnection
// Register all global plugin message channels // Register all global plugin message channels
// TODO: Allow player-specific plugin message channels for full mod support // TODO: Allow player-specific plugin message channels for full mod support
for (String channel : BungeeCord.instance.globalPluginChannels) for (String channel : BungeeCord.getInstance().globalPluginChannels)
{ {
out.write(new PacketFAPluginMessage("REGISTER", channel.getBytes()).getPacket()); out.write(new PacketFAPluginMessage("REGISTER", channel.getBytes()).getPacket());
} }
@ -91,7 +97,7 @@ public class ServerConnection extends GenericConnection
throw ex; throw ex;
} catch (Exception ex) } catch (Exception ex)
{ {
InetSocketAddress def = BungeeCord.instance.config.getServer(null); InetSocketAddress def = BungeeCord.getInstance().config.getServer(null);
if (retry && !address.equals(def)) if (retry && !address.equals(def))
{ {
return connect(user, name, def, handshake, false); return connect(user, name, def, handshake, false);
@ -101,4 +107,34 @@ public class ServerConnection extends GenericConnection
} }
} }
} }
@Override
public ServerInfo getInfo()
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void sendData(String channel, byte[] data)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void ping(Callback<ServerPing> callback)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Collection<ProxiedPlayer> getPlayers()
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public InetSocketAddress getAddress()
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
} }

View File

@ -6,17 +6,18 @@ import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import net.md_5.bungee.command.CommandSender; import javax.print.attribute.standard.Destination;
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.packet.*; import net.md_5.bungee.packet.*;
import net.md_5.bungee.plugin.ChatEvent;
import net.md_5.bungee.plugin.PluginMessageEvent;
import net.md_5.bungee.plugin.PluginMessageEvent.Destination;
import net.md_5.bungee.plugin.ServerConnectEvent;
public class UserConnection extends GenericConnection implements CommandSender public class UserConnection extends GenericConnection implements ProxiedPlayer
{ {
public final Packet2Handshake handshake; public final Packet2Handshake handshake;
@ -212,6 +213,72 @@ public class UserConnection extends GenericConnection implements CommandSender
return username; return username;
} }
@Override
public String getDisplayName()
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setDisplayName(String name)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void connect(Server server)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Server getServer()
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void sendData(String channel, byte[] data)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public InetSocketAddress getAddress()
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Collection<String> getGroups()
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void addGroups(String... groups)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void removeGroups(String... groups)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean hasPermission(String permission)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setPermission(String permission, boolean value)
{
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private class UpstreamBridge extends Thread private class UpstreamBridge extends Thread
{ {

View File

@ -19,7 +19,7 @@ public class GlobalPingTabList extends GlobalTabList
Integer lastPing = lastPings.get(player); Integer lastPing = lastPings.get(player);
if (lastPing == null || (ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing)) if (lastPing == null || (ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing))
{ {
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, ping)); BungeeCord.getInstance().broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, ping));
lastPings.put(player, ping); lastPings.put(player, ping);
} }
} }

View File

@ -17,9 +17,9 @@ public class GlobalTabList implements TabListHandler
@Override @Override
public void onConnect(ProxiedPlayer player) public void onConnect(ProxiedPlayer player)
{ {
for (UserConnection c : BungeeCord.instance.connections.values()) for (UserConnection c : BungeeCord.getInstance().connections.values())
{ {
con.packetQueue.add(new PacketC9PlayerListItem(c.tabListName, true, c.getPing())); c.packetQueue.add(new PacketC9PlayerListItem(c.tabListName, true, c.getPing()));
} }
} }
@ -28,7 +28,7 @@ public class GlobalTabList implements TabListHandler
{ {
if (!sentPings.contains(player)) if (!sentPings.contains(player))
{ {
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, player.getPing())); BungeeCord.getInstance().broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, player.getPing()));
sentPings.add(player); sentPings.add(player);
} }
} }
@ -36,7 +36,7 @@ public class GlobalTabList implements TabListHandler
@Override @Override
public void onDisconnect(ProxiedPlayer player) public void onDisconnect(ProxiedPlayer player)
{ {
BungeeCord.instance.broadcast(new PacketC9PlayerListItem(player.getDisplayName(), false, 9999)); BungeeCord.getInstance().broadcast(new PacketC9PlayerListItem(player.getDisplayName(), false, 9999));
sentPings.remove(player); sentPings.remove(player);
} }

View File

@ -5,6 +5,7 @@ import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.TabListHandler; import net.md_5.bungee.api.TabListHandler;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.packet.PacketC9PlayerListItem; import net.md_5.bungee.packet.PacketC9PlayerListItem;
@ -39,7 +40,7 @@ public class ServerUniqueTabList implements TabListHandler
{ {
for (String username : usernames) for (String username : usernames)
{ {
player.packetQueue.add(new PacketC9PlayerListItem(username, false, 9999)); ((UserConnection) player).packetQueue.add(new PacketC9PlayerListItem(username, false, 9999));
} }
usernames.clear(); usernames.clear();
} }