Changed too many things to fit in commit log
This commit is contained in:
@@ -72,6 +72,7 @@ public class Administration {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void rollbackWorld(int rollbackTimes) {
|
||||
for(IntMap.Entry<Array<EditLog>> editLog : editLogs.entries()) {
|
||||
int coords = editLog.key;
|
||||
@@ -118,7 +119,7 @@ public class Administration {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
public boolean validateBreak(String id, String ip){
|
||||
if(!isAntiGrief() || isAdmin(id, ip)) return true;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class Interpolator {
|
||||
//used for movement
|
||||
public Vector2 target = new Vector2();
|
||||
public Vector2 last = new Vector2();
|
||||
public float[] targets;
|
||||
public float spacing = 1f;
|
||||
public float time;
|
||||
|
||||
//current state
|
||||
public Vector2 pos = new Vector2();
|
||||
public float[] values = {};
|
||||
|
||||
public Vector2 smoothPos = new Vector2();
|
||||
|
||||
public void read(float cx, float cy, float x, float y, long sent, float... target1ds){
|
||||
targets = target1ds;
|
||||
time = 0f;
|
||||
last.set(cx, cy);
|
||||
target.set(x, y);
|
||||
spacing = Math.min(Math.max(((TimeUtils.timeSinceMillis(sent) / 1000f) * 60f), 4f), 10);
|
||||
}
|
||||
|
||||
public void update(){
|
||||
|
||||
time += 1f / spacing * Math.min(Timers.delta(), 1f);
|
||||
|
||||
time = Mathf.clamp(time, 0, 2f);
|
||||
|
||||
Mathf.lerp2(pos.set(last), target, time);
|
||||
|
||||
if(values.length != targets.length){
|
||||
values = new float[targets.length];
|
||||
}
|
||||
|
||||
for(int i = 0; i < values.length; i ++){
|
||||
values[i] = Mathf.slerpDelta(values[i], targets[i], 0.6f);
|
||||
}
|
||||
|
||||
if(target.dst(pos) > 128){
|
||||
pos.set(target);
|
||||
last.set(target);
|
||||
time = 0f;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,138 +1,5 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
import io.anuke.mindustry.type.Upgrade;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class NetEvents {
|
||||
|
||||
public static void handleGameOver(){
|
||||
Net.send(Pools.obtain(GameOverPacket.class), SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleUnitDeath(Unit entity){
|
||||
EntityDeathPacket packet = Pools.obtain(EntityDeathPacket.class);
|
||||
packet.id = entity.id;
|
||||
packet.group = (byte)entity.getGroup().getID();
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleBlockDestroyed(TileEntity entity){
|
||||
BlockDestroyPacket packet = Pools.obtain(BlockDestroyPacket.class);
|
||||
packet.position = entity.tile.packedPosition();
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleBlockDamaged(TileEntity entity){
|
||||
BlockUpdatePacket packet = Pools.obtain(BlockUpdatePacket.class);
|
||||
packet.health = (int)entity.health;
|
||||
packet.position = entity.tile.packedPosition();
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
public static void handleBlockConfig(Tile tile, byte data){
|
||||
BlockConfigPacket packet = Pools.obtain(BlockConfigPacket.class);
|
||||
packet.data = data;
|
||||
packet.position = tile.packedPosition();
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleBlockTap(Tile tile){
|
||||
BlockTapPacket packet = Pools.obtain(BlockTapPacket.class);
|
||||
packet.position = tile.packedPosition();
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleWeaponSwitch(Player player){
|
||||
WeaponSwitchPacket packet = Pools.obtain(WeaponSwitchPacket.class);
|
||||
packet.weapon = player.weapon.id;
|
||||
packet.playerid = player.id;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleUpgrade(Player player, Upgrade weapon){
|
||||
UpgradePacket packet = Pools.obtain(UpgradePacket.class);
|
||||
packet.upgradeid = weapon.id;
|
||||
packet.playerid = player.id;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleSendMessage(Player player, String message){
|
||||
ChatPacket packet = Pools.obtain(ChatPacket.class);
|
||||
packet.text = message;
|
||||
packet.name = player.name;
|
||||
packet.id = player.id;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
|
||||
if(Net.server() && !headless){
|
||||
ui.chatfrag.addMessage(message, netCommon.colorizeName(player.id, player.name));
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleShoot(SyncEntity entity, float x, float y, float angle, short data){
|
||||
EntityShootPacket packet = Pools.obtain(EntityShootPacket.class);
|
||||
packet.groupid = (byte)entity.getGroup().getID();
|
||||
packet.x = x;
|
||||
packet.y = y;
|
||||
packet.data = data;
|
||||
packet.rotation = angle;
|
||||
packet.entityid = entity.id;
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
public static void handlePlace(Player player, int x, int y, Recipe recipe, int rotation){
|
||||
PlacePacket packet = Pools.obtain(PlacePacket.class);
|
||||
packet.x = (short)x;
|
||||
packet.y = (short)y;
|
||||
packet.rotation = (byte)rotation;
|
||||
packet.playerid = player.id;
|
||||
packet.recipe = (byte)recipe.id;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleBreak(int x, int y){
|
||||
BreakPacket packet = Pools.obtain(BreakPacket.class);
|
||||
packet.x = (short)x;
|
||||
packet.y = (short)y;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleAdministerRequest(Player target, AdminAction action){
|
||||
AdministerRequestPacket packet = Pools.obtain(AdministerRequestPacket.class);
|
||||
packet.id = target.id;
|
||||
packet.action = action;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleTraceRequest(Player target){
|
||||
if(Net.client()) {
|
||||
handleAdministerRequest(target, AdminAction.trace);
|
||||
}else{
|
||||
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;
|
||||
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
public static void handleRollbackRequest(int rollbackTimes) {
|
||||
RollbackRequestPacket packet = new RollbackRequestPacket();
|
||||
packet.rollbackTimes = rollbackTimes;
|
||||
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,10 @@
|
||||
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;
|
||||
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;
|
||||
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
||||
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.util.IOUtils;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -31,6 +21,10 @@ public class Packets {
|
||||
public String addressTCP;
|
||||
}
|
||||
|
||||
public static class WorldStream extends Streamable{
|
||||
|
||||
}
|
||||
|
||||
public static class InvokePacket implements Packet{
|
||||
public byte type;
|
||||
|
||||
@@ -61,165 +55,19 @@ public class Packets {
|
||||
}
|
||||
}
|
||||
|
||||
public static class WorldData extends Streamable{
|
||||
public static class SnapshotPacket implements Packet, UnimportantPacket{
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
|
||||
}
|
||||
|
||||
public static class SyncPacket implements Packet, UnimportantPacket{
|
||||
public byte[] data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putShort((short)data.length);
|
||||
buffer.put(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
data = new byte[buffer.getShort()];
|
||||
buffer.get(data);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BlockSyncPacket extends Streamable{
|
||||
|
||||
}
|
||||
|
||||
public static class ConnectPacket implements Packet{
|
||||
public int version;
|
||||
public int players;
|
||||
public String name;
|
||||
public boolean mobile;
|
||||
public int color;
|
||||
public byte[] uuid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(Version.build);
|
||||
IOUtils.writeString(buffer, name);
|
||||
buffer.put(mobile ? (byte)1 : 0);
|
||||
buffer.putInt(color);
|
||||
buffer.put(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
version = buffer.getInt();
|
||||
name = IOUtils.readString(buffer);
|
||||
mobile = buffer.get() == 1;
|
||||
color = buffer.getInt();
|
||||
uuid = new byte[8];
|
||||
buffer.get(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConnectConfirmPacket implements Packet{
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) { }
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) { }
|
||||
}
|
||||
|
||||
public static class DisconnectPacket implements Packet{
|
||||
public int playerid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(playerid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
playerid = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static class StateSyncPacket implements Packet, UnimportantPacket{
|
||||
//todo fix item syncing
|
||||
public float countdown, time;
|
||||
public int enemies, wave;
|
||||
public long timestamp;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putFloat(countdown);
|
||||
buffer.putFloat(time);
|
||||
buffer.putShort((short)enemies);
|
||||
buffer.putShort((short)wave);
|
||||
buffer.putLong(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
countdown = buffer.getFloat();
|
||||
time = buffer.getFloat();
|
||||
enemies = buffer.getShort();
|
||||
wave = buffer.getShort();
|
||||
timestamp = buffer.getLong();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if(editlogs != null) {
|
||||
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());
|
||||
}
|
||||
}else{
|
||||
buffer.putInt(0);
|
||||
}
|
||||
}
|
||||
|
||||
@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 static class ClientSnapshotPacket implements Packet{
|
||||
public Player player;
|
||||
|
||||
@Override
|
||||
@@ -238,199 +86,6 @@ public class Packets {
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntityShootPacket implements Packet, UnimportantPacket{
|
||||
public float x, y, rotation;
|
||||
public short bulletid;
|
||||
public byte groupid;
|
||||
public short data;
|
||||
public int entityid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.put(groupid);
|
||||
buffer.putInt(entityid);
|
||||
buffer.putFloat(x);
|
||||
buffer.putFloat(y);
|
||||
buffer.putFloat(rotation);
|
||||
buffer.putShort(bulletid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
groupid = buffer.get();
|
||||
entityid = buffer.getInt();
|
||||
x = buffer.getFloat();
|
||||
y = buffer.getFloat();
|
||||
rotation = buffer.getFloat();
|
||||
bulletid = buffer.getShort();
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlacePacket implements Packet{
|
||||
public int playerid;
|
||||
public byte rotation;
|
||||
public short x, y;
|
||||
public byte recipe;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(playerid);
|
||||
buffer.put(rotation);
|
||||
buffer.putShort(x);
|
||||
buffer.putShort(y);
|
||||
buffer.put(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
playerid = buffer.getInt();
|
||||
rotation = buffer.get();
|
||||
x = buffer.getShort();
|
||||
y = buffer.getShort();
|
||||
recipe = buffer.get();
|
||||
}
|
||||
}
|
||||
|
||||
public static class BreakPacket implements Packet{
|
||||
public int playerid;
|
||||
public short x, y;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(playerid);
|
||||
buffer.putShort(x);
|
||||
buffer.putShort(y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
playerid = buffer.getInt();
|
||||
x = buffer.getShort();
|
||||
y = buffer.getShort();
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntitySpawnPacket implements Packet{
|
||||
public SyncEntity entity;
|
||||
public EntityGroup<?> group;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer){
|
||||
buffer.put((byte)group.getID());
|
||||
buffer.putInt(entity.id);
|
||||
entity.writeSpawn(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
byte groupid = buffer.get();
|
||||
int id = buffer.getInt();
|
||||
group = Entities.getGroup(groupid);
|
||||
try {
|
||||
entity = (SyncEntity) ClassReflection.newInstance(group.getType());
|
||||
entity.id = id;
|
||||
entity.readSpawn(buffer);
|
||||
entity.setNet(entity.x, entity.y);
|
||||
}catch (ReflectionException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntityDeathPacket implements Packet{
|
||||
public byte group;
|
||||
public int id;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.put(group);
|
||||
buffer.putInt(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
group = buffer.get();
|
||||
id = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static class BlockDestroyPacket implements Packet{
|
||||
public int position;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
position = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static class BlockUpdatePacket implements Packet{
|
||||
public int health, position;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putShort((short)health);
|
||||
buffer.putInt(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
health = buffer.getShort();
|
||||
position = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChatPacket implements Packet{
|
||||
public String name;
|
||||
public String text;
|
||||
public int id;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
if(name != null) {
|
||||
buffer.putShort((short) name.getBytes().length);
|
||||
buffer.put(name.getBytes());
|
||||
}else{
|
||||
buffer.putShort((short)-1);
|
||||
}
|
||||
IOUtils.writeString(buffer, text);
|
||||
buffer.putInt(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
short nlength = buffer.getShort();
|
||||
if(nlength != -1) {
|
||||
byte[] n = new byte[nlength];
|
||||
buffer.get(n);
|
||||
name = new String(n);
|
||||
}else{
|
||||
name = null;
|
||||
}
|
||||
|
||||
text = IOUtils.readString(buffer);
|
||||
id = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static class KickPacket implements Packet, ImportantPacket{
|
||||
public KickReason reason;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.put((byte)reason.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
reason = KickReason.values()[buffer.get()];
|
||||
}
|
||||
}
|
||||
|
||||
public enum KickReason{
|
||||
kick, invalidPassword, clientOutdated, serverOutdated, banned, gameover(true), recentKick, nameInUse, idInUse, fastShoot;
|
||||
public final boolean quiet;
|
||||
@@ -442,178 +97,7 @@ public class Packets {
|
||||
}
|
||||
}
|
||||
|
||||
public static class UpgradePacket implements Packet{
|
||||
public byte upgradeid; //weapon ID only, currently
|
||||
public int playerid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.put(upgradeid);
|
||||
buffer.putInt(playerid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
upgradeid = buffer.get();
|
||||
playerid = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static class WeaponSwitchPacket implements Packet{
|
||||
public int playerid;
|
||||
public byte weapon;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(playerid);
|
||||
buffer.put(weapon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
playerid = buffer.getInt();
|
||||
weapon = buffer.get();
|
||||
}
|
||||
}
|
||||
|
||||
public static class BlockTapPacket implements Packet{
|
||||
public int position, player;
|
||||
//todo implement
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
position = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static class BlockConfigPacket implements Packet{
|
||||
public int position;
|
||||
public byte data;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(position);
|
||||
buffer.put(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
position = buffer.getInt();
|
||||
data = buffer.get();
|
||||
}
|
||||
}
|
||||
|
||||
public static class EntityRequestPacket implements Packet{
|
||||
public int id;
|
||||
public byte group;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(id);
|
||||
buffer.put(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
id = buffer.getInt();
|
||||
group = buffer.get();
|
||||
}
|
||||
}
|
||||
|
||||
public static class GameOverPacket implements Packet{
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) { }
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) { }
|
||||
}
|
||||
|
||||
public static class MapAckPacket implements Packet{
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) { }
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) { }
|
||||
}
|
||||
|
||||
public static class NetErrorPacket implements Packet{
|
||||
public String message;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
IOUtils.writeString(buffer, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
message = IOUtils.readString(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdministerRequestPacket implements Packet{
|
||||
public AdminAction action;
|
||||
public int id;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.put((byte)action.ordinal());
|
||||
buffer.putInt(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
action = AdminAction.values()[buffer.get()];
|
||||
id = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public enum AdminAction{
|
||||
kick, ban, trace
|
||||
}
|
||||
|
||||
public static class TracePacket implements Packet{
|
||||
public TraceInfo info;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(info.playerid);
|
||||
IOUtils.writeString(buffer, info.ip);
|
||||
buffer.put(info.modclient ? (byte)1 : 0);
|
||||
buffer.put(info.android ? (byte)1 : 0);
|
||||
|
||||
buffer.putInt(info.totalBlocksBroken);
|
||||
buffer.putInt(info.structureBlocksBroken);
|
||||
buffer.putInt(info.lastBlockBroken.id);
|
||||
|
||||
buffer.putInt(info.totalBlocksPlaced);
|
||||
buffer.putInt(info.lastBlockPlaced.id);
|
||||
buffer.put(Base64Coder.decode(info.uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
int id = buffer.getInt();
|
||||
String ip = IOUtils.readString(buffer);
|
||||
|
||||
info = new TraceInfo(ip);
|
||||
|
||||
info.playerid = id;
|
||||
info.modclient = buffer.get() == 1;
|
||||
info.android = buffer.get() == 1;
|
||||
info.totalBlocksBroken = buffer.getInt();
|
||||
info.structureBlocksBroken = buffer.getInt();
|
||||
info.lastBlockBroken = Block.getByID(buffer.getInt());
|
||||
info.totalBlocksPlaced = buffer.getInt();
|
||||
info.lastBlockPlaced = Block.getByID(buffer.getInt());
|
||||
byte[] uuid = new byte[8];
|
||||
buffer.get(uuid);
|
||||
|
||||
info.uuid = new String(Base64Coder.encode(uuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,36 +10,10 @@ public class Registrator {
|
||||
private static Class<?>[] classes = {
|
||||
StreamBegin.class,
|
||||
StreamChunk.class,
|
||||
WorldData.class,
|
||||
SyncPacket.class,
|
||||
PositionPacket.class,
|
||||
EntityShootPacket.class,
|
||||
PlacePacket.class,
|
||||
BreakPacket.class,
|
||||
StateSyncPacket.class,
|
||||
BlockSyncPacket.class,
|
||||
EntityDeathPacket.class,
|
||||
BlockUpdatePacket.class,
|
||||
BlockDestroyPacket.class,
|
||||
ConnectPacket.class,
|
||||
DisconnectPacket.class,
|
||||
ChatPacket.class,
|
||||
KickPacket.class,
|
||||
UpgradePacket.class,
|
||||
WeaponSwitchPacket.class,
|
||||
BlockTapPacket.class,
|
||||
BlockConfigPacket.class,
|
||||
EntityRequestPacket.class,
|
||||
ConnectConfirmPacket.class,
|
||||
GameOverPacket.class,
|
||||
MapAckPacket.class,
|
||||
EntitySpawnPacket.class,
|
||||
NetErrorPacket.class,
|
||||
AdministerRequestPacket.class,
|
||||
TracePacket.class,
|
||||
InvokePacket.class,
|
||||
BlockLogRequestPacket.class,
|
||||
RollbackRequestPacket.class
|
||||
WorldStream.class,
|
||||
ClientSnapshotPacket.class,
|
||||
SnapshotPacket.class,
|
||||
InvokePacket.class
|
||||
};
|
||||
private static ObjectIntMap<Class<?>> ids = new ObjectIntMap<>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user