Skip to content

Commit

Permalink
v1.0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
pwaillette committed Dec 29, 2023
1 parent b18b98b commit 8cbd63b
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Publish package to GitHub Packages
on:
release:
types: [created]
types: [ created ]
workflow_dispatch:
jobs:
publish:
Expand Down
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,23 @@


<!-- ABOUT CORAL -->

## About Coral

Nothing to see here
<p align="right">(<a href="#readme-top">back to top</a>)</p>

### Built With

[![Java][Java]][Java-url]
[![Java][Java]][Java-url]
[![Gradle][Gradle]][Gradle-url]

<p align="right">(<a href="#readme-top">back to top</a>)</p>



<!-- GETTING STARTED -->

## Getting Started

Currently, this project is not ready for use. Please check back later.
Expand All @@ -83,25 +85,30 @@ Not ready yet


<!-- ROADMAP -->

## Roadmap

<!-- - [ ] Feature 1-->
<!-- - [ ] Feature 2-->
<!-- - [ ] Feature 3-->
<!-- - [ ] Nested Feature-->

See the [open issues](https://github.com/github_username/repo_name/issues) for a full list of proposed features (and known issues).
See the [open issues](https://github.com/github_username/repo_name/issues) for a full list of proposed features (and
known issues).

<p align="right">(<a href="#readme-top">back to top</a>)</p>



<!-- CONTRIBUTING -->

## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any
contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also
simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!

1. Fork the Project
Expand All @@ -115,13 +122,15 @@ Don't forget to give the project a star! Thanks again!


<!-- LICENSE -->

## License

Distributed under the Apache Licence v2.0. See `LICENSE` for more information.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

<!-- CONTACT -->

## Contact

Léa - [Discord](https://discord.com/users/985986599995187270) - [[email protected]]([email protected])
Expand All @@ -131,6 +140,7 @@ Project Link: [https://github.com/St-Mary/Coral](https://github.com/St-Mary/Game
<p align="right">(<a href="#readme-top">back to top</a>)</p>

<!-- ACKNOWLEDGMENTS -->

## Acknowledgments

* [RedBoxing](https://github.com/RedBoxing)
Expand All @@ -141,17 +151,31 @@ Project Link: [https://github.com/St-Mary/Coral](https://github.com/St-Mary/Game

<!-- MARKDOWN LINKS & IMAGES -->
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->

[contributors-shield]: https://img.shields.io/github/contributors/St-Mary/Coral.svg?style=for-the-badge

[contributors-url]: https://github.com/St-Mary/Coral/graphs/contributors

[forks-shield]: https://img.shields.io/github/forks/St-Mary/Coral.svg?style=for-the-badge

[forks-url]: https://github.com/St-Mary/Coral/network/members

[stars-shield]: https://img.shields.io/github/stars/St-Mary/Coral.svg?style=for-the-badge

[stars-url]: https://github.com/St-Mary/Coral/stargazers

[issues-shield]: https://img.shields.io/github/issues/St-Mary/Coral.svg?style=for-the-badge

[issues-url]: https://github.com/St-Mary/Coral/issues

[license-shield]: https://img.shields.io/github/license/St-Mary/Coral.svg?style=for-the-badge

[license-url]: https://github.com/St-Mary/Coral/blob/master/LICENSE

[Java-url]: https://www.java.com/fr/

[Java]: https://img.shields.io/badge/Java-ED8B00?style=for-the-badge&logo=openjdk&logoColor=white

[Gradle]: https://img.shields.io/badge/gradle-02303A?logo=gradle&style=for-the-badge&logoWidth=25

[Gradle-url]: https://gradle.org/
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "com.stmarygate"
version = "1.0.13"
version = "1.0.14"

repositories {
mavenCentral()
Expand Down Expand Up @@ -37,6 +37,7 @@ dependencies {
implementation("org.springframework.security:spring-security-core:6.2.1")
implementation("org.springframework.security:spring-security-crypto:6.2.1")
implementation("org.bouncycastle:bcprov-jdk18on:1.77")
implementation("org.jetbrains:annotations:24.1.0")

testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/stmarygate/coral/network/BaseChannel.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.stmarygate.coral.network;

import com.stmarygate.coral.network.packets.Packet;
import com.stmarygate.coral.network.packets.PacketHandler;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import java.lang.reflect.InvocationTargetException;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;

/**
* Represents a channel handler for handling incoming packets of type {@link Packet}. It uses a
Expand All @@ -28,7 +30,7 @@ public class BaseChannel extends SimpleChannelInboundHandler<Packet> {
* @param clazz The class of the packet handler to be used.
* @throws RuntimeException If the packet handler class does not contain the required constructor.
*/
public BaseChannel(Class<? extends PacketHandler> clazz) {
public BaseChannel(@NotNull Class<? extends PacketHandler> clazz) {
try {
this.handler = clazz.getDeclaredConstructor(BaseChannel.class).newInstance(this);
} catch (InstantiationException
Expand All @@ -48,7 +50,8 @@ public BaseChannel(Class<? extends PacketHandler> clazz) {
* @param msg The incoming packet to be handled.
*/
@Override
protected void channelRead0(ChannelHandlerContext ctx, Packet msg) throws Exception {
protected void channelRead0(@NotNull ChannelHandlerContext ctx, @NotNull Packet msg)
throws Exception {
this.handler.handlePacket(msg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import lombok.AllArgsConstructor;
import org.jetbrains.annotations.NotNull;

/**
* Initializes a {@link SocketChannel} by configuring its {@link ChannelPipeline} with necessary
Expand All @@ -24,7 +25,7 @@ public class BaseInitializer extends ChannelInitializer<SocketChannel> {
* @param ch The {@link SocketChannel} to be initialized.
*/
@Override
protected void initChannel(SocketChannel ch) {
protected void initChannel(@NotNull SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();

// Add packet decoding and encoding handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.stmarygate.coral.network.packets.Packet;
import io.netty.channel.Channel;
import java.util.Arrays;
import org.jetbrains.annotations.NotNull;

/**
* Represents a session associated with a client's communication channel. It provides methods to
Expand All @@ -28,7 +29,7 @@ public ClientSession(Channel channel) {
*
* @param packet The packet to be sent to the client.
*/
public void write(Packet packet) throws Exception {
public void write(@NotNull Packet packet) throws Exception {
try {
this.channel.writeAndFlush(packet);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import java.util.List;
import org.jetbrains.annotations.NotNull;

/**
* The {@code PacketDecoder} class is responsible for decoding raw bytes received over the network
Expand Down Expand Up @@ -51,7 +52,8 @@ public PacketDecoder() {}
* @throws Exception if an error occurs during the decoding process
*/
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
protected void decode(@NotNull ChannelHandlerContext ctx, ByteBuf msg, @NotNull List<Object> out)
throws Exception {
// Duplicate and retain the incoming buffer for manipulation
if (this.buffer == null || this.buffer.readableBytes() == 0) {
this.buffer = msg.duplicate().retain();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.jetbrains.annotations.NotNull;

/**
* The {@code PacketEncoder} class is responsible for encoding instances of the {@link Packet} class
Expand Down Expand Up @@ -65,7 +66,9 @@ public PacketEncoder() {
* @see Packet#encode(PacketBuffer)
*/
@Override
protected void encode(ChannelHandlerContext ctx, Packet msg, ByteBuf out) throws Exception {
protected void encode(
@NotNull ChannelHandlerContext ctx, @NotNull Packet msg, @NotNull ByteBuf out)
throws Exception {
try {
msg.encode(
new PacketBuffer(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.stmarygate.coral.network.packets;

import com.stmarygate.coral.network.PacketHandler;

/** Represents a generic packet in the network communication. */
public class Packet {
/** The size of the packet header in bytes. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.stmarygate.coral.network;
package com.stmarygate.coral.network.packets;

import com.stmarygate.coral.network.packets.Packet;
import com.stmarygate.coral.network.BaseChannel;
import com.stmarygate.coral.network.ClientSession;
import com.stmarygate.coral.network.packets.client.PacketLoginUsingCredentials;
import com.stmarygate.coral.network.packets.client.PacketVersion;
import com.stmarygate.coral.network.packets.server.PacketVersionResult;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;

@Getter
@RequiredArgsConstructor
Expand All @@ -18,7 +23,7 @@ public class PacketHandler {
* @param packet The packet to be handled.
* @throws RuntimeException If the packet is not handled or an error occurs during handling.
*/
public void handlePacket(Packet packet) throws Exception {
public void handlePacket(@NotNull Packet packet) throws Exception {
try {
Method method = findHandlerMethod(packet);
method.invoke(this, packet);
Expand All @@ -42,14 +47,23 @@ public ClientSession getSession() {
return this.channel.getSession();
}

public void handlePacketVersion(@NotNull PacketVersion packet) {}
;

public void handlePacketVersionResult(@NotNull PacketVersionResult packet) {}
;

public void handlePacketLoginUsingCredentials(@NotNull PacketLoginUsingCredentials packet) {}
;

/**
* Finds the handler method for the given packet class.
*
* @param packet The packet for which to find the handler method.
* @return The handler method.
* @throws NoSuchMethodException If no handler method is found.
*/
private Method findHandlerMethod(Packet packet) throws NoSuchMethodException {
private Method findHandlerMethod(@NotNull Packet packet) throws NoSuchMethodException {
Class<?> packetClass = packet.getClass();
String handlerMethodName = "handle" + packetClass.getSimpleName();
return this.getClass().getMethod(handlerMethodName, packetClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.jetbrains.annotations.NotNull;

/**
* Manages the protocol for packet communication by registering and retrieving packet classes based
Expand Down Expand Up @@ -42,7 +43,7 @@ public static Protocol getInstance() {
* @param packet The class of the packet to be registered.
* @throws RuntimeException If the packet class does not contain a default constructor.
*/
private void register(int id, Class<? extends Packet> packet) {
private void register(int id, @NotNull Class<? extends Packet> packet) {
try {
packet.getDeclaredConstructor().newInstance();
PACKETS_MAP.put(id, packet);
Expand All @@ -62,7 +63,7 @@ private void register(int id, Class<? extends Packet> packet) {
* @return The ID associated with the packet.
* @throws RuntimeException If the packet is not registered.
*/
public int getPacketId(Packet packet) {
public int getPacketId(@NotNull Packet packet) {
Optional<Integer> id =
PACKETS_MAP.entrySet().stream()
.filter(entry -> entry.getValue().isInstance(packet))
Expand Down Expand Up @@ -90,7 +91,6 @@ public Packet getPacket(int id)
NoSuchMethodException,
InvocationTargetException {
if (!PACKETS_MAP.containsKey(id)) return null;
// throw new RuntimeException("Packet with id " + id + " is not registered.");
return PACKETS_MAP.get(id).getDeclaredConstructor().newInstance();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.stmarygate.coral.network.packets.client;

import com.stmarygate.coral.network.PacketHandler;
import com.stmarygate.coral.network.packets.Packet;
import com.stmarygate.coral.network.packets.PacketBuffer;
import com.stmarygate.coral.network.packets.PacketHandler;
import lombok.Getter;
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.stmarygate.coral.network.packets.client;

import com.stmarygate.coral.network.PacketHandler;
import com.stmarygate.coral.network.packets.Packet;
import com.stmarygate.coral.network.packets.PacketBuffer;
import com.stmarygate.coral.network.packets.PacketHandler;
import lombok.Getter;
import lombok.Setter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.stmarygate.coral.network.packets.server;

import com.stmarygate.coral.network.PacketHandler;
import com.stmarygate.coral.network.packets.Packet;
import com.stmarygate.coral.network.packets.PacketBuffer;
import com.stmarygate.coral.network.packets.PacketHandler;
import lombok.Getter;
import lombok.Setter;

Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/stmarygate/coral/utils/SSLContextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,27 @@
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;

/**
* This class contains utility methods for creating and initializing SSL contexts.
*
* <p>SSLContextUtils use {@link KeyStore} to create and initialize SSL contexts, which are used to
* create a secure connection between a client and a server. This {@link SSLContext} is used to
* create a {@link javax.net.ssl.SSLEngine} which is used to create a {@link
* javax.net.ssl.SSLSession} which is us.
*
* <p><strong>Usage:</strong> To use this class, call {@link
* #createAndInitSSLContext(FileInputStream, String)} with the JKS file and the store password.
*/
public class SSLContextUtils {

/**
* Creates and initializes an SSL context using the specified JKS file and store password.
*
* @param jksFile The JKS file.
* @param storePass The store password for the JKS file.
* @return The initialized SSL context that can be used to create a secure connection.
* @throws Exception If an exception occurs during the initialization process.
*/
public static SSLContext createAndInitSSLContext(FileInputStream jksFile, String storePass)
throws Exception {
KeyStore trustStore = KeyStore.getInstance("jks");
Expand Down
Loading

0 comments on commit 8cbd63b

Please sign in to comment.