1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-09-22 13:57:46 +03:00

Fixed chat packets not being received properly

This commit is contained in:
Anuken 2018-01-08 20:38:29 -05:00
parent 30d06b9b08
commit 36964be6ac
5 changed files with 24 additions and 12 deletions

View File

@ -244,7 +244,7 @@ public class NetClient extends Module {
Net.handle(Player.class, Player::add);
Net.handle(ChatPacket.class, packet -> Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(packet.name, packet.text)));
Net.handle(ChatPacket.class, packet -> Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(packet.text, packet.name)));
Net.handle(KickPacket.class, packet -> {
kicked = true;
@ -294,9 +294,7 @@ public class NetClient extends Module {
packet.name = Vars.player.name;
Net.send(packet, SendMode.tcp);
if(Net.server()){
Vars.ui.chatfrag.addMessage(packet.text, Vars.player.name);
}
Vars.ui.chatfrag.addMessage(packet.text, Vars.player.name);
}
public void handleShoot(Weapon weapon, float x, float y, float angle){

View File

@ -86,7 +86,7 @@ public class NetServer extends Module{
Net.sendTo(id, dp, SendMode.tcp);
Vars.ui.showInfo(Bundles.format("text.server.connected", packet.name));
sendMessage("[accent]"+Bundles.format("text.server.connected", packet.name));
});
});
@ -94,11 +94,11 @@ public class NetServer extends Module{
Player player = connections.get(packet.id);
if(player == null) {
Gdx.app.postRunnable(() -> Vars.ui.showInfo(Bundles.format("text.server.disconnected", "<???>")));
sendMessage("[accent]"+Bundles.format("text.server.disconnected", "<???>"));
return;
}
Gdx.app.postRunnable(() -> Vars.ui.showInfo(Bundles.format("text.server.disconnected", player.name)));
sendMessage("[accent]"+Bundles.format("text.server.disconnected", player.name));
player.remove();
@ -147,10 +147,14 @@ public class NetServer extends Module{
Net.handleServer(ChatPacket.class, packet -> {
Player player = connections.get(Net.getLastConnection());
if(player == null) return; //GHOSTS AAAA
if(player == null){
Gdx.app.error("Mindustry", "Could not find player for chat: " + Net.getLastConnection());
return; //GHOSTS AAAA
}
packet.name = player.name;
Net.send(packet, SendMode.tcp);
Net.sendExcept(player.clientid, packet, SendMode.tcp);
Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(packet.text, packet.name));
});
Net.handleServer(UpgradePacket.class, packet -> {
@ -172,6 +176,15 @@ public class NetServer extends Module{
});
}
public void sendMessage(String message){
ChatPacket packet = new ChatPacket();
packet.name = null;
packet.text = message;
Net.send(packet, SendMode.tcp);
Gdx.app.postRunnable(() -> Vars.ui.chatfrag.addMessage(message, null));
}
public void handleBullet(BulletType type, Entity owner, float x, float y, float angle, short damage){
BulletPacket packet = new BulletPacket();
packet.x = x;

View File

@ -22,6 +22,7 @@ public class Player extends DestructibleEntity implements Syncable{
public String name = "name";
public boolean isAndroid;
//TODO send these.
public transient Weapon weaponLeft = Weapon.blaster;
public transient Weapon weaponRight = Weapon.blaster;
public transient Mech mech = Mech.standard;

View File

@ -71,7 +71,7 @@ public class ChatFragment extends Table implements Fragment{
chatfield = new TextField("", new TextField.TextFieldStyle(skin.get(TextField.TextFieldStyle.class)));
chatfield.setTextFieldFilter((field, c) -> field.getText().length() < maxLength);
chatfield.getStyle().background = skin.getDrawable("chatfield");
chatfield.getStyle().background = null;
chatfield.getStyle().fontColor = Color.WHITE;
chatfield.getStyle().font = skin.getFont("default-font-chat");
chatfield.setStyle(chatfield.getStyle());
@ -118,7 +118,7 @@ public class ChatFragment extends Table implements Fragment{
batch.setColor(0, 0, 0, shadowColor.a*(fadetime-i));
}
batch.draw(skin.getRegion("white"), offsetx, theight-layout.height+1-4, textWidth + Unit.dp.scl(4f), layout.height+textspacing);
batch.draw(skin.getRegion("white"), offsetx, theight-layout.height-2, textWidth + Unit.dp.scl(4f), layout.height+textspacing);
batch.setColor(shadowColor);
font.getCache().draw(batch);

View File

@ -102,7 +102,7 @@ public class WeaponBlocks{
shootsound = "bigshot";
rotatespeed = 0.2f;
range = 120;
reload = 50f;
reload = 65f;
bullet = BulletType.flak;
shots = 3;
inaccuracy = 8f;