uCore update / Kick packet priority / Custom client lock / Net fixes

This commit is contained in:
Anuken 2018-07-03 19:48:29 -04:00
parent 359a392cca
commit 60deb9205b
17 changed files with 108 additions and 61 deletions

View File

@ -27,7 +27,7 @@ allprojects {
gdxVersion = '1.9.8'
roboVMVersion = '2.3.0'
aiVersion = '1.8.1'
uCoreVersion = '5f35012fef'
uCoreVersion = 'e7a37cff68'
getVersionString = {
String buildVersion = getBuildVersion()

View File

@ -76,6 +76,7 @@ text.server.kicked.recentKick=You have been kicked recently.\nWait before connec
text.server.kicked.nameInUse=There is someone with that name\nalready on this server.
text.server.kicked.nameEmpty=Your name must contain at least one character or number.
text.server.kicked.idInUse=You are already on this server! Connecting with two accounts is not permitted.
text.server.kicked.customClient=This server does not support custom builds. Download an official version.
text.server.connected={0} has joined.
text.server.disconnected={0} has disconnected.
text.nohost=Can't host server on a custom map!

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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{

View File

@ -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;
}
}

View File

@ -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; }

View File

@ -13,7 +13,6 @@ public class Registrator {
WorldStream.class,
ConnectPacket.class,
ClientSnapshotPacket.class,
SnapshotPacket.class,
InvokePacket.class
};
private static ObjectIntMap<Class<?>> ids = new ObjectIntMap<>();

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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");

View File

@ -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());

View File

@ -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;

View File

@ -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);

View File

@ -4,11 +4,11 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntMap;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.core.NetServer;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.game.Difficulty;
import io.anuke.mindustry.game.EventType.GameOverEvent;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.io.Map;
import io.anuke.mindustry.io.SaveIO;
import io.anuke.mindustry.io.Version;
@ -221,11 +221,7 @@ public class ServerControl extends Module {
if(playerGroup.size() > 0) {
info("&lyPlayers: {0}", playerGroup.size());
for (Player p : playerGroup.all()) {
if(Net.getConnection(p.clientid) == null){
NetServer.onDisconnect(p);
continue;
}
print(" &y{0} / Connection {1} / IP: {2}", p.name, p.clientid, Net.getConnection(p.clientid).address);
print(" &y{0} / Connection {1} / IP: {2}", p.name, p.con, p.con.address);
}
}else{
info("&lyNo players connected.");
@ -239,7 +235,7 @@ public class ServerControl extends Module {
return;
}
//netCommon.sendMessage("[GRAY][[Server]:[] " + arg[0]);
Call.sendMessage("[GRAY][[Server]:[] " + arg[0]);
info("&lyServer: &lb{0}", arg[0]);
});
@ -296,6 +292,24 @@ public class ServerControl extends Module {
}
});
handler.register("allow-custom-clients", "[on/off]", "Allow or disallow custom clients.", arg -> {
if(arg.length == 0){
info("Custom clients are currently &lc{0}.", netServer.admins.allowsCustomClients() ? "allowed" : "disallowed");
return;
}
String s = arg[0];
if(s.equalsIgnoreCase("on")){
netServer.admins.setCustomClients(true);
info("Custom clients enabled.");
}else if(s.equalsIgnoreCase("off")){
netServer.admins.setCustomClients(false);
info("Custom clients disabled.");
}else{
err("Incorrect command usage.");
}
});
handler.register("shuffle", "<normal/custom/both/off>", "Set map shuffling.", arg -> {
try{
@ -324,7 +338,7 @@ public class ServerControl extends Module {
}
if(target != null){
netServer.kick(target.clientid, KickReason.kick);
netServer.kick(target.con.id, KickReason.kick);
info("It is done.");
}else{
info("Nobody with that name could be found...");
@ -347,10 +361,10 @@ public class ServerControl extends Module {
}
if(target != null){
String ip = Net.getConnection(target.clientid).address;
String ip = target.con.address;
netServer.admins.banPlayerIP(ip);
netServer.admins.banPlayerID(target.uuid);
netServer.kick(target.clientid, KickReason.banned);
netServer.kick(target.con.id, KickReason.banned);
info("Banned player by IP and ID: {0} / {1}", ip, target.uuid);
}else{
info("Nobody with that name could be found.");
@ -391,10 +405,9 @@ public class ServerControl extends Module {
info("Banned player by IP: {0}.", arg[0]);
for(Player player : playerGroup.all()){
if(Net.getConnection(player.clientid) != null &&
Net.getConnection(player.clientid).address != null &&
Net.getConnection(player.clientid).address.equals(arg[0])){
netServer.kick(player.clientid, KickReason.banned);
if(player.con.address != null &&
player.con.address.equals(arg[0])){
netServer.kick(player.con.id, KickReason.banned);
break;
}
}
@ -409,7 +422,7 @@ public class ServerControl extends Module {
for(Player player : playerGroup.all()){
if(player.uuid.equals(arg[0])){
netServer.kick(player.clientid, KickReason.banned);
netServer.kick(player.con.id, KickReason.banned);
break;
}
}