Merge branch 'master' of https://github.com/Anuken/Mindustry into 4.0
This commit is contained in:
@@ -7,16 +7,20 @@ import io.anuke.ucore.core.Settings;
|
||||
|
||||
public class Administration {
|
||||
private Json json = new Json();
|
||||
private Array<String> bannedIPS = new Array<>();
|
||||
private Array<String> bannedIPs = new Array<>();
|
||||
private Array<String> bannedIDs = new Array<>();
|
||||
private Array<String> admins = new Array<>();
|
||||
private ObjectMap<String, String> known = new ObjectMap<>();
|
||||
private ObjectMap<String, String> ipNames = new ObjectMap<>();
|
||||
private ObjectMap<String, String> idIPs = new ObjectMap<>();
|
||||
private ObjectMap<String, TraceInfo> traces = new ObjectMap<>();
|
||||
|
||||
public Administration(){
|
||||
Settings.defaultList(
|
||||
"bans", "{}",
|
||||
"bannedIDs", "{}",
|
||||
"admins", "{}",
|
||||
"knownIPs", "{}"
|
||||
"knownIPs", "{}",
|
||||
"knownIDs", "{}"
|
||||
);
|
||||
|
||||
load();
|
||||
@@ -34,35 +38,81 @@ public class Administration {
|
||||
|
||||
/**Sets last known name for an IP.*/
|
||||
public void setKnownName(String ip, String name){
|
||||
known.put(ip, name);
|
||||
ipNames.put(ip, name);
|
||||
saveKnown();
|
||||
}
|
||||
|
||||
/**Sets last known UUID for an IP.*/
|
||||
public void setKnownIP(String id, String ip){
|
||||
idIPs.put(id, ip);
|
||||
saveKnown();
|
||||
}
|
||||
|
||||
/**Returns the last known name for an IP. Returns 'unknown' if this IP has an unknown username.*/
|
||||
public String getLastName(String ip){
|
||||
return known.get(ip, "unknown");
|
||||
return ipNames.get(ip, "unknown");
|
||||
}
|
||||
|
||||
/**Returns the last known IP for a UUID. Returns 'unknown' if this IP has an unknown IP.*/
|
||||
public String getLastIP(String id){
|
||||
return idIPs.get(id, "unknown");
|
||||
}
|
||||
|
||||
/**Return the last known device ID associated with an IP. Returns 'unknown' if this IP has an unknown device.*/
|
||||
public String getLastID(String ip){
|
||||
for(String id : idIPs.keys()){
|
||||
if(idIPs.get(id).equals(ip)){
|
||||
return id;
|
||||
}
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
/**Returns list of banned IPs.*/
|
||||
public Array<String> getBanned(){
|
||||
return bannedIPS;
|
||||
return bannedIPs;
|
||||
}
|
||||
|
||||
/**Returns list of banned IDs.*/
|
||||
public Array<String> getBannedIDs(){
|
||||
return bannedIDs;
|
||||
}
|
||||
|
||||
/**Bans a player by IP; returns whether this player was already banned.*/
|
||||
public boolean banPlayer(String ip){
|
||||
if(bannedIPS.contains(ip, false))
|
||||
public boolean banPlayerIP(String ip){
|
||||
if(bannedIPs.contains(ip, false))
|
||||
return false;
|
||||
bannedIPS.add(ip);
|
||||
bannedIPs.add(ip);
|
||||
saveBans();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**Bans a player by UUID.*/
|
||||
public boolean banPlayerID(String id){
|
||||
if(bannedIDs.contains(id, false))
|
||||
return false;
|
||||
bannedIDs.add(id);
|
||||
saveBans();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**Unbans a player by IP; returns whether this player was banned in the first place..*/
|
||||
public boolean unbanPlayer(String ip){
|
||||
if(!bannedIPS.contains(ip, false))
|
||||
public boolean unbanPlayerIP(String ip){
|
||||
if(!bannedIPs.contains(ip, false))
|
||||
return false;
|
||||
bannedIPS.removeValue(ip, false);
|
||||
bannedIPs.removeValue(ip, false);
|
||||
saveBans();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**Unbans a player by IP; returns whether this player was banned in the first place..*/
|
||||
public boolean unbanPlayerID(String ip){
|
||||
if(!bannedIDs.contains(ip, false))
|
||||
return false;
|
||||
bannedIDs.removeValue(ip, false);
|
||||
saveBans();
|
||||
|
||||
return true;
|
||||
@@ -93,8 +143,12 @@ public class Administration {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isBanned(String ip){
|
||||
return bannedIPS.contains(ip, false);
|
||||
public boolean isIPBanned(String ip){
|
||||
return bannedIPs.contains(ip, false);
|
||||
}
|
||||
|
||||
public boolean isIDBanned(String uuid){
|
||||
return bannedIDs.contains(uuid, false);
|
||||
}
|
||||
|
||||
public boolean isAdmin(String ip){
|
||||
@@ -102,12 +156,14 @@ public class Administration {
|
||||
}
|
||||
|
||||
private void saveKnown(){
|
||||
Settings.putString("knownIPs", json.toJson(known));
|
||||
Settings.putString("knownIPs", json.toJson(ipNames));
|
||||
Settings.putString("knownIDs", json.toJson(idIPs));
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
private void saveBans(){
|
||||
Settings.putString("bans", json.toJson(bannedIPS));
|
||||
Settings.putString("bans", json.toJson(bannedIPs));
|
||||
Settings.putString("bannedIDs", json.toJson(bannedIDs));
|
||||
Settings.save();
|
||||
}
|
||||
|
||||
@@ -117,9 +173,11 @@ public class Administration {
|
||||
}
|
||||
|
||||
private void load(){
|
||||
bannedIPS = json.fromJson(Array.class, Settings.getString("bans"));
|
||||
bannedIPs = json.fromJson(Array.class, Settings.getString("bans"));
|
||||
bannedIDs = json.fromJson(Array.class, Settings.getString("bannedIDs"));
|
||||
admins = json.fromJson(Array.class, Settings.getString("admins"));
|
||||
known = json.fromJson(ObjectMap.class, Settings.getString("knownIPs"));
|
||||
ipNames = json.fromJson(ObjectMap.class, Settings.getString("knownIPs"));
|
||||
idIPs = json.fromJson(ObjectMap.class, Settings.getString("knownIDs"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,12 +6,14 @@ public class Host {
|
||||
public final String mapname;
|
||||
public final int wave;
|
||||
public final int players;
|
||||
public final int version;
|
||||
|
||||
public Host(String name, String address, String mapname, int wave, int players){
|
||||
public Host(String name, String address, String mapname, int wave, int players, int version){
|
||||
this.name = name;
|
||||
this.address = address;
|
||||
this.players = players;
|
||||
this.mapname = mapname;
|
||||
this.wave = wave;
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ 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.io.Version;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.*;
|
||||
@@ -16,6 +17,7 @@ import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
@@ -342,4 +344,46 @@ public class NetworkIO {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static ByteBuffer writeServerData(){
|
||||
int maxlen = 32;
|
||||
|
||||
String host = (headless ? "Server" : player.name);
|
||||
String map = world.getMap().name;
|
||||
|
||||
host = host.substring(0, Math.min(host.length(), maxlen));
|
||||
map = map.substring(0, Math.min(map.length(), maxlen));
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocate(128);
|
||||
|
||||
buffer.put((byte)host.getBytes().length);
|
||||
buffer.put(host.getBytes());
|
||||
|
||||
buffer.put((byte)map.getBytes().length);
|
||||
buffer.put(map.getBytes());
|
||||
|
||||
buffer.putInt(playerGroup.size());
|
||||
buffer.putInt(state.wave);
|
||||
buffer.putInt(Version.build);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static Host readServerData(String hostAddress, ByteBuffer buffer){
|
||||
byte hlength = buffer.get();
|
||||
byte[] hb = new byte[hlength];
|
||||
buffer.get(hb);
|
||||
|
||||
byte mlength = buffer.get();
|
||||
byte[] mb = new byte[mlength];
|
||||
buffer.get(mb);
|
||||
|
||||
String host = new String(hb);
|
||||
String map = new String(mb);
|
||||
|
||||
int players = buffer.getInt();
|
||||
int wave = buffer.getInt();
|
||||
int version = buffer.getInt();
|
||||
|
||||
return new Host(host, hostAddress, map, wave, players, version);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.utils.Base64Coder;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import com.badlogic.gdx.utils.reflect.ReflectionException;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
@@ -56,6 +57,7 @@ public class Packets {
|
||||
public String name;
|
||||
public boolean android;
|
||||
public int color;
|
||||
public byte[] uuid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
@@ -64,6 +66,7 @@ public class Packets {
|
||||
buffer.put(name.getBytes());
|
||||
buffer.put(android ? (byte)1 : 0);
|
||||
buffer.putInt(color);
|
||||
buffer.put(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,6 +78,8 @@ public class Packets {
|
||||
name = new String(bytes);
|
||||
android = buffer.get() == 1;
|
||||
color = buffer.getInt();
|
||||
uuid = new byte[8];
|
||||
buffer.get(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,6 +574,7 @@ public class Packets {
|
||||
buffer.putShort((short)info.ip.getBytes().length);
|
||||
buffer.put(info.ip.getBytes());
|
||||
buffer.put(info.modclient ? (byte)1 : 0);
|
||||
buffer.put(info.android ? (byte)1 : 0);
|
||||
|
||||
buffer.putInt(info.totalBlocksBroken);
|
||||
buffer.putInt(info.structureBlocksBroken);
|
||||
@@ -576,6 +582,7 @@ public class Packets {
|
||||
|
||||
buffer.putInt(info.totalBlocksPlaced);
|
||||
buffer.putInt(info.lastBlockPlaced.id);
|
||||
buffer.put(Base64Coder.decode(info.uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -589,11 +596,16 @@ public class Packets {
|
||||
|
||||
info.playerid = id;
|
||||
info.modclient = buffer.get() == 1;
|
||||
info.android = buffer.get() == 1;
|
||||
info.totalBlocksBroken = buffer.getInt();
|
||||
info.structureBlocksBroken = buffer.getInt();
|
||||
info.lastBlockBroken = Block.getByID(buffer.getInt());
|
||||
info.totalBlocksPlaced = buffer.getInt();
|
||||
info.lastBlockPlaced = Block.getByID(buffer.getInt());
|
||||
byte[] uuid = new byte[8];
|
||||
buffer.get(uuid);
|
||||
|
||||
info.uuid = new String(Base64Coder.encode(uuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.badlogic.gdx.utils.TimeUtils;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.net.Packets.Disconnect;
|
||||
import io.anuke.ucore.util.Log;
|
||||
|
||||
import static io.anuke.mindustry.Vars.playerGroup;
|
||||
|
||||
@@ -13,12 +14,16 @@ public class ServerDebug {
|
||||
private IntMap<OrderedMap<Class<?>, Long>> last = new IntMap<>();
|
||||
|
||||
public void handle(int connection, Object packet){
|
||||
if(!last.containsKey(connection))
|
||||
last.put(connection, new OrderedMap<>());
|
||||
if(packet instanceof Disconnect)
|
||||
last.remove(connection);
|
||||
else
|
||||
last.get(connection).put(packet.getClass(), TimeUtils.millis());
|
||||
try {
|
||||
if (!last.containsKey(connection))
|
||||
last.put(connection, new OrderedMap<>());
|
||||
if (packet instanceof Disconnect)
|
||||
last.remove(connection);
|
||||
else
|
||||
last.get(connection).put(packet.getClass(), TimeUtils.millis());
|
||||
}catch (Exception e){
|
||||
Log.err("<An internal debug error has occurred.>");
|
||||
}
|
||||
}
|
||||
|
||||
public String getOut(){
|
||||
|
||||
@@ -7,6 +7,7 @@ public class TraceInfo {
|
||||
public int playerid;
|
||||
public String ip;
|
||||
public boolean modclient;
|
||||
public boolean android;
|
||||
|
||||
public int totalBlocksBroken;
|
||||
public int structureBlocksBroken;
|
||||
@@ -15,6 +16,8 @@ public class TraceInfo {
|
||||
public int totalBlocksPlaced;
|
||||
public Block lastBlockPlaced = Blocks.air;
|
||||
|
||||
public String uuid;
|
||||
|
||||
public TraceInfo(String ip){
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user