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 != null){
|
||||||
world.getCore().entity.onDeath(true);
|
world.getCore().entity.onDeath(true);
|
||||||
}
|
}
|
||||||
netServer.admins.getEditLogs().clear();
|
|
||||||
kicked = true;
|
kicked = true;
|
||||||
ui.restart.show();
|
ui.restart.show();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ public class NetServer extends Module{
|
|||||||
|
|
||||||
public NetServer(){
|
public NetServer(){
|
||||||
|
|
||||||
Events.on(GameOverEvent.class, () -> weapons.clear());
|
Events.on(GameOverEvent.class, () -> {
|
||||||
|
weapons.clear();
|
||||||
|
admins.getEditLogs().clear();
|
||||||
|
});
|
||||||
|
|
||||||
Net.handleServer(Connect.class, (id, connect) -> {
|
Net.handleServer(Connect.class, (id, connect) -> {
|
||||||
if(admins.isIPBanned(connect.addressTCP)){
|
if(admins.isIPBanned(connect.addressTCP)){
|
||||||
@@ -349,7 +352,7 @@ public class NetServer extends Module{
|
|||||||
});
|
});
|
||||||
|
|
||||||
Net.handleServer(BlockLogRequestPacket.class, (id, packet) -> {
|
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);
|
Net.sendTo(id, packet, SendMode.udp);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,10 +63,6 @@ public class Administration {
|
|||||||
return editLogs;
|
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) {
|
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(block instanceof BlockPart || block instanceof Rock || block instanceof Floor || block instanceof StaticBlock) return;
|
||||||
if(editLogs.containsKey(x + y * world.width())) {
|
if(editLogs.containsKey(x + y * world.width())) {
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
package io.anuke.mindustry.net;
|
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.entities.Player;
|
||||||
import io.anuke.mindustry.world.Block;
|
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 class EditLog {
|
||||||
|
|
||||||
public Player player;
|
public Player player;
|
||||||
public Block block;
|
public Block block;
|
||||||
public int rotation;
|
public int rotation;
|
||||||
public EditAction action;
|
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.player = player;
|
||||||
this.block = block;
|
this.block = block;
|
||||||
this.rotation = rotation;
|
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());
|
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) {
|
public enum EditAction {
|
||||||
String[] parts = string.split(":");
|
PLACE, BREAK;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.badlogic.gdx.utils.Base64Coder;
|
|||||||
import com.badlogic.gdx.utils.IntMap;
|
import com.badlogic.gdx.utils.IntMap;
|
||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||||
import com.badlogic.gdx.utils.reflect.ReflectionException;
|
import com.badlogic.gdx.utils.reflect.ReflectionException;
|
||||||
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.entities.SyncEntity;
|
import io.anuke.mindustry.entities.SyncEntity;
|
||||||
import io.anuke.mindustry.io.Version;
|
import io.anuke.mindustry.io.Version;
|
||||||
@@ -148,28 +149,30 @@ public class Packets {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuffer buffer) {
|
public void write(ByteBuffer buffer) {
|
||||||
buffer.putInt(x);
|
buffer.putShort((short)x);
|
||||||
buffer.putInt(y);
|
buffer.putShort((short)y);
|
||||||
buffer.putInt(editlogs.size);
|
buffer.putInt(editlogs.size);
|
||||||
for(EditLog value : editlogs) {
|
for(EditLog value : editlogs) {
|
||||||
|
buffer.putInt(value.player.id);
|
||||||
String rawValue = value.toString();
|
buffer.putInt(value.block.id);
|
||||||
buffer.put((byte) rawValue.getBytes().length);
|
buffer.put((byte) value.rotation);
|
||||||
buffer.put(rawValue.getBytes());
|
buffer.put((byte) value.action.ordinal());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(ByteBuffer buffer) {
|
public void read(ByteBuffer buffer) {
|
||||||
x = buffer.getInt();
|
x = buffer.getShort();
|
||||||
y = buffer.getInt();
|
y = buffer.getShort();
|
||||||
editlogs = new Array<>();
|
editlogs = new Array<>();
|
||||||
int arraySize = buffer.getInt();
|
int arraySize = buffer.getInt();
|
||||||
for(int a = 0; a < arraySize; a ++) {
|
for(int a = 0; a < arraySize; a ++) {
|
||||||
|
int playerid = buffer.getInt();
|
||||||
byte[] arraybytes = new byte[buffer.get()];
|
int blockid = buffer.getInt();
|
||||||
buffer.get(arraybytes);
|
int rotation = buffer.get();
|
||||||
editlogs.add(EditLog.valueOf(new String(arraybytes)));
|
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