Disabled multiplayer for HTML5, net bugfixes
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="io.anuke.mindustry"
|
package="io.anuke.mindustry"
|
||||||
android:versionCode="56"
|
android:versionCode="57"
|
||||||
android:versionName="3.3b7.1" >
|
android:versionName="3.3b8" >
|
||||||
|
|
||||||
<uses-permission android:name="com.android.vending.BILLING" />
|
<uses-permission android:name="com.android.vending.BILLING" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class NetClient extends Module {
|
|||||||
IntSet requests = new IntSet();
|
IntSet requests = new IntSet();
|
||||||
IntSet recieved = new IntSet();
|
IntSet recieved = new IntSet();
|
||||||
float playerSyncTime = 2;
|
float playerSyncTime = 2;
|
||||||
float dataTimeout = 60*15; //13 seconds timeout
|
float dataTimeout = 60*18; //18 seconds timeout
|
||||||
|
|
||||||
public NetClient(){
|
public NetClient(){
|
||||||
|
|
||||||
@@ -61,7 +61,6 @@ public class NetClient extends Module {
|
|||||||
gotData = false;
|
gotData = false;
|
||||||
kicked = false;
|
kicked = false;
|
||||||
|
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
Vars.ui.loadfrag.hide();
|
Vars.ui.loadfrag.hide();
|
||||||
Vars.ui.loadfrag.show("$text.connecting.data");
|
Vars.ui.loadfrag.show("$text.connecting.data");
|
||||||
|
|
||||||
@@ -71,7 +70,6 @@ public class NetClient extends Module {
|
|||||||
c.name = Vars.player.name;
|
c.name = Vars.player.name;
|
||||||
c.android = Vars.android;
|
c.android = Vars.android;
|
||||||
Net.send(c, SendMode.tcp);
|
Net.send(c, SendMode.tcp);
|
||||||
});
|
|
||||||
|
|
||||||
Timers.runTask(dataTimeout, () -> {
|
Timers.runTask(dataTimeout, () -> {
|
||||||
if (!gotData) {
|
if (!gotData) {
|
||||||
@@ -85,7 +83,6 @@ public class NetClient extends Module {
|
|||||||
Net.handle(Disconnect.class, packet -> {
|
Net.handle(Disconnect.class, packet -> {
|
||||||
if (kicked) return;
|
if (kicked) return;
|
||||||
|
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
Timers.runFor(3f, Vars.ui.loadfrag::hide);
|
Timers.runFor(3f, Vars.ui.loadfrag::hide);
|
||||||
|
|
||||||
GameState.set(State.menu);
|
GameState.set(State.menu);
|
||||||
@@ -93,10 +90,8 @@ public class NetClient extends Module {
|
|||||||
Vars.ui.showError("$text.disconnect");
|
Vars.ui.showError("$text.disconnect");
|
||||||
connecting = false;
|
connecting = false;
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
Net.handle(WorldData.class, data -> {
|
Net.handle(WorldData.class, data -> {
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
UCore.log("Recieved world data: " + data.stream.available() + " bytes.");
|
UCore.log("Recieved world data: " + data.stream.available() + " bytes.");
|
||||||
NetworkIO.load(data.stream);
|
NetworkIO.load(data.stream);
|
||||||
Vars.player.set(Vars.control.core.worldx(), Vars.control.core.worldy() - Vars.tilesize * 2);
|
Vars.player.set(Vars.control.core.worldx(), Vars.control.core.worldy() - Vars.tilesize * 2);
|
||||||
@@ -110,7 +105,6 @@ public class NetClient extends Module {
|
|||||||
GameState.set(State.playing);
|
GameState.set(State.playing);
|
||||||
Net.setClientLoaded(true);
|
Net.setClientLoaded(true);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
Net.handle(SyncPacket.class, packet -> {
|
Net.handle(SyncPacket.class, packet -> {
|
||||||
if (!gotData) return;
|
if (!gotData) return;
|
||||||
@@ -146,23 +140,20 @@ public class NetClient extends Module {
|
|||||||
Player player = Vars.control.playerGroup.getByID(packet.playerid);
|
Player player = Vars.control.playerGroup.getByID(packet.playerid);
|
||||||
|
|
||||||
Weapon weapon = (Weapon) Upgrade.getByID(packet.weaponid);
|
Weapon weapon = (Weapon) Upgrade.getByID(packet.weaponid);
|
||||||
Gdx.app.postRunnable(() -> weapon.shoot(player, packet.x, packet.y, packet.rotation));
|
weapon.shoot(player, packet.x, packet.y, packet.rotation);
|
||||||
});
|
});
|
||||||
|
|
||||||
Net.handle(PlacePacket.class, packet -> {
|
Net.handle(PlacePacket.class, packet -> {
|
||||||
Gdx.app.postRunnable(() ->{
|
|
||||||
Recipe recipe = Recipes.getByResult(Block.getByID(packet.block));
|
Recipe recipe = Recipes.getByResult(Block.getByID(packet.block));
|
||||||
if (recipe != null) Vars.control.removeItems(recipe.requirements);
|
if (recipe != null) Vars.control.removeItems(recipe.requirements);
|
||||||
Vars.control.input.placeBlockInternal(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false);
|
Vars.control.input.placeBlockInternal(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
Net.handle(BreakPacket.class, packet -> {
|
Net.handle(BreakPacket.class, packet -> {
|
||||||
Gdx.app.postRunnable(() -> Vars.control.input.breakBlockInternal(packet.x, packet.y, false));
|
Vars.control.input.breakBlockInternal(packet.x, packet.y, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
Net.handle(StateSyncPacket.class, packet -> {
|
Net.handle(StateSyncPacket.class, packet -> {
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
|
|
||||||
System.arraycopy(packet.items, 0, Vars.control.items, 0, packet.items.length);
|
System.arraycopy(packet.items, 0, Vars.control.items, 0, packet.items.length);
|
||||||
|
|
||||||
@@ -170,12 +161,10 @@ public class NetClient extends Module {
|
|||||||
|
|
||||||
Timers.resetTime(packet.time + (float) (TimeUtils.timeSinceMillis(packet.timestamp) / 1000.0 * 60.0));
|
Timers.resetTime(packet.time + (float) (TimeUtils.timeSinceMillis(packet.timestamp) / 1000.0 * 60.0));
|
||||||
|
|
||||||
Gdx.app.postRunnable(Vars.ui.hudfrag::updateItems);
|
Vars.ui.hudfrag.updateItems();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Net.handle(EnemySpawnPacket.class, spawn -> {
|
Net.handle(EnemySpawnPacket.class, spawn -> {
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
//duplicates.
|
//duplicates.
|
||||||
if (Vars.control.enemyGroup.getByID(spawn.id) != null ||
|
if (Vars.control.enemyGroup.getByID(spawn.id) != null ||
|
||||||
recieved.contains(spawn.id)) return;
|
recieved.contains(spawn.id)) return;
|
||||||
@@ -192,30 +181,23 @@ public class NetClient extends Module {
|
|||||||
|
|
||||||
Effects.effect(Fx.spawn, enemy);
|
Effects.effect(Fx.spawn, enemy);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
Net.handle(EnemyDeathPacket.class, spawn -> {
|
Net.handle(EnemyDeathPacket.class, spawn -> {
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
Enemy enemy = Vars.control.enemyGroup.getByID(spawn.id);
|
Enemy enemy = Vars.control.enemyGroup.getByID(spawn.id);
|
||||||
if (enemy != null) enemy.onDeath();
|
if (enemy != null) enemy.onDeath();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
Net.handle(BulletPacket.class, packet -> {
|
Net.handle(BulletPacket.class, packet -> {
|
||||||
//TODO shoot effects for enemies, clientside as well as serverside
|
//TODO shoot effects for enemies, clientside as well as serverside
|
||||||
BulletType type = (BulletType) BaseBulletType.getByID(packet.type);
|
BulletType type = (BulletType) BaseBulletType.getByID(packet.type);
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
Entity owner = Vars.control.enemyGroup.getByID(packet.owner);
|
Entity owner = Vars.control.enemyGroup.getByID(packet.owner);
|
||||||
new Bullet(type, owner, packet.x, packet.y, packet.angle).add();
|
new Bullet(type, owner, packet.x, packet.y, packet.angle).add();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
Net.handle(BlockDestroyPacket.class, packet -> {
|
Net.handle(BlockDestroyPacket.class, packet -> {
|
||||||
Tile tile = Vars.world.tile(packet.position % Vars.world.width(), packet.position / Vars.world.width());
|
Tile tile = Vars.world.tile(packet.position % Vars.world.width(), packet.position / Vars.world.width());
|
||||||
if (tile != null && tile.entity != null) {
|
if (tile != null && tile.entity != null) {
|
||||||
Gdx.app.postRunnable(() ->{
|
|
||||||
if (tile.entity != null) tile.entity.onDeath(true);
|
if (tile.entity != null) tile.entity.onDeath(true);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -231,7 +213,6 @@ public class NetClient extends Module {
|
|||||||
|
|
||||||
DataInputStream stream = new DataInputStream(packet.stream);
|
DataInputStream stream = new DataInputStream(packet.stream);
|
||||||
|
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
float time = stream.readFloat();
|
float time = stream.readFloat();
|
||||||
@@ -261,7 +242,6 @@ public class NetClient extends Module {
|
|||||||
//do nothing else...
|
//do nothing else...
|
||||||
//TODO fix
|
//TODO fix
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -269,14 +249,13 @@ public class NetClient extends Module {
|
|||||||
Player player = Vars.control.playerGroup.getByID(packet.playerid);
|
Player player = Vars.control.playerGroup.getByID(packet.playerid);
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
Gdx.app.postRunnable(player::remove);
|
player.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
Mindustry.platforms.updateRPC();
|
Mindustry.platforms.updateRPC();
|
||||||
});
|
});
|
||||||
|
|
||||||
Net.handle(PlayerSpawnPacket.class, packet -> {
|
Net.handle(PlayerSpawnPacket.class, packet -> {
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
//duplicates.
|
//duplicates.
|
||||||
if (Vars.control.enemyGroup.getByID(packet.id) != null ||
|
if (Vars.control.enemyGroup.getByID(packet.id) != null ||
|
||||||
recieved.contains(packet.id)) return;
|
recieved.contains(packet.id)) return;
|
||||||
@@ -297,19 +276,17 @@ public class NetClient extends Module {
|
|||||||
|
|
||||||
Mindustry.platforms.updateRPC();
|
Mindustry.platforms.updateRPC();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
Net.handle(ChatPacket.class, packet -> Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(packet.text, Vars.netClient.colorizeName(packet.id, packet.name))));
|
Net.handle(ChatPacket.class, packet -> Vars.ui.chatfrag.addMessage(packet.text, Vars.netClient.colorizeName(packet.id, packet.name)));
|
||||||
|
|
||||||
Net.handle(KickPacket.class, packet -> {
|
Net.handle(KickPacket.class, packet -> {
|
||||||
kicked = true;
|
kicked = true;
|
||||||
Net.disconnect();
|
Net.disconnect();
|
||||||
GameState.set(State.menu);
|
GameState.set(State.menu);
|
||||||
Gdx.app.postRunnable(() -> Vars.ui.showError("$text.server.kicked." + packet.reason.name()));
|
Vars.ui.showError("$text.server.kicked." + packet.reason.name());
|
||||||
});
|
});
|
||||||
|
|
||||||
Net.handle(WeaponSwitchPacket.class, packet -> {
|
Net.handle(WeaponSwitchPacket.class, packet -> {
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
Player player = Vars.control.playerGroup.getByID(packet.playerid);
|
Player player = Vars.control.playerGroup.getByID(packet.playerid);
|
||||||
|
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
@@ -317,7 +294,6 @@ public class NetClient extends Module {
|
|||||||
player.weaponLeft = (Weapon) Upgrade.getByID(packet.left);
|
player.weaponLeft = (Weapon) Upgrade.getByID(packet.left);
|
||||||
player.weaponRight = (Weapon) Upgrade.getByID(packet.right);
|
player.weaponRight = (Weapon) Upgrade.getByID(packet.right);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
Net.handle(BlockTapPacket.class, packet -> {
|
Net.handle(BlockTapPacket.class, packet -> {
|
||||||
Tile tile = Vars.world.tile(packet.position);
|
Tile tile = Vars.world.tile(packet.position);
|
||||||
@@ -331,7 +307,7 @@ public class NetClient extends Module {
|
|||||||
|
|
||||||
Net.handle(GameOverPacket.class, packet -> {
|
Net.handle(GameOverPacket.class, packet -> {
|
||||||
kicked = true;
|
kicked = true;
|
||||||
Gdx.app.postRunnable(ui.restart::show);
|
ui.restart.show();
|
||||||
});
|
});
|
||||||
|
|
||||||
Net.handle(FriendlyFireChangePacket.class, packet -> Vars.control.setFriendlyFire(packet.enabled));
|
Net.handle(FriendlyFireChangePacket.class, packet -> Vars.control.setFriendlyFire(packet.enabled));
|
||||||
@@ -404,6 +380,7 @@ public class NetClient extends Module {
|
|||||||
packet.x = x;
|
packet.x = x;
|
||||||
packet.y = y;
|
packet.y = y;
|
||||||
packet.rotation = angle;
|
packet.rotation = angle;
|
||||||
|
packet.playerid = Vars.player.id;
|
||||||
Net.send(packet, SendMode.udp);
|
Net.send(packet, SendMode.udp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ public class NetServer extends Module{
|
|||||||
|
|
||||||
UCore.log("Sending world data to client (ID=" + id + ")");
|
UCore.log("Sending world data to client (ID=" + id + ")");
|
||||||
|
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.clientid = id;
|
player.clientid = id;
|
||||||
player.name = packet.name;
|
player.name = packet.name;
|
||||||
@@ -67,7 +66,7 @@ public class NetServer extends Module{
|
|||||||
data.stream = new ByteArrayInputStream(stream.toByteArray());
|
data.stream = new ByteArrayInputStream(stream.toByteArray());
|
||||||
|
|
||||||
Net.sendStream(id, data);
|
Net.sendStream(id, data);
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Net.handleServer(ConnectConfirmPacket.class, packet -> {
|
Net.handleServer(ConnectConfirmPacket.class, packet -> {
|
||||||
@@ -75,7 +74,7 @@ public class NetServer extends Module{
|
|||||||
|
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
Gdx.app.postRunnable(player::add);
|
player.add();
|
||||||
sendMessage("[accent]" + Bundles.format("text.server.connected", player.name));
|
sendMessage("[accent]" + Bundles.format("text.server.connected", player.name));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -88,7 +87,6 @@ public class NetServer extends Module{
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendMessage("[accent]" + Bundles.format("text.server.disconnected", player.name));
|
sendMessage("[accent]" + Bundles.format("text.server.disconnected", player.name));
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
player.remove();
|
player.remove();
|
||||||
|
|
||||||
DisconnectPacket dc = new DisconnectPacket();
|
DisconnectPacket dc = new DisconnectPacket();
|
||||||
@@ -96,7 +94,6 @@ public class NetServer extends Module{
|
|||||||
|
|
||||||
Net.send(dc, SendMode.tcp);
|
Net.send(dc, SendMode.tcp);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
Net.handleServer(PositionPacket.class, pos -> {
|
Net.handleServer(PositionPacket.class, pos -> {
|
||||||
Player player = connections.get(Net.getLastConnection());
|
Player player = connections.get(Net.getLastConnection());
|
||||||
@@ -114,7 +111,7 @@ public class NetServer extends Module{
|
|||||||
});
|
});
|
||||||
|
|
||||||
Net.handleServer(PlacePacket.class, packet -> {
|
Net.handleServer(PlacePacket.class, packet -> {
|
||||||
Gdx.app.postRunnable(() -> Vars.control.input.placeBlockInternal(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false));
|
Vars.control.input.placeBlockInternal(packet.x, packet.y, Block.getByID(packet.block), packet.rotation, true, false);
|
||||||
packet.playerid = connections.get(Net.getLastConnection()).id;
|
packet.playerid = connections.get(Net.getLastConnection()).id;
|
||||||
|
|
||||||
Recipe recipe = Recipes.getByResult(Block.getByID(packet.block));
|
Recipe recipe = Recipes.getByResult(Block.getByID(packet.block));
|
||||||
@@ -128,7 +125,7 @@ public class NetServer extends Module{
|
|||||||
});
|
});
|
||||||
|
|
||||||
Net.handleServer(BreakPacket.class, packet -> {
|
Net.handleServer(BreakPacket.class, packet -> {
|
||||||
Gdx.app.postRunnable(() -> Vars.control.input.breakBlockInternal(packet.x, packet.y, false));
|
Vars.control.input.breakBlockInternal(packet.x, packet.y, false);
|
||||||
packet.playerid = connections.get(Net.getLastConnection()).id;
|
packet.playerid = connections.get(Net.getLastConnection()).id;
|
||||||
|
|
||||||
Net.sendExcept(Net.getLastConnection(), packet, SendMode.tcp);
|
Net.sendExcept(Net.getLastConnection(), packet, SendMode.tcp);
|
||||||
@@ -145,7 +142,7 @@ public class NetServer extends Module{
|
|||||||
packet.name = player.name;
|
packet.name = player.name;
|
||||||
packet.id = player.id;
|
packet.id = player.id;
|
||||||
Net.sendExcept(player.clientid, packet, SendMode.tcp);
|
Net.sendExcept(player.clientid, packet, SendMode.tcp);
|
||||||
Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(packet.text, Vars.netClient.colorizeName(packet.id, packet.name)));
|
Vars.ui.chatfrag.addMessage(packet.text, Vars.netClient.colorizeName(packet.id, packet.name));
|
||||||
});
|
});
|
||||||
|
|
||||||
Net.handleServer(UpgradePacket.class, packet -> {
|
Net.handleServer(UpgradePacket.class, packet -> {
|
||||||
@@ -189,7 +186,6 @@ public class NetServer extends Module{
|
|||||||
Net.handleServer(EntityRequestPacket.class, packet -> {
|
Net.handleServer(EntityRequestPacket.class, packet -> {
|
||||||
int id = packet.id;
|
int id = packet.id;
|
||||||
int dest = Net.getLastConnection();
|
int dest = Net.getLastConnection();
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
if (Vars.control.playerGroup.getByID(id) != null) {
|
if (Vars.control.playerGroup.getByID(id) != null) {
|
||||||
Player player = Vars.control.playerGroup.getByID(id);
|
Player player = Vars.control.playerGroup.getByID(id);
|
||||||
PlayerSpawnPacket p = new PlayerSpawnPacket();
|
PlayerSpawnPacket p = new PlayerSpawnPacket();
|
||||||
@@ -218,7 +214,6 @@ public class NetServer extends Module{
|
|||||||
Gdx.app.error("Mindustry", "Entity request target not found!");
|
Gdx.app.error("Mindustry", "Entity request target not found!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(String message){
|
public void sendMessage(String message){
|
||||||
@@ -226,8 +221,6 @@ public class NetServer extends Module{
|
|||||||
packet.name = null;
|
packet.name = null;
|
||||||
packet.text = message;
|
packet.text = message;
|
||||||
Net.send(packet, SendMode.tcp);
|
Net.send(packet, SendMode.tcp);
|
||||||
|
|
||||||
Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(message, null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleFriendlyFireChange(boolean enabled){
|
public void handleFriendlyFireChange(boolean enabled){
|
||||||
|
|||||||
@@ -422,6 +422,7 @@ public class Renderer extends RendererModule{
|
|||||||
|
|
||||||
//TODO optimize!
|
//TODO optimize!
|
||||||
public void drawBar(Color color, float x, float y, float fraction){
|
public void drawBar(Color color, float x, float y, float fraction){
|
||||||
|
fraction = Mathf.clamp(fraction);
|
||||||
float len = 3;
|
float len = 3;
|
||||||
|
|
||||||
float w = (int) (len * 2 * fraction) + 0.5f;
|
float w = (int) (len * 2 * fraction) + 0.5f;
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public class UI extends SceneModule{
|
|||||||
font.getData().setScale(Vars.fontscale);
|
font.getData().setScale(Vars.fontscale);
|
||||||
font.getData().down += Unit.dp.scl(4f);
|
font.getData().down += Unit.dp.scl(4f);
|
||||||
font.getData().lineHeight -= Unit.dp.scl(2f);
|
font.getData().lineHeight -= Unit.dp.scl(2f);
|
||||||
}, skin.font(), skin.getFont("default-font-chat"));
|
}, skin.font(), skin.getFont("default-font-chat"), skin.getFont("korean"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class DamageArea{
|
|||||||
};
|
};
|
||||||
|
|
||||||
Entities.getNearby(Vars.control.enemyGroup, rect, cons);
|
Entities.getNearby(Vars.control.enemyGroup, rect, cons);
|
||||||
if(!Vars.control.isFriendlyFire()) Entities.getNearby(Vars.control.playerGroup, rect, cons);
|
if(Vars.control.isFriendlyFire()) Entities.getNearby(Vars.control.playerGroup, rect, cons);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void damageEntities(float x, float y, float radius, int damage){
|
public static void damageEntities(float x, float y, float radius, int damage){
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ public class Net{
|
|||||||
|
|
||||||
/**Get the client ping. Only valid after updatePing().*/
|
/**Get the client ping. Only valid after updatePing().*/
|
||||||
public static int getPing(){
|
public static int getPing(){
|
||||||
return clientProvider.getPing();
|
return server() ? 0 : clientProvider.getPing();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**Returns the last connection that sent a packet to this server.*/
|
/**Returns the last connection that sent a packet to this server.*/
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class Packets {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuffer buffer) {
|
public void write(ByteBuffer buffer) {
|
||||||
buffer.put((byte)name.length());
|
buffer.put((byte)name.getBytes().length);
|
||||||
buffer.put(name.getBytes());
|
buffer.put(name.getBytes());
|
||||||
buffer.put(android ? (byte)1 : 0);
|
buffer.put(android ? (byte)1 : 0);
|
||||||
}
|
}
|
||||||
@@ -275,7 +275,7 @@ public class Packets {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuffer buffer) {
|
public void write(ByteBuffer buffer) {
|
||||||
buffer.put((byte)name.length());
|
buffer.put((byte)name.getBytes().length);
|
||||||
buffer.put(name.getBytes());
|
buffer.put(name.getBytes());
|
||||||
buffer.put(weaponleft);
|
buffer.put(weaponleft);
|
||||||
buffer.put(weaponright);
|
buffer.put(weaponright);
|
||||||
@@ -352,12 +352,12 @@ public class Packets {
|
|||||||
@Override
|
@Override
|
||||||
public void write(ByteBuffer buffer) {
|
public void write(ByteBuffer buffer) {
|
||||||
if(name != null) {
|
if(name != null) {
|
||||||
buffer.putShort((short) name.length());
|
buffer.putShort((short) name.getBytes().length);
|
||||||
buffer.put(name.getBytes());
|
buffer.put(name.getBytes());
|
||||||
}else{
|
}else{
|
||||||
buffer.putShort((short)-1);
|
buffer.putShort((short)-1);
|
||||||
}
|
}
|
||||||
buffer.putShort((short)text.length());
|
buffer.putShort((short)text.getBytes().length);
|
||||||
buffer.put(text.getBytes());
|
buffer.put(text.getBytes());
|
||||||
buffer.putInt(id);
|
buffer.putInt(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,9 +28,10 @@ public class MenuFragment implements Fragment{
|
|||||||
add(new MenuButton("$text.play", group, ui.levels::show));
|
add(new MenuButton("$text.play", group, ui.levels::show));
|
||||||
row();
|
row();
|
||||||
|
|
||||||
|
if(!Vars.gwt) {
|
||||||
add(new MenuButton("$text.joingame", group, ui.join::show));
|
add(new MenuButton("$text.joingame", group, ui.join::show));
|
||||||
row();
|
row();
|
||||||
|
}
|
||||||
|
|
||||||
add(new MenuButton("$text.tutorial", group, ()-> control.playMap(world.maps().getMap("tutorial"))));
|
add(new MenuButton("$text.tutorial", group, ()-> control.playMap(world.maps().getMap("tutorial"))));
|
||||||
row();
|
row();
|
||||||
|
|||||||
@@ -62,40 +62,33 @@ public class KryoClient implements ClientProvider{
|
|||||||
c.id = connection.getID();
|
c.id = connection.getID();
|
||||||
if(connection.getRemoteAddressTCP() != null) c.addressTCP = connection.getRemoteAddressTCP().toString();
|
if(connection.getRemoteAddressTCP() != null) c.addressTCP = connection.getRemoteAddressTCP().toString();
|
||||||
|
|
||||||
try{
|
Gdx.app.postRunnable(() -> Net.handleClientReceived(c));
|
||||||
Net.handleClientReceived(c);
|
|
||||||
}catch (Exception e){
|
|
||||||
Gdx.app.postRunnable(() -> {throw new RuntimeException(e);});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnected (Connection connection) {
|
public void disconnected (Connection connection) {
|
||||||
Disconnect c = new Disconnect();
|
Disconnect c = new Disconnect();
|
||||||
|
|
||||||
try{
|
Gdx.app.postRunnable(() -> Net.handleClientReceived(c));
|
||||||
Net.handleClientReceived(c);
|
|
||||||
}catch (Exception e){
|
|
||||||
Gdx.app.postRunnable(() -> {throw new RuntimeException(e);});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received (Connection connection, Object object) {
|
public void received (Connection connection, Object object) {
|
||||||
if(object instanceof FrameworkMessage) return;
|
if(object instanceof FrameworkMessage) return;
|
||||||
|
|
||||||
|
Gdx.app.postRunnable(() -> {
|
||||||
try{
|
try{
|
||||||
Net.handleClientReceived(object);
|
Net.handleClientReceived(object);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
if(e instanceof KryoNetException && e.getMessage() != null && e.getMessage().toLowerCase().contains("incorrect")) {
|
if(e instanceof KryoNetException && e.getMessage() != null && e.getMessage().toLowerCase().contains("incorrect")) {
|
||||||
Gdx.app.postRunnable(() -> Vars.ui.showError("$text.server.mismatch"));
|
Vars.ui.showError("$text.server.mismatch");
|
||||||
Vars.netClient.disconnectQuietly();
|
Vars.netClient.disconnectQuietly();
|
||||||
}else{
|
}else{
|
||||||
Gdx.app.postRunnable(() -> {
|
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -66,12 +66,8 @@ public class KryoServer implements ServerProvider {
|
|||||||
c.id = kn.id;
|
c.id = kn.id;
|
||||||
c.addressTCP = connection.getRemoteAddressTCP().toString();
|
c.addressTCP = connection.getRemoteAddressTCP().toString();
|
||||||
|
|
||||||
try {
|
|
||||||
Net.handleServerReceived(c, kn.id);
|
|
||||||
connections.add(kn);
|
connections.add(kn);
|
||||||
}catch (Exception e){
|
Gdx.app.postRunnable(() -> Net.handleServerReceived(c, kn.id));
|
||||||
Gdx.app.postRunnable(() -> {throw new RuntimeException(e);});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -83,11 +79,7 @@ public class KryoServer implements ServerProvider {
|
|||||||
Disconnect c = new Disconnect();
|
Disconnect c = new Disconnect();
|
||||||
c.id = k.id;
|
c.id = k.id;
|
||||||
|
|
||||||
try{
|
Gdx.app.postRunnable(() -> Net.handleServerReceived(c, c.id));
|
||||||
Net.handleServerReceived(c, c.id);
|
|
||||||
}catch (Exception e){
|
|
||||||
Gdx.app.postRunnable(() -> {throw new RuntimeException(e);});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -95,11 +87,13 @@ public class KryoServer implements ServerProvider {
|
|||||||
KryoConnection k = getByKryoID(connection.getID());
|
KryoConnection k = getByKryoID(connection.getID());
|
||||||
if(object instanceof FrameworkMessage || k == null) return;
|
if(object instanceof FrameworkMessage || k == null) return;
|
||||||
|
|
||||||
|
Gdx.app.postRunnable(() -> {
|
||||||
try{
|
try{
|
||||||
Net.handleServerReceived(object, k.id);
|
Net.handleServerReceived(object, k.id);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user