-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
659 additions
and
62 deletions.
There are no files selected for viewing
34 changes: 18 additions & 16 deletions
34
bungeecord/src/main/java/net/chrotos/ingress/minecraft/bungeecord/IngressPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
shared/src/main/java/net/chrotos/ingress/minecraft/Endpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package net.chrotos.ingress.minecraft; | ||
|
||
import io.kubernetes.client.openapi.apis.CoreV1Api; | ||
import io.kubernetes.client.openapi.models.V1Endpoint; | ||
import io.kubernetes.client.openapi.models.V1Pod; | ||
|
||
import java.net.InetAddress; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class Endpoint { | ||
private final InetAddress[] addresses; | ||
private final boolean ready; | ||
private final String podName; | ||
private final String podNamespace; | ||
private final String nodeName; | ||
private final List<Integer> ports; | ||
private String gameMode = null; | ||
|
||
public Endpoint(V1Endpoint endpoint, EndpointSlice endpointSlice, CoreV1Api api) { | ||
this.ports = endpointSlice.getPorts(); | ||
|
||
// Translate addresses | ||
this.addresses = new InetAddress[endpoint.getAddresses().size()]; | ||
for (int i = 0; i < addresses.length; i++) { | ||
try { | ||
this.addresses[i] = InetAddress.getByName(endpoint.getAddresses().get(i)); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
// Get ready condition | ||
if (endpoint.getConditions() == null || endpoint.getConditions().getReady() == null) { | ||
this.ready = false; | ||
} else { | ||
this.ready = endpoint.getConditions().getReady(); | ||
} | ||
|
||
// Get Pod name and namespace | ||
if (endpoint.getTargetRef() == null || endpoint.getTargetRef().getKind() == null || | ||
endpoint.getTargetRef().getKind() == null || endpoint.getTargetRef().getName() == null || | ||
endpoint.getTargetRef().getNamespace() == null || | ||
!endpoint.getTargetRef().getKind().equalsIgnoreCase("Pod")) { | ||
this.podName = endpoint.getTargetRef().getName(); | ||
this.podNamespace = endpoint.getTargetRef().getNamespace(); | ||
|
||
try { | ||
V1Pod pod = api.readNamespacedPod(this.podName, this.podNamespace, null); | ||
if (pod.getMetadata() != null && pod.getMetadata().getLabels() != null) { | ||
this.gameMode = pod.getMetadata().getLabels().get("net.chrotos.chrotoscloud.gameserver/gamemode"); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} else { | ||
this.podName = null; | ||
this.podNamespace = null; | ||
} | ||
|
||
this.nodeName = endpoint.getNodeName(); | ||
} | ||
|
||
public InetAddress[] getAddresses() { | ||
return addresses; | ||
} | ||
|
||
public List<Integer> getPorts() { | ||
return ports; | ||
} | ||
|
||
public boolean isReady() { | ||
return ready && this.podName != null && this.podNamespace != null && addresses.length > 0; | ||
} | ||
|
||
public String getPodName() { | ||
return podName; | ||
} | ||
|
||
public String getPodNamespace() { | ||
return podNamespace; | ||
} | ||
|
||
public String getNodeName() { | ||
return nodeName; | ||
} | ||
|
||
public String getGameMode() { | ||
return gameMode; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof Endpoint endpoint)) { | ||
return false; | ||
} | ||
|
||
return Objects.equals(endpoint.podName, podName) && Objects.equals(endpoint.podNamespace, podNamespace); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
shared/src/main/java/net/chrotos/ingress/minecraft/EndpointResourceHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.chrotos.ingress.minecraft; | ||
|
||
public interface EndpointResourceHandler { | ||
void onEventReceived(Endpoint endpointSlice, boolean deleted, Watcher watcher) throws Throwable; | ||
} |
55 changes: 55 additions & 0 deletions
55
shared/src/main/java/net/chrotos/ingress/minecraft/EndpointSlice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package net.chrotos.ingress.minecraft; | ||
|
||
import io.kubernetes.client.openapi.apis.CoreV1Api; | ||
import io.kubernetes.client.openapi.models.DiscoveryV1EndpointPort; | ||
import io.kubernetes.client.openapi.models.V1EndpointSlice; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
public class EndpointSlice { | ||
public static final String APP_PROTOCOL = "com.mojang/minecraft"; | ||
private final V1EndpointSlice endpointSlice; | ||
private final List<Endpoint> readyEndpoints; | ||
private final List<Integer> ports; | ||
|
||
protected EndpointSlice(V1EndpointSlice endpointSlice, CoreV1Api api) { | ||
this.endpointSlice = endpointSlice; | ||
|
||
if (endpointSlice.getPorts() != null) { | ||
this.ports = endpointSlice.getPorts().stream().filter(port -> APP_PROTOCOL.equals(port.getAppProtocol()) && port.getPort() != null) | ||
.map(DiscoveryV1EndpointPort::getPort) | ||
.parallel() | ||
.collect(Collectors.toList()); | ||
} else { | ||
this.ports = Collections.emptyList(); | ||
} | ||
|
||
if (!ports.isEmpty()) { | ||
this.readyEndpoints = endpointSlice.getEndpoints().stream().map(endpoint -> new Endpoint(endpoint, this, api)) | ||
.filter(Endpoint::isReady) | ||
.parallel() | ||
.collect(Collectors.toList()); | ||
} else { | ||
this.readyEndpoints = Collections.emptyList(); | ||
} | ||
} | ||
|
||
public List<Endpoint> getReadyEndpoints() { | ||
return readyEndpoints; | ||
} | ||
|
||
public String getName() { | ||
return Objects.requireNonNull(endpointSlice.getMetadata()).getName(); | ||
} | ||
|
||
public List<Integer> getPorts() { | ||
return ports; | ||
} | ||
|
||
public V1EndpointSlice getEndpointSlice() { | ||
return this.endpointSlice; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
shared/src/main/java/net/chrotos/ingress/minecraft/EndpointSliceRessourceHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package net.chrotos.ingress.minecraft; | ||
|
||
@FunctionalInterface | ||
public interface EndpointSliceRessourceHandler { | ||
void onEventReceived(EndpointSlice endpointSlice, boolean deleted) throws Throwable; | ||
} |
8 changes: 8 additions & 0 deletions
8
shared/src/main/java/net/chrotos/ingress/minecraft/GameModeRessourceHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package net.chrotos.ingress.minecraft; | ||
|
||
import net.chrotos.ingress.minecraft.gamemode.GameMode; | ||
|
||
@FunctionalInterface | ||
public interface GameModeRessourceHandler { | ||
void onEventReceived(GameMode gameMode, boolean deleted) throws Throwable; | ||
} |
Oops, something went wrong.