Updated the way packets are exchanged for edit logs.
This commit is contained in:
@@ -256,7 +256,6 @@ public class NetClient extends Module {
|
||||
world.getCore().entity != null){
|
||||
world.getCore().entity.onDeath(true);
|
||||
}
|
||||
netServer.admins.getEditLogs().clear();
|
||||
kicked = true;
|
||||
ui.restart.show();
|
||||
});
|
||||
|
||||
@@ -44,7 +44,10 @@ public class NetServer extends Module{
|
||||
|
||||
public NetServer(){
|
||||
|
||||
Events.on(GameOverEvent.class, () -> weapons.clear());
|
||||
Events.on(GameOverEvent.class, () -> {
|
||||
weapons.clear();
|
||||
admins.getEditLogs().clear();
|
||||
});
|
||||
|
||||
Net.handleServer(Connect.class, (id, connect) -> {
|
||||
if(admins.isIPBanned(connect.addressTCP)){
|
||||
@@ -349,7 +352,7 @@ public class NetServer extends Module{
|
||||
});
|
||||
|
||||
Net.handleServer(BlockLogRequestPacket.class, (id, packet) -> {
|
||||
packet.editlogs = EditLog.logsFromTile(packet.x, packet.y);
|
||||
packet.editlogs = admins.getEditLogs().get(packet.x + packet.y * world.width(), new Array<>());
|
||||
Net.sendTo(id, packet, SendMode.udp);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -63,10 +63,6 @@ public class Administration {
|
||||
return editLogs;
|
||||
}
|
||||
|
||||
public void setEditLogs(IntMap<Array<EditLog>> editLogs) {
|
||||
this.editLogs = editLogs;
|
||||
}
|
||||
|
||||
public void logEdit(int x, int y, Player player, Block block, int rotation, EditLog.EditAction action) {
|
||||
if(block instanceof BlockPart || block instanceof Rock || block instanceof Floor || block instanceof StaticBlock) return;
|
||||
if(editLogs.containsKey(x + y * world.width())) {
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import static io.anuke.mindustry.Vars.netServer;
|
||||
import static io.anuke.mindustry.Vars.playerGroup;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class EditLog {
|
||||
|
||||
public Player player;
|
||||
public Block block;
|
||||
public int rotation;
|
||||
public EditAction action;
|
||||
|
||||
EditLog(Player player, Block block, int rotation, EditAction action){
|
||||
EditLog(Player player, Block block, int rotation, EditAction action) {
|
||||
this.player = player;
|
||||
this.block = block;
|
||||
this.rotation = rotation;
|
||||
@@ -26,29 +20,7 @@ public class EditLog {
|
||||
return String.format("Player: %s, Block: %s, Rotation: %s, Edit Action: %s", player.name, block.name(), rotation, action.toString());
|
||||
}
|
||||
|
||||
public static EditLog valueOf(String string) {
|
||||
String[] parts = string.split(":");
|
||||
return new EditLog(playerGroup.getByID(Integer.valueOf(parts[0])),
|
||||
Block.getByID(Integer.valueOf(parts[1])),
|
||||
Integer.valueOf(parts[2]),
|
||||
EditAction.valueOf(parts[3]));
|
||||
}
|
||||
|
||||
public static Array<EditLog> logsFromTile(int x, int y) {
|
||||
for(IntMap.Entry<Array<EditLog>> editLog : netServer.admins.getEditLogs().entries()) {
|
||||
if(editLog.key == (x + y * world.width())) {
|
||||
return editLog.value;
|
||||
}
|
||||
}
|
||||
return new Array<>();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("%s:%s:%s:%s", player.id, block.id, rotation, action.toString());
|
||||
}
|
||||
|
||||
public enum EditAction{
|
||||
PLACE,
|
||||
BREAK;
|
||||
public enum EditAction {
|
||||
PLACE, BREAK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.utils.Base64Coder;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import com.badlogic.gdx.utils.reflect.ReflectionException;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
import io.anuke.mindustry.io.Version;
|
||||
@@ -148,28 +149,30 @@ public class Packets {
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(x);
|
||||
buffer.putInt(y);
|
||||
buffer.putShort((short)x);
|
||||
buffer.putShort((short)y);
|
||||
buffer.putInt(editlogs.size);
|
||||
for(EditLog value : editlogs) {
|
||||
|
||||
String rawValue = value.toString();
|
||||
buffer.put((byte) rawValue.getBytes().length);
|
||||
buffer.put(rawValue.getBytes());
|
||||
buffer.putInt(value.player.id);
|
||||
buffer.putInt(value.block.id);
|
||||
buffer.put((byte) value.rotation);
|
||||
buffer.put((byte) value.action.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
x = buffer.getInt();
|
||||
y = buffer.getInt();
|
||||
x = buffer.getShort();
|
||||
y = buffer.getShort();
|
||||
editlogs = new Array<>();
|
||||
int arraySize = buffer.getInt();
|
||||
for(int a = 0; a < arraySize; a ++) {
|
||||
|
||||
byte[] arraybytes = new byte[buffer.get()];
|
||||
buffer.get(arraybytes);
|
||||
editlogs.add(EditLog.valueOf(new String(arraybytes)));
|
||||
int playerid = buffer.getInt();
|
||||
int blockid = buffer.getInt();
|
||||
int rotation = buffer.get();
|
||||
int ordinal = buffer.get();
|
||||
|
||||
editlogs.add(new EditLog(Vars.playerGroup.getByID(playerid), Block.getByID(blockid), rotation, EditLog.EditAction.values()[ordinal]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user