uCore update / Kick packet priority / Custom client lock / Net fixes
This commit is contained in:
@@ -3,6 +3,7 @@ package io.anuke.mindustry.core;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.utils.Base64Coder;
|
||||
import com.badlogic.gdx.utils.IntSet;
|
||||
import io.anuke.annotations.Annotations.PacketPriority;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.annotations.Annotations.Variant;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
@@ -222,7 +223,7 @@ public class NetClient extends Module {
|
||||
}
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.one)
|
||||
@Remote(variants = Variant.one, priority = PacketPriority.high)
|
||||
public static void onKick(KickReason reason){
|
||||
netClient.disconnectQuietly();
|
||||
state.set(State.menu);
|
||||
@@ -247,7 +248,7 @@ public class NetClient extends Module {
|
||||
playerGroup.removeByID(playerid);
|
||||
}
|
||||
|
||||
@Remote(variants = Variant.one, unreliable = true)
|
||||
@Remote(variants = Variant.one, priority = PacketPriority.low, unreliable = true)
|
||||
public static void onSnapshot(byte[] chunk, int snapshotID, short chunkID, short totalLength, int base){
|
||||
if(NetServer.showSnapshotSize) Log.info("Recieved snapshot: len {0} ID {1} chunkID {2} totalLength {3} base {4} client-base {5}", chunk.length, snapshotID, chunkID, totalLength, base, netClient.lastSnapshotBaseID);
|
||||
|
||||
|
||||
@@ -98,6 +98,11 @@ public class NetServer extends Module{
|
||||
return;
|
||||
}
|
||||
|
||||
if(packet.version == -1 && Version.build != -1 && admins.allowsCustomClients()){
|
||||
kick(id, KickReason.customClient);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean preventDuplicates = headless;
|
||||
|
||||
if(preventDuplicates) {
|
||||
@@ -138,7 +143,7 @@ public class NetServer extends Module{
|
||||
|
||||
Player player = new Player();
|
||||
player.isAdmin = admins.isAdmin(uuid, packet.usid);
|
||||
player.clientid = id;
|
||||
player.con = Net.getConnection(id);
|
||||
player.usid = packet.usid;
|
||||
player.name = packet.name;
|
||||
player.uuid = uuid;
|
||||
@@ -323,9 +328,9 @@ public class NetServer extends Module{
|
||||
|
||||
//iterate through each player
|
||||
for (Player player : connections.values()) {
|
||||
NetConnection connection = Net.getConnection(player.clientid);
|
||||
NetConnection connection = player.con;
|
||||
|
||||
if(connection == null || !connection.isConnected()){
|
||||
if(!connection.isConnected()){
|
||||
//player disconnected, ignore them
|
||||
onDisconnect(player);
|
||||
return;
|
||||
@@ -468,7 +473,7 @@ public class NetServer extends Module{
|
||||
Call.sendMessage("[accent]" + player.name + " has disconnected.");
|
||||
Call.onPlayerDisconnect(player.id);
|
||||
player.remove();
|
||||
netServer.connections.remove(player.clientid);
|
||||
netServer.connections.remove(player.con.id);
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.client, called = Loc.server)
|
||||
@@ -476,7 +481,7 @@ public class NetServer extends Module{
|
||||
|
||||
if(!player.isAdmin){
|
||||
Log.err("ACCESS DENIED: Player {0} / {1} attempted to perform admin action without proper security access.",
|
||||
player.name, Net.getConnection(player.clientid).address);
|
||||
player.name, player.con.address);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -485,18 +490,19 @@ public class NetServer extends Module{
|
||||
return;
|
||||
}
|
||||
|
||||
String ip = Net.getConnection(other.clientid).address;
|
||||
String ip = player.con.address;
|
||||
|
||||
if(action == AdminAction.ban){
|
||||
netServer.admins.banPlayerIP(ip);
|
||||
netServer.kick(other.clientid, KickReason.banned);
|
||||
netServer.kick(other.con.id, KickReason.banned);
|
||||
Log.info("&lc{0} has banned {1}.", player.name, other.name);
|
||||
}else if(action == AdminAction.kick){
|
||||
netServer.kick(other.clientid, KickReason.kick);
|
||||
netServer.kick(other.con.id, KickReason.kick);
|
||||
Log.info("&lc{0} has kicked {1}.", player.name, other.name);
|
||||
}else if(action == AdminAction.trace){
|
||||
if(player.clientid != -1) {
|
||||
Call.onTraceInfo(player.clientid, netServer.admins.getTraceByID(other.uuid));
|
||||
//TODO
|
||||
if(player.con != null) {
|
||||
Call.onTraceInfo(player.con.id, netServer.admins.getTraceByID(other.uuid));
|
||||
}else{
|
||||
NetClient.onTraceInfo(netServer.admins.getTraceByID(other.uuid));
|
||||
}
|
||||
@@ -507,7 +513,7 @@ public class NetServer extends Module{
|
||||
@Remote(targets = Loc.client)
|
||||
public static void connectConfirm(Player player){
|
||||
player.add();
|
||||
Net.getConnection(player.clientid).hasConnected = true;
|
||||
player.con.hasConnected = true;
|
||||
Call.sendMessage("[accent]" + player.name + " has connected.");
|
||||
Log.info("&y{0} has connected.", player.name);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.graphics.Trail;
|
||||
import io.anuke.mindustry.net.In;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetConnection;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@@ -58,7 +59,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
||||
public Color color = new Color();
|
||||
public Mech mech;
|
||||
|
||||
public int clientid = -1;
|
||||
public NetConnection con;
|
||||
public int playerIndex = 0;
|
||||
public boolean isLocal = false;
|
||||
public Timer timer = new Timer(4);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.net.Administration.PlayerInfo;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetConnection;
|
||||
import io.anuke.ucore.scene.ui.ScrollPane;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
@@ -46,9 +44,8 @@ public class AdminsDialog extends FloatingDialog {
|
||||
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> {
|
||||
netServer.admins.unAdminPlayer(info.id);
|
||||
for(Player player : playerGroup.all()){
|
||||
NetConnection c = Net.getConnection(player.clientid);
|
||||
if(c != null){
|
||||
//CallClient.adminSet(player, false);
|
||||
if(player.con != null){
|
||||
player.isAdmin = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public class BlocksFragment extends Fragment{
|
||||
|
||||
//add actual recipes
|
||||
for (Recipe r : recipes) {
|
||||
if(r.debugOnly && !debug) continue;
|
||||
if((r.debugOnly && !debug) || (r.desktopOnly && mobile)) continue;
|
||||
|
||||
ImageButton image = new ImageButton(new TextureRegion(), "select");
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ public class DebugFragment extends Fragment {
|
||||
result.append(player.id);
|
||||
result.append("\n");
|
||||
result.append(" cid: ");
|
||||
result.append(player.clientid);
|
||||
result.append(player.con.id);
|
||||
result.append("\n");
|
||||
result.append(" dead: ");
|
||||
result.append(player.isDead());
|
||||
|
||||
@@ -87,7 +87,7 @@ public class PlayerListFragment extends Fragment{
|
||||
float h = 74f;
|
||||
|
||||
for(Player player : playerGroup.all()){
|
||||
NetConnection connection = gwt ? null : Net.getConnection(player.clientid);
|
||||
NetConnection connection = gwt ? null : player.con;
|
||||
|
||||
if(connection == null && Net.server() && !player.isLocal) continue;
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ public class CoreBlock extends StorageBlock {
|
||||
rect.setSize(supplyRadius*2).setCenter(tile.drawx(), tile.drawy());
|
||||
|
||||
Units.getNearby(tile.getTeam(), rect, unit -> {
|
||||
if(unit.isDead() || unit.distanceTo(tile.drawx(), tile.drawy()) > supplyRadius) return;
|
||||
if(unit.isDead() || unit.distanceTo(tile.drawx(), tile.drawy()) > supplyRadius || unit.getGroup() == null) return;
|
||||
|
||||
for(int i = 0; i < tile.entity.items.items.length; i ++){
|
||||
Item item = Item.getByID(i);
|
||||
|
||||
Reference in New Issue
Block a user