Implemented LAN refreshing and kick reasons

This commit is contained in:
Anuken
2018-01-03 16:50:13 -05:00
parent 494f18e892
commit 0063e32f6f
6 changed files with 31 additions and 15 deletions

View File

@@ -14,12 +14,14 @@ text.joingame=Join Game
text.quit=Quit text.quit=Quit
text.name=Name: text.name=Name:
text.players={0} players online text.players={0} players online
text.server.kicked=You have been kicked from the server! text.server.kicked.kick=You have been kicked from the server!
text.server.kicked.invalidPassword=Invalid password!
text.server.connected=A player has joined. text.server.connected=A player has joined.
text.server.disconnected={0} has disconnected. text.server.disconnected={0} has disconnected.
text.nohost=Can't host server on a custom map! text.nohost=Can't host server on a custom map!
text.hostserver=Host Server text.hostserver=Host Server
text.host=Host text.host=Host
text.hosts.refresh=Refresh
text.hosts.discovering=Discovering LAN games text.hosts.discovering=Discovering LAN games
text.hosts.none=[lightgray]No hosts found! text.hosts.none=[lightgray]No hosts found!
text.joingame.byip=Join by IP... text.joingame.byip=Join by IP...

View File

@@ -272,7 +272,7 @@ public class NetClient extends Module {
Net.handle(KickPacket.class, packet -> { Net.handle(KickPacket.class, packet -> {
kicked = true; kicked = true;
Net.disconnect(); Net.disconnect();
Gdx.app.postRunnable(() -> Vars.ui.showError("$text.server.kicked")); Gdx.app.postRunnable(() -> Vars.ui.showError("$text.server.kicked." + KickReason.values()[packet.reason].name()));
}); });
} }

View File

@@ -217,7 +217,7 @@ public class Renderer extends RendererModule{
Draw.tscl(0.25f/2); Draw.tscl(0.25f/2);
for(Player player : Vars.control.playerGroup.all()){ for(Player player : Vars.control.playerGroup.all()){
if(!player.isLocal){ if(!player.isLocal){
Draw.text(player.name, player.x, player.y - 8); Draw.text(player.name, player.x, player.y - 9);
} }
} }
Draw.tscl(Vars.fontscale); Draw.tscl(Vars.fontscale);

View File

@@ -115,6 +115,10 @@ public class Packets {
} }
public static class KickPacket{ public static class KickPacket{
public byte reason;
}
public enum KickReason{
kick, invalidPassword
} }
} }

View File

@@ -9,6 +9,7 @@ import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.style.Drawable; import io.anuke.ucore.scene.style.Drawable;
import io.anuke.ucore.scene.ui.Dialog; import io.anuke.ucore.scene.ui.Dialog;
import io.anuke.ucore.scene.ui.ScrollPane;
import io.anuke.ucore.scene.ui.TextButton; import io.anuke.ucore.scene.ui.TextButton;
import io.anuke.ucore.scene.ui.TextField.TextFieldFilter.DigitsOnlyFilter; import io.anuke.ucore.scene.ui.TextField.TextFieldFilter.DigitsOnlyFilter;
import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.ucore.scene.ui.layout.Table;
@@ -48,20 +49,24 @@ public class JoinDialog extends FloatingDialog {
setup(); setup();
shown(() -> { shown(this::refresh);
}
void refresh(){
hosts.clear(); hosts.clear();
hosts.background("button"); hosts.background("button");
hosts.label(() -> "[accent]" + Bundles.get("text.hosts.discovering") + new String(new char[(int)(Timers.time() / 10) % 4]).replace("\0", ".")).pad(10f); hosts.label(() -> "[accent]" + Bundles.get("text.hosts.discovering") + new String(new char[(int)(Timers.time() / 10) % 4]).replace("\0", ".")).pad(10f);
Net.discoverServers(list -> { Net.discoverServers(this::addHosts);
addHosts(list);
});
});
} }
void setup(){ void setup(){
hosts.background("button"); hosts.background("button");
content().clear();
ScrollPane pane = new ScrollPane(hosts, "clear");
pane.setFadeScrollBars(false);
pane.setScrollingDisabled(true, false);
content().clear();
content().table(t -> { content().table(t -> {
t.add("$text.name").padRight(10); t.add("$text.name").padRight(10);
t.addField(Settings.getString("name"), text -> { t.addField(Settings.getString("name"), text -> {
@@ -72,7 +77,7 @@ public class JoinDialog extends FloatingDialog {
}).grow().pad(8); }).grow().pad(8);
}).width(w).height(70f).pad(4); }).width(w).height(70f).pad(4);
content().row(); content().row();
content().add(hosts).width(w).pad(0); content().add(pane).width(w).pad(0);
content().row(); content().row();
content().addButton("$text.joingame.byip", "clear", join::show).width(w).height(80f); content().addButton("$text.joingame.byip", "clear", join::show).width(w).height(80f);
} }
@@ -81,7 +86,9 @@ public class JoinDialog extends FloatingDialog {
hosts.clear(); hosts.clear();
if(array.size == 0){ if(array.size == 0){
hosts.add("$text.hosts.none").pad(20f); hosts.add("$text.hosts.none").pad(10f);
hosts.add().growX();
hosts.addIButton("icon-loading", 16*2f, this::refresh).pad(-10f).padLeft(0).padTop(-6).size(70f, 74f);
}else { }else {
for (Address a : array) { for (Address a : array) {
TextButton button = hosts.addButton("[accent]"+a.name, "clear", () -> { TextButton button = hosts.addButton("[accent]"+a.name, "clear", () -> {

View File

@@ -10,6 +10,7 @@ import io.anuke.mindustry.net.Net.ServerProvider;
import io.anuke.mindustry.net.Packets.Connect; import io.anuke.mindustry.net.Packets.Connect;
import io.anuke.mindustry.net.Packets.Disconnect; import io.anuke.mindustry.net.Packets.Disconnect;
import io.anuke.mindustry.net.Packets.KickPacket; import io.anuke.mindustry.net.Packets.KickPacket;
import io.anuke.mindustry.net.Packets.KickReason;
import io.anuke.mindustry.net.Registrator; import io.anuke.mindustry.net.Registrator;
import io.anuke.mindustry.net.Streamable; import io.anuke.mindustry.net.Streamable;
import io.anuke.mindustry.net.Streamable.StreamBegin; import io.anuke.mindustry.net.Streamable.StreamBegin;
@@ -104,8 +105,10 @@ public class KryoServer implements ServerProvider {
@Override @Override
public void kick(int connection) { public void kick(int connection) {
Connection conn = getByID(connection); Connection conn = getByID(connection);
KickPacket p = new KickPacket();
p.reason = (byte)KickReason.kick.ordinal();
conn.sendTCP(new KickPacket()); conn.sendTCP(p);
Timers.runTask(1f, () -> { Timers.runTask(1f, () -> {
if(conn.isConnected()){ if(conn.isConnected()){
conn.close(); conn.close();