Well, it compiles, time to start fixing stuff.

This commit is contained in:
md_5 2013-01-19 13:33:04 +11:00
parent cf42a10ba4
commit bf1e7f09a9
8 changed files with 51 additions and 42 deletions

View File

@ -3,6 +3,7 @@ package net.md_5.bungee.api;
import net.md_5.bungee.api.plugin.PluginManager; import net.md_5.bungee.api.plugin.PluginManager;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import java.util.Collection; import java.util.Collection;
import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
import lombok.Getter; import lombok.Getter;
import net.md_5.bungee.api.config.ConfigurationAdapter; import net.md_5.bungee.api.config.ConfigurationAdapter;
@ -68,13 +69,24 @@ public abstract class ProxyServer
public abstract ProxiedPlayer getPlayer(String name); public abstract ProxiedPlayer getPlayer(String name);
/** /**
* Get a server by its name. * Get a server by its name. The instance returned will be taken from a
* player currently on that server to facilitate abstract proxy -> server
* actions.
* *
* @param name the name to lookup * @param name the name to lookup
* @return the associated server * @return the associated server
*/ */
public abstract Server getServer(String name); public abstract Server getServer(String name);
/**
* Return all servers registered to this proxy, keyed by name. Unlike the
* methods in {@link ConfigurationAdapter#getServers()}, this will not
* return a fresh map each time.
*
* @return all registered remote server destinations
*/
public abstract Map<String, ServerInfo> getServers();
/** /**
* Get the {@link PluginManager} associated with loading plugins and * Get the {@link PluginManager} associated with loading plugins and
* dispatching events. It is recommended that implementations use the * dispatching events. It is recommended that implementations use the

View File

@ -1,9 +1,5 @@
package net.md_5.bungee.api.connection; package net.md_5.bungee.api.connection;
import java.net.InetSocketAddress;
import java.util.Collection;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.ServerPing;
@ -35,11 +31,4 @@ public interface Server extends Connection
* @param callback the callback to call when the count has been retrieved. * @param callback the callback to call when the count has been retrieved.
*/ */
public abstract void ping(Callback<ServerPing> callback); public abstract void ping(Callback<ServerPing> callback);
/**
* Get all players on this instance connected to this server.
*
* @return all players connected to this server
*/
public abstract Collection<ProxiedPlayer> getPlayers();
} }

View File

@ -5,7 +5,6 @@ import java.io.BufferedReader;
import java.io.File; 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.Socket; import java.net.Socket;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
@ -27,6 +26,7 @@ import net.md_5.bungee.api.ReconnectHandler;
import net.md_5.bungee.api.TabListHandler; 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.config.ListenerInfo; import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.config.ServerInfo;
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;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
@ -153,9 +153,8 @@ public class BungeeCord extends ProxyServer
for (ListenerInfo info : config.getListeners()) for (ListenerInfo info : config.getListeners())
{ {
InetSocketAddress addr = info.getHost(); $().info("Listening on " + info.getHost());
$().info("Listening on " + addr); ListenThread listener = new ListenThread(info);
ListenThread listener = new ListenThread(addr);
listener.start(); listener.start();
listeners.add(listener); listeners.add(listener);
} }
@ -276,4 +275,10 @@ public class BungeeCord extends ProxyServer
List<UserConnection> users = connectionsByServer.get(name); List<UserConnection> users = connectionsByServer.get(name);
return (users != null && !users.isEmpty()) ? users.get(0).getServer() : null; return (users != null && !users.isEmpty()) ? users.get(0).getServer() : null;
} }
@Override
public Map<String, ServerInfo> getServers()
{
return config.getServers();
}
} }

View File

