mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-10 07:07:03 +07:00
Mod packet support
This commit is contained in:
parent
becc23ca42
commit
bdb1e29c85
@ -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<String, Array<Cons<String>>> 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<String> handler){
|
||||
customPacketHandlers.getOr(type, Array::new).add(handler);
|
||||
}
|
||||
|
||||
public Array<Cons<String>> 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<String> 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,
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=6069cba645e3d301a6bf4169182bb191f562b4da
|
||||
archash=caa68598497505cd1aa4531648c56c1b6b48a1a6
|
||||
|
Loading…
Reference in New Issue
Block a user