mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-13 12:16:53 +07:00
Added basic subnet bans
This commit is contained in:
parent
2345b48e97
commit
e06f514023
@ -76,7 +76,7 @@ public class NetServer implements ApplicationListener{
|
|||||||
public NetServer(){
|
public NetServer(){
|
||||||
|
|
||||||
net.handleServer(Connect.class, (con, connect) -> {
|
net.handleServer(Connect.class, (con, connect) -> {
|
||||||
if(admins.isIPBanned(connect.addressTCP)){
|
if(admins.isIPBanned(connect.addressTCP) || admins.isSubnetBanned(connect.addressTCP)){
|
||||||
con.kick(KickReason.banned);
|
con.kick(KickReason.banned);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -94,7 +94,7 @@ public class NetServer implements ApplicationListener{
|
|||||||
|
|
||||||
String uuid = packet.uuid;
|
String uuid = packet.uuid;
|
||||||
|
|
||||||
if(admins.isIPBanned(con.address)) return;
|
if(admins.isIPBanned(con.address) || admins.isSubnetBanned(con.address)) return;
|
||||||
|
|
||||||
if(con.hasBegunConnecting){
|
if(con.hasBegunConnecting){
|
||||||
con.kick(KickReason.idInUse);
|
con.kick(KickReason.idInUse);
|
||||||
|
@ -18,6 +18,7 @@ public class Administration{
|
|||||||
private Array<String> whitelist = new Array<>();
|
private Array<String> whitelist = new Array<>();
|
||||||
private Array<ChatFilter> chatFilters = new Array<>();
|
private Array<ChatFilter> chatFilters = new Array<>();
|
||||||
private Array<ActionFilter> actionFilters = new Array<>();
|
private Array<ActionFilter> actionFilters = new Array<>();
|
||||||
|
private Array<String> subnetBans = new Array<>();
|
||||||
|
|
||||||
public Administration(){
|
public Administration(){
|
||||||
load();
|
load();
|
||||||
@ -55,6 +56,24 @@ public class Administration{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Array<String> getSubnetBans(){
|
||||||
|
return subnetBans;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeSubnetBan(String ip){
|
||||||
|
subnetBans.remove(ip);
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSubnetBan(String ip){
|
||||||
|
subnetBans.add(ip);
|
||||||
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSubnetBanned(String ip){
|
||||||
|
return subnetBans.contains(ip::startsWith);
|
||||||
|
}
|
||||||
|
|
||||||
/** Adds a chat filter. This will transform the chat messages of every player.
|
/** Adds a chat filter. This will transform the chat messages of every player.
|
||||||
* This functionality can be used to implement things like swear filters and special commands.
|
* This functionality can be used to implement things like swear filters and special commands.
|
||||||
* Note that commands (starting with /) are not filtered.*/
|
* Note that commands (starting with /) are not filtered.*/
|
||||||
@ -354,6 +373,7 @@ public class Administration{
|
|||||||
Core.settings.putObject("player-info", playerInfo);
|
Core.settings.putObject("player-info", playerInfo);
|
||||||
Core.settings.putObject("banned-ips", bannedIPs);
|
Core.settings.putObject("banned-ips", bannedIPs);
|
||||||
Core.settings.putObject("whitelisted", whitelist);
|
Core.settings.putObject("whitelisted", whitelist);
|
||||||
|
Core.settings.putObject("subnet-bans", subnetBans);
|
||||||
Core.settings.save();
|
Core.settings.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,6 +382,7 @@ public class Administration{
|
|||||||
playerInfo = Core.settings.getObject("player-info", ObjectMap.class, ObjectMap::new);
|
playerInfo = Core.settings.getObject("player-info", ObjectMap.class, ObjectMap::new);
|
||||||
bannedIPs = Core.settings.getObject("banned-ips", Array.class, Array::new);
|
bannedIPs = Core.settings.getObject("banned-ips", Array.class, Array::new);
|
||||||
whitelist = Core.settings.getObject("whitelisted", Array.class, Array::new);
|
whitelist = Core.settings.getObject("whitelisted", Array.class, Array::new);
|
||||||
|
subnetBans = Core.settings.getObject("subnet-bans", Array.class, Array::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Server configuration definition. Each config value can be a string, boolean or number. */
|
/** Server configuration definition. Each config value can be a string, boolean or number. */
|
||||||
|
@ -491,6 +491,37 @@ public class ServerControl implements ApplicationListener{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
handler.register("subnet-ban", "[add/remove] [address]", "Ban a subnet. This simply rejects all connections with IPs starting with some string.", arg -> {
|
||||||
|
if(arg.length == 0){
|
||||||
|
Log.info("Subnets banned: &lc{0}", netServer.admins.getSubnetBans().isEmpty() ? "<none>" : "");
|
||||||
|
for(String subnet : netServer.admins.getSubnetBans()){
|
||||||
|
Log.info("&ly " + subnet + "");
|
||||||
|
}
|
||||||
|
}else if(arg.length == 1){
|
||||||
|
err("You must provide a subnet to add or remove.");
|
||||||
|
}else{
|
||||||
|
if(arg[0].equals("add")){
|
||||||
|
if(netServer.admins.getSubnetBans().contains(arg[1])){
|
||||||
|
err("That subnet is already banned.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
netServer.admins.addSubnetBan(arg[1]);
|
||||||
|
Log.info("Banned &ly{0}&lc**", arg[1]);
|
||||||
|
}else if(arg[0].equals("remove")){
|
||||||
|
if(!netServer.admins.getSubnetBans().contains(arg[1])){
|
||||||
|
err("That subnet isn't banned.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
netServer.admins.removeSubnetBan(arg[1]);
|
||||||
|
Log.info("Unbanned &ly{0}&lc**", arg[1]);
|
||||||
|
}else{
|
||||||
|
err("Incorrect usage. You must provide add/remove as the second argument.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
handler.register("whitelisted", "List the entire whitelist.", arg -> {
|
handler.register("whitelisted", "List the entire whitelist.", arg -> {
|
||||||
if(netServer.admins.getWhitelisted().isEmpty()){
|
if(netServer.admins.getWhitelisted().isEmpty()){
|
||||||
info("&lyNo whitelisted players found.");
|
info("&lyNo whitelisted players found.");
|
||||||
|
Loading…
Reference in New Issue
Block a user