public ProxyObject getFreeProxy(ProxyGroupObject group) { if (group.getProxyChooseStrategy() == null) { TimoCloudCord.getInstance().severe("Error while choosing proxy: ProxyChooseStrategy of group '" + group.getName() + "' is null. Please report this."); return null; } List<ProxyObject> proxies = group.getProxies().stream().filter(proxy -> proxy.getOnlinePlayerCount() < proxy.getGroup().getMaxPlayerCountPerProxy()).collect(Collectors.toList()); proxies.sort(Comparator.comparing(ProxyObject::getOnlinePlayerCount)); if (proxies.size() == 0) return null; switch (group.getProxyChooseStrategy()) { case RANDOM: return proxies.get(new Random().nextInt(proxies.size())); case FILL: return proxies.get(proxies.size() - 1); case BALANCE: return proxies.get(0); } return null; }
cf.addListener((ChannelFutureListener) future -> { if (future.isSuccess()) { TimoCloudCord.getInstance().info("[" + channel.remoteAddress() + "] connected to hostname '" + hostName + "'. Using proxy " + proxyObject.getName() + " of group " + proxyObject.getGroup().getName() + "."); if (channel.attr(UPSTREAM_HANDLER).get() == null) { ProxyUpstreamHandler upstreamHandler = new ProxyUpstreamHandler(cf.channel(), downstreamHandler);
public static void connectClient(Channel channel, ProxyGroupObject proxyGroupObject, String hostName, ByteBuf loginPacket) { ProxyObject proxyObject = TimoCloudCord.getInstance().getProxyManager().getFreeProxy(proxyGroupObject); if (proxyObject == null) { TimoCloudCord.getInstance().severe("No free proxy of group '" + proxyGroupObject.getName() + "' found. Disconnecting client."); channel.close(); return; } connectClient(channel, proxyObject, hostName, loginPacket); }