This commit is contained in:
Anuken
2018-07-03 20:07:15 -04:00
32 changed files with 293 additions and 218 deletions

View File

@@ -108,8 +108,8 @@ public class Recipes implements ContentList{
new Recipe(distribution, StorageBlocks.vault, new ItemStack(Items.carbide, 500), new ItemStack(Items.thorium, 350));
//DRILLS, PRODUCERS
new Recipe(production, ProductionBlocks.tungstenDrill, new ItemStack(Items.tungsten, 30));
new Recipe(production, ProductionBlocks.carbideDrill, new ItemStack(Items.tungsten, 60), new ItemStack(Items.carbide, 60));
new Recipe(production, ProductionBlocks.tungstenDrill, new ItemStack(Items.tungsten, 25));
new Recipe(production, ProductionBlocks.carbideDrill, new ItemStack(Items.tungsten, 50), new ItemStack(Items.carbide, 60));
new Recipe(production, ProductionBlocks.laserdrill, new ItemStack(Items.tungsten, 90), new ItemStack(Items.carbide, 110), new ItemStack(Items.silicon, 70), new ItemStack(Items.titanium, 80));
new Recipe(production, ProductionBlocks.waterextractor, new ItemStack(Items.tungsten, 50), new ItemStack(Items.carbide, 50), new ItemStack(Items.lead, 40));

View File

@@ -18,7 +18,7 @@ public class ProductionBlocks extends BlockList implements ContentList {
public void load() {
tungstenDrill = new Drill("tungsten-drill") {{
tier = 2;
drillTime = 360;
drillTime = 340;
}};
carbideDrill = new Drill("carbide-drill") {{

View File

@@ -21,11 +21,12 @@ public class TurretBlocks extends BlockList implements ContentList {
ammoTypes = new AmmoType[]{AmmoTypes.bulletTungsten, AmmoTypes.bulletLead, AmmoTypes.bulletCarbide, AmmoTypes.bulletPyratite, AmmoTypes.bulletSilicon};
reload = 25f;
restitution = 0.03f;
range = 80f;
range = 90f;
shootCone = 15f;
ammoUseEffect = ShootFx.shellEjectSmall;
health = 80;
inaccuracy = 3f;
inaccuracy = 2f;
rotatespeed = 10f;
}};
/*
scatter = new BurstTurret("scatter") {{
@@ -52,10 +53,10 @@ public class TurretBlocks extends BlockList implements ContentList {
scorch = new LiquidTurret("scorch") {{
ammoTypes = new AmmoType[]{AmmoTypes.basicFlame};
recoil = 0f;
reload = 5f;
reload = 4f;
shootCone = 50f;
ammoUseEffect = ShootFx.shellEjectSmall;
health = 140;
health = 160;
drawer = (tile, entity) -> Draw.rect(entity.target != null ? name + "-shoot" : name, tile.drawx() + tr2.x, tile.drawy() + tr2.y, entity.rotation - 90);
}};

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);
@@ -301,7 +302,7 @@ public class NetClient extends Module {
length = snapshot.length;
netClient.lastSnapshotBase = Arrays.copyOf(snapshot, snapshot.length);
} else { //otherwise, last snapshot must not be null, decode it
if(NetServer.showSnapshotSize) Log.info("Base size: {0} Path size: {1}", netClient.lastSnapshotBase.length, snapshot.length);
if(NetServer.showSnapshotSize) Log.info("Base size: {0} Patch size: {1}", netClient.lastSnapshotBase.length, snapshot.length);
netClient.decoder.init(netClient.lastSnapshotBase, snapshot);
result = netClient.decoder.decode();
length = netClient.decoder.getDecodedLength();

View File

@@ -74,6 +74,7 @@ public class NetServer extends Module{
if(player != null){
onDisconnect(player);
}
connections.remove(id);
});
Net.handleServer(ConnectPacket.class, (id, packet) -> {
@@ -97,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) {
@@ -137,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;
@@ -322,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;
@@ -406,18 +412,25 @@ public class NetServer extends Module{
byte[] bytes = syncStream.toByteArray();
connection.lastSentRawSnapshot = bytes;
if(connection.currentBaseID == -1){
//assign to last sent snapshot so that there is only ever one unique snapshot with ID 0
if(connection.lastSentSnapshot != null){
bytes = connection.lastSentSnapshot;
}else{
connection.lastSentRawSnapshot = bytes;
connection.lastSentSnapshot = bytes;
}
if(showSnapshotSize) Log.info("Sent raw snapshot: {0} bytes.", bytes.length);
///Nothing to diff off of in this case, send the whole thing, but increment the counter
connection.lastSentSnapshot = bytes;
///Nothing to diff off of in this case, send the whole thing
sendSplitSnapshot(connection.id, bytes, 0, -1);
}else{
connection.lastSentRawSnapshot = bytes;
//send diff, otherwise
byte[] diff = ByteDeltaEncoder.toDiff(new ByteMatcherHash(connection.currentBaseSnapshot, bytes), encoder);
if(showSnapshotSize) Log.info("Shrank snapshot: {0} -> {1}, Base {2} ID {3}", bytes.length, diff.length, connection.currentBaseID, connection.lastSentSnapshotID);
sendSplitSnapshot(connection.id, diff, connection.lastSentSnapshotID + 1, connection.currentBaseID);
if(showSnapshotSize) Log.info("Shrank snapshot: {0} -> {1}, Base {2} ID {3} base length = {4}", bytes.length, diff.length, connection.currentBaseID, connection.currentBaseID + 1, connection.currentBaseSnapshot.length);
sendSplitSnapshot(connection.id, diff, connection.currentBaseID + 1, connection.currentBaseID);
connection.lastSentSnapshot = diff;
connection.lastSentSnapshotID = connection.currentBaseID + 1;
connection.lastSentBase = connection.currentBaseID;
@@ -432,7 +445,6 @@ public class NetServer extends Module{
/**Sends a raw byte[] snapshot to a client, splitting up into chunks when needed.*/
private static void sendSplitSnapshot(int userid, byte[] bytes, int snapshotID, int base){
if(bytes.length < maxSnapshotSize){
if(showSnapshotSize) Log.info("Raw send() snapshot call: {0} bytes, sID {1}", bytes.length, snapshotID);
Call.onSnapshot(userid, bytes, snapshotID, (short)0, (short)bytes.length, base);
}else{
int remaining = bytes.length;
@@ -461,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)
@@ -469,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;
}
@@ -478,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));
}
@@ -500,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

@@ -9,6 +9,7 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Disposable;
import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.content.blocks.StorageBlocks;
import io.anuke.mindustry.core.Platform;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.io.Map;
@@ -587,7 +588,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
for(Block block : Block.all()){
TextureRegion[] regions = block.getCompactIcon();
if((block.synthetic() && (Recipe.getByResult(block) == null || !control.database().isUnlocked(Recipe.getByResult(block)))) && !debug) continue;
if((block.synthetic() && (Recipe.getByResult(block) == null || !control.database().isUnlocked(Recipe.getByResult(block)))) && !debug && block != StorageBlocks.core) continue;
if(regions.length == 0 || regions[0] == Draw.region("jjfgj")) continue;

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);
@@ -250,6 +251,11 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
@Override
public void removed() {
dropCarryLocal();
TileEntity core = getClosestCore();
if(core != null && ((CoreEntity)core).currentUnit == this){
((CoreEntity)core).currentUnit = null;
}
}
@Override

View File

@@ -28,7 +28,6 @@ import io.anuke.ucore.entities.trait.TimeTrait;
import io.anuke.ucore.entities.trait.VelocityTrait;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Pooling;
import java.io.DataInput;
import java.io.DataOutput;
@@ -48,7 +47,7 @@ public class ItemDrop extends SolidEntity implements SaveTrait, SyncTrait, DrawT
private float sinktime;
public static ItemDrop create(Item item, int amount, float x, float y, float angle){
ItemDrop drop = Pooling.obtain(ItemDrop.class);
ItemDrop drop = new ItemDrop();
drop.item = item;
drop.amount = amount;
drop.velocity.set(4f, 0f).rotate(angle);
@@ -188,11 +187,6 @@ public class ItemDrop extends SolidEntity implements SaveTrait, SyncTrait, DrawT
}
}
@Override
public void removed() {
Pooling.free(this);
}
@Override
public void reset() {
time = 0f;

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,15 @@ public class Administration {
return Settings.getBool("antigrief");
}
public boolean allowsCustomClients(){
return Settings.getBool("allow-custom", !headless);
}
public void setCustomClients(boolean allowed){
Settings.putBool("allow-custom", allowed);
Settings.save();
}
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

@@ -91,6 +91,8 @@ public class BreakBlock extends Block {
Shaders.blockbuild.color = Palette.remove;
if(entity.previous == null) return;
for(TextureRegion region : entity.previous.getBlockIcon()){
Shaders.blockbuild.region = region;
Shaders.blockbuild.progress = (float)(1f-entity.progress); //progress reversed

View File

@@ -29,9 +29,9 @@ public class BurstTurret extends ItemTurret {
entity.recoil = recoil;
tr.trns(entity.rotation, size * tilesize / 2, Mathf.range(xRand));
useAmmo(tile);
bullet(tile, ammo.bullet, entity.rotation + Mathf.range(inaccuracy));
effects(tile);
useAmmo(tile);
});
}
}

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);
@@ -272,7 +272,7 @@ public class CoreBlock extends StorageBlock {
}
public class CoreEntity extends TileEntity{
Unit currentUnit;
public Unit currentUnit;
int droneID = -1;
boolean solid = true;
float warmup;