From 727fce8540f258090fe87d83d0c5d10e5ed9e60e Mon Sep 17 00:00:00 2001 From: Juan Ortiz Date: Fri, 8 Jan 2021 15:52:28 -0500 Subject: [PATCH 1/4] Migrate contextless network objects to separate module --- build.gradle.kts | 1 + .../main/java/io/luna/network}/codec/ByteMessage.java | 2 +- .../main/java/io/luna/network}/codec/ByteOrder.java | 2 +- .../main/java/io/luna/network}/codec/IsaacCipher.java | 2 +- .../main/java/io/luna/network}/codec/MessageType.java | 2 +- .../network}/codec/ProgressiveMessageDecoder.java | 2 +- .../main/java/io/luna/network}/codec/ValueType.java | 2 +- settings.gradle.kts | 2 ++ src/main/java/io/luna/net/LunaChannelFilter.java | 2 +- .../io/luna/net/codec/game/GameMessageDecoder.java | 8 ++++---- .../io/luna/net/codec/game/GameMessageEncoder.java | 4 ++-- .../java/io/luna/net/codec/login/LoginDecoder.java | 6 +++--- .../io/luna/net/codec/login/LoginRequestMessage.java | 2 +- src/main/java/io/luna/net/msg/GameMessage.java | 4 ++-- src/main/java/io/luna/net/msg/GameMessageReader.java | 2 +- src/main/java/io/luna/net/msg/GameMessageWriter.java | 2 +- .../io/luna/net/msg/in/CastOnNpcMessageReader.java | 5 ++--- .../io/luna/net/msg/in/ObjectClickMessageReader.java | 11 +++-------- .../io/luna/net/msg/out/WidgetTextMessageWriter.java | 7 +++---- 19 files changed, 32 insertions(+), 36 deletions(-) rename {src/main/java/io/luna/net => network/src/main/java/io/luna/network}/codec/ByteMessage.java (99%) rename {src/main/java/io/luna/net => network/src/main/java/io/luna/network}/codec/ByteOrder.java (94%) rename {src/main/java/io/luna/net => network/src/main/java/io/luna/network}/codec/IsaacCipher.java (99%) rename {src/main/java/io/luna/net => network/src/main/java/io/luna/network}/codec/MessageType.java (92%) rename {src/main/java/io/luna/net => network/src/main/java/io/luna/network}/codec/ProgressiveMessageDecoder.java (98%) rename {src/main/java/io/luna/net => network/src/main/java/io/luna/network}/codec/ValueType.java (92%) diff --git a/build.gradle.kts b/build.gradle.kts index 1a51f8fa..8d99660d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,6 +19,7 @@ repositories { val junitVersion: String by project dependencies { + implementation(project("network")) implementation("com.google.code.gson:gson:2.8.5") implementation("org.apache.logging.log4j:log4j-core:2.14.0") implementation("org.apache.logging.log4j:log4j-api:2.14.0") diff --git a/src/main/java/io/luna/net/codec/ByteMessage.java b/network/src/main/java/io/luna/network/codec/ByteMessage.java similarity index 99% rename from src/main/java/io/luna/net/codec/ByteMessage.java rename to network/src/main/java/io/luna/network/codec/ByteMessage.java index ced86e3e..c045b3a8 100644 --- a/src/main/java/io/luna/net/codec/ByteMessage.java +++ b/network/src/main/java/io/luna/network/codec/ByteMessage.java @@ -1,4 +1,4 @@ -package io.luna.net.codec; +package io.luna.network.codec; import io.netty.buffer.ByteBuf; import io.netty.buffer.DefaultByteBufHolder; diff --git a/src/main/java/io/luna/net/codec/ByteOrder.java b/network/src/main/java/io/luna/network/codec/ByteOrder.java similarity index 94% rename from src/main/java/io/luna/net/codec/ByteOrder.java rename to network/src/main/java/io/luna/network/codec/ByteOrder.java index c9670654..ba37d631 100644 --- a/src/main/java/io/luna/net/codec/ByteOrder.java +++ b/network/src/main/java/io/luna/network/codec/ByteOrder.java @@ -1,4 +1,4 @@ -package io.luna.net.codec; +package io.luna.network.codec; /** * An enum representing endianness of game messages. diff --git a/src/main/java/io/luna/net/codec/IsaacCipher.java b/network/src/main/java/io/luna/network/codec/IsaacCipher.java similarity index 99% rename from src/main/java/io/luna/net/codec/IsaacCipher.java rename to network/src/main/java/io/luna/network/codec/IsaacCipher.java index eef80bd0..b27fdf82 100644 --- a/src/main/java/io/luna/net/codec/IsaacCipher.java +++ b/network/src/main/java/io/luna/network/codec/IsaacCipher.java @@ -1,4 +1,4 @@ -package io.luna.net.codec; +package io.luna.network.codec; /** *

An implementation of the ISAAC psuedorandom number diff --git a/src/main/java/io/luna/net/codec/MessageType.java b/network/src/main/java/io/luna/network/codec/MessageType.java similarity index 92% rename from src/main/java/io/luna/net/codec/MessageType.java rename to network/src/main/java/io/luna/network/codec/MessageType.java index a842d519..80b749bc 100644 --- a/src/main/java/io/luna/net/codec/MessageType.java +++ b/network/src/main/java/io/luna/network/codec/MessageType.java @@ -1,4 +1,4 @@ -package io.luna.net.codec; +package io.luna.network.codec; /** * An enum representing different types of outgoing data. diff --git a/src/main/java/io/luna/net/codec/ProgressiveMessageDecoder.java b/network/src/main/java/io/luna/network/codec/ProgressiveMessageDecoder.java similarity index 98% rename from src/main/java/io/luna/net/codec/ProgressiveMessageDecoder.java rename to network/src/main/java/io/luna/network/codec/ProgressiveMessageDecoder.java index 2ed8b78c..9dec07b4 100644 --- a/src/main/java/io/luna/net/codec/ProgressiveMessageDecoder.java +++ b/network/src/main/java/io/luna/network/codec/ProgressiveMessageDecoder.java @@ -1,4 +1,4 @@ -package io.luna.net.codec; +package io.luna.network.codec; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; diff --git a/src/main/java/io/luna/net/codec/ValueType.java b/network/src/main/java/io/luna/network/codec/ValueType.java similarity index 92% rename from src/main/java/io/luna/net/codec/ValueType.java rename to network/src/main/java/io/luna/network/codec/ValueType.java index 04566d1e..56b260b1 100644 --- a/src/main/java/io/luna/net/codec/ValueType.java +++ b/network/src/main/java/io/luna/network/codec/ValueType.java @@ -1,4 +1,4 @@ -package io.luna.net.codec; +package io.luna.network.codec; /** * An enum representing custom Runescape value types. diff --git a/settings.gradle.kts b/settings.gradle.kts index ff326966..f2104d12 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,3 +3,5 @@ */ rootProject.name = "luna" + +include("network") diff --git a/src/main/java/io/luna/net/LunaChannelFilter.java b/src/main/java/io/luna/net/LunaChannelFilter.java index 7daa03e6..8b06d3ae 100644 --- a/src/main/java/io/luna/net/LunaChannelFilter.java +++ b/src/main/java/io/luna/net/LunaChannelFilter.java @@ -5,7 +5,7 @@ import com.google.common.collect.Multiset; import com.google.common.collect.Sets; import io.luna.Luna; -import io.luna.net.codec.ByteMessage; +import io.luna.network.codec.ByteMessage; import io.luna.net.codec.login.LoginResponse; import io.luna.net.codec.login.LoginResponseMessage; import io.netty.buffer.ByteBuf; diff --git a/src/main/java/io/luna/net/codec/game/GameMessageDecoder.java b/src/main/java/io/luna/net/codec/game/GameMessageDecoder.java index 8abaf56a..345da47b 100644 --- a/src/main/java/io/luna/net/codec/game/GameMessageDecoder.java +++ b/src/main/java/io/luna/net/codec/game/GameMessageDecoder.java @@ -1,9 +1,9 @@ package io.luna.net.codec.game; -import io.luna.net.codec.ByteMessage; -import io.luna.net.codec.IsaacCipher; -import io.luna.net.codec.MessageType; -import io.luna.net.codec.ProgressiveMessageDecoder; +import io.luna.network.codec.ByteMessage; +import io.luna.network.codec.IsaacCipher; +import io.luna.network.codec.MessageType; +import io.luna.network.codec.ProgressiveMessageDecoder; import io.luna.net.msg.GameMessage; import io.luna.net.msg.GameMessageRepository; import io.netty.buffer.ByteBuf; diff --git a/src/main/java/io/luna/net/codec/game/GameMessageEncoder.java b/src/main/java/io/luna/net/codec/game/GameMessageEncoder.java index 4688520a..2b830ea2 100644 --- a/src/main/java/io/luna/net/codec/game/GameMessageEncoder.java +++ b/src/main/java/io/luna/net/codec/game/GameMessageEncoder.java @@ -1,7 +1,7 @@ package io.luna.net.codec.game; -import io.luna.net.codec.IsaacCipher; -import io.luna.net.codec.MessageType; +import io.luna.network.codec.IsaacCipher; +import io.luna.network.codec.MessageType; import io.luna.net.msg.GameMessage; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; diff --git a/src/main/java/io/luna/net/codec/login/LoginDecoder.java b/src/main/java/io/luna/net/codec/login/LoginDecoder.java index b7ea93e9..7f74d9f0 100644 --- a/src/main/java/io/luna/net/codec/login/LoginDecoder.java +++ b/src/main/java/io/luna/net/codec/login/LoginDecoder.java @@ -4,9 +4,9 @@ import io.luna.LunaContext; import io.luna.net.client.Client; import io.luna.net.client.LoginClient; -import io.luna.net.codec.ByteMessage; -import io.luna.net.codec.IsaacCipher; -import io.luna.net.codec.ProgressiveMessageDecoder; +import io.luna.network.codec.ByteMessage; +import io.luna.network.codec.IsaacCipher; +import io.luna.network.codec.ProgressiveMessageDecoder; import io.luna.net.msg.GameMessageRepository; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; diff --git a/src/main/java/io/luna/net/codec/login/LoginRequestMessage.java b/src/main/java/io/luna/net/codec/login/LoginRequestMessage.java index dba8c20a..a2545e7b 100644 --- a/src/main/java/io/luna/net/codec/login/LoginRequestMessage.java +++ b/src/main/java/io/luna/net/codec/login/LoginRequestMessage.java @@ -1,6 +1,6 @@ package io.luna.net.codec.login; -import io.luna.net.codec.IsaacCipher; +import io.luna.network.codec.IsaacCipher; import io.netty.channel.ChannelPipeline; /** diff --git a/src/main/java/io/luna/net/msg/GameMessage.java b/src/main/java/io/luna/net/msg/GameMessage.java index 1d033e5c..6c898248 100644 --- a/src/main/java/io/luna/net/msg/GameMessage.java +++ b/src/main/java/io/luna/net/msg/GameMessage.java @@ -1,7 +1,7 @@ package io.luna.net.msg; -import io.luna.net.codec.ByteMessage; -import io.luna.net.codec.MessageType; +import io.luna.network.codec.ByteMessage; +import io.luna.network.codec.MessageType; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; diff --git a/src/main/java/io/luna/net/msg/GameMessageReader.java b/src/main/java/io/luna/net/msg/GameMessageReader.java index 31b49c54..b25cb408 100644 --- a/src/main/java/io/luna/net/msg/GameMessageReader.java +++ b/src/main/java/io/luna/net/msg/GameMessageReader.java @@ -2,7 +2,7 @@ import io.luna.game.event.Event; import io.luna.game.model.mob.Player; -import io.luna.net.codec.ByteMessage; +import io.luna.network.codec.ByteMessage; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; diff --git a/src/main/java/io/luna/net/msg/GameMessageWriter.java b/src/main/java/io/luna/net/msg/GameMessageWriter.java index b0368d78..559ef175 100644 --- a/src/main/java/io/luna/net/msg/GameMessageWriter.java +++ b/src/main/java/io/luna/net/msg/GameMessageWriter.java @@ -1,7 +1,7 @@ package io.luna.net.msg; import io.luna.game.model.mob.Player; -import io.luna.net.codec.ByteMessage; +import io.luna.network.codec.ByteMessage; /** * An abstraction model that converts raw written byte messages into game messages. diff --git a/src/main/java/io/luna/net/msg/in/CastOnNpcMessageReader.java b/src/main/java/io/luna/net/msg/in/CastOnNpcMessageReader.java index da0a9e94..43d01cef 100644 --- a/src/main/java/io/luna/net/msg/in/CastOnNpcMessageReader.java +++ b/src/main/java/io/luna/net/msg/in/CastOnNpcMessageReader.java @@ -3,12 +3,11 @@ import io.luna.game.action.InteractionAction; import io.luna.game.event.Event; import io.luna.game.event.impl.CastOnNpcEvent; -import io.luna.game.event.impl.CastOnPlayerEvent; import io.luna.game.model.mob.MobList; import io.luna.game.model.mob.Npc; import io.luna.game.model.mob.Player; -import io.luna.net.codec.ByteOrder; -import io.luna.net.codec.ValueType; +import io.luna.network.codec.ByteOrder; +import io.luna.network.codec.ValueType; import io.luna.net.msg.GameMessage; import io.luna.net.msg.GameMessageReader; diff --git a/src/main/java/io/luna/net/msg/in/ObjectClickMessageReader.java b/src/main/java/io/luna/net/msg/in/ObjectClickMessageReader.java index e6da25fe..eba344b9 100644 --- a/src/main/java/io/luna/net/msg/in/ObjectClickMessageReader.java +++ b/src/main/java/io/luna/net/msg/in/ObjectClickMessageReader.java @@ -12,16 +12,11 @@ import io.luna.game.model.object.GameObject; import io.luna.game.model.object.ObjectDirection; import io.luna.game.model.object.ObjectType; -import io.luna.net.codec.ByteMessage; -import io.luna.net.codec.ByteOrder; -import io.luna.net.codec.ValueType; +import io.luna.network.codec.ByteMessage; +import io.luna.network.codec.ByteOrder; +import io.luna.network.codec.ValueType; import io.luna.net.msg.GameMessage; import io.luna.net.msg.GameMessageReader; -import javafx.geometry.Pos; - -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Supplier; import static com.google.common.base.Preconditions.checkState; diff --git a/src/main/java/io/luna/net/msg/out/WidgetTextMessageWriter.java b/src/main/java/io/luna/net/msg/out/WidgetTextMessageWriter.java index 443fb19e..dfe14921 100644 --- a/src/main/java/io/luna/net/msg/out/WidgetTextMessageWriter.java +++ b/src/main/java/io/luna/net/msg/out/WidgetTextMessageWriter.java @@ -1,10 +1,9 @@ package io.luna.net.msg.out; -import io.luna.game.event.impl.PlayerEvent; import io.luna.game.model.mob.Player; -import io.luna.net.codec.ByteMessage; -import io.luna.net.codec.MessageType; -import io.luna.net.codec.ValueType; +import io.luna.network.codec.ByteMessage; +import io.luna.network.codec.MessageType; +import io.luna.network.codec.ValueType; import io.luna.net.msg.GameMessageWriter; /** From d921b8108393e0bd9eeb3526a3631a8bcee3f92f Mon Sep 17 00:00:00 2001 From: Juan Ortiz Date: Sat, 9 Jan 2021 16:27:56 -0500 Subject: [PATCH 2/4] Migrate static methods from NetworkUtils.java to Client.java This enables the deletion of the NetworkUtils class since it's not in use by any other objects. --- src/main/java/io/luna/net/client/Client.java | 13 ++++++-- src/main/java/io/luna/util/NetworkUtils.java | 31 -------------------- 2 files changed, 11 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/io/luna/util/NetworkUtils.java diff --git a/src/main/java/io/luna/net/client/Client.java b/src/main/java/io/luna/net/client/Client.java index a4d3a443..ad79f8f9 100644 --- a/src/main/java/io/luna/net/client/Client.java +++ b/src/main/java/io/luna/net/client/Client.java @@ -2,12 +2,12 @@ import com.google.common.base.MoreObjects; import io.luna.net.LunaChannelFilter; -import io.luna.util.NetworkUtils; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.util.AttributeKey; import io.netty.util.internal.TypeParameterMatcher; +import java.net.InetSocketAddress; import java.util.Objects; /** @@ -47,7 +47,7 @@ public abstract class Client { */ Client(Channel channel) { this.channel = channel; - ipAddress = NetworkUtils.getIpAddress(channel); + ipAddress = getIpAddressFrom(channel); parameterMatcher = TypeParameterMatcher.find(this, Client.class, "I"); } @@ -127,6 +127,15 @@ public final Channel getChannel() { return channel; } + /** + * @param channel + * @return The connected remote address the argued channel. + */ + final String getIpAddressFrom(Channel channel) { + InetSocketAddress socketAddress = (InetSocketAddress) channel.remoteAddress(); + return socketAddress.getAddress().getHostAddress(); + } + /** * @return The client's channel filter. */ diff --git a/src/main/java/io/luna/util/NetworkUtils.java b/src/main/java/io/luna/util/NetworkUtils.java deleted file mode 100644 index 18d2721b..00000000 --- a/src/main/java/io/luna/util/NetworkUtils.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.luna.util; - - -import io.netty.channel.Channel; - -import java.net.InetSocketAddress; - -/** - * A static-utility class that contains functions for networking. - * - * @author lare96 - */ -public class NetworkUtils { - - /** - * Retrieves the IP address for {@code channel}. - * - * @param channel The channel. - * @return The IP address of the channel. - */ - public static String getIpAddress(Channel channel) { - InetSocketAddress socketAddress = (InetSocketAddress) channel.remoteAddress(); - return socketAddress.getAddress().getHostAddress(); - } - - /** - * A private constructor to discourage external instantiation. - */ - private NetworkUtils() { - } -} \ No newline at end of file From 9568d4c2f46cabee0d84a651f633ba58c35a28df Mon Sep 17 00:00:00 2001 From: Juan Ortiz Date: Sat, 9 Jan 2021 16:30:26 -0500 Subject: [PATCH 3/4] Remove unused method Client.getChannelFilter() --- src/main/java/io/luna/net/client/Client.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/main/java/io/luna/net/client/Client.java b/src/main/java/io/luna/net/client/Client.java index ad79f8f9..188173f4 100644 --- a/src/main/java/io/luna/net/client/Client.java +++ b/src/main/java/io/luna/net/client/Client.java @@ -1,7 +1,6 @@ package io.luna.net.client; import com.google.common.base.MoreObjects; -import io.luna.net.LunaChannelFilter; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.util.AttributeKey; @@ -136,13 +135,6 @@ final String getIpAddressFrom(Channel channel) { return socketAddress.getAddress().getHostAddress(); } - /** - * @return The client's channel filter. - */ - public final LunaChannelFilter getChannelFilter() { - return channel.attr(LunaChannelFilter.KEY).get(); - } - /** * @return The client's IP address. */ From ecff1c364513bc98c48d78d8ce51fe64e6a36e6a Mon Sep 17 00:00:00 2001 From: Juan Ortiz Date: Sun, 10 Jan 2021 11:27:53 -0500 Subject: [PATCH 4/4] Move abstract Client to network module (io.luna.net.client -> io.luna.net) This also reverts the updated network package name to avoid a huge commit of import changes --- build.gradle.kts | 2 +- network/build.gradle.kts | 20 +++++++++++++++++++ .../src/main/java/io/luna/net}/Client.java | 8 ++++---- .../{network => net}/codec/ByteMessage.java | 2 +- .../{network => net}/codec/ByteOrder.java | 2 +- .../{network => net}/codec/IsaacCipher.java | 2 +- .../{network => net}/codec/MessageType.java | 2 +- .../codec/ProgressiveMessageDecoder.java | 2 +- .../{network => net}/codec/ValueType.java | 2 +- settings.gradle.kts | 2 +- .../java/io/luna/net/LunaChannelFilter.java | 2 +- .../io/luna/net/LunaChannelInitializer.java | 1 - .../java/io/luna/net/LunaUpstreamHandler.java | 1 - .../java/io/luna/net/client/GameClient.java | 3 ++- .../java/io/luna/net/client/IdleClient.java | 3 ++- .../java/io/luna/net/client/LoginClient.java | 3 ++- .../net/codec/game/GameMessageDecoder.java | 8 ++++---- .../net/codec/game/GameMessageEncoder.java | 4 ++-- .../io/luna/net/codec/login/LoginDecoder.java | 8 ++++---- .../net/codec/login/LoginRequestMessage.java | 2 +- .../luna/net/codec/login/LoginResponse.java | 2 +- .../net/codec/login/LoginResponseMessage.java | 2 +- .../java/io/luna/net/msg/GameMessage.java | 4 ++-- .../io/luna/net/msg/GameMessageReader.java | 2 +- .../io/luna/net/msg/GameMessageWriter.java | 2 +- .../net/msg/in/CastOnNpcMessageReader.java | 4 ++-- .../net/msg/in/ObjectClickMessageReader.java | 6 +++--- .../net/msg/out/WidgetTextMessageWriter.java | 6 +++--- 28 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 network/build.gradle.kts rename {src/main/java/io/luna/net/client => network/src/main/java/io/luna/net}/Client.java (95%) rename network/src/main/java/io/luna/{network => net}/codec/ByteMessage.java (99%) rename network/src/main/java/io/luna/{network => net}/codec/ByteOrder.java (94%) rename network/src/main/java/io/luna/{network => net}/codec/IsaacCipher.java (99%) rename network/src/main/java/io/luna/{network => net}/codec/MessageType.java (92%) rename network/src/main/java/io/luna/{network => net}/codec/ProgressiveMessageDecoder.java (98%) rename network/src/main/java/io/luna/{network => net}/codec/ValueType.java (92%) diff --git a/build.gradle.kts b/build.gradle.kts index 8d99660d..825aef7b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,7 +19,7 @@ repositories { val junitVersion: String by project dependencies { - implementation(project("network")) + implementation(project(":network")) implementation("com.google.code.gson:gson:2.8.5") implementation("org.apache.logging.log4j:log4j-core:2.14.0") implementation("org.apache.logging.log4j:log4j-api:2.14.0") diff --git a/network/build.gradle.kts b/network/build.gradle.kts new file mode 100644 index 00000000..c79515e7 --- /dev/null +++ b/network/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + java +} + +group = "luna" +version = "1.0" + +repositories { + jcenter() +} + +val junitVersion: String by project + +dependencies { + implementation("io.netty:netty-all:4.1.56.Final") + implementation("com.google.guava:guava:30.1-jre") + testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion") + testImplementation("org.junit.jupiter:junit-jupiter-params:$junitVersion") + testImplementation("org.junit.jupiter:junit-jupiter-engine:$junitVersion") +} diff --git a/src/main/java/io/luna/net/client/Client.java b/network/src/main/java/io/luna/net/Client.java similarity index 95% rename from src/main/java/io/luna/net/client/Client.java rename to network/src/main/java/io/luna/net/Client.java index 188173f4..ac6a7c9b 100644 --- a/src/main/java/io/luna/net/client/Client.java +++ b/network/src/main/java/io/luna/net/Client.java @@ -1,4 +1,4 @@ -package io.luna.net.client; +package io.luna.net; import com.google.common.base.MoreObjects; import io.netty.channel.Channel; @@ -27,7 +27,7 @@ public abstract class Client { /** * The underlying channel. */ - final Channel channel; + protected final Channel channel; /** * The IP address. @@ -44,7 +44,7 @@ public abstract class Client { * * @param channel The underlying channel. */ - Client(Channel channel) { + protected Client(Channel channel) { this.channel = channel; ipAddress = getIpAddressFrom(channel); parameterMatcher = TypeParameterMatcher.find(this, Client.class, "I"); @@ -78,7 +78,7 @@ public final String toString() { * @param msg The message to handle. * @throws Exception If any errors occur. */ - abstract void onMessageReceived(I msg) throws Exception; + protected abstract void onMessageReceived(I msg) throws Exception; /** * Called when the underlying channel is disconnected. diff --git a/network/src/main/java/io/luna/network/codec/ByteMessage.java b/network/src/main/java/io/luna/net/codec/ByteMessage.java similarity index 99% rename from network/src/main/java/io/luna/network/codec/ByteMessage.java rename to network/src/main/java/io/luna/net/codec/ByteMessage.java index c045b3a8..ced86e3e 100644 --- a/network/src/main/java/io/luna/network/codec/ByteMessage.java +++ b/network/src/main/java/io/luna/net/codec/ByteMessage.java @@ -1,4 +1,4 @@ -package io.luna.network.codec; +package io.luna.net.codec; import io.netty.buffer.ByteBuf; import io.netty.buffer.DefaultByteBufHolder; diff --git a/network/src/main/java/io/luna/network/codec/ByteOrder.java b/network/src/main/java/io/luna/net/codec/ByteOrder.java similarity index 94% rename from network/src/main/java/io/luna/network/codec/ByteOrder.java rename to network/src/main/java/io/luna/net/codec/ByteOrder.java index ba37d631..c9670654 100644 --- a/network/src/main/java/io/luna/network/codec/ByteOrder.java +++ b/network/src/main/java/io/luna/net/codec/ByteOrder.java @@ -1,4 +1,4 @@ -package io.luna.network.codec; +package io.luna.net.codec; /** * An enum representing endianness of game messages. diff --git a/network/src/main/java/io/luna/network/codec/IsaacCipher.java b/network/src/main/java/io/luna/net/codec/IsaacCipher.java similarity index 99% rename from network/src/main/java/io/luna/network/codec/IsaacCipher.java rename to network/src/main/java/io/luna/net/codec/IsaacCipher.java index b27fdf82..eef80bd0 100644 --- a/network/src/main/java/io/luna/network/codec/IsaacCipher.java +++ b/network/src/main/java/io/luna/net/codec/IsaacCipher.java @@ -1,4 +1,4 @@ -package io.luna.network.codec; +package io.luna.net.codec; /** *

An implementation of the ISAAC psuedorandom number diff --git a/network/src/main/java/io/luna/network/codec/MessageType.java b/network/src/main/java/io/luna/net/codec/MessageType.java similarity index 92% rename from network/src/main/java/io/luna/network/codec/MessageType.java rename to network/src/main/java/io/luna/net/codec/MessageType.java index 80b749bc..a842d519 100644 --- a/network/src/main/java/io/luna/network/codec/MessageType.java +++ b/network/src/main/java/io/luna/net/codec/MessageType.java @@ -1,4 +1,4 @@ -package io.luna.network.codec; +package io.luna.net.codec; /** * An enum representing different types of outgoing data. diff --git a/network/src/main/java/io/luna/network/codec/ProgressiveMessageDecoder.java b/network/src/main/java/io/luna/net/codec/ProgressiveMessageDecoder.java similarity index 98% rename from network/src/main/java/io/luna/network/codec/ProgressiveMessageDecoder.java rename to network/src/main/java/io/luna/net/codec/ProgressiveMessageDecoder.java index 9dec07b4..2ed8b78c 100644 --- a/network/src/main/java/io/luna/network/codec/ProgressiveMessageDecoder.java +++ b/network/src/main/java/io/luna/net/codec/ProgressiveMessageDecoder.java @@ -1,4 +1,4 @@ -package io.luna.network.codec; +package io.luna.net.codec; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; diff --git a/network/src/main/java/io/luna/network/codec/ValueType.java b/network/src/main/java/io/luna/net/codec/ValueType.java similarity index 92% rename from network/src/main/java/io/luna/network/codec/ValueType.java rename to network/src/main/java/io/luna/net/codec/ValueType.java index 56b260b1..04566d1e 100644 --- a/network/src/main/java/io/luna/network/codec/ValueType.java +++ b/network/src/main/java/io/luna/net/codec/ValueType.java @@ -1,4 +1,4 @@ -package io.luna.network.codec; +package io.luna.net.codec; /** * An enum representing custom Runescape value types. diff --git a/settings.gradle.kts b/settings.gradle.kts index f2104d12..2f987c2a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,4 +4,4 @@ rootProject.name = "luna" -include("network") +include(":network") diff --git a/src/main/java/io/luna/net/LunaChannelFilter.java b/src/main/java/io/luna/net/LunaChannelFilter.java index 8b06d3ae..7daa03e6 100644 --- a/src/main/java/io/luna/net/LunaChannelFilter.java +++ b/src/main/java/io/luna/net/LunaChannelFilter.java @@ -5,7 +5,7 @@ import com.google.common.collect.Multiset; import com.google.common.collect.Sets; import io.luna.Luna; -import io.luna.network.codec.ByteMessage; +import io.luna.net.codec.ByteMessage; import io.luna.net.codec.login.LoginResponse; import io.luna.net.codec.login.LoginResponseMessage; import io.netty.buffer.ByteBuf; diff --git a/src/main/java/io/luna/net/LunaChannelInitializer.java b/src/main/java/io/luna/net/LunaChannelInitializer.java index eae415e8..879a5290 100644 --- a/src/main/java/io/luna/net/LunaChannelInitializer.java +++ b/src/main/java/io/luna/net/LunaChannelInitializer.java @@ -1,7 +1,6 @@ package io.luna.net; import io.luna.LunaContext; -import io.luna.net.client.Client; import io.luna.net.client.IdleClient; import io.luna.net.codec.login.LoginDecoder; import io.luna.net.codec.login.LoginEncoder; diff --git a/src/main/java/io/luna/net/LunaUpstreamHandler.java b/src/main/java/io/luna/net/LunaUpstreamHandler.java index cf01574c..2b62c073 100644 --- a/src/main/java/io/luna/net/LunaUpstreamHandler.java +++ b/src/main/java/io/luna/net/LunaUpstreamHandler.java @@ -1,6 +1,5 @@ package io.luna.net; -import io.luna.net.client.Client; import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; diff --git a/src/main/java/io/luna/net/client/GameClient.java b/src/main/java/io/luna/net/client/GameClient.java index 8a3bf3ac..7864e5dd 100644 --- a/src/main/java/io/luna/net/client/GameClient.java +++ b/src/main/java/io/luna/net/client/GameClient.java @@ -5,6 +5,7 @@ import io.luna.net.msg.GameMessageReader; import io.luna.net.msg.GameMessageRepository; import io.luna.net.msg.GameMessageWriter; +import io.luna.net.Client; import io.netty.channel.Channel; import java.util.Queue; @@ -49,7 +50,7 @@ public void onInactive() { } @Override - void onMessageReceived(GameMessage msg) { + public void onMessageReceived(GameMessage msg) { if (!decodedMessages.offer(msg)) { msg.getPayload().releaseAll(); } diff --git a/src/main/java/io/luna/net/client/IdleClient.java b/src/main/java/io/luna/net/client/IdleClient.java index 2e59590b..f1b528e7 100644 --- a/src/main/java/io/luna/net/client/IdleClient.java +++ b/src/main/java/io/luna/net/client/IdleClient.java @@ -1,5 +1,6 @@ package io.luna.net.client; +import io.luna.net.Client; import io.netty.channel.Channel; /** @@ -20,7 +21,7 @@ public IdleClient(Channel channel) { } @Override - void onMessageReceived(Object msg) { + public void onMessageReceived(Object msg) { throw new UnsupportedOperationException("Not ready for I/O."); } } \ No newline at end of file diff --git a/src/main/java/io/luna/net/client/LoginClient.java b/src/main/java/io/luna/net/client/LoginClient.java index f7067522..771304de 100644 --- a/src/main/java/io/luna/net/client/LoginClient.java +++ b/src/main/java/io/luna/net/client/LoginClient.java @@ -13,6 +13,7 @@ import io.luna.net.codec.login.LoginResponse; import io.luna.net.codec.login.LoginResponseMessage; import io.luna.net.msg.GameMessageRepository; +import io.luna.net.Client; import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; import org.mindrot.jbcrypt.BCrypt; @@ -59,7 +60,7 @@ public LoginClient(Channel channel, LunaContext context, GameMessageRepository m } @Override - void onMessageReceived(LoginRequestMessage msg) { + public void onMessageReceived(LoginRequestMessage msg) { String username = msg.getUsername(); String password = msg.getPassword(); var player = new Player(context, new PlayerCredentials(username, password)); diff --git a/src/main/java/io/luna/net/codec/game/GameMessageDecoder.java b/src/main/java/io/luna/net/codec/game/GameMessageDecoder.java index 345da47b..8abaf56a 100644 --- a/src/main/java/io/luna/net/codec/game/GameMessageDecoder.java +++ b/src/main/java/io/luna/net/codec/game/GameMessageDecoder.java @@ -1,9 +1,9 @@ package io.luna.net.codec.game; -import io.luna.network.codec.ByteMessage; -import io.luna.network.codec.IsaacCipher; -import io.luna.network.codec.MessageType; -import io.luna.network.codec.ProgressiveMessageDecoder; +import io.luna.net.codec.ByteMessage; +import io.luna.net.codec.IsaacCipher; +import io.luna.net.codec.MessageType; +import io.luna.net.codec.ProgressiveMessageDecoder; import io.luna.net.msg.GameMessage; import io.luna.net.msg.GameMessageRepository; import io.netty.buffer.ByteBuf; diff --git a/src/main/java/io/luna/net/codec/game/GameMessageEncoder.java b/src/main/java/io/luna/net/codec/game/GameMessageEncoder.java index 2b830ea2..4688520a 100644 --- a/src/main/java/io/luna/net/codec/game/GameMessageEncoder.java +++ b/src/main/java/io/luna/net/codec/game/GameMessageEncoder.java @@ -1,7 +1,7 @@ package io.luna.net.codec.game; -import io.luna.network.codec.IsaacCipher; -import io.luna.network.codec.MessageType; +import io.luna.net.codec.IsaacCipher; +import io.luna.net.codec.MessageType; import io.luna.net.msg.GameMessage; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; diff --git a/src/main/java/io/luna/net/codec/login/LoginDecoder.java b/src/main/java/io/luna/net/codec/login/LoginDecoder.java index 7f74d9f0..6642f2fb 100644 --- a/src/main/java/io/luna/net/codec/login/LoginDecoder.java +++ b/src/main/java/io/luna/net/codec/login/LoginDecoder.java @@ -2,11 +2,11 @@ import com.moandjiezana.toml.Toml; import io.luna.LunaContext; -import io.luna.net.client.Client; +import io.luna.net.Client; import io.luna.net.client.LoginClient; -import io.luna.network.codec.ByteMessage; -import io.luna.network.codec.IsaacCipher; -import io.luna.network.codec.ProgressiveMessageDecoder; +import io.luna.net.codec.ByteMessage; +import io.luna.net.codec.IsaacCipher; +import io.luna.net.codec.ProgressiveMessageDecoder; import io.luna.net.msg.GameMessageRepository; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; diff --git a/src/main/java/io/luna/net/codec/login/LoginRequestMessage.java b/src/main/java/io/luna/net/codec/login/LoginRequestMessage.java index a2545e7b..dba8c20a 100644 --- a/src/main/java/io/luna/net/codec/login/LoginRequestMessage.java +++ b/src/main/java/io/luna/net/codec/login/LoginRequestMessage.java @@ -1,6 +1,6 @@ package io.luna.net.codec.login; -import io.luna.network.codec.IsaacCipher; +import io.luna.net.codec.IsaacCipher; import io.netty.channel.ChannelPipeline; /** diff --git a/src/main/java/io/luna/net/codec/login/LoginResponse.java b/src/main/java/io/luna/net/codec/login/LoginResponse.java index 2e2305ef..c934956d 100644 --- a/src/main/java/io/luna/net/codec/login/LoginResponse.java +++ b/src/main/java/io/luna/net/codec/login/LoginResponse.java @@ -1,6 +1,6 @@ package io.luna.net.codec.login; -import io.luna.net.client.Client; +import io.luna.net.Client; /** * An enumerated type whose values represent login responses. Any response other than {@link #NORMAL} will diff --git a/src/main/java/io/luna/net/codec/login/LoginResponseMessage.java b/src/main/java/io/luna/net/codec/login/LoginResponseMessage.java index f6dd3624..96c5b0a7 100644 --- a/src/main/java/io/luna/net/codec/login/LoginResponseMessage.java +++ b/src/main/java/io/luna/net/codec/login/LoginResponseMessage.java @@ -1,7 +1,7 @@ package io.luna.net.codec.login; import io.luna.game.model.mob.PlayerRights; -import io.luna.net.client.Client; +import io.luna.net.Client; /** * An immutable model representing login response data. diff --git a/src/main/java/io/luna/net/msg/GameMessage.java b/src/main/java/io/luna/net/msg/GameMessage.java index 6c898248..1d033e5c 100644 --- a/src/main/java/io/luna/net/msg/GameMessage.java +++ b/src/main/java/io/luna/net/msg/GameMessage.java @@ -1,7 +1,7 @@ package io.luna.net.msg; -import io.luna.network.codec.ByteMessage; -import io.luna.network.codec.MessageType; +import io.luna.net.codec.ByteMessage; +import io.luna.net.codec.MessageType; import static com.google.common.base.Preconditions.checkArgument; import static java.util.Objects.requireNonNull; diff --git a/src/main/java/io/luna/net/msg/GameMessageReader.java b/src/main/java/io/luna/net/msg/GameMessageReader.java index b25cb408..31b49c54 100644 --- a/src/main/java/io/luna/net/msg/GameMessageReader.java +++ b/src/main/java/io/luna/net/msg/GameMessageReader.java @@ -2,7 +2,7 @@ import io.luna.game.event.Event; import io.luna.game.model.mob.Player; -import io.luna.network.codec.ByteMessage; +import io.luna.net.codec.ByteMessage; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; diff --git a/src/main/java/io/luna/net/msg/GameMessageWriter.java b/src/main/java/io/luna/net/msg/GameMessageWriter.java index 559ef175..b0368d78 100644 --- a/src/main/java/io/luna/net/msg/GameMessageWriter.java +++ b/src/main/java/io/luna/net/msg/GameMessageWriter.java @@ -1,7 +1,7 @@ package io.luna.net.msg; import io.luna.game.model.mob.Player; -import io.luna.network.codec.ByteMessage; +import io.luna.net.codec.ByteMessage; /** * An abstraction model that converts raw written byte messages into game messages. diff --git a/src/main/java/io/luna/net/msg/in/CastOnNpcMessageReader.java b/src/main/java/io/luna/net/msg/in/CastOnNpcMessageReader.java index 43d01cef..56d946c8 100644 --- a/src/main/java/io/luna/net/msg/in/CastOnNpcMessageReader.java +++ b/src/main/java/io/luna/net/msg/in/CastOnNpcMessageReader.java @@ -6,8 +6,8 @@ import io.luna.game.model.mob.MobList; import io.luna.game.model.mob.Npc; import io.luna.game.model.mob.Player; -import io.luna.network.codec.ByteOrder; -import io.luna.network.codec.ValueType; +import io.luna.net.codec.ByteOrder; +import io.luna.net.codec.ValueType; import io.luna.net.msg.GameMessage; import io.luna.net.msg.GameMessageReader; diff --git a/src/main/java/io/luna/net/msg/in/ObjectClickMessageReader.java b/src/main/java/io/luna/net/msg/in/ObjectClickMessageReader.java index eba344b9..8fb2f592 100644 --- a/src/main/java/io/luna/net/msg/in/ObjectClickMessageReader.java +++ b/src/main/java/io/luna/net/msg/in/ObjectClickMessageReader.java @@ -12,9 +12,9 @@ import io.luna.game.model.object.GameObject; import io.luna.game.model.object.ObjectDirection; import io.luna.game.model.object.ObjectType; -import io.luna.network.codec.ByteMessage; -import io.luna.network.codec.ByteOrder; -import io.luna.network.codec.ValueType; +import io.luna.net.codec.ByteMessage; +import io.luna.net.codec.ByteOrder; +import io.luna.net.codec.ValueType; import io.luna.net.msg.GameMessage; import io.luna.net.msg.GameMessageReader; diff --git a/src/main/java/io/luna/net/msg/out/WidgetTextMessageWriter.java b/src/main/java/io/luna/net/msg/out/WidgetTextMessageWriter.java index dfe14921..8846fc39 100644 --- a/src/main/java/io/luna/net/msg/out/WidgetTextMessageWriter.java +++ b/src/main/java/io/luna/net/msg/out/WidgetTextMessageWriter.java @@ -1,9 +1,9 @@ package io.luna.net.msg.out; import io.luna.game.model.mob.Player; -import io.luna.network.codec.ByteMessage; -import io.luna.network.codec.MessageType; -import io.luna.network.codec.ValueType; +import io.luna.net.codec.ByteMessage; +import io.luna.net.codec.MessageType; +import io.luna.net.codec.ValueType; import io.luna.net.msg.GameMessageWriter; /**