Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

IPv6 Integration #281

Merged
merged 10 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
import org.bukkit.plugin.java.JavaPlugin;

import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.file.Paths;

/**
* Created by Tareko on 17.08.2017.
*/
public final class BukkitBootstrap extends JavaPlugin {

/**
Expand All @@ -27,9 +25,13 @@ public final class BukkitBootstrap extends JavaPlugin {

@Override
public void onLoad() {
api = new CloudAPI(new CloudConfigLoader(Paths.get("CLOUD", "connection.json"),
Paths.get("CLOUD", "config.json"),
ConfigTypeLoader.INTERNAL), getLogger());
try {
api = new CloudAPI(new CloudConfigLoader(Paths.get("CLOUD", "connection.json"),
Paths.get("CLOUD", "config.json"),
ConfigTypeLoader.INTERNAL), getLogger());
} catch (UnknownHostException e) {
e.printStackTrace();
}
}

@Override
Expand Down Expand Up @@ -63,16 +65,6 @@ public void onEnable() {
loadPlayers();
}

/**
* If players are joined on the Bukkit server prior to this plugin being enabled (ie. a reload just happened),
* loads all players from the cloud into the cache.
*/
private void loadPlayers() {
for (Player all : getServer().getOnlinePlayers()) {
api.getOnlinePlayer(all.getUniqueId());
}
}

/**
* Starts the update task for this server.
*/
Expand All @@ -89,6 +81,16 @@ private void startUpdateTask() {
}
}

/**
* If players are joined on the Bukkit server prior to this plugin being enabled (ie. a reload just happened),
* loads all players from the cloud into the cache.
*/
private void loadPlayers() {
for (Player all : getServer().getOnlinePlayers()) {
api.getOnlinePlayer(all.getUniqueId());
}
}

/**
* Returns the runnable to be executed when updating the server instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Plugin;
import org.apache.commons.validator.routines.InetAddressValidator;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -228,11 +231,13 @@ private String getDefaultFallbackServer(final String kickedFrom) {
}
}

@Override
public CompletableFuture<ProxyProcessMeta> waitForProxy(final UUID uuid) {
final CompletableFuture<ProxyProcessMeta> future = new CompletableFuture<>();
this.waitingProxies.put(uuid, future);
return future;
/**
* Returns the instance of this {@link CloudProxy}.
*
* @return the singleton instance of this class.
*/
public static CloudProxy getInstance() {
return instance;
}

/**
Expand Down Expand Up @@ -294,14 +299,22 @@ public void updateAsync() {
* Updates this proxy instance with all of its' state using the API.
*/
public void update() {
new ProxyInfo(this.cloudAPI.getServiceId(),
this.cloudAPI.getConfig().getString("host"),
0,
true,
ProxyServer.getInstance().getPlayers().stream()
.collect(Collectors.toMap(ProxiedPlayer::getUniqueId, CommandSender::getName)),
proxyProcessMeta.getMemory())
.fetch(this.cloudAPI::update);
String host = this.cloudAPI.getConfig().getString("host");

try {
if (InetAddressValidator.getInstance().isValid(host)) {
new ProxyInfo(this.cloudAPI.getServiceId(),
InetAddress.getByName(host),
0,
true,
ProxyServer.getInstance().getPlayers().stream()
.collect(Collectors.toMap(ProxiedPlayer::getUniqueId, CommandSender::getName)),
proxyProcessMeta.getMemory())
.fetch(this.cloudAPI::update);
}
} catch (UnknownHostException e) {
e.printStackTrace();
}
}

/**
Expand Down Expand Up @@ -355,6 +368,13 @@ public Map<String, ServerInfo> getServers() {
return this.cachedServers;
}

@Override
public CompletableFuture<ProxyProcessMeta> waitForProxy(final UUID uuid) {
final CompletableFuture<ProxyProcessMeta> future = new CompletableFuture<>();
this.waitingProxies.put(uuid, future);
return future;
}

@Override
public CompletableFuture<ServerProcessMeta> waitForServer(final UUID uuid) {
final CompletableFuture<ServerProcessMeta> future = new CompletableFuture<>();
Expand Down Expand Up @@ -492,15 +512,6 @@ public void onCloudNetworkUpdate(CloudNetwork cloudNetwork) {

}

/**
* Returns the instance of this {@link CloudProxy}.
*
* @return the singleton instance of this class.
*/
public static CloudProxy getInstance() {
return instance;
}

@Override
public void onCustomChannelMessageReceive(String channel, String message, Document document) {
if (handle(channel, message, document)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
Expand All @@ -50,7 +51,7 @@ public class CloudServer implements CloudService, NetworkHandler {
private final BukkitBootstrap bukkitBootstrap;

private final Map<UUID, CloudPlayer> cloudPlayers = new ConcurrentHashMap<>();
private final String hostAddress;
private final InetAddress hostAddress;
private final int port;
private final Template template;
private final int memory;
Expand Down Expand Up @@ -210,7 +211,7 @@ public int getPort() {
return port;
}

public String getHostAddress() {
public InetAddress getHostAddress() {
return hostAddress;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;

import java.net.UnknownHostException;
import java.nio.file.Paths;
import java.util.logging.Level;

Expand All @@ -32,9 +33,13 @@ public class ProxiedBootstrap extends Plugin {

@Override
public void onLoad() {
this.api = new CloudAPI(new CloudConfigLoader(Paths.get("CLOUD", "connection.json"),
Paths.get("CLOUD", "config.json"),
ConfigTypeLoader.INTERNAL), this.getLogger());
try {
this.api = new CloudAPI(new CloudConfigLoader(Paths.get("CLOUD", "connection.json"),
Paths.get("CLOUD", "config.json"),
ConfigTypeLoader.INTERNAL), this.getLogger());
} catch (UnknownHostException e) {
e.printStackTrace();
}
getLogger().setLevel(Level.INFO);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.bukkit.Bukkit;

import java.lang.reflect.Type;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -62,15 +64,16 @@ public final class CloudAPI {
//Init
private CloudNetwork cloudNetwork = new CloudNetwork();

public CloudAPI(CloudConfigLoader loader, final Logger logger) {
public CloudAPI(CloudConfigLoader loader, final Logger logger) throws UnknownHostException {
if (instance != null) {
throw new IllegalStateException("CloudAPI already instantiated.");
}
instance = this;
this.cloudConfigLoader = loader;
this.logger = logger;
this.config = loader.loadConfig();
this.networkConnection = new NetworkConnection(loader.loadConnnection(), new ConnectableAddress("0.0.0.0", 0));
this.networkConnection = new NetworkConnection(loader.loadConnnection(),
new ConnectableAddress(InetAddress.getByName("0.0.0.0"), 0));
this.serviceId = config.getObject("serviceId", ServiceId.TYPE);
this.memory = config.getInt("memory");

Expand Down
6 changes: 6 additions & 0 deletions cloudnet-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-validator/commons-validator -->
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,28 @@
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.net.InetAddress;

/**
* Created by Tareko on 07.06.2017.
* Class specifying a Adress & Port Combination
* for Wrapper & Master Connections
*/
public class ConnectableAddress {

public static final Type TYPE = TypeToken.get(ConnectableAddress.class).getType();
private final String hostName;
private final InetAddress hostName;
private final int port;

public ConnectableAddress(String hostName, int port) {
this.hostName = hostName;
public ConnectableAddress(InetAddress adress, int port) {
this.hostName = adress;
this.port = port;
}

public int getPort() {
return port;
}

public String getHostName() {
public InetAddress getHostName() {
return hostName;
}
}
Loading