Fixed some multiplayer crashes

This commit is contained in:
Anuken
2018-07-10 21:04:14 -04:00
parent bba418c79d
commit bce0101278
8 changed files with 13 additions and 15 deletions

View File

@ -250,7 +250,7 @@ public class NetClient extends Module {
}
@Remote(variants = Variant.one, priority = PacketPriority.low, unreliable = true)
public static void onSnapshot(byte[] chunk, int snapshotID, short chunkID, short totalLength, int base){
public static void onSnapshot(byte[] chunk, int snapshotID, short chunkID, int 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);
//skip snapshot IDs that have already been recieved OR snapshots that are too far in front

View File

@ -449,7 +449,7 @@ 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){
Call.onSnapshot(userid, bytes, snapshotID, (short)0, (short)bytes.length, base);
Call.onSnapshot(userid, bytes, snapshotID, (short)0, bytes.length, base);
}else{
int remaining = bytes.length;
int offset = 0;
@ -464,7 +464,7 @@ public class NetServer extends Module{
}else {
toSend = Arrays.copyOfRange(bytes, offset, Math.min(offset + maxSnapshotSize, bytes.length));
}
Call.onSnapshot(userid, toSend, snapshotID, (short)chunkid, (short)bytes.length, base);
Call.onSnapshot(userid, toSend, snapshotID, (short)chunkid, bytes.length, base);
remaining -= used;
offset += used;

View File

@ -473,7 +473,9 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
updateMech();
}
avoidOthers(8f);
if(isLocal) {
avoidOthers(8f);
}
if(!isShooting()) {
updateBuilding(this);

View File

@ -199,7 +199,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
}
public void avoidOthers(float avoidRange){
if(Net.client()) return;
EntityPhysics.getNearby(getGroup(), x, y, avoidRange*2f, t -> {
if(t == this || (t instanceof Unit && (((Unit) t).isDead() || (((Unit) t).isFlying() != isFlying()) || ((Unit) t).getCarrier() == this) || getCarrier() == t)) return;

View File

@ -41,6 +41,7 @@ public interface CarryTrait extends TeamTrait, SolidTrait, TargetTrait{
@Remote(called = Loc.both, targets = Loc.both, forward = true, in = In.entities)
static void setCarryOf(Player player, CarryTrait trait, CarriableTrait unit){
if(trait == null) return;
if(player != null){ //when a server recieves this called from a player, set the carrier to the player.
trait = player;
}

View File

@ -283,7 +283,9 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
return;
}
avoidOthers(8f);
if(!Net.client()){
avoidOthers(8f);
}
if(squad != null){
squad.update();

View File

@ -106,6 +106,7 @@ public class TypeIO {
public static void writeCarry(ByteBuffer buffer, CarryTrait unit){
if(unit == null){
buffer.put((byte)-1);
return;
}
buffer.put((byte)unit.getGroup().getID());
buffer.putInt(unit.getID());
@ -123,7 +124,7 @@ public class TypeIO {
@WriteClass(BaseUnit.class)
public static void writeBaseUnit(ByteBuffer buffer, BaseUnit unit){
buffer.put((byte)unit.getGroup().getID());
buffer.put((byte)unitGroups[unit.getTeam().ordinal()].getID());
buffer.putInt(unit.getID());
}

View File

@ -27,16 +27,9 @@ import static io.anuke.mindustry.Vars.headless;
public class GenericCrafter extends Block{
protected final int timerDump = timers++;
/**Can be null. If you use this, make sure to set hasItems to true!*/
//protected ItemStack inputItem;
/**Can be null. If you use this, make sure to set hasLiquids to true!*/
//protected Liquid inputLiquid;
/**Required.*/
protected Item output;
protected float craftTime = 80;
//protected float powerUse;
//protected float liquidUse;
protected Effect craftEffect = BlockFx.purify;
protected Effect updateEffect = Fx.none;
protected float updateEffectChance = 0.04f;