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
a3db816
commit 7087c35
Showing
21 changed files
with
604 additions
and
186 deletions.
There are no files selected for viewing
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
44 changes: 44 additions & 0 deletions
44
api/src/main/java/fr/atlasworld/network/api/networking/ConnectionSource.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,44 @@ | ||
package fr.atlasworld.network.api.networking; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import fr.atlasworld.network.api.concurrent.action.FutureAction; | ||
import fr.atlasworld.network.api.networking.packet.NetworkPacket; | ||
import fr.atlasworld.network.api.networking.packet.PacketByteBuf; | ||
import fr.atlasworld.network.api.networking.packet.SentPacket; | ||
|
||
import java.util.UUID; | ||
|
||
public interface ConnectionSource { | ||
|
||
/** | ||
* Get the connection's unique identifier. | ||
* @return null if the connection is still in the handshake process. | ||
*/ | ||
UUID getUniqueIdentifier(); | ||
|
||
/** | ||
* Get the state of the connection. | ||
*/ | ||
ConnectionState getState(); | ||
|
||
/** | ||
* Creates an empty PacketByteBuf. | ||
*/ | ||
PacketByteBuf createBuffer(); | ||
|
||
/** | ||
* Sends a packet to the source. | ||
* @param packet packet to send. | ||
* @return future async action of the sending task. | ||
*/ | ||
@CanIgnoreReturnValue | ||
FutureAction<SentPacket> send(NetworkPacket packet); | ||
|
||
/** | ||
* Sends a packet to the source. | ||
* @param buffer packet to send. | ||
* @return future async action of the sending task. | ||
*/ | ||
@CanIgnoreReturnValue | ||
FutureAction<SentPacket> send(PacketByteBuf buffer); | ||
} |
21 changes: 21 additions & 0 deletions
21
api/src/main/java/fr/atlasworld/network/api/networking/ConnectionState.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,21 @@ | ||
package fr.atlasworld.network.api.networking; | ||
|
||
public enum ConnectionState { | ||
/** | ||
* Connection is in the handshake process, | ||
* at this state the connection is neither authenticated nor encrypted. | ||
*/ | ||
HANDSHAKE, | ||
|
||
/** | ||
* Connection is connected and validated, | ||
* at this state the connection has been fully authenticated and is encrypted. | ||
*/ | ||
CONNECTED, | ||
|
||
/** | ||
* Used for packet registration, this state will never be on an actual connection. | ||
* This makes the packet available in the handshake and connected state. | ||
*/ | ||
HANDSHAKE_AND_CONNECTED; | ||
} |
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
15 changes: 15 additions & 0 deletions
15
...rc/main/java/fr/atlasworld/network/api/networking/exception/PacketExecutionException.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,15 @@ | ||
package fr.atlasworld.network.api.networking.exception; | ||
|
||
public class PacketExecutionException extends PacketNetworkingException { | ||
public PacketExecutionException(String packetIdentifier) { | ||
super("Something went wrong while processing " + packetIdentifier + ".", packetIdentifier); | ||
} | ||
|
||
public PacketExecutionException(String message, String packetIdentifier) { | ||
super(message, packetIdentifier); | ||
} | ||
|
||
public PacketExecutionException(String message, Throwable cause, String packetIdentifier) { | ||
super(message, cause, packetIdentifier); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...c/main/java/fr/atlasworld/network/api/networking/exception/PacketNetworkingException.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,19 @@ | ||
package fr.atlasworld.network.api.networking.exception; | ||
|
||
public class PacketNetworkingException extends NetworkingException { | ||
private final String packetIdentifier; | ||
|
||
public PacketNetworkingException(String packetIdentifier) { | ||
this.packetIdentifier = packetIdentifier; | ||
} | ||
|
||
public PacketNetworkingException(String message, String packetIdentifier) { | ||
super(message); | ||
this.packetIdentifier = packetIdentifier; | ||
} | ||
|
||
public PacketNetworkingException(String message, Throwable cause, String packetIdentifier) { | ||
super(message, cause); | ||
this.packetIdentifier = packetIdentifier; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
api/src/main/java/fr/atlasworld/network/api/networking/exception/UnknownPacketException.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,11 @@ | ||
package fr.atlasworld.network.api.networking.exception; | ||
|
||
public class UnknownPacketException extends PacketNetworkingException { | ||
public UnknownPacketException(String packetIdentifier) { | ||
super("Received unknown packet '" + packetIdentifier + "'.", packetIdentifier); | ||
} | ||
|
||
public UnknownPacketException(String message, String packetIdentifier) { | ||
super(message, packetIdentifier); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
api/src/main/java/fr/atlasworld/network/api/networking/packet/NetworkPacket.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,28 @@ | ||
package fr.atlasworld.network.api.networking.packet; | ||
|
||
import fr.atlasworld.network.api.networking.ConnectionSource; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Represents a network packet. | ||
*/ | ||
public interface NetworkPacket { | ||
|
||
/** | ||
* Get the unique identifier of the packet. | ||
*/ | ||
@NotNull String getKey(); | ||
|
||
/** | ||
* Decodes and process received requests. | ||
* @param source source from which we received a packet. | ||
* @param buf received buffer. | ||
*/ | ||
void decode(@NotNull ConnectionSource source, @NotNull PacketByteBuf buf); | ||
|
||
/** | ||
* Used when the packet is created before sending. | ||
* @param buffer to encode. | ||
*/ | ||
void encode(@NotNull PacketByteBuf buffer); | ||
} |
25 changes: 25 additions & 0 deletions
25
api/src/main/java/fr/atlasworld/network/api/networking/packet/PacketRegistry.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,25 @@ | ||
package fr.atlasworld.network.api.networking.packet; | ||
|
||
import fr.atlasworld.network.api.module.Module; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Packet Registry, holds every packet. | ||
*/ | ||
public interface PacketRegistry { | ||
|
||
/** | ||
* Register a packet to the registry. | ||
* @param builder packet builder. | ||
*/ | ||
<T extends NetworkPacket> void register(@NotNull Supplier<T> builder); | ||
|
||
/** | ||
* Unregister a packet from registry. | ||
* @param key key of the packet. | ||
*/ | ||
void unregister(@NotNull String key); | ||
} |
14 changes: 14 additions & 0 deletions
14
api/src/main/java/fr/atlasworld/network/api/networking/packet/SentPacket.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,14 @@ | ||
package fr.atlasworld.network.api.networking.packet; | ||
|
||
import fr.atlasworld.network.api.networking.ConnectionSource; | ||
|
||
/** | ||
* Abstract sent packet, this is supposed to be a sent packet. | ||
*/ | ||
public interface SentPacket { | ||
|
||
/** | ||
* Get the target of the packet. | ||
*/ | ||
ConnectionSource getTarget(); | ||
} |
14 changes: 14 additions & 0 deletions
14
...va/fr/atlasworld/network/api/services/database/exceptions/UncheckedDatabaseException.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,14 @@ | ||
package fr.atlasworld.network.api.services.database.exceptions; | ||
|
||
import java.io.UncheckedIOException; | ||
|
||
public class UncheckedDatabaseException extends UncheckedIOException { | ||
|
||
public UncheckedDatabaseException(String message, DatabaseException cause) { | ||
super(message, cause); | ||
} | ||
|
||
public UncheckedDatabaseException(DatabaseException cause) { | ||
super(cause); | ||
} | ||
} |
137 changes: 0 additions & 137 deletions
137
src/main/java/fr/atlasworld/network/core/networking/handler/DecodeHandler.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.