Added edit logging and whole world rollback
This commit is contained in:
@@ -1,10 +1,19 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.types.BlockPart;
|
||||
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 {
|
||||
public static final int defaultMaxBrokenBlocks = 15;
|
||||
@@ -15,6 +24,9 @@ public class Administration {
|
||||
private ObjectMap<String, PlayerInfo> playerInfo = new ObjectMap<>();
|
||||
/**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 Array<String> bannedIPs = new Array<>();
|
||||
|
||||
public Administration(){
|
||||
@@ -48,6 +60,22 @@ public class Administration {
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
public IntMap<ArrayList<EditLog>> getEditLogs() {
|
||||
return 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<>();
|
||||
logs.add(new EditLog(player, block, rotation, action));
|
||||
editLogs.put(x + y * world.width(), logs);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validateBreak(String id, String ip){
|
||||
if(!isAntiGrief() || isAdmin(id, ip)) return true;
|
||||
|
||||
|
||||
41
core/src/io/anuke/mindustry/net/EditLog.java
Normal file
41
core/src/io/anuke/mindustry/net/EditLog.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import static io.anuke.mindustry.Vars.playerGroup;
|
||||
|
||||
public class EditLog {
|
||||
|
||||
public Player player;
|
||||
public Block block;
|
||||
public int rotation;
|
||||
public EditAction action;
|
||||
|
||||
EditLog(Player player, Block block, int rotation, EditAction action){
|
||||
this.player = player;
|
||||
this.block = block;
|
||||
this.rotation = rotation;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public String info() {
|
||||
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 String toString() {
|
||||
return String.format("%s:%s:%s:%s", player.id, block.id, rotation, action.toString());
|
||||
}
|
||||
|
||||
public enum EditAction{
|
||||
PLACE,
|
||||
BREAK;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
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.entities.Player;
|
||||
@@ -12,8 +13,8 @@ import io.anuke.mindustry.resource.Item;
|
||||
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,6 +141,54 @@ public class Packets {
|
||||
}
|
||||
}
|
||||
|
||||
public static class BlockLogSyncPacket implements Packet {
|
||||
public IntMap<ArrayList<EditLog>> editlogs;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
int size = editlogs.size;
|
||||
buffer.putInt(size);
|
||||
for(IntMap.Entry<ArrayList<EditLog>> editlog :editlogs.entries()) {
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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 ++) {
|
||||
|
||||
byte[] arraybytes = new byte[buffer.get()];
|
||||
buffer.get(arraybytes);
|
||||
list.add(EditLog.valueOf(new String(arraybytes)));
|
||||
}
|
||||
editlogs.put(key, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PositionPacket implements Packet{
|
||||
public byte[] data;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ public class Registrator {
|
||||
PlacePacket.class,
|
||||
BreakPacket.class,
|
||||
StateSyncPacket.class,
|
||||
BlockLogSyncPacket.class,
|
||||
BlockSyncPacket.class,
|
||||
BulletPacket.class,
|
||||
EnemyDeathPacket.class,
|
||||
@@ -44,7 +45,7 @@ public class Registrator {
|
||||
NetErrorPacket.class,
|
||||
PlayerAdminPacket.class,
|
||||
AdministerRequestPacket.class,
|
||||
TracePacket.class,
|
||||
TracePacket.class
|
||||
};
|
||||
private static ObjectIntMap<Class<?>> ids = new ObjectIntMap<>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user