Added UUID banning
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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,6 +630,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);
|
||||
@@ -632,6 +638,7 @@ public class Packets {
|
||||
|
||||
buffer.putInt(info.totalBlocksPlaced);
|
||||
buffer.putInt(info.lastBlockPlaced.id);
|
||||
buffer.put(Base64Coder.decode(info.uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -645,11 +652,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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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