Well, it compiles, time to start fixing stuff.
This commit is contained in:
parent
cf42a10ba4
commit
bf1e7f09a9
@ -3,6 +3,7 @@ package net.md_5.bungee.api;
|
||||
import net.md_5.bungee.api.plugin.PluginManager;
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.config.ConfigurationAdapter;
|
||||
@ -68,13 +69,24 @@ public abstract class ProxyServer
|
||||
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
|
||||
* @return the associated server
|
||||
*/
|
||||
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
|
||||
* dispatching events. It is recommended that implementations use the
|
||||
|
@ -1,9 +1,5 @@
|
||||
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.config.ServerInfo;
|
||||
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.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.Collection;
|
||||
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.config.ConfigurationAdapter;
|
||||
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.Server;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
@ -153,9 +153,8 @@ public class BungeeCord extends ProxyServer
|
||||
|
||||
for (ListenerInfo info : config.getListeners())
|
||||
{
|
||||
InetSocketAddress addr = info.getHost();
|
||||
$().info("Listening on " + addr);
|
||||
ListenThread listener = new ListenThread(addr);
|
||||
$().info("Listening on " + info.getHost());
|
||||
ListenThread listener = new ListenThread(info);
|
||||
listener.start();
|
||||
listeners.add(listener);
|
||||
}
|
||||
@ -276,4 +275,10 @@ public class BungeeCord extends ProxyServer
|
||||
List<UserConnection> users = connectionsByServer.get(name);
|
||||
return (users != null && !users.isEmpty()) ? users.get(0).getServer() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ServerInfo> getServers()
|
||||
{
|
||||
return config.getServers();
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import java.util.List;
|
||||
import javax.crypto.SecretKey;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
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.event.LoginEvent;
|
||||
import net.md_5.bungee.packet.Packet2Handshake;
|
||||
@ -24,13 +26,15 @@ public class InitialHandler implements Runnable, PendingConnection
|
||||
{
|
||||
|
||||
private final Socket socket;
|
||||
private final ListenerInfo info;
|
||||
private PacketInputStream in;
|
||||
private OutputStream out;
|
||||
private Packet2Handshake handshake;
|
||||
|
||||
public InitialHandler(Socket socket) throws IOException
|
||||
public InitialHandler(Socket socket, ListenerInfo info) throws IOException
|
||||
{
|
||||
this.socket = socket;
|
||||
this.info = info;
|
||||
in = new PacketInputStream(socket.getInputStream());
|
||||
out = socket.getOutputStream();
|
||||
}
|
||||
@ -73,7 +77,10 @@ public class InitialHandler implements Runnable, PendingConnection
|
||||
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;
|
||||
case 0xFE:
|
||||
socket.setSoTimeout(100);
|
||||
@ -89,10 +96,10 @@ public class InitialHandler implements Runnable, PendingConnection
|
||||
String ping = (newPing) ? ChatColor.COLOR_CHAR + "1"
|
||||
+ "\00" + BungeeCord.PROTOCOL_VERSION
|
||||
+ "\00" + BungeeCord.GAME_VERSION
|
||||
+ "\00" + conf.motd
|
||||
+ "\00" + info.getMotd()
|
||||
+ "\00" + ProxyServer.getInstance().getPlayers().size()
|
||||
+ "\00" + conf.maxPlayers
|
||||
: conf.motd + ChatColor.COLOR_CHAR + ProxyServer.getInstance().getPlayers().size() + ChatColor.COLOR_CHAR + conf.maxPlayers;
|
||||
+ "\00" + info.getMaxPlayers()
|
||||
: info.getMotd() + ChatColor.COLOR_CHAR + ProxyServer.getInstance().getPlayers().size() + ChatColor.COLOR_CHAR + info.getMaxPlayers();
|
||||
throw new KickException(ping);
|
||||
default:
|
||||
if (id == 0xFA)
|
||||
|
@ -1,11 +1,11 @@
|
||||
package net.md_5.bungee;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
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.
|
||||
@ -14,12 +14,14 @@ public class ListenThread extends Thread
|
||||
{
|
||||
|
||||
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.bind(addr);
|
||||
socket.bind(info.getHost());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -32,7 +34,7 @@ public class ListenThread extends Thread
|
||||
Socket client = socket.accept();
|
||||
BungeeCord.getInstance().setSocketOptions(client);
|
||||
$().info(client.getInetAddress() + " has connected");
|
||||
InitialHandler handler = new InitialHandler(client);
|
||||
InitialHandler handler = new InitialHandler(client,info);
|
||||
BungeeCord.getInstance().threadPool.submit(handler);
|
||||
} catch (SocketException ex)
|
||||
{
|
||||
|
@ -4,14 +4,12 @@ import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Collection;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
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.Packet1Login;
|
||||
@ -46,7 +44,7 @@ public class ServerConnection extends GenericConnection implements Server
|
||||
try
|
||||
{
|
||||
Socket socket = new Socket();
|
||||
socket.connect(address, BungeeCord.getInstance().config.timeout);
|
||||
socket.connect(address, BungeeCord.getInstance().config.getTimeout());
|
||||
BungeeCord.getInstance().setSocketOptions(socket);
|
||||
|
||||
PacketInputStream in = new PacketInputStream(socket.getInputStream());
|
||||
@ -89,7 +87,7 @@ public class ServerConnection extends GenericConnection implements Server
|
||||
throw 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))
|
||||
{
|
||||
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.
|
||||
}
|
||||
|
||||
@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.
|
||||
return getInfo().getAddress();
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ 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.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
@ -31,6 +32,7 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer
|
||||
public final Packet2Handshake handshake;
|
||||
public Queue<DefinedPacket> packetQueue = new ConcurrentLinkedQueue<>();
|
||||
public List<byte[]> loginPackets = new ArrayList<>();
|
||||
final ListenerInfo info;
|
||||
@Getter
|
||||
private ServerConnection server;
|
||||
private UpstreamBridge upBridge;
|
||||
@ -49,9 +51,10 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer
|
||||
private final Map<String, Boolean> permissions = new HashMap<>();
|
||||
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);
|
||||
this.info = info;
|
||||
this.handshake = handshake;
|
||||
name = handshake.username;
|
||||
displayName = handshake.username;
|
||||
@ -372,7 +375,7 @@ public class UserConnection extends GenericConnection implements ProxiedPlayer
|
||||
in.readFully(data);
|
||||
break;
|
||||
case "BungeeCord::Connect":
|
||||
ServerInfo server = ProxyServer.getInstance().getConfigurationAdapter().getServers().get(in.readUTF());
|
||||
ServerInfo server = BungeeCord.getInstance().config.getServers().get(in.readUTF());
|
||||
if (server != null)
|
||||
{
|
||||
connect(server);
|
||||
|
@ -1,12 +1,11 @@
|
||||
package net.md_5.bungee.command;
|
||||
|
||||
import java.util.Map;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
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.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
|
||||
/**
|
||||
@ -28,7 +27,7 @@ public class CommandServer extends Command
|
||||
return;
|
||||
}
|
||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||
Map<String, ServerInfo> servers = ProxyServer.getInstance().getConfigurationAdapter().getServers();
|
||||
Map<String, ServerInfo> servers = BungeeCord.getInstance().config.getServers();
|
||||
if (args.length == 0)
|
||||
{
|
||||
StringBuilder serverList = new StringBuilder();
|
||||
|
Loading…
Reference in New Issue
Block a user