uCore update / Kick packet priority / Custom client lock / Net fixes
This commit is contained in:
@@ -12,6 +12,7 @@ import io.anuke.mindustry.world.blocks.Rock;
|
||||
import io.anuke.mindustry.world.blocks.StaticBlock;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
|
||||
import static io.anuke.mindustry.Vars.headless;
|
||||
import static io.anuke.mindustry.Vars.world;
|
||||
|
||||
public class Administration {
|
||||
@@ -41,6 +42,14 @@ public class Administration {
|
||||
return Settings.getBool("antigrief");
|
||||
}
|
||||
|
||||
public boolean allowsCustomClients(){
|
||||
return Settings.getBool("kick-custom", headless);
|
||||
}
|
||||
|
||||
public void setCustomClients(boolean allowed){
|
||||
Settings.getBool("kick-custom", allowed);
|
||||
}
|
||||
|
||||
public boolean isValidateReplace(){
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@ import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import io.anuke.mindustry.core.Platform;
|
||||
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
||||
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
||||
import io.anuke.mindustry.net.Packets.StreamBegin;
|
||||
import io.anuke.mindustry.net.Packets.StreamChunk;
|
||||
import io.anuke.mindustry.net.Streamable.StreamBuilder;
|
||||
@@ -183,13 +181,13 @@ public class Net{
|
||||
}else if(clientListeners.get(object.getClass()) != null ||
|
||||
listeners.get(object.getClass()) != null){
|
||||
|
||||
if(clientLoaded || object instanceof ImportantPacket){
|
||||
if(clientLoaded || ((object instanceof Packet) && ((Packet) object).isImportant())){
|
||||
if(clientListeners.get(object.getClass()) != null) clientListeners.get(object.getClass()).accept(object);
|
||||
if(listeners.get(object.getClass()) != null) listeners.get(object.getClass()).accept(object);
|
||||
synchronized (packetPoolLock) {
|
||||
Pooling.free(object);
|
||||
}
|
||||
}else if(!(object instanceof UnimportantPacket)){
|
||||
}else if(!((object instanceof Packet) && ((Packet) object).isUnimportant())){
|
||||
packetQueue.add(object);
|
||||
Log.info("Queuing packet {0}.", ClassReflection.getSimpleName(object.getClass()));
|
||||
}else{
|
||||
|
||||
@@ -5,11 +5,16 @@ import com.badlogic.gdx.utils.Pool.Poolable;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public interface Packet extends Poolable{
|
||||
void read(ByteBuffer buffer);
|
||||
void write(ByteBuffer buffer);
|
||||
default void read(ByteBuffer buffer){}
|
||||
default void write(ByteBuffer buffer){}
|
||||
|
||||
default void reset() {}
|
||||
|
||||
interface ImportantPacket{}
|
||||
interface UnimportantPacket{}
|
||||
default boolean isImportant(){
|
||||
return false;
|
||||
}
|
||||
|
||||
default boolean isUnimportant(){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
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.Tile;
|
||||
import io.anuke.ucore.io.IOUtils;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
@@ -19,13 +17,23 @@ import static io.anuke.mindustry.Vars.world;
|
||||
/**Class for storing all packets.*/
|
||||
public class Packets {
|
||||
|
||||
public static class Connect implements ImportantPacket{
|
||||
public static class Connect implements Packet{
|
||||
public int id;
|
||||
public String addressTCP;
|
||||
|
||||
@Override
|
||||
public boolean isImportant() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Disconnect implements ImportantPacket{
|
||||
public static class Disconnect implements Packet{
|
||||
public int id;
|
||||
|
||||
@Override
|
||||
public boolean isImportant() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class WorldStream extends Streamable{
|
||||
@@ -62,7 +70,7 @@ public class Packets {
|
||||
}
|
||||
|
||||
public static class InvokePacket implements Packet{
|
||||
public byte type;
|
||||
public byte type, priority;
|
||||
|
||||
public ByteBuffer writeBuffer;
|
||||
public int writeLength;
|
||||
@@ -70,6 +78,7 @@ public class Packets {
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
type = buffer.get();
|
||||
priority = buffer.get();
|
||||
writeLength = buffer.getShort();
|
||||
byte[] bytes = new byte[writeLength];
|
||||
buffer.get(bytes);
|
||||
@@ -79,6 +88,7 @@ public class Packets {
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.put(type);
|
||||
buffer.put(priority);
|
||||
buffer.putShort((short)writeLength);
|
||||
|
||||
writeBuffer.position(0);
|
||||
@@ -86,17 +96,20 @@ public class Packets {
|
||||
buffer.put(writeBuffer.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SnapshotPacket implements Packet, UnimportantPacket{
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
|
||||
public void reset() {
|
||||
priority = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
public boolean isImportant() {
|
||||
return priority == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnimportant() {
|
||||
return priority == 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +168,7 @@ public class Packets {
|
||||
}
|
||||
|
||||
public enum KickReason{
|
||||
kick, invalidPassword, clientOutdated, serverOutdated, banned, gameover(true), recentKick, nameInUse, idInUse, fastShoot, nameEmpty;
|
||||
kick, invalidPassword, clientOutdated, serverOutdated, banned, gameover(true), recentKick, nameInUse, idInUse, fastShoot, nameEmpty, customClient;
|
||||
public final boolean quiet;
|
||||
|
||||
KickReason(){ quiet = false; }
|
||||
|
||||
@@ -13,7 +13,6 @@ public class Registrator {
|
||||
WorldStream.class,
|
||||
ConnectPacket.class,
|
||||
ClientSnapshotPacket.class,
|
||||
SnapshotPacket.class,
|
||||
InvokePacket.class
|
||||
};
|
||||
private static ObjectIntMap<Class<?>> ids = new ObjectIntMap<>();
|
||||
|
||||
@@ -2,14 +2,13 @@ package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import com.badlogic.gdx.utils.reflect.ReflectionException;
|
||||
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
||||
import io.anuke.mindustry.net.Packets.StreamBegin;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Streamable implements ImportantPacket{
|
||||
public class Streamable implements Packet{
|
||||
public transient ByteArrayInputStream stream;
|
||||
|
||||
public static class StreamBuilder{
|
||||
@@ -47,4 +46,9 @@ public class Streamable implements ImportantPacket{
|
||||
return stream.size() >= total;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isImportant() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user