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.name=Name:
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.disconnected={0} has disconnected.
text.nohost=Can't host server on a custom map!
text.hostserver=Host Server
text.host=Host
text.hosts.refresh=Refresh
text.hosts.discovering=Discovering LAN games
text.hosts.none=[lightgray]No hosts found!
text.joingame.byip=Join by IP...

View file

@ -272,7 +272,7 @@ public class NetClient extends Module {
Net.handle(KickPacket.class, packet -> {
kicked = true;
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);
for(Player player : Vars.control.playerGroup.all()){
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);

View file

@ -115,6 +115,10 @@ public class Packets {
}
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.scene.style.Drawable;
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.TextField.TextFieldFilter.DigitsOnlyFilter;
import io.anuke.ucore.scene.ui.layout.Table;
@ -48,20 +49,24 @@ public class JoinDialog extends FloatingDialog {
setup();
shown(() -> {
hosts.clear();
hosts.background("button");
hosts.label(() -> "[accent]" + Bundles.get("text.hosts.discovering") + new String(new char[(int)(Timers.time() / 10) % 4]).replace("\0", ".")).pad(10f);
Net.discoverServers(list -> {
addHosts(list);
});
});
shown(this::refresh);
}
void refresh(){
hosts.clear();
hosts.background("button");
hosts.label(() -> "[accent]" + Bundles.get("text.hosts.discovering") + new String(new char[(int)(Timers.time() / 10) % 4]).replace("\0", ".")).pad(10f);
Net.discoverServers(this::addHosts);
}
void setup(){
hosts.background("button");
content().clear();
ScrollPane pane = new ScrollPane(hosts, "clear");
pane.setFadeScrollBars(false);
pane.setScrollingDisabled(true, false);
content().clear();
content().table(t -> {
t.add("$text.name").padRight(10);
t.addField(Settings.getString("name"), text -> {
@ -72,7 +77,7 @@ public class JoinDialog extends FloatingDialog {
}).grow().pad(8);
}).width(w).height(70f).pad(4);
content().row();
content().add(hosts).width(w).pad(0);
content().add(pane).width(w).pad(0);
content().row();
content().addButton("$text.joingame.byip", "clear", join::show).width(w).height(80f);
}
@ -81,7 +86,9 @@ public class JoinDialog extends FloatingDialog {
hosts.clear();
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 {
for (Address a : array) {
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.Disconnect;
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.Streamable;
import io.anuke.mindustry.net.Streamable.StreamBegin;
@ -104,8 +105,10 @@ public class KryoServer implements ServerProvider {
@Override
public void kick(int 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, () -> {
if(conn.isConnected()){
conn.close();