mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-25 15:18:24 +07:00
client/server separation
This commit is contained in:
@ -19,6 +19,7 @@ const run = method => new java.lang.Runnable(){run: method}
|
|||||||
const boolf = method => new Boolf(){get: method}
|
const boolf = method => new Boolf(){get: method}
|
||||||
const boolp = method => new Boolp(){get: method}
|
const boolp = method => new Boolp(){get: method}
|
||||||
const cons = method => new Cons(){get: method}
|
const cons = method => new Cons(){get: method}
|
||||||
|
const cons2 = method => new Cons2(){get: method}
|
||||||
const prov = method => new Prov(){get: method}
|
const prov = method => new Prov(){get: method}
|
||||||
const newEffect = (lifetime, renderer) => new Effects.Effect(lifetime, new Effects.EffectRenderer({render: renderer}))
|
const newEffect = (lifetime, renderer) => new Effects.Effect(lifetime, new Effects.EffectRenderer({render: renderer}))
|
||||||
Call = Packages.mindustry.gen.Call
|
Call = Packages.mindustry.gen.Call
|
||||||
|
@ -23,6 +23,7 @@ const boolp = method => new Boolp(){get: method}
|
|||||||
const floatf = method => new Floatf(){get: method}
|
const floatf = method => new Floatf(){get: method}
|
||||||
const floatp = method => new Floatp(){get: method}
|
const floatp = method => new Floatp(){get: method}
|
||||||
const cons = method => new Cons(){get: method}
|
const cons = method => new Cons(){get: method}
|
||||||
|
const cons2 = method => new Cons2(){get: method}
|
||||||
const prov = method => new Prov(){get: method}
|
const prov = method => new Prov(){get: method}
|
||||||
const func = method => new Func(){get: method}
|
const func = method => new Func(){get: method}
|
||||||
const newEffect = (lifetime, renderer) => new Effects.Effect(lifetime, new Effects.EffectRenderer({render: renderer}))
|
const newEffect = (lifetime, renderer) => new Effects.Effect(lifetime, new Effects.EffectRenderer({render: renderer}))
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package mindustry.core;
|
package mindustry.core;
|
||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
|
import arc.func.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
@ -49,6 +50,8 @@ public class NetClient implements ApplicationListener{
|
|||||||
/** Byte stream for reading in snapshots. */
|
/** Byte stream for reading in snapshots. */
|
||||||
private ReusableByteInStream byteStream = new ReusableByteInStream();
|
private ReusableByteInStream byteStream = new ReusableByteInStream();
|
||||||
private DataInputStream dataStream = new DataInputStream(byteStream);
|
private DataInputStream dataStream = new DataInputStream(byteStream);
|
||||||
|
/** Packet handlers for custom types of messages. */
|
||||||
|
private ObjectMap<String, Array<Cons<String>>> customPacketHandlers = new ObjectMap<>();
|
||||||
|
|
||||||
public NetClient(){
|
public NetClient(){
|
||||||
|
|
||||||
@ -126,6 +129,28 @@ public class NetClient implements ApplicationListener{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Remote(targets = Loc.server, variants = Variant.both)
|
||||||
|
public static void clientPacketReliable(String type, String contents){
|
||||||
|
if(netClient.customPacketHandlers.containsKey(type)){
|
||||||
|
for(Cons<String> c : netClient.customPacketHandlers.get(type)){
|
||||||
|
c.get(contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Remote(targets = Loc.server, variants = Variant.both, unreliable = true)
|
||||||
|
public static void clientPacketUnreliable(String type, String contents){
|
||||||
|
clientPacketReliable(type, contents);
|
||||||
|
}
|
||||||
|
|
||||||
//called on all clients
|
//called on all clients
|
||||||
@Remote(targets = Loc.server, variants = Variant.both)
|
@Remote(targets = Loc.server, variants = Variant.both)
|
||||||
public static void sendMessage(String message, String sender, Playerc playersender){
|
public static void sendMessage(String message, String sender, Playerc playersender){
|
||||||
|
@ -74,7 +74,7 @@ public class NetServer implements ApplicationListener{
|
|||||||
/** Data stream for writing player sync data to. */
|
/** Data stream for writing player sync data to. */
|
||||||
private DataOutputStream dataStream = new DataOutputStream(syncStream);
|
private DataOutputStream dataStream = new DataOutputStream(syncStream);
|
||||||
/** Packet handlers for custom types of messages. */
|
/** Packet handlers for custom types of messages. */
|
||||||
private ObjectMap<String, Array<Cons<String>>> customPacketHandlers = new ObjectMap<>();
|
private ObjectMap<String, Array<Cons2<Playerc, String>>> customPacketHandlers = new ObjectMap<>();
|
||||||
|
|
||||||
public NetServer(){
|
public NetServer(){
|
||||||
|
|
||||||
@ -474,11 +474,11 @@ public class NetServer implements ApplicationListener{
|
|||||||
Log.debug("Packed @ compressed bytes of world data.", stream.size());
|
Log.debug("Packed @ compressed bytes of world data.", stream.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPacketHandler(String type, Cons<String> handler){
|
public void addPacketHandler(String type, Cons2<Playerc, String> handler){
|
||||||
customPacketHandlers.getOr(type, Array::new).add(handler);
|
customPacketHandlers.getOr(type, Array::new).add(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Array<Cons<String>> getPacketHandlers(String type){
|
public Array<Cons2<Playerc, String>> getPacketHandlers(String type){
|
||||||
return customPacketHandlers.getOr(type, Array::new);
|
return customPacketHandlers.getOr(type, Array::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,18 +503,18 @@ public class NetServer implements ApplicationListener{
|
|||||||
player.con().hasDisconnected = true;
|
player.con().hasDisconnected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.both, variants = Variant.both)
|
@Remote(targets = Loc.client)
|
||||||
public static void packetReliable(String type, String contents){
|
public static void serverPacketReliable(Playerc player, String type, String contents){
|
||||||
if(netServer.customPacketHandlers.containsKey(type)){
|
if(netServer.customPacketHandlers.containsKey(type)){
|
||||||
for(Cons<String> c : netServer.customPacketHandlers.get(type)){
|
for(Cons2<Playerc, String> c : netServer.customPacketHandlers.get(type)){
|
||||||
c.get(contents);
|
c.get(player, contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.both, variants = Variant.both, unreliable = true)
|
@Remote(targets = Loc.client, unreliable = true)
|
||||||
public static void packetUnreliable(String type, String contents){
|
public static void serverPacketUnreliable(Playerc player, String type, String contents){
|
||||||
packetReliable(type, contents);
|
serverPacketReliable(player, type, contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Remote(targets = Loc.client, unreliable = true)
|
@Remote(targets = Loc.client, unreliable = true)
|
||||||
|
Reference in New Issue
Block a user