Replaced ArrayLists with Arrays, overhauled requesting of logs from the server, improved rollback command and added log resetting.
This commit is contained in:
@@ -12,7 +12,6 @@ import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
import io.anuke.mindustry.world.blocks.types.Rock;
|
||||
import io.anuke.mindustry.world.blocks.types.StaticBlock;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import java.util.ArrayList;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class Administration {
|
||||
@@ -25,7 +24,7 @@ public class Administration {
|
||||
/**Maps UUIDs to trace infos. This is wiped when a player logs off.*/
|
||||
private ObjectMap<String, TraceInfo> traceInfo = new ObjectMap<>();
|
||||
/**Maps packed coordinates to logs for that coordinate */
|
||||
private IntMap<ArrayList<EditLog>> editLogs = new IntMap<>();
|
||||
private IntMap<Array<EditLog>> editLogs = new IntMap<>();
|
||||
|
||||
private Array<String> bannedIPs = new Array<>();
|
||||
|
||||
@@ -60,17 +59,21 @@ public class Administration {
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
public IntMap<ArrayList<EditLog>> getEditLogs() {
|
||||
public IntMap<Array<EditLog>> getEditLogs() {
|
||||
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())) {
|
||||
editLogs.get(x + y * world.width()).add(new EditLog(player, block, rotation, action));
|
||||
}
|
||||
else {
|
||||
ArrayList<EditLog> logs = new ArrayList<>();
|
||||
Array<EditLog> logs = new Array<>();
|
||||
logs.add(new EditLog(player, block, rotation, action));
|
||||
editLogs.put(x + y * world.width(), logs);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
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 {
|
||||
|
||||
@@ -30,6 +34,15 @@ public class EditLog {
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -177,4 +177,13 @@ public class NetEvents {
|
||||
ui.traces.show(target, netServer.admins.getTrace(Net.getConnection(target.clientid).address));
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleBlockLogRequest(int x, int y) {
|
||||
BlockLogRequestPacket packet = new BlockLogRequestPacket();
|
||||
packet.x = x;
|
||||
packet.y = y;
|
||||
packet.editlogs = Vars.currentEditLogs;
|
||||
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Base64Coder;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
@@ -14,7 +15,6 @@ import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**Class for storing all packets.*/
|
||||
public class Packets {
|
||||
@@ -140,51 +140,36 @@ public class Packets {
|
||||
timestamp = buffer.getLong();
|
||||
}
|
||||
}
|
||||
|
||||
public static class BlockLogSyncPacket implements Packet {
|
||||
public IntMap<ArrayList<EditLog>> editlogs;
|
||||
|
||||
public static class BlockLogRequestPacket implements Packet {
|
||||
public int x;
|
||||
public int y;
|
||||
public Array<EditLog> editlogs;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
int size = editlogs.size;
|
||||
buffer.putInt(size);
|
||||
for(IntMap.Entry<ArrayList<EditLog>> editlog :editlogs.entries()) {
|
||||
buffer.putInt(x);
|
||||
buffer.putInt(y);
|
||||
buffer.putInt(editlogs.size);
|
||||
for(EditLog value : editlogs) {
|
||||
|
||||
String key = String.valueOf(editlog.key);
|
||||
buffer.put((byte) key.getBytes().length);
|
||||
buffer.put(key.getBytes());
|
||||
|
||||
ArrayList<EditLog> values = editlog.value;
|
||||
buffer.putInt(values.size());
|
||||
for(EditLog value : values) {
|
||||
|
||||
String rawValue = value.toString();
|
||||
buffer.put((byte) rawValue.getBytes().length);
|
||||
buffer.put(rawValue.getBytes());
|
||||
}
|
||||
String rawValue = value.toString();
|
||||
buffer.put((byte) rawValue.getBytes().length);
|
||||
buffer.put(rawValue.getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
editlogs = new IntMap<>();
|
||||
int logssize = buffer.getInt();
|
||||
for(int i = 0; i < logssize; i ++){
|
||||
|
||||
byte length = buffer.get();
|
||||
byte[] bytes = new byte[length];
|
||||
buffer.get(bytes);
|
||||
Integer key = Integer.valueOf(new String(bytes));
|
||||
|
||||
ArrayList<EditLog> list = new ArrayList<>();
|
||||
int arraySize = buffer.getInt();
|
||||
for(int a = 0; a < arraySize; a ++) {
|
||||
x = buffer.getInt();
|
||||
y = buffer.getInt();
|
||||
editlogs = new Array<>();
|
||||
int arraySize = buffer.getInt();
|
||||
for(int a = 0; a < arraySize; a ++) {
|
||||
|
||||
byte[] arraybytes = new byte[buffer.get()];
|
||||
buffer.get(arraybytes);
|
||||
list.add(EditLog.valueOf(new String(arraybytes)));
|
||||
}
|
||||
editlogs.put(key, list);
|
||||
byte[] arraybytes = new byte[buffer.get()];
|
||||
buffer.get(arraybytes);
|
||||
editlogs.add(EditLog.valueOf(new String(arraybytes)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class Registrator {
|
||||
PlacePacket.class,
|
||||
BreakPacket.class,
|
||||
StateSyncPacket.class,
|
||||
BlockLogSyncPacket.class,
|
||||
BlockLogRequestPacket.class,
|
||||
BlockSyncPacket.class,
|
||||
BulletPacket.class,
|
||||
EnemyDeathPacket.class,
|
||||
|
||||
Reference in New Issue
Block a user