Massive amount of fixes and changes with multiplayer/annotations
This commit is contained in:
8
core/src/io/anuke/mindustry/net/In.java
Normal file
8
core/src/io/anuke/mindustry/net/In.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
/**Stores class nameas for remote method invocation for consistency's sake.*/
|
||||
public class In {
|
||||
public static final String normal = "Call";
|
||||
public static final String entities = "CallEntity";
|
||||
public static final String blocks = "CallBlocks";
|
||||
}
|
||||
@@ -10,7 +10,7 @@ public class Interpolator {
|
||||
//used for movement
|
||||
public Vector2 target = new Vector2();
|
||||
public Vector2 last = new Vector2();
|
||||
public float[] targets;
|
||||
public float[] targets = {};
|
||||
public float spacing = 1f;
|
||||
public float time;
|
||||
|
||||
|
||||
@@ -56,7 +56,6 @@ public class Net{
|
||||
for(int i = 0; i < packetQueue.size; i ++){
|
||||
Log.info("Processing {0} packet post-load.", ClassReflection.getSimpleName(packetQueue.get(i).getClass()));
|
||||
handleClientReceived(packetQueue.get(i));
|
||||
Pools.free(packetQueue.get(i));
|
||||
}
|
||||
}
|
||||
//clear inbound packet queue
|
||||
@@ -180,6 +179,7 @@ public class Net{
|
||||
}
|
||||
}else if(clientListeners.get(object.getClass()) != null ||
|
||||
listeners.get(object.getClass()) != null){
|
||||
|
||||
if(clientLoaded || object instanceof ImportantPacket){
|
||||
if(clientListeners.get(object.getClass()) != null) clientListeners.get(object.getClass()).accept(object);
|
||||
if(listeners.get(object.getClass()) != null) listeners.get(object.getClass()).accept(object);
|
||||
|
||||
@@ -1,5 +1,32 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.annotations.Annotations.Loc;
|
||||
import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.annotations.Annotations.Variant;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
|
||||
import static io.anuke.mindustry.Vars.playerGroup;
|
||||
|
||||
public class NetEvents {
|
||||
|
||||
@Remote(called = Loc.both, targets = Loc.both)
|
||||
public static void sendMessage(Player player, String message){
|
||||
if(Vars.ui != null){
|
||||
Vars.ui.chatfrag.addMessage(message, player == null ? null : colorizeName(player.id, player.name));
|
||||
}
|
||||
}
|
||||
|
||||
@Remote(called = Loc.both, variants = Variant.both)
|
||||
public static void sendMessage(String message){
|
||||
if(Vars.ui != null){
|
||||
Vars.ui.chatfrag.addMessage(message, null);
|
||||
}
|
||||
}
|
||||
|
||||
private static String colorizeName(int id, String name){
|
||||
Player player = playerGroup.getByID(id);
|
||||
if(name == null || player == null) return null;
|
||||
return "[#" + player.color.toString().toUpperCase() + "]" + name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@ package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.content.Weapons;
|
||||
import io.anuke.mindustry.content.blocks.Blocks;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.game.GameMode;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.mindustry.game.TeamInfo;
|
||||
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||
import io.anuke.mindustry.io.Map;
|
||||
import io.anuke.mindustry.io.MapMeta;
|
||||
import io.anuke.mindustry.io.Version;
|
||||
import io.anuke.mindustry.type.Upgrade;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.BlockPart;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@@ -37,16 +37,11 @@ public class NetworkIO {
|
||||
|
||||
stream.writeInt(state.wave); //wave
|
||||
stream.writeFloat(state.wavetime); //wave countdown
|
||||
stream.writeInt(state.enemies); //enemy amount
|
||||
|
||||
stream.writeBoolean(state.friendlyFire); //friendly fire state
|
||||
stream.writeInt(player.id); //player remap ID
|
||||
stream.writeBoolean(player.isAdmin);
|
||||
|
||||
stream.writeByte(player.upgrades.size);
|
||||
for(Upgrade u : player.upgrades){
|
||||
stream.writeByte(u.id);
|
||||
}
|
||||
stream.writeInt(player.id);
|
||||
player.write(stream);
|
||||
|
||||
//--MAP DATA--
|
||||
|
||||
@@ -80,6 +75,17 @@ public class NetworkIO {
|
||||
}
|
||||
}
|
||||
|
||||
//write team data
|
||||
stream.writeByte(state.teams.getTeams().size);
|
||||
for(TeamData data : state.teams.getTeams()){
|
||||
stream.writeByte(data.team.ordinal());
|
||||
stream.writeBoolean(data.ally);
|
||||
stream.writeShort(data.cores.size);
|
||||
for(Tile tile : data.cores){
|
||||
stream.writeInt(tile.packedPosition());
|
||||
}
|
||||
}
|
||||
|
||||
}catch (IOException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -105,29 +111,18 @@ public class NetworkIO {
|
||||
|
||||
int wave = stream.readInt();
|
||||
float wavetime = stream.readFloat();
|
||||
int enemies = stream.readInt();
|
||||
|
||||
boolean friendlyfire = stream.readBoolean();
|
||||
|
||||
state.enemies = enemies;
|
||||
state.wave = wave;
|
||||
state.wavetime = wavetime;
|
||||
state.mode = GameMode.values()[mode];
|
||||
state.friendlyFire = friendlyfire;
|
||||
|
||||
int pid = stream.readInt();
|
||||
boolean admin = stream.readBoolean();
|
||||
|
||||
byte weapons = stream.readByte();
|
||||
|
||||
for(int i = 0; i < weapons; i ++){
|
||||
player.upgrades.add(Upgrade.getByID(stream.readByte()));
|
||||
}
|
||||
|
||||
player.weapon = Weapons.blaster;
|
||||
|
||||
Entities.clear();
|
||||
player.id = pid;
|
||||
player.isAdmin = admin;
|
||||
int id = stream.readInt();
|
||||
player.read(stream, TimeUtils.millis());
|
||||
player.resetID(id);
|
||||
player.add();
|
||||
|
||||
world.beginMapLoad();
|
||||
@@ -174,7 +169,20 @@ public class NetworkIO {
|
||||
}
|
||||
}
|
||||
|
||||
player.dead = true;
|
||||
player.reset();
|
||||
state.teams = new TeamInfo();
|
||||
|
||||
byte teams = stream.readByte();
|
||||
for (int i = 0; i < teams; i++) {
|
||||
Team team = Team.values()[stream.readByte()];
|
||||
boolean ally = stream.readBoolean();
|
||||
short cores = stream.readShort();
|
||||
state.teams.add(team, ally);
|
||||
|
||||
for (int j = 0; j < cores; j++) {
|
||||
state.teams.get(team).cores.add(world.tile(stream.readInt()));
|
||||
}
|
||||
}
|
||||
|
||||
world.endMapLoad();
|
||||
|
||||
|
||||
@@ -3,14 +3,14 @@ package io.anuke.mindustry.net;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.gen.RemoteReadClient;
|
||||
import io.anuke.mindustry.io.Version;
|
||||
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
||||
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
||||
import io.anuke.ucore.io.ByteBufferInput;
|
||||
import io.anuke.ucore.io.ByteBufferOutput;
|
||||
import io.anuke.ucore.io.IOUtils;
|
||||
import io.anuke.ucore.io.ByteBufferInput;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**Class for storing all packets.*/
|
||||
@@ -66,19 +66,17 @@ public class Packets {
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
type = buffer.get();
|
||||
|
||||
if(Net.client()){
|
||||
RemoteReadClient.readPacket(buffer, type);
|
||||
}else{
|
||||
byte[] bytes = new byte[writeLength];
|
||||
buffer.get(bytes);
|
||||
writeBuffer = ByteBuffer.wrap(bytes);
|
||||
}
|
||||
writeLength = buffer.getShort();
|
||||
byte[] bytes = new byte[writeLength];
|
||||
buffer.get(bytes);
|
||||
writeBuffer = ByteBuffer.wrap(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.put(type);
|
||||
buffer.putShort((short)writeLength);
|
||||
|
||||
writeBuffer.position(0);
|
||||
for(int i = 0; i < writeLength; i ++){
|
||||
buffer.put(writeBuffer.get());
|
||||
@@ -109,7 +107,11 @@ public class Packets {
|
||||
buffer.putInt(lastSnapshot);
|
||||
buffer.putInt(player.id);
|
||||
buffer.putLong(TimeUtils.millis());
|
||||
player.write(out);
|
||||
try {
|
||||
player.write(out);
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,7 +122,11 @@ public class Packets {
|
||||
int id = buffer.getInt();
|
||||
long time = buffer.getLong();
|
||||
player = Vars.playerGroup.getByID(id);
|
||||
player.read(in, time);
|
||||
try {
|
||||
player.read(in, time);
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
13
core/src/io/anuke/mindustry/net/ValidateException.java
Normal file
13
core/src/io/anuke/mindustry/net/ValidateException.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
|
||||
/**Thrown when a client sends invalid information.*/
|
||||
public class ValidateException extends RuntimeException{
|
||||
public final Player player;
|
||||
|
||||
public ValidateException(Player player, String s) {
|
||||
super(s);
|
||||
this.player = player;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user