Added admins with in-game icons and permissions; untested
This commit is contained in:
@@ -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<>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user