diff --git a/core/src/mindustry/core/NetClient.java b/core/src/mindustry/core/NetClient.java index cfa908ca59..c2ee93cfbe 100644 --- a/core/src/mindustry/core/NetClient.java +++ b/core/src/mindustry/core/NetClient.java @@ -345,6 +345,7 @@ public class NetClient implements ApplicationListener{ Groups.clear(); netClient.removed.clear(); logic.reset(); + netClient.connecting = true; net.setClientLoaded(false); diff --git a/core/src/mindustry/core/NetServer.java b/core/src/mindustry/core/NetServer.java index e4fe62e126..7bc4e8f295 100644 --- a/core/src/mindustry/core/NetServer.java +++ b/core/src/mindustry/core/NetServer.java @@ -706,10 +706,12 @@ public class NetServer implements ApplicationListener{ @Remote(targets = Loc.client) public static void connectConfirm(Player player){ + player.add(); + if(player.con == null || player.con.hasConnected) return; - player.add(); player.con.hasConnected = true; + if(Config.showConnectMessages.bool()){ Call.sendMessage("[accent]" + player.name + "[accent] has connected."); Log.info("&lm[@] &y@ has connected. ", player.uuid(), player.name); diff --git a/core/src/mindustry/logic/LStatement.java b/core/src/mindustry/logic/LStatement.java index f1e76c06b9..d965101296 100644 --- a/core/src/mindustry/logic/LStatement.java +++ b/core/src/mindustry/logic/LStatement.java @@ -116,6 +116,6 @@ public abstract class LStatement{ } public String name(){ - return getClass().getSimpleName().replace("Statement", ""); + return Strings.insertSpaces(getClass().getSimpleName().replace("Statement", "")); } } diff --git a/core/src/mindustry/net/Net.java b/core/src/mindustry/net/Net.java index f151de2f10..8993b84f83 100644 --- a/core/src/mindustry/net/Net.java +++ b/core/src/mindustry/net/Net.java @@ -152,6 +152,7 @@ public class Net{ } public void disconnect(){ + Log.info("Disconnecting."); provider.disconnectClient(); server = false; active = false; diff --git a/core/src/mindustry/world/blocks/logic/LogicBlock.java b/core/src/mindustry/world/blocks/logic/LogicBlock.java index f16ed183e1..06a9046e64 100644 --- a/core/src/mindustry/world/blocks/logic/LogicBlock.java +++ b/core/src/mindustry/world/blocks/logic/LogicBlock.java @@ -35,7 +35,7 @@ public class LogicBlock extends Block{ update = true; configurable = true; - config(byte[].class, LogicBuild::readCompressed); + config(byte[].class, (LogicBuild build, byte[] data) -> build.readCompressed(data, true)); config(Integer.class, (LogicBuild entity, Integer pos) -> { if(entity.connections.contains(pos)){ @@ -80,11 +80,13 @@ public class LogicBlock extends Block{ public String code = ""; public LExecutor executor = new LExecutor(); public float accumulator = 0; + + //TODO refactor this system, it's broken. public IntSeq connections = new IntSeq(); public IntSeq invalidConnections = new IntSeq(); public boolean loaded = false; - public void readCompressed(byte[] data){ + public void readCompressed(byte[] data, boolean relative){ DataInputStream stream = new DataInputStream(new InflaterInputStream(new ByteArrayInputStream(data))); try{ @@ -99,7 +101,8 @@ public class LogicBlock extends Block{ int cons = stream.readInt(); for(int i = 0; i < cons; i++){ - connections.add(stream.readInt()); + int pos = stream.readInt(); + connections.add(relative ? Point2.pack(Point2.x(pos) + tileX(), Point2.y(pos) + tileY()) : pos); } updateCode(new String(bytes, charset)); @@ -211,14 +214,17 @@ public class LogicBlock extends Block{ } @Override - public String config(){ - //set connections to use relative coordinates, not absolute (TODO maybe just store them like this?) + public byte[] config(){ + return compress(code, relativeConnections()); + } + + public IntSeq relativeConnections(){ IntSeq copy = new IntSeq(connections); for(int i = 0; i < copy.size; i++){ int pos = copy.items[i]; copy.items[i] = Point2.pack(Point2.x(pos) - tileX(), Point2.y(pos) - tileY()); } - return JsonIO.write(new LogicConfig(code, copy)); + return copy; } @Override @@ -264,7 +270,7 @@ public class LogicBlock extends Block{ cont.button(Icon.pencil, Styles.clearTransi, () -> { Vars.ui.logic.show(code, code -> { - configure(compress(code, connections)); + configure(compress(code, relativeConnections())); }); }); @@ -331,7 +337,7 @@ public class LogicBlock extends Block{ int compl = read.i(); byte[] bytes = new byte[compl]; read.b(bytes); - readCompressed(bytes); + readCompressed(bytes, false); }else{ code = read.str(); connections.clear(); diff --git a/server/src/mindustry/server/ServerControl.java b/server/src/mindustry/server/ServerControl.java index b33430ca0b..e5b2187cad 100644 --- a/server/src/mindustry/server/ServerControl.java +++ b/server/src/mindustry/server/ServerControl.java @@ -924,7 +924,7 @@ public class ServerControl implements ApplicationListener{ players.add(p); p.clearUnit(); } - + logic.reset(); Call.worldDataBegin();