one painful merge later
This commit is contained in:
@@ -1,9 +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.Placement;
|
||||
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 static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class Administration {
|
||||
public static final int defaultMaxBrokenBlocks = 15;
|
||||
@@ -13,6 +23,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<Array<EditLog>> editLogs = new IntMap<>();
|
||||
|
||||
private Array<String> bannedIPs = new Array<>();
|
||||
|
||||
public Administration(){
|
||||
@@ -44,6 +57,68 @@ public class Administration {
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
public IntMap<Array<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.name, block, rotation, action));
|
||||
}
|
||||
else {
|
||||
Array<EditLog> logs = new Array<>();
|
||||
logs.add(new EditLog(player.name, block, rotation, action));
|
||||
editLogs.put(x + y * world.width(), logs);
|
||||
}
|
||||
}
|
||||
|
||||
public void rollbackWorld(int rollbackTimes) {
|
||||
for(IntMap.Entry<Array<EditLog>> editLog : editLogs.entries()) {
|
||||
int coords = editLog.key;
|
||||
Array<EditLog> logs = editLog.value;
|
||||
|
||||
for(int i = 0; i < rollbackTimes; i++) {
|
||||
|
||||
EditLog log = logs.get(logs.size - 1);
|
||||
|
||||
int x = coords % world.width();
|
||||
int y = coords / world.width();
|
||||
Block result = log.block;
|
||||
int rotation = log.rotation;
|
||||
|
||||
if(log.action == EditLog.EditAction.PLACE) {
|
||||
Placement.breakBlock(x, y, false, false);
|
||||
|
||||
Packets.BreakPacket packet = new Packets.BreakPacket();
|
||||
packet.x = (short) x;
|
||||
packet.y = (short) y;
|
||||
packet.playerid = 0;
|
||||
|
||||
Net.send(packet, Net.SendMode.tcp);
|
||||
}
|
||||
else if(log.action == EditLog.EditAction.BREAK) {
|
||||
Placement.placeBlock(x, y, result, rotation, false, false);
|
||||
|
||||
Packets.PlacePacket packet = new Packets.PlacePacket();
|
||||
packet.x = (short) x;
|
||||
packet.y = (short) y;
|
||||
packet.rotation = (byte) rotation;
|
||||
packet.playerid = 0;
|
||||
packet.block = result.id;
|
||||
|
||||
Net.send(packet, Net.SendMode.tcp);
|
||||
}
|
||||
|
||||
logs.removeIndex(logs.size - 1);
|
||||
if(logs.size == 0) {
|
||||
editLogs.remove(coords);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validateBreak(String id, String ip){
|
||||
if(!isAntiGrief() || isAdmin(id, ip)) return true;
|
||||
|
||||
|
||||
26
core/src/io/anuke/mindustry/net/EditLog.java
Normal file
26
core/src/io/anuke/mindustry/net/EditLog.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
|
||||
public class EditLog {
|
||||
public String playername;
|
||||
public Block block;
|
||||
public int rotation;
|
||||
public EditAction action;
|
||||
|
||||
EditLog(String playername, Block block, int rotation, EditAction action) {
|
||||
this.playername = playername;
|
||||
this.block = block;
|
||||
this.rotation = rotation;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public String info() {
|
||||
return String.format("Player: %s, Block: %s, Rotation: %s, Edit Action: %s", playername, block.name(), rotation, action.toString());
|
||||
}
|
||||
|
||||
public enum EditAction {
|
||||
PLACE, BREAK;
|
||||
}
|
||||
}
|
||||
@@ -120,4 +120,20 @@ public class NetEvents {
|
||||
ui.traces.show(target, netServer.admins.getTraceByID(target.uuid));
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public static void handleRollbackRequest(int rollbackTimes) {
|
||||
RollbackRequestPacket packet = new RollbackRequestPacket();
|
||||
packet.rollbackTimes = rollbackTimes;
|
||||
|
||||
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.TimeUtils;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
@@ -159,6 +160,60 @@ public class Packets {
|
||||
}
|
||||
}
|
||||
|
||||
public static class BlockLogRequestPacket implements Packet {
|
||||
public int x;
|
||||
public int y;
|
||||
public Array<EditLog> editlogs;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putShort((short)x);
|
||||
buffer.putShort((short)y);
|
||||
buffer.putInt(editlogs.size);
|
||||
for(EditLog value : editlogs) {
|
||||
buffer.put((byte)value.playername.getBytes().length);
|
||||
buffer.put(value.playername.getBytes());
|
||||
buffer.putInt(value.block.id);
|
||||
buffer.put((byte) value.rotation);
|
||||
buffer.put((byte) value.action.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
x = buffer.getShort();
|
||||
y = buffer.getShort();
|
||||
editlogs = new Array<>();
|
||||
int arraySize = buffer.getInt();
|
||||
for(int a = 0; a < arraySize; a ++) {
|
||||
byte length = buffer.get();
|
||||
byte[] bytes = new byte[length];
|
||||
buffer.get(bytes);
|
||||
String name = new String(bytes);
|
||||
|
||||
int blockid = buffer.getInt();
|
||||
int rotation = buffer.get();
|
||||
int ordinal = buffer.get();
|
||||
|
||||
editlogs.add(new EditLog(name, Block.getByID(blockid), rotation, EditLog.EditAction.values()[ordinal]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class RollbackRequestPacket implements Packet {
|
||||
public int rollbackTimes;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(rollbackTimes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
rollbackTimes = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static class PositionPacket implements Packet{
|
||||
public Player player;
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ public class Registrator {
|
||||
AdministerRequestPacket.class,
|
||||
TracePacket.class,
|
||||
InvokePacket.class,
|
||||
BlockLogRequestPacket.class,
|
||||
RollbackRequestPacket.class
|
||||
};
|
||||
private static ObjectIntMap<Class<?>> ids = new ObjectIntMap<>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user