@ -10,6 +10,8 @@ import java.util.List;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import net.md_5.bungee.api.ChatColor; 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.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.PendingConnection;
import net.md_5.bungee.api.event.LoginEvent; import net.md_5.bungee.api.event.LoginEvent;
import net.md_5.bungee.packet.Packet2Handshake; import net.md_5.bungee.packet.Packet2Handshake;
@ -24,13 +26,15 @@ public class InitialHandler implements Runnable, PendingConnection
{ {
private final Socket socket; private final Socket socket;
private final ListenerInfo info;
private PacketInputStream in; private PacketInputStream in;
private OutputStream out; private OutputStream out;
private Packet2Handshake handshake; private Packet2Handshake handshake;
public InitialHandler(Socket socket) throws IOException public InitialHandler(Socket socket, ListenerInfo info) throws IOException
{ {
this.socket = socket; this.socket = socket;
this.info = info;
in = new PacketInputStream(socket.getInputStream()); in = new PacketInputStream(socket.getInputStream());
out = socket.getOutputStream(); out = socket.getOutputStream();
} }
@ -73,7 +77,10 @@ public class InitialHandler implements Runnable, PendingConnection
customPackets.add(custom); customPackets.add(custom);
} }
UserConnection userCon = new UserConnection(socket, in, out, handshake, customPackets); UserConnection userCon = new UserConnection(socket, info, in, out, handshake, customPackets);
String server = ProxyServer.getInstance().getReconnectHandler().getServer(userCon);
ServerInfo s = BungeeCord.getInstance().config.getServers().get(server);
userCon.connect(s);
break; break;
case 0xFE: case 0xFE:
socket.setSoTimeout(100); socket.setSoTimeout(100);
@ -89,10 +96,10 @@ public class InitialHandler implements Runnable, PendingConnection
String ping = (newPing) ? ChatColor.COLOR_CHAR + "1" String ping = (newPing) ? ChatColor.COLOR_CHAR + "1"
+ "\00" + BungeeCord.PROTOCOL_VERSION + "\00" + BungeeCord.PROTOCOL_VERSION
+ "\00" + BungeeCord.GAME_VERSION + "\00" + BungeeCord.GAME_VERSION
+ "\00" + conf.motd + "\00" + info.getMotd()
+ "\00" + ProxyServer.getInstance().getPlayers().size() + "\00" + ProxyServer.getInstance().getPlayers().size()
+ "\00" + conf.maxPlayers + "\00" + info.getMaxPlayers()
: conf.motd + ChatColor.COLOR_CHAR + ProxyServer.getInstance().getPlayers().size() + ChatColor.COLOR_CHAR + conf.maxPlayers; : info.getMotd() + ChatColor.COLOR_CHAR + ProxyServer.getInstance().getPlayers().size() + ChatColor.COLOR_CHAR + info.getMaxPlayers();
throw new KickException(ping); throw new KickException(ping);
default: default:
if (id == 0xFA) if (id == 0xFA)

View File

