Added admins with in-game icons and permissions; untested
This commit is contained in:
@@ -51,6 +51,7 @@ public class NetClient extends Module {
|
||||
public NetClient(){
|
||||
|
||||
Net.handleClient(Connect.class, packet -> {
|
||||
player.isAdmin = false;
|
||||
|
||||
Net.setClientLoaded(false);
|
||||
recieved.clear();
|
||||
@@ -331,6 +332,12 @@ public class NetClient extends Module {
|
||||
ui.showError(packet.message);
|
||||
disconnectQuietly();
|
||||
});
|
||||
|
||||
Net.handleClient(PlayerAdminPacket.class, packet -> {
|
||||
Player player = playerGroup.getByID(packet.id);
|
||||
player.isAdmin = packet.admin;
|
||||
ui.listfrag.rebuild();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -80,6 +80,7 @@ public class NetServer extends Module{
|
||||
Log.info("Sending data to player '{0}' / {1}", packet.name, id);
|
||||
|
||||
Player player = new Player();
|
||||
player.isAdmin = admins.isAdmin(Net.getConnection(id).address);
|
||||
player.clientid = id;
|
||||
player.name = packet.name;
|
||||
player.isAndroid = packet.android;
|
||||
@@ -109,7 +110,7 @@ public class NetServer extends Module{
|
||||
Player player = connections.get(id);
|
||||
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
NetworkIO.writeWorld(player.id, weapons.get(player.name, new ByteArray()), stream);
|
||||
NetworkIO.writeWorld(player, weapons.get(player.name, new ByteArray()), stream);
|
||||
WorldData data = new WorldData();
|
||||
data.stream = new ByteArrayInputStream(stream.toByteArray());
|
||||
Net.sendStream(id, data);
|
||||
@@ -239,6 +240,32 @@ public class NetServer extends Module{
|
||||
packet.id = connections.get(id).id;
|
||||
Net.sendExcept(id, packet, SendMode.tcp);
|
||||
});
|
||||
|
||||
Net.handleServer(AdministerRequestPacket.class, (id, packet) -> {
|
||||
Player player = connections.get(id);
|
||||
|
||||
if(!player.isAdmin){
|
||||
Log.err("ACCESS DENIED: Player {0} / {1} attempted to perform admin action without proper security access.",
|
||||
player.name, Net.getConnection(player.clientid).address);
|
||||
return;
|
||||
}
|
||||
|
||||
Player other = playerGroup.getByID(packet.id);
|
||||
|
||||
if(other == null){
|
||||
Log.err("{0} attempted to perform admin action on nonexistant player.", player.name);
|
||||
return;
|
||||
}
|
||||
|
||||
if(packet.action == AdminAction.ban){
|
||||
admins.banPlayer(Net.getConnection(other.clientid).address);
|
||||
Net.kickConnection(other.clientid, KickReason.banned);
|
||||
Log.info("&lc{0} has banned {1}.", player.name, other.name);
|
||||
}else if(packet.action == AdminAction.kick){
|
||||
Net.kickConnection(other.clientid, KickReason.kick);
|
||||
Log.info("&lc{0} has kicked {1}.", player.name, other.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void update(){
|
||||
|
||||
@@ -264,8 +264,14 @@ public class Renderer extends RendererModule{
|
||||
Draw.color();
|
||||
Draw.tcolor(player.getColor());
|
||||
Draw.text(player.name, player.x, player.y + 8);
|
||||
Draw.tcolor();
|
||||
}
|
||||
|
||||
if(player.isAdmin){
|
||||
Draw.color(player.getColor());
|
||||
float s = 3f;
|
||||
Draw.rect("icon-admin-small", player.x + layout.width/2f + 2 + 1, player.y + 7f, s, s);
|
||||
}
|
||||
Draw.reset();
|
||||
}
|
||||
}
|
||||
Pools.free(layout);
|
||||
Draw.tscl(fontscale);
|
||||
|
||||
@@ -34,6 +34,7 @@ public class Player extends SyncEntity{
|
||||
|
||||
public String name = "name";
|
||||
public boolean isAndroid;
|
||||
public boolean isAdmin;
|
||||
public Color color = new Color();
|
||||
|
||||
public Weapon weaponLeft = Weapon.blaster;
|
||||
@@ -44,7 +45,7 @@ public class Player extends SyncEntity{
|
||||
public float stucktime = 0f;
|
||||
public boolean dashing = false;
|
||||
|
||||
public int clientid;
|
||||
public int clientid = -1;
|
||||
public boolean isLocal = false;
|
||||
public Timer timer = new Timer(4);
|
||||
|
||||
@@ -240,6 +241,7 @@ public class Player extends SyncEntity{
|
||||
buffer.put(weaponLeft.id);
|
||||
buffer.put(weaponRight.id);
|
||||
buffer.put(isAndroid ? 1 : (byte)0);
|
||||
buffer.put(isAdmin ? 1 : (byte)0);
|
||||
buffer.putInt(Color.rgba8888(color));
|
||||
buffer.putFloat(x);
|
||||
buffer.putFloat(y);
|
||||
@@ -254,6 +256,7 @@ public class Player extends SyncEntity{
|
||||
weaponLeft = (Weapon) Upgrade.getByID(buffer.get());
|
||||
weaponRight = (Weapon) Upgrade.getByID(buffer.get());
|
||||
isAndroid = buffer.get() == 1;
|
||||
isAdmin = buffer.get() == 1;
|
||||
color.set(buffer.getInt());
|
||||
x = buffer.getFloat();
|
||||
y = buffer.getFloat();
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
@@ -149,4 +150,19 @@ public class NetEvents {
|
||||
packet.itemid = (byte)item.id;
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
public static void handleAdminSet(Player player, boolean admin){
|
||||
PlayerAdminPacket packet = new PlayerAdminPacket();
|
||||
packet.admin = admin;
|
||||
packet.id = player.id;
|
||||
player.isAdmin = admin;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleAdministerRequest(Player target, AdminAction action){
|
||||
AdministerRequestPacket packet = new AdministerRequestPacket();
|
||||
packet.id = target.id;
|
||||
packet.action = action;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||
import com.badlogic.gdx.utils.ByteArray;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.game.GameMode;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
@@ -100,7 +101,7 @@ public class NetworkIO {
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeWorld(int playerID, ByteArray upgrades, OutputStream os){
|
||||
public static void writeWorld(Player player, ByteArray upgrades, OutputStream os){
|
||||
|
||||
try(DataOutputStream stream = new DataOutputStream(os)){
|
||||
|
||||
@@ -116,7 +117,8 @@ public class NetworkIO {
|
||||
stream.writeInt(state.enemies); //enemy amount
|
||||
|
||||
stream.writeBoolean(state.friendlyFire); //friendly fire state
|
||||
stream.writeInt(playerID); //player remap ID
|
||||
stream.writeInt(player.id); //player remap ID
|
||||
stream.writeBoolean(player.isAdmin);
|
||||
|
||||
//--INVENTORY--
|
||||
|
||||
@@ -246,6 +248,7 @@ public class NetworkIO {
|
||||
state.friendlyFire = friendlyfire;
|
||||
|
||||
int pid = stream.readInt();
|
||||
boolean admin = stream.readBoolean();
|
||||
|
||||
//inventory
|
||||
for(int i = 0; i < state.inventory.getItems().length; i ++){
|
||||
@@ -268,6 +271,7 @@ public class NetworkIO {
|
||||
|
||||
Entities.clear();
|
||||
player.id = pid;
|
||||
player.isAdmin = admin;
|
||||
player.add();
|
||||
|
||||
//map
|
||||
|
||||
@@ -576,4 +576,42 @@ public class Packets {
|
||||
message = new String(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlayerAdminPacket implements Packet{
|
||||
public boolean admin;
|
||||
public int id;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.put(admin ? (byte)1 : 0);
|
||||
buffer.putInt(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
admin = buffer.get() == 1;
|
||||
id = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdministerRequestPacket implements Packet{
|
||||
public AdminAction action;
|
||||
public int id;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.put((byte)action.ordinal());
|
||||
buffer.putInt(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
action = AdminAction.values()[buffer.get()];
|
||||
id = buffer.getInt();
|
||||
}
|
||||
}
|
||||
|
||||
public enum AdminAction{
|
||||
kick, ban
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ public class Registrator {
|
||||
ItemSetPacket.class,
|
||||
ItemOffloadPacket.class,
|
||||
NetErrorPacket.class,
|
||||
PlayerAdminPacket.class,
|
||||
AdministerRequestPacket.class,
|
||||
};
|
||||
private static ObjectIntMap<Class<?>> ids = new ObjectIntMap<>();
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
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.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;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class AdminsDialog extends FloatingDialog {
|
||||
|
||||
@@ -40,6 +43,13 @@ public class AdminsDialog extends FloatingDialog {
|
||||
res.addImageButton("icon-cancel", 14*3, () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> {
|
||||
netServer.admins.unAdminPlayer(ip);
|
||||
for(Player player : playerGroup.all()){
|
||||
NetConnection c = Net.getConnection(player.clientid);
|
||||
if(c != null){
|
||||
NetEvents.handleAdminSet(player, false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
setup();
|
||||
});
|
||||
}).size(h).pad(-14f);
|
||||
|
||||
@@ -50,6 +50,7 @@ public class HostDialog extends FloatingDialog{
|
||||
Timers.runTask(5f, () -> {
|
||||
try{
|
||||
Net.host(Vars.port);
|
||||
player.isAdmin = true;
|
||||
}catch (IOException e){
|
||||
ui.showError(Bundles.format("text.server.error", Strings.parseException(e, false)));
|
||||
}
|
||||
@@ -58,19 +59,4 @@ public class HostDialog extends FloatingDialog{
|
||||
});
|
||||
}).width(w).height(70f);
|
||||
}
|
||||
|
||||
/*
|
||||
showTextInput("$text.hostserver", "$text.server.port", Vars.port + "", new DigitsOnlyFilter(), text -> {
|
||||
int result = Strings.parseInt(text);
|
||||
if(result == Integer.MIN_VALUE || result >= 65535){
|
||||
ui.showError("$text.server.invalidport");
|
||||
}else{
|
||||
try{
|
||||
Net.host(result);
|
||||
}catch (IOException e){
|
||||
ui.showError(Bundles.format("text.server.error", Strings.parseException(e, false)));
|
||||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package io.anuke.mindustry.ui.fragments;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
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.AdminAction;
|
||||
import io.anuke.mindustry.net.Packets.KickReason;
|
||||
import io.anuke.mindustry.ui.BorderImage;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
@@ -86,7 +88,7 @@ public class PlayerListFragment implements Fragment{
|
||||
for(Player player : playerGroup.all()){
|
||||
NetConnection connection = Net.getConnection(player.clientid);
|
||||
|
||||
if(connection == null && !player.isLocal) continue;
|
||||
if(connection == null && Net.server() && !player.isLocal) continue;
|
||||
|
||||
Table button = new Table("button");
|
||||
button.left();
|
||||
@@ -113,7 +115,9 @@ public class PlayerListFragment implements Fragment{
|
||||
button.labelWrap("[#" + player.getColor().toString().toUpperCase() + "]" + player.name).width(170f).pad(10);
|
||||
button.add().grow();
|
||||
|
||||
if(Net.server() && !player.isLocal){
|
||||
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){
|
||||
button.add().growY();
|
||||
|
||||
float bs = (h + 14)/2f;
|
||||
@@ -123,30 +127,45 @@ public class PlayerListFragment implements Fragment{
|
||||
|
||||
t.addImageButton("icon-ban", 14*2, () -> {
|
||||
ui.showConfirm("$text.confirm", "$text.confirmban", () -> {
|
||||
netServer.admins.banPlayer(connection.address);
|
||||
Net.kickConnection(player.clientid, KickReason.banned);
|
||||
if(Net.server()) {
|
||||
netServer.admins.banPlayer(connection.address);
|
||||
Net.kickConnection(player.clientid, KickReason.banned);
|
||||
}else{
|
||||
NetEvents.handleAdministerRequest(player, AdminAction.ban);
|
||||
}
|
||||
});
|
||||
}).padBottom(-5.1f);
|
||||
|
||||
t.addImageButton("icon-cancel", 14*2, () -> Net.kickConnection(player.clientid, KickReason.kick)).padBottom(-5.1f);
|
||||
t.addImageButton("icon-cancel", 14*2, () -> {
|
||||
if(Net.server()) {
|
||||
Net.kickConnection(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;
|
||||
|
||||
if(netServer.admins.isAdmin(connection.address)){
|
||||
ui.showConfirm("$text.confirm", "$text.confirmunadmin", () -> {
|
||||
netServer.admins.unAdminPlayer(connection.address);
|
||||
//TODO send aproppriate packets.
|
||||
NetEvents.handleAdminSet(player, false);
|
||||
});
|
||||
}else{
|
||||
ui.showConfirm("$text.confirm", "$text.confirmadmin", () -> {
|
||||
netServer.admins.adminPlayer(connection.address);
|
||||
//TODO send aproppriate packets.
|
||||
NetEvents.handleAdminSet(player, true);
|
||||
});
|
||||
}
|
||||
}).update(b -> b.setChecked(netServer.admins.isAdmin(connection.address)));
|
||||
}).update(b -> b.setChecked(connection != null && netServer.admins.isAdmin(connection.address)))
|
||||
.disabled(Net.client());
|
||||
|
||||
//TODO unused?
|
||||
t.addImageButton("icon-cancel", 14*2, () -> {});
|
||||
|
||||
t.addImageButton("icon-cancel", 14*2, () -> Net.kickConnection(player.clientid, KickReason.kick));
|
||||
}).padRight(12).padTop(-5).padLeft(0).padBottom(-10).size(bs + 10f, bs);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user