use of io.anuke.mindustry.net.NetConnection in project Mindustry by Anuken.
the class PlayerListFragment method rebuild.
public void rebuild() {
content.clear();
float h = 74f;
for (Player player : playerGroup.all()) {
NetConnection connection = gwt ? null : Net.getConnection(player.clientid);
if (connection == null && Net.server() && !player.isLocal)
continue;
Table button = new Table("button");
button.left();
button.margin(5).marginBottom(10);
Stack stack = new Stack();
BorderImage image = new BorderImage(Draw.region(player.isAndroid ? "ship-standard" : "mech-standard-icon"), 3f);
stack.add(image);
if (!player.isAndroid) {
stack.add(new Element() {
public void draw() {
float s = getWidth() / 12f;
for (int i : Mathf.signs) {
Draw.rect((i < 0 ? player.weaponLeft.name : player.weaponRight.name) + "-equip", x + s * 6 + i * 3 * s, y + s * 6 + 2 * s, -8 * s * i, 8 * s);
}
}
});
}
button.add(stack).size(h);
button.labelWrap("[#" + player.getColor().toString().toUpperCase() + "]" + player.name).width(170f).pad(10);
button.add().grow();
button.addImage("icon-admin").size(14 * 2).visible(() -> player.isAdmin && !(!player.isLocal && Net.server())).padRight(5);
if ((Net.server() || Vars.player.isAdmin) && !player.isLocal && (!player.isAdmin || Net.server())) {
button.add().growY();
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", () -> {
if (Net.server()) {
netServer.admins.banPlayerIP(connection.address);
netServer.kick(player.clientid, KickReason.banned);
} else {
NetEvents.handleAdministerRequest(player, AdminAction.ban);
}
});
}).padBottom(-5.1f);
t.addImageButton("icon-cancel", 14 * 2, () -> {
if (Net.server()) {
netServer.kick(player.clientid, KickReason.kick);
} else {
NetEvents.handleAdministerRequest(player, AdminAction.kick);
}
}).padBottom(-5.1f);
t.row();
t.addImageButton("icon-admin", "toggle", 14 * 2, () -> {
if (Net.client())
return;
String id = netServer.admins.getTrace(connection.address).uuid;
if (netServer.admins.isAdmin(id, connection.address)) {
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> {
netServer.admins.unAdminPlayer(id);
NetEvents.handleAdminSet(player, false);
});
} else {
ui.showConfirm("$text.confirm", "$text.confirmadmin", () -> {
netServer.admins.adminPlayer(id, connection.address);
NetEvents.handleAdminSet(player, true);
});
}
}).update(b -> {
b.setChecked(player.isAdmin);
b.setDisabled(Net.client());
}).get().setTouchable(() -> Net.client() ? Touchable.disabled : Touchable.enabled);
t.addImageButton("icon-zoom-small", 14 * 2, () -> NetEvents.handleTraceRequest(player));
}).padRight(12).padTop(-5).padLeft(0).padBottom(-10).size(bs + 10f, bs);
}
content.add(button).padBottom(-6).width(350f).maxHeight(h + 14);
content.row();
}
content.marginBottom(5);
}
use of io.anuke.mindustry.net.NetConnection in project Mindustry by Anuken.
the class AdminsDialog method setup.
private void setup() {
content().clear();
if (gwt)
return;
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 (PlayerInfo info : netServer.admins.getAdmins()) {
Table res = new Table("button");
res.margin(14f);
res.labelWrap("[LIGHT_GRAY]" + info.lastName).width(w - h - 24f);
res.add().growX();
res.addImageButton("icon-cancel", 14 * 3, () -> {
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> {
netServer.admins.unAdminPlayer(info.id);
for (Player player : playerGroup.all()) {
NetConnection c = Net.getConnection(player.clientid);
if (c != null) {
NetEvents.handleAdminSet(player, false);
break;
}
}
setup();
});
}).size(h).pad(-14f);
table.add(res).width(w).height(h);
table.row();
}
content().add(pane);
}
Aggregations