@ -1,11 +1,11 @@
package net.md_5.bungee; package net.md_5.bungee;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.SocketException; import java.net.SocketException;
import static net.md_5.bungee.Logger.$; import static net.md_5.bungee.Logger.$;
import net.md_5.bungee.api.config.ListenerInfo;
/** /**
* Thread to listen and dispatch incoming connections to the proxy. * Thread to listen and dispatch incoming connections to the proxy.
@ -14,12 +14,14 @@ public class ListenThread extends Thread
{ {
public final ServerSocket socket; public final ServerSocket socket;
private final ListenerInfo info;
public ListenThread(InetSocketAddress addr) throws IOException public ListenThread(ListenerInfo info) throws IOException
{ {
super("Listen Thread"); super("Listen Thread - "+ info);
this.info = info;
socket = new ServerSocket(); socket = new ServerSocket();
socket.bind(addr); socket.bind(info.getHost());
} }
@Override @Override
@ -32,7 +34,7 @@ public class ListenThread extends Thread
Socket client = socket.accept(); Socket client = socket.accept();
BungeeCord.getInstance().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,info);
BungeeCord.getInstance().threadPool.submit(handler); BungeeCord.getInstance().threadPool.submit(handler);
} catch (SocketException ex) } catch (SocketException ex)
{ {

View File

@ -4,14 +4,12 @@ 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.Callback;
import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.config.ServerInfo; 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.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;
@ -46,7 +44,7 @@ public class ServerConnection extends GenericConnection implements Server
try try
{ {
Socket socket = new Socket(); Socket socket = new Socket();
socket.connect(address, BungeeCord.getInstance().config.timeout); socket.connect(address, BungeeCord.getInstance().config.getTimeout());
BungeeCord.getInstance().setSocketOptions(socket); BungeeCord.getInstance().setSocketOptions(socket);
PacketInputStream in = new PacketInputStream(socket.getInputStream()); PacketInputStream in = new PacketInputStream(socket.getInputStream());
@ -89,7 +87,7 @@ public class ServerConnection extends GenericConnection implements Server
throw ex; throw ex;
} catch (Exception ex) } catch (Exception ex)
{ {
InetSocketAddress def = BungeeCord.getInstance().config.getServer(null); InetSocketAddress def = BungeeCord.getInstance().config.getServers().get(user.info.getDefaultServer()).getAddress();
if (retry && !address.equals(def)) if (retry && !address.equals(def))
{ {
return connect(user, name, def, handshake, false); return connect(user, name, def, handshake, false);
@ -118,15 +116,9 @@ public class ServerConnection extends GenericConnection implements Server
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 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 @Override
public InetSocketAddress getAddress() public InetSocketAddress getAddress()
{ {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. return getInfo().getAddress();
} }
} }

View File

@ -18,6 +18,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import lombok.Getter; import lombok.Getter;
import lombok.Synchronized; import lombok.Synchronized;
import net.md_5.bungee.api.ProxyServer; 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.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.event.ChatEvent;
@ -31,6 +32,7 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer
public final Packet2Handshake handshake; public final Packet2Handshake handshake;
public Queue<DefinedPacket> packetQueue = new ConcurrentLinkedQueue<>(); public Queue<DefinedPacket> packetQueue = new ConcurrentLinkedQueue<>();
public List<byte[]> loginPackets = new ArrayList<>(); public List<byte[]> loginPackets = new ArrayList<>();
final ListenerInfo info;
@Getter @Getter
private ServerConnection server; private ServerConnection server;
private UpstreamBridge upBridge; private UpstreamBridge upBridge;
@ -49,9 +51,10 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer
private final Map<String, Boolean> permissions = new HashMap<>(); private final Map<String, Boolean> permissions = new HashMap<>();
private final Object permMutex = new Object(); private final Object permMutex = new Object();
public UserConnection(Socket socket, PacketInputStream in, OutputStream out, Packet2Handshake handshake, List<byte[]> loginPackets) public UserConnection(Socket socket, ListenerInfo info, PacketInputStream in, OutputStream out, Packet2Handshake handshake, List<byte[]> loginPackets)
{ {
super(socket, in, out); super(socket, in, out);
this.info = info;
this.handshake = handshake; this.handshake = handshake;
name = handshake.username; name = handshake.username;
displayName = handshake.username; displayName = handshake.username;
@ -372,7 +375,7 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer
in.readFully(data); in.readFully(data);
break; break;
case "BungeeCord::Connect": case "BungeeCord::Connect":
ServerInfo server = ProxyServer.getInstance().getConfigurationAdapter().getServers().get(in.readUTF()); ServerInfo server = BungeeCord.getInstance().config.getServers().get(in.readUTF());
if (server != null) if (server != null)
{ {
connect(server); connect(server);

View File

@ -1,12 +1,11 @@
package net.md_5.bungee.command; package net.md_5.bungee.command;
import java.util.Map; import java.util.Map;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
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.plugin.Command; import net.md_5.bungee.api.plugin.Command;
/** /**
@ -28,7 +27,7 @@ public class CommandServer extends Command
return; return;
} }
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) sender;
Map<String, ServerInfo> servers = ProxyServer.getInstance().getConfigurationAdapter().getServers(); Map<String, ServerInfo> servers = BungeeCord.getInstance().config.getServers();
if (args.length == 0) if (args.length == 0)
{ {
StringBuilder serverList = new StringBuilder(); StringBuilder serverList = new StringBuilder();