mirror of
https://github.com/OvercastNetwork/ProjectAres.git
synced 2025-04-11 22:56:08 +02:00
Report external ip address to api
This commit is contained in:
parent
736803709c
commit
50ef439922
@ -50,7 +50,8 @@ public interface ServerDoc {
|
||||
}
|
||||
|
||||
@Serialize
|
||||
interface CurrentPort extends Partial {
|
||||
interface Ip extends Partial {
|
||||
String ip();
|
||||
Integer current_port();
|
||||
}
|
||||
|
||||
@ -95,7 +96,7 @@ public interface ServerDoc {
|
||||
* Startup info sent to the API
|
||||
*/
|
||||
@Serialize
|
||||
interface Startup extends Online, CurrentPort {
|
||||
interface Startup extends Online, Ip {
|
||||
@Nullable DeployInfo deploy_info();
|
||||
Map<String, String> plugin_versions();
|
||||
Set<Integer> protocol_versions();
|
||||
|
@ -1,9 +1,14 @@
|
||||
package tc.oc.api.minecraft.servers;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
@ -51,10 +56,25 @@ public class StartupServerDocument implements ServerDoc.Startup {
|
||||
}
|
||||
});
|
||||
|
||||
private final Lazy<String> ip = Lazy.from(() -> {
|
||||
try {
|
||||
URL url = new URL("http://checkip.amazonaws.com");
|
||||
return new BufferedReader(new InputStreamReader(url.openStream())).readLine();
|
||||
} catch(IOException e) {
|
||||
logger.log(Level.SEVERE, "Unable to find external ip", e);
|
||||
return minecraftServer.getAddress().getHostName();
|
||||
}
|
||||
});
|
||||
|
||||
@Override public boolean online() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String ip() {
|
||||
return ip.get();
|
||||
}
|
||||
|
||||
@Override public Integer current_port() {
|
||||
return minecraftServer.getAddress().getPort();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user