From bdb1e29c85202477a61fcba5e079fedf4542cf63 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 3 May 2020 21:28:51 -0400 Subject: [PATCH] Mod packet support --- core/src/mindustry/core/NetServer.java | 27 +++++++++++++++++++++++++- gradle.properties | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/core/NetServer.java b/core/src/mindustry/core/NetServer.java index 1f558a1965..ca00dfd5b4 100644 --- a/core/src/mindustry/core/NetServer.java +++ b/core/src/mindustry/core/NetServer.java @@ -1,12 +1,13 @@ package mindustry.core; import arc.*; +import arc.func.*; import arc.graphics.*; import arc.math.*; import arc.math.geom.*; import arc.struct.*; -import arc.util.*; import arc.util.ArcAnnotate.*; +import arc.util.*; import arc.util.CommandHandler.*; import arc.util.io.*; import arc.util.serialization.*; @@ -72,6 +73,8 @@ public class NetServer implements ApplicationListener{ private ReusableByteOutStream syncStream = new ReusableByteOutStream(); /** Data stream for writing player sync data to. */ private DataOutputStream dataStream = new DataOutputStream(syncStream); + /** Packet handlers for custom types of messages. */ + private ObjectMap>> customPacketHandlers = new ObjectMap<>(); public NetServer(){ @@ -471,6 +474,14 @@ public class NetServer implements ApplicationListener{ Log.debug("Packed @ compressed bytes of world data.", stream.size()); } + public void addPacketHandler(String type, Cons handler){ + customPacketHandlers.getOr(type, Array::new).add(handler); + } + + public Array> getPacketHandlers(String type){ + return customPacketHandlers.getOr(type, Array::new); + } + public static void onDisconnect(Playerc player, String reason){ //singleplayer multiplayer wierdness if(player.con() == null){ @@ -492,6 +503,20 @@ public class NetServer implements ApplicationListener{ player.con().hasDisconnected = true; } + @Remote(targets = Loc.both, variants = Variant.both) + public static void packetReliable(String type, String contents){ + if(netServer.customPacketHandlers.containsKey(type)){ + for(Cons c : netServer.customPacketHandlers.get(type)){ + c.get(contents); + } + } + } + + @Remote(targets = Loc.both, variants = Variant.both, unreliable = true) + public static void packetUnreliable(String type, String contents){ + packetReliable(type, contents); + } + @Remote(targets = Loc.client, unreliable = true) public static void onClientShapshot( Playerc player, diff --git a/gradle.properties b/gradle.properties index 68d4c5cf20..38a2de2fcf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=6069cba645e3d301a6bf4169182bb191f562b4da +archash=caa68598497505cd1aa4531648c56c1b6b48a1a6