Skip to content

Commit

Permalink
rewrite messaging to use one channel per packet
Browse files Browse the repository at this point in the history
  • Loading branch information
tahmid-23 committed Jul 15, 2023
1 parent 991a4ff commit 40788a0
Show file tree
Hide file tree
Showing 39 changed files with 308 additions and 556 deletions.
1 change: 1 addition & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {

dependencies {
api(projects.phantazmCommons)
api(projects.phantazmMessaging)
api(libs.ethylene.core)
api(libs.ethylene.mapper)
api(libs.commons.lang3)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.phantazm.server.packet;
package org.phantazm.core.packet;

import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.binary.BinaryWriter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.phantazm.server.packet;
package org.phantazm.core.packet;

import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import org.phantazm.messaging.serialization.DataReader;
Expand All @@ -23,6 +24,10 @@ public BinaryDataWriter(@NotNull BinaryWriter binaryWriter) {
this.binaryWriter = Objects.requireNonNull(binaryWriter, "binaryWriter");
}

public static @NotNull BinaryDataWriter fromNetworkBuffer(@NotNull NetworkBuffer networkBuffer) {
return new BinaryDataWriter(new BinaryWriter(Objects.requireNonNull(networkBuffer, "networkBuffer")));
}

@Override
public void writeByte(byte data) {
binaryWriter.writeByte(data);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.phantazm.core.packet;

import net.minestom.server.network.NetworkBuffer;
import org.jetbrains.annotations.NotNull;
import org.phantazm.messaging.packet.Packet;

public class MinestomPacketUtils {

public static byte @NotNull[] serialize(@NotNull Packet packet) {
return NetworkBuffer.makeArray(buffer -> {
packet.write(BinaryDataWriter.fromNetworkBuffer(buffer));
});
}

}
5 changes: 5 additions & 0 deletions messaging/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
plugins {
id("phantazm.java-library-conventions")
}

dependencies {
implementation(projects.phantazmCommons)
api(libs.adventure.key)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.phantazm.messaging.packet;

import net.kyori.adventure.key.Key;
import org.jetbrains.annotations.NotNull;
import org.phantazm.messaging.serialization.DataWriter;

Expand All @@ -8,14 +9,7 @@
*/
public interface Packet {

/**
* Gets the ID of the packet. This should be unique for a single messaging channel.
* For example, all the packets in the proxy plugin messaging channel should be unique.
* However, they can share IDs with packets on other channels.
*
* @return The ID of the packet
*/
byte getId();
@NotNull Key getId();

/**
* Writes the packet to a {@link DataWriter}.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.phantazm.messaging.packet.c2p;
package org.phantazm.messaging.packet.player;

import net.kyori.adventure.key.Key;
import org.jetbrains.annotations.NotNull;
import org.phantazm.commons.Namespaces;
import org.phantazm.messaging.packet.Packet;
import org.phantazm.messaging.serialization.DataReader;
import org.phantazm.messaging.serialization.DataWriter;
Expand All @@ -12,18 +14,15 @@
*/
public record MapDataVersionQueryPacket() implements Packet {

/**
* The ID of the {@link MapDataVersionQueryPacket}.
*/
public static final byte ID = 0;
public static final Key ID = Key.key(Namespaces.PHANTAZM, "client/mapdata_version_query");

public static @NotNull MapDataVersionQueryPacket read(@NotNull DataReader reader) {
Objects.requireNonNull(reader, "reader");
return new MapDataVersionQueryPacket();
}

@Override
public byte getId() {
public @NotNull Key getId() {
return ID;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.phantazm.messaging.packet.c2p;
package org.phantazm.messaging.packet.proxy;

import net.kyori.adventure.key.Key;
import org.jetbrains.annotations.NotNull;
import org.phantazm.commons.Namespaces;
import org.phantazm.messaging.packet.Packet;
import org.phantazm.messaging.serialization.DataReader;
import org.phantazm.messaging.serialization.DataWriter;
Expand All @@ -14,18 +16,15 @@
*/
public record MapDataVersionResponsePacket(int version) implements Packet {

/**
* The ID of the {@link MapDataVersionResponsePacket}.
*/
public static final byte ID = 1;
public static final Key ID = Key.key(Namespaces.PHANTAZM, "proxy/mapdata_version_response");

public static @NotNull MapDataVersionResponsePacket read(@NotNull DataReader reader) {
Objects.requireNonNull(reader, "reader");
return new MapDataVersionResponsePacket(reader.readInt());
}

@Override
public byte getId() {
public @NotNull Key getId() {
return ID;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.phantazm.messaging.packet.c2s;
package org.phantazm.messaging.packet.server;

import net.kyori.adventure.key.Key;
import org.jetbrains.annotations.NotNull;
import org.phantazm.commons.Namespaces;
import org.phantazm.messaging.packet.Packet;
import org.phantazm.messaging.serialization.DataReader;
import org.phantazm.messaging.serialization.DataWriter;
Expand All @@ -9,15 +11,15 @@

public record RoundStartPacket() implements Packet {

public static final byte ID = 0;
public static final Key ID = Key.key(Namespaces.PHANTAZM, "server/round_start");

public static @NotNull RoundStartPacket read(@NotNull DataReader reader) {
Objects.requireNonNull(reader, "reader");
return new RoundStartPacket();
}

@Override
public byte getId() {
public @NotNull Key getId() {
return ID;
}

Expand Down

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ repositories {

dependencies {
implementation(projects.phantazmCore)
implementation(projects.phantazmMessaging)
implementation(projects.phantazmMob)
implementation(projects.phantazmZombiesMapdata)
implementation(projects.phantazmZombies)
Expand Down
Loading

0 comments on commit 40788a0

Please sign in to comment.