This repository has been archived by the owner on Mar 11, 2024. It is now read-only.
-
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
1 parent
a330e9b
commit bad6e80
Showing
23 changed files
with
299 additions
and
25 deletions.
There are no files selected for viewing
2 changes: 0 additions & 2 deletions
2
api/src/main/java/fr/atlasworld/network/api/AtlasNetwork.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
2 changes: 1 addition & 1 deletion
2
...etwork/api/server/AtlasNetworkServer.java → ...world/network/api/AtlasNetworkServer.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
2 changes: 1 addition & 1 deletion
2
api/src/main/java/fr/atlasworld/network/api/command/CommandSource.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
2 changes: 1 addition & 1 deletion
2
api/src/main/java/fr/atlasworld/network/api/module/lifecycle/ModuleActivationContext.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
2 changes: 1 addition & 1 deletion
2
api/src/main/java/fr/atlasworld/network/api/module/lifecycle/ModuleDeactivationContext.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
2 changes: 1 addition & 1 deletion
2
api/src/main/java/fr/atlasworld/network/api/module/lifecycle/ModuleLoadContext.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
101 changes: 101 additions & 0 deletions
101
api/src/main/java/fr/atlasworld/network/api/server/NetworkServer.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,101 @@ | ||
package fr.atlasworld.network.api.server; | ||
|
||
import fr.atlasworld.network.api.concurrent.action.FutureAction; | ||
import fr.atlasworld.network.api.server.lifecycle.ServerStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.PrintStream; | ||
import java.net.InetSocketAddress; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Represents a server running on AtlasWorld's Network. | ||
* A server can be anything, from a Minecraft Server to the Discord bot. | ||
*/ | ||
public interface NetworkServer { | ||
|
||
/** | ||
* Retrieve the unique identifier of the server. | ||
* @return unique identifier | ||
*/ | ||
@NotNull UUID identifier(); | ||
|
||
/** | ||
* Retrieve the user readable name of the server. | ||
* @return the user readable name of the server | ||
*/ | ||
@NotNull String getUserReadableName(); | ||
|
||
/** | ||
* Retrieve the local status of the server. | ||
* <p> | ||
* Warning: This data may not be entirely true. | ||
* The server may be marked as running or active, | ||
* but this does not mean that the server is accessible! | ||
* <p> | ||
* if you want to make sure that the server is accessible you should ping the server. | ||
* With {@link #retrieveCachedPingRequest()} and {@link #ping()} | ||
* @return the detected server status | ||
*/ | ||
ServerStatus getStatus(); | ||
|
||
/** | ||
* Retrieve the remote address of the server. | ||
* @return remote server address | ||
*/ | ||
InetSocketAddress remoteAddress(); | ||
|
||
/** | ||
* Retrieve the last cached ping request. | ||
* <p> | ||
* Use {@link PingRequest#timestamp()} to check the time of the last request | ||
* always check the timestamp of the request before trusting the data! | ||
* It may be out-dated! | ||
* @return null if no ping request was sent. | ||
*/ | ||
PingRequest retrieveCachedPingRequest(); | ||
|
||
/** | ||
* Send a ping request to the server. | ||
* <p> | ||
* Do not use this method extensively! | ||
* If you need to fetch the ping request multiple times use {@link #retrieveCachedPingRequest()} | ||
* Instead of pinging the server multiple times | ||
* @return the future answer of the ping request. | ||
*/ | ||
FutureAction<PingRequest> ping(); | ||
|
||
/** | ||
* Checks if the server was created by the automated system or by the user. | ||
* <p> | ||
* If this returns false the server should not be managed by the system. | ||
* | ||
* @return false if the server was created or added by a user. | ||
*/ | ||
boolean isDynamicallyCreated(); | ||
|
||
/** | ||
* Checks whether the server should be listed in the server selection menu. | ||
* | ||
* @return false if it shouldn't be listed, true otherwise. | ||
*/ | ||
boolean shouldBeListed(); | ||
|
||
/** | ||
* Starts the server. | ||
* | ||
* @return the future action completed when the server is started. | ||
* @throws UnsupportedOperationException if the server implementation does not support starting the server. | ||
* @throws IllegalStateException if the server is not running. | ||
*/ | ||
FutureAction<Void> start(); | ||
|
||
/** | ||
* Stops the server. | ||
* | ||
* @return the future action completed when the server is stopped. | ||
* @throws UnsupportedOperationException if the server implementation does not support stopping the server. | ||
* @throws IllegalStateException if the server is not running. | ||
*/ | ||
FutureAction<Void> stop(); | ||
} |
40 changes: 40 additions & 0 deletions
40
api/src/main/java/fr/atlasworld/network/api/server/PingRequest.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,40 @@ | ||
package fr.atlasworld.network.api.server; | ||
|
||
import com.google.gson.JsonObject; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Abstract Ping request implementation that represents a server ping request. | ||
*/ | ||
public interface PingRequest { | ||
|
||
/** | ||
* Get the timestamp of the time the request was received. | ||
*/ | ||
long timestamp(); | ||
|
||
/** | ||
* Checks if the request was successful. | ||
* @return true if the request was successful, false otherwise | ||
*/ | ||
boolean success(); | ||
|
||
/** | ||
* Get the returned request code. | ||
* @return returns the resulted HTTP code request. Returns -1 if the request failed. | ||
*/ | ||
int requestCode(); | ||
|
||
/** | ||
* Retrieve the retrieved response of the server. | ||
* @return null if the server did not respond or did not send any data back. | ||
*/ | ||
@Nullable | ||
JsonObject getResponse(); | ||
|
||
/** | ||
* Check if the server sent data back. | ||
* @return false if the server did not respond or did not send any data back. | ||
*/ | ||
boolean hasResponse(); | ||
} |
6 changes: 3 additions & 3 deletions
6
.../api/server/event/ServerStartedEvent.java → ...erver/event/SystemServerStartedEvent.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
57 changes: 57 additions & 0 deletions
57
api/src/main/java/fr/atlasworld/network/api/server/lifecycle/ServerStatus.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,57 @@ | ||
package fr.atlasworld.network.api.server.lifecycle; | ||
|
||
import fr.atlasworld.network.api.server.NetworkServer; | ||
|
||
/** | ||
* Server status, this list every status possible by the server. | ||
*/ | ||
public enum ServerStatus { | ||
|
||
/** | ||
* Server is setting up / installing. | ||
* In this state not much can be done. | ||
*/ | ||
INSTALLING, | ||
|
||
/** | ||
* Server installation failed. | ||
* This could mean that the server installation instructions may not be correct. | ||
*/ | ||
CORRUPTED, | ||
|
||
/** | ||
* Server is stopped and in an inactive state. | ||
*/ | ||
STOPPED, | ||
|
||
/** | ||
* Server is starting and is not yet able to handle requests. | ||
*/ | ||
STARTING, | ||
|
||
/** | ||
* Server is started/running and is in an active state. | ||
*/ | ||
STARTED, | ||
|
||
/** | ||
* Server is stopping. | ||
*/ | ||
STOPPING, | ||
|
||
/** | ||
* Server is deleted and in this state the server should not be interacted with. | ||
* The server actions are very limited, | ||
* and interacting with it may cause unexpected crashes or issues. | ||
*/ | ||
DELETED, | ||
|
||
/** | ||
* The server status could not be detected, | ||
* or the {@link NetworkServer} implementation did not support server statuses. | ||
* <p> | ||
* Methods changing the server state will skip the state checks if the server is | ||
* in this state. | ||
*/ | ||
UNKNOWN; | ||
} |
13 changes: 13 additions & 0 deletions
13
api/src/main/java/fr/atlasworld/network/api/server/servers/MinecraftProxyServer.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,13 @@ | ||
package fr.atlasworld.network.api.server.servers; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public abstract class MinecraftProxyServer extends MinecraftServer{ | ||
protected MinecraftProxyServer(UUID identifier, String name, boolean dynamicallyCreated, InetSocketAddress address) { | ||
super(identifier, name, dynamicallyCreated, address); | ||
} | ||
|
||
public abstract List<MinecraftServer> listAvailableServers(); | ||
} |
65 changes: 65 additions & 0 deletions
65
api/src/main/java/fr/atlasworld/network/api/server/servers/MinecraftServer.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,65 @@ | ||
package fr.atlasworld.network.api.server.servers; | ||
|
||
import fr.atlasworld.network.api.server.NetworkServer; | ||
import fr.atlasworld.network.api.server.lifecycle.ServerStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.util.UUID; | ||
|
||
/** | ||
* Abstract representation of a Minecraft Server running on AtlasWorld's Network. | ||
*/ | ||
public abstract class MinecraftServer implements NetworkServer { | ||
protected final UUID identifier; | ||
protected final String name; | ||
protected final boolean dynamicallyCreated; | ||
protected final InetSocketAddress address; | ||
|
||
protected ServerStatus status; | ||
|
||
protected MinecraftServer(UUID identifier, String name, boolean dynamicallyCreated, InetSocketAddress address) { | ||
this.identifier = identifier; | ||
this.name = name; | ||
this.dynamicallyCreated = dynamicallyCreated; | ||
this.address = address; | ||
} | ||
|
||
|
||
@Override | ||
public @NotNull UUID identifier() { | ||
return this.identifier; | ||
} | ||
|
||
@Override | ||
public @NotNull String getUserReadableName() { | ||
return this.name; | ||
} | ||
|
||
@Override | ||
public ServerStatus getStatus() { | ||
return this.status; | ||
} | ||
|
||
@Override | ||
public InetSocketAddress remoteAddress() { | ||
return this.remoteAddress(); | ||
} | ||
|
||
@Override | ||
public boolean isDynamicallyCreated() { | ||
return this.dynamicallyCreated; | ||
} | ||
|
||
/** | ||
* Retrieve the server player count. | ||
* @return player count. | ||
*/ | ||
public abstract int getPlayerCount(); | ||
|
||
/** | ||
* Retrieve the MOTD of the server. | ||
* @return MOTD of the server. | ||
*/ | ||
public abstract String getMOTD(); | ||
} |
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
Oops, something went wrong.