Security changes: placement verification, banning, unfinished admins
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.ucore.scene.ui.ScrollPane;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
import static io.anuke.mindustry.Vars.netServer;
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
|
||||
public class AdminsDialog extends FloatingDialog {
|
||||
|
||||
public AdminsDialog(){
|
||||
super("$text.server.admins");
|
||||
|
||||
addCloseButton();
|
||||
|
||||
setup();
|
||||
shown(this::setup);
|
||||
}
|
||||
|
||||
private void setup(){
|
||||
content().clear();
|
||||
|
||||
float w = 400f, h = 80f;
|
||||
|
||||
Table table = new Table();
|
||||
|
||||
ScrollPane pane = new ScrollPane(table, "clear");
|
||||
pane.setFadeScrollBars(false);
|
||||
|
||||
if(netServer.admins.getAdmins().size == 0){
|
||||
table.add("$text.server.admins.none");
|
||||
}
|
||||
|
||||
for(String ip : netServer.admins.getAdmins()){
|
||||
Table res = new Table("button");
|
||||
res.margin(14f);
|
||||
|
||||
res.labelWrap("[LIGHT_GRAY]" + netServer.admins.getLastName(ip)).width(w - h - 24f);
|
||||
res.add().growX();
|
||||
res.addImageButton("icon-cancel", 14*3, () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> {
|
||||
netServer.admins.unAdminPlayer(ip);
|
||||
setup();
|
||||
});
|
||||
}).size(h).pad(-14f);
|
||||
|
||||
table.add(res).width(w).height(h);
|
||||
table.row();
|
||||
}
|
||||
|
||||
content().add(pane);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.ucore.scene.ui.ScrollPane;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class BansDialog extends FloatingDialog {
|
||||
|
||||
public BansDialog(){
|
||||
super("$text.server.bans");
|
||||
|
||||
addCloseButton();
|
||||
|
||||
setup();
|
||||
|
||||
shown(this::setup);
|
||||
}
|
||||
|
||||
private void setup(){
|
||||
content().clear();
|
||||
|
||||
float w = 400f, h = 80f;
|
||||
|
||||
Table table = new Table();
|
||||
|
||||
ScrollPane pane = new ScrollPane(table, "clear");
|
||||
pane.setFadeScrollBars(false);
|
||||
|
||||
if(netServer.admins.getBanned().size == 0){
|
||||
table.add("$text.server.bans.none");
|
||||
}
|
||||
|
||||
for(String ip : netServer.admins.getBanned()){
|
||||
Table res = new Table("button");
|
||||
res.margin(14f);
|
||||
|
||||
res.labelWrap("IP: [LIGHT_GRAY]" + ip + "\n[]Name: [LIGHT_GRAY]" + netServer.admins.getLastName(ip)).width(w - h - 24f);
|
||||
res.add().growX();
|
||||
res.addImageButton("icon-cancel", 14*3, () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.confirmunban", () -> {
|
||||
netServer.admins.unbanPlayer(ip);
|
||||
setup();
|
||||
});
|
||||
}).size(h).pad(-14f);
|
||||
|
||||
table.add(res).width(w).height(h);
|
||||
table.row();
|
||||
}
|
||||
|
||||
content().add(pane);
|
||||
}
|
||||
}
|
||||
@@ -31,13 +31,13 @@ public class HostDialog extends FloatingDialog{
|
||||
Settings.put("name", text);
|
||||
Settings.save();
|
||||
ui.listfrag.rebuild();
|
||||
}).grow().pad(8);
|
||||
}).grow().pad(8).get().setMaxLength(48);
|
||||
|
||||
ImageButton button = t.addImageButton("white", 40, () -> {
|
||||
new ColorPickDialog().show(color -> {
|
||||
player.color.set(color);
|
||||
Settings.putInt("color", Color.rgba8888(color));
|
||||
Settings.save();;
|
||||
Settings.save();
|
||||
});
|
||||
}).size(50f, 54f).get();
|
||||
button.update(() -> button.getStyle().imageUpColor = player.getColor());
|
||||
|
||||
@@ -85,7 +85,7 @@ public class JoinDialog extends FloatingDialog {
|
||||
|
||||
TextButton button = buttons[0] = remote.addButton("[accent]"+server.ip, "clear", () -> {
|
||||
if(!buttons[0].childrenPressed()) connect(server.ip, Vars.port);
|
||||
}).width(w).height(120f).pad(4f).get();
|
||||
}).width(w).height(140f).pad(4f).get();
|
||||
|
||||
button.getLabel().setWrap(true);
|
||||
|
||||
@@ -134,10 +134,14 @@ public class JoinDialog extends FloatingDialog {
|
||||
Net.pingHost(server.ip, server.port, host -> {
|
||||
server.content.clear();
|
||||
|
||||
server.content.add("[lightgray]" + Bundles.format("text.server.hostname", host.name)).pad(4);
|
||||
server.content.add("[lightgray]" + Bundles.format("text.server.hostname", host.name)).left();
|
||||
server.content.row();
|
||||
server.content.add("[lightgray]" + (host.players != 1 ? Bundles.format("text.players", host.players) :
|
||||
Bundles.format("text.players.single", host.players)));
|
||||
Bundles.format("text.players.single", host.players))).left();
|
||||
server.content.row();
|
||||
server.content.add("[lightgray]" + Bundles.format("text.save.map", host.mapname)).left();
|
||||
server.content.row();
|
||||
server.content.add("[lightgray]" + Bundles.format("text.save.wave", host.wave)).left();
|
||||
}, e -> {
|
||||
server.content.clear();
|
||||
server.content.add("$text.host.invalid");
|
||||
@@ -175,7 +179,7 @@ public class JoinDialog extends FloatingDialog {
|
||||
Vars.player.name = text;
|
||||
Settings.put("name", text);
|
||||
Settings.save();
|
||||
}).grow().pad(8);
|
||||
}).grow().pad(8).get().setMaxLength(48);
|
||||
|
||||
ImageButton button = t.addImageButton("white", 40, () -> {
|
||||
new ColorPickDialog().show(color -> {
|
||||
|
||||
@@ -3,12 +3,14 @@ package io.anuke.mindustry.ui.fragments;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetConnection;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.net.Packets.KickReason;
|
||||
import io.anuke.mindustry.ui.BorderImage;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.scene.Element;
|
||||
import io.anuke.ucore.scene.builders.button;
|
||||
import io.anuke.ucore.scene.builders.label;
|
||||
import io.anuke.ucore.scene.builders.table;
|
||||
import io.anuke.ucore.scene.ui.ScrollPane;
|
||||
@@ -40,10 +42,20 @@ public class PlayerListFragment implements Fragment{
|
||||
row();
|
||||
new table("pane"){{
|
||||
margin(12f);
|
||||
|
||||
get().addCheck("$text.server.friendlyfire", b -> {
|
||||
state.friendlyFire = b;
|
||||
NetEvents.handleFriendlyFireChange(b);
|
||||
}).growX().update(i -> i.setChecked(state.friendlyFire)).disabled(b -> Net.client());
|
||||
}).growX().update(i -> i.setChecked(state.friendlyFire)).disabled(b -> Net.client()).padRight(5);
|
||||
|
||||
new button("$text.server.bans", () -> {
|
||||
ui.bans.show();
|
||||
}).padTop(-12).padBottom(-12).fillY().cell.disabled(b -> Net.client());
|
||||
|
||||
new button("$text.server.admins", () -> {
|
||||
ui.admins.show();
|
||||
}).padTop(-12).padBottom(-12).padRight(-12).fillY().cell.disabled(b -> Net.client());
|
||||
|
||||
}}.pad(10f).growX().end();
|
||||
}}.end();
|
||||
|
||||
@@ -69,9 +81,13 @@ public class PlayerListFragment implements Fragment{
|
||||
public void rebuild(){
|
||||
content.clear();
|
||||
|
||||
float h = 60f;
|
||||
float h = 74f;
|
||||
|
||||
for(Player player : playerGroup.all()){
|
||||
NetConnection connection = Net.getConnection(player.clientid);
|
||||
|
||||
if(connection == null && !player.isLocal) continue;
|
||||
|
||||
Table button = new Table("button");
|
||||
button.left();
|
||||
button.margin(5).marginBottom(10);
|
||||
@@ -93,19 +109,50 @@ public class PlayerListFragment implements Fragment{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
button.add(stack).size(h);
|
||||
button.add("[#" + player.getColor().toString().toUpperCase() + "]" + player.name).pad(10);
|
||||
button.labelWrap("[#" + player.getColor().toString().toUpperCase() + "]" + player.name).width(170f).pad(10);
|
||||
button.add().grow();
|
||||
|
||||
if(Net.server() && !player.isLocal){
|
||||
button.add().growY();
|
||||
button.addImageButton("icon-cancel", 14*3, () ->
|
||||
Net.kickConnection(player.clientid, KickReason.kick)
|
||||
).pad(-5).padBottom(-10).size(h+10, h+14);
|
||||
|
||||
float bs = (h + 14)/2f;
|
||||
|
||||
button.table(t -> {
|
||||
t.defaults().size(bs - 1, bs + 3);
|
||||
|
||||
t.addImageButton("icon-ban", 14*2, () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.confirmban", () -> {
|
||||
netServer.admins.banPlayer(connection.address);
|
||||
Net.kickConnection(player.clientid, KickReason.banned);
|
||||
});
|
||||
}).padBottom(-5.1f);
|
||||
|
||||
t.addImageButton("icon-cancel", 14*2, () -> Net.kickConnection(player.clientid, KickReason.kick)).padBottom(-5.1f);
|
||||
|
||||
t.row();
|
||||
|
||||
t.addImageButton("icon-admin", "toggle", 14*2, () -> {
|
||||
if(netServer.admins.isAdmin(connection.address)){
|
||||
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> {
|
||||
netServer.admins.unAdminPlayer(connection.address);
|
||||
//TODO send aproppriate packets.
|
||||
});
|
||||
}else{
|
||||
ui.showConfirm("$text.confirm", "$text.confirmadmin", () -> {
|
||||
netServer.admins.adminPlayer(connection.address);
|
||||
//TODO send aproppriate packets.
|
||||
});
|
||||
}
|
||||
}).update(b -> b.setChecked(netServer.admins.isAdmin(connection.address)));
|
||||
|
||||
t.addImageButton("icon-cancel", 14*2, () -> Net.kickConnection(player.clientid, KickReason.kick));
|
||||
}).padRight(12).padTop(-5).padLeft(0).padBottom(-10).size(bs + 10f, bs);
|
||||
|
||||
|
||||
}
|
||||
|
||||
content.add(button).padBottom(-5).width(350f);
|
||||
content.add(button).padBottom(-6).width(350f).maxHeight(h + 14);
|
||||
content.row();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user