Massive amount of refactoring for local multiplayer, annotations
This commit is contained in:
@@ -172,10 +172,10 @@ public class Invoke {
|
||||
|
||||
/**Marks a method as invokable remotely with {@link Invoke#on(Class, String, Object...)}*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Remote{}
|
||||
public @interface Remote{}
|
||||
|
||||
/**Marks a method to be locally invoked as well as remotely invoked.*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Local{}
|
||||
public @interface Local{}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import io.anuke.mindustry.net.Invoke.Local;
|
||||
import io.anuke.mindustry.net.Invoke.Remote;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
@@ -63,20 +64,21 @@ public class NetEvents {
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleWeaponSwitch(){
|
||||
public static void handleWeaponSwitch(Player player){
|
||||
WeaponSwitchPacket packet = Pools.obtain(WeaponSwitchPacket.class);
|
||||
packet.weapon = Vars.player.weapon.id;
|
||||
packet.playerid = Vars.player.id;
|
||||
packet.weapon = player.weapon.id;
|
||||
packet.playerid = player.id;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleUpgrade(Weapon weapon){
|
||||
public static void handleUpgrade(Player player, Upgrade weapon){
|
||||
UpgradePacket packet = Pools.obtain(UpgradePacket.class);
|
||||
packet.id = weapon.id;
|
||||
packet.upgradeid = weapon.id;
|
||||
packet.playerid = player.id;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleSendMessage(String message){
|
||||
public static void handleSendMessage(Player player, String message){
|
||||
ChatPacket packet = Pools.obtain(ChatPacket.class);
|
||||
packet.text = message;
|
||||
packet.name = player.name;
|
||||
@@ -99,12 +101,12 @@ public class NetEvents {
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
public static void handlePlace(int x, int y, Block block, int rotation){
|
||||
public static void handlePlace(Player player, int x, int y, Block block, int rotation){
|
||||
PlacePacket packet = Pools.obtain(PlacePacket.class);
|
||||
packet.x = (short)x;
|
||||
packet.y = (short)y;
|
||||
packet.rotation = (byte)rotation;
|
||||
packet.playerid = Vars.player.id;
|
||||
packet.playerid = player.id;
|
||||
packet.block = block.id;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
@@ -85,6 +85,8 @@ public class NetworkIO {
|
||||
/**Return whether a custom map is expected, and thus whether the client should wait for additional data.*/
|
||||
public static void loadWorld(InputStream is){
|
||||
|
||||
Player player = players[0];
|
||||
|
||||
//TODO !! use map name as the network map in Maps, so getMap() isn't null.
|
||||
|
||||
try(DataInputStream stream = new DataInputStream(is)){
|
||||
|
||||
@@ -86,16 +86,16 @@ public class Packets {
|
||||
public static class ConnectPacket implements Packet{
|
||||
public int version;
|
||||
public int players;
|
||||
public String[] names;
|
||||
public boolean android;
|
||||
public int[] colors;
|
||||
public String name;
|
||||
public boolean mobile;
|
||||
public int color;
|
||||
public byte[] uuid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(Version.build);
|
||||
IOUtils.writeString(buffer, name);
|
||||
buffer.put(android ? (byte)1 : 0);
|
||||
buffer.put(mobile ? (byte)1 : 0);
|
||||
buffer.putInt(color);
|
||||
buffer.put(uuid);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class Packets {
|
||||
public void read(ByteBuffer buffer) {
|
||||
version = buffer.getInt();
|
||||
name = IOUtils.readString(buffer);
|
||||
android = buffer.get() == 1;
|
||||
mobile = buffer.get() == 1;
|
||||
color = buffer.getInt();
|
||||
uuid = new byte[8];
|
||||
buffer.get(uuid);
|
||||
@@ -392,16 +392,19 @@ public class Packets {
|
||||
}
|
||||
|
||||
public static class UpgradePacket implements Packet{
|
||||
public byte id; //weapon ID only, currently
|
||||
public byte upgradeid; //weapon ID only, currently
|
||||
public int playerid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.put(id);
|
||||
buffer.put(upgradeid);
|
||||
buffer.putInt(playerid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
id = buffer.get();
|
||||
upgradeid = buffer.get();
|
||||
playerid = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user