Many various network fixes
This commit is contained in:
@@ -315,7 +315,7 @@ public class NetServer extends Module{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!player.timer.get(Player.timerSync, serverSyncTime)) continue;
|
if(!player.timer.get(Player.timerSync, serverSyncTime) || !connection.hasConnected) continue;
|
||||||
|
|
||||||
//if the player hasn't acknowledged that it has recieved the packet, send the same thing again
|
//if the player hasn't acknowledged that it has recieved the packet, send the same thing again
|
||||||
if(connection.lastSentSnapshotID > connection.lastSnapshotID){
|
if(connection.lastSentSnapshotID > connection.lastSnapshotID){
|
||||||
@@ -454,6 +454,7 @@ public class NetServer extends Module{
|
|||||||
@Remote(targets = Loc.client)
|
@Remote(targets = Loc.client)
|
||||||
public static void connectConfirm(Player player){
|
public static void connectConfirm(Player player){
|
||||||
player.add();
|
player.add();
|
||||||
|
Net.getConnection(player.clientid).hasConnected = true;
|
||||||
Call.sendMessage("[accent]" + player.name + " has connected.");
|
Call.sendMessage("[accent]" + player.name + " has connected.");
|
||||||
Log.info("&y{0} has connected.", player.name);
|
Log.info("&y{0} has connected.", player.name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class ItemDrop extends SolidEntity implements SaveTrait, SyncTrait, DrawT
|
|||||||
drop.item = item;
|
drop.item = item;
|
||||||
drop.amount = amount;
|
drop.amount = amount;
|
||||||
drop.velocity.set(4f, 0f).rotate(angle);
|
drop.velocity.set(4f, 0f).rotate(angle);
|
||||||
drop.set(x, y);
|
drop.setNet(x, y);
|
||||||
drop.add();
|
drop.add();
|
||||||
|
|
||||||
return drop;
|
return drop;
|
||||||
@@ -162,6 +162,9 @@ public class ItemDrop extends SolidEntity implements SaveTrait, SyncTrait, DrawT
|
|||||||
}else{
|
}else{
|
||||||
updateVelocity(0.2f);
|
updateVelocity(0.2f);
|
||||||
updateTime();
|
updateTime();
|
||||||
|
if(time >= lifetime()){
|
||||||
|
CallEntity.onPickup(getID());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Tile tile = world.tileWorld(x, y);
|
Tile tile = world.tileWorld(x, y);
|
||||||
|
|||||||
@@ -125,9 +125,9 @@ public interface BuilderTrait {
|
|||||||
|
|
||||||
if (!(tile.block() instanceof BreakBlock)) { //check if haven't started placing
|
if (!(tile.block() instanceof BreakBlock)) { //check if haven't started placing
|
||||||
if(Build.validBreak(unit.getTeam(), current.x, current.y)){
|
if(Build.validBreak(unit.getTeam(), current.x, current.y)){
|
||||||
|
|
||||||
//if it's valid, place it
|
//if it's valid, place it
|
||||||
//FIXME a player instance is required here, but the the builder may not be a player
|
if(!current.requested && unit instanceof Player){
|
||||||
if(!current.requested){
|
|
||||||
CallBlocks.breakBlock((Player)unit, unit.getTeam(), current.x, current.y);
|
CallBlocks.breakBlock((Player)unit, unit.getTeam(), current.x, current.y);
|
||||||
current.requested = true;
|
current.requested = true;
|
||||||
}
|
}
|
||||||
@@ -154,10 +154,9 @@ public interface BuilderTrait {
|
|||||||
}else{
|
}else{
|
||||||
if (!(tile.block() instanceof BuildBlock)) { //check if haven't started placing
|
if (!(tile.block() instanceof BuildBlock)) { //check if haven't started placing
|
||||||
if(Build.validPlace(unit.getTeam(), current.x, current.y, current.recipe.result, current.rotation)){
|
if(Build.validPlace(unit.getTeam(), current.x, current.y, current.recipe.result, current.rotation)){
|
||||||
//if it's valid, place it
|
|
||||||
//FIXME a player instance is required here, but the the builder may not be a player
|
|
||||||
|
|
||||||
if(!current.requested){
|
//if it's valid, place it
|
||||||
|
if(!current.requested && unit instanceof Player){
|
||||||
CallBlocks.placeBlock((Player)unit, unit.getTeam(), current.x, current.y, current.recipe, current.rotation);
|
CallBlocks.placeBlock((Player)unit, unit.getTeam(), current.x, current.y, current.recipe, current.rotation);
|
||||||
current.requested = true;
|
current.requested = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ package io.anuke.mindustry.entities.units.types;
|
|||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.utils.ObjectSet;
|
import com.badlogic.gdx.utils.ObjectSet;
|
||||||
import com.badlogic.gdx.utils.Queue;
|
import com.badlogic.gdx.utils.Queue;
|
||||||
import io.anuke.annotations.Annotations.Remote;
|
|
||||||
import io.anuke.mindustry.content.Items;
|
import io.anuke.mindustry.content.Items;
|
||||||
import io.anuke.mindustry.content.blocks.Blocks;
|
import io.anuke.mindustry.content.blocks.Blocks;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.entities.Unit;
|
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.entities.Units;
|
||||||
import io.anuke.mindustry.entities.effect.ItemDrop;
|
import io.anuke.mindustry.entities.effect.ItemDrop;
|
||||||
import io.anuke.mindustry.entities.traits.BuilderTrait;
|
import io.anuke.mindustry.entities.traits.BuilderTrait;
|
||||||
@@ -17,7 +15,6 @@ import io.anuke.mindustry.entities.units.UnitState;
|
|||||||
import io.anuke.mindustry.game.EventType.BlockBuildEvent;
|
import io.anuke.mindustry.game.EventType.BlockBuildEvent;
|
||||||
import io.anuke.mindustry.gen.CallEntity;
|
import io.anuke.mindustry.gen.CallEntity;
|
||||||
import io.anuke.mindustry.graphics.Palette;
|
import io.anuke.mindustry.graphics.Palette;
|
||||||
import io.anuke.mindustry.net.In;
|
|
||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.mindustry.type.ItemStack;
|
import io.anuke.mindustry.type.ItemStack;
|
||||||
import io.anuke.mindustry.type.Recipe;
|
import io.anuke.mindustry.type.Recipe;
|
||||||
@@ -84,7 +81,7 @@ public class Drone extends FlyingUnit implements BuilderTrait {
|
|||||||
float dist = Math.min(entity.distanceTo(x, y) - placeDistance, 0);
|
float dist = Math.min(entity.distanceTo(x, y) - placeDistance, 0);
|
||||||
|
|
||||||
if(dist / type.maxVelocity < timeToBuild * 0.9f){
|
if(dist / type.maxVelocity < timeToBuild * 0.9f){
|
||||||
CallEntity.onDroneBeginBuild(this, entity.tile, entity.recipe);
|
//CallEntity.onDroneBeginBuild(this, entity.tile, entity.recipe);
|
||||||
target = entity;
|
target = entity;
|
||||||
setState(build);
|
setState(build);
|
||||||
}
|
}
|
||||||
@@ -207,24 +204,26 @@ public class Drone extends FlyingUnit implements BuilderTrait {
|
|||||||
public void write(DataOutput data) throws IOException {
|
public void write(DataOutput data) throws IOException {
|
||||||
super.write(data);
|
super.write(data);
|
||||||
data.writeInt(mineTile == null ? -1 : mineTile.packedPosition());
|
data.writeInt(mineTile == null ? -1 : mineTile.packedPosition());
|
||||||
|
data.writeInt(placeQueue.size == 0 ? -1 : world.tile(placeQueue.last().x, placeQueue.last().y).packedPosition());
|
||||||
|
data.writeByte(placeQueue.size == 0 ? -1 : placeQueue.last().recipe.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void read(DataInput data, long time) throws IOException {
|
public void read(DataInput data, long time) throws IOException {
|
||||||
super.read(data, time);
|
super.read(data, time);
|
||||||
int mined = data.readInt();
|
int mined = data.readInt();
|
||||||
|
int pp = data.readInt();
|
||||||
|
byte rid = data.readByte();
|
||||||
|
|
||||||
if(mined != -1){
|
if(mined != -1){
|
||||||
mineTile = world.tile(mined);
|
mineTile = world.tile(mined);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Remote(in = In.entities)
|
if(pp != -1){
|
||||||
public static void onDroneBeginBuild(Unit unit, Tile tile, Recipe recipe){
|
Tile tile = world.tile(pp);
|
||||||
if(unit == null) return;
|
placeQueue.clear();
|
||||||
|
placeQueue.addLast(new BuildRequest(tile.x, tile.y, tile.getRotation(), Recipe.getByID(rid)));
|
||||||
Drone drone = (Drone)unit;
|
}
|
||||||
|
|
||||||
drone.getPlaceQueue().addLast(new BuildRequest(tile.x, tile.y, tile.getRotation(), recipe));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final UnitState
|
public final UnitState
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public abstract class NetConnection {
|
|||||||
/**Timestamp of last recieved snapshot.*/
|
/**Timestamp of last recieved snapshot.*/
|
||||||
public long lastRecievedTime;
|
public long lastRecievedTime;
|
||||||
|
|
||||||
|
public boolean hasConnected = false;
|
||||||
|
|
||||||
public NetConnection(int id, String address){
|
public NetConnection(int id, String address){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.address = address;
|
this.address = address;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import java.io.StringWriter;
|
|||||||
import static io.anuke.mindustry.Vars.headless;
|
import static io.anuke.mindustry.Vars.headless;
|
||||||
|
|
||||||
public class KryoRegistrator {
|
public class KryoRegistrator {
|
||||||
public static boolean fakeLag = false;
|
public static boolean fakeLag = true;
|
||||||
public static final int fakeLagMax = 1000;
|
public static final int fakeLagMax = 1000;
|
||||||
public static final int fakeLagMin = 0;
|
public static final int fakeLagMin = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user