More tweaks to Karst / Default player limit of 30
This commit is contained in:
Binary file not shown.
@@ -224,6 +224,13 @@ public class NetClient implements ApplicationListener{
|
|||||||
//do not receive chat messages from clients that are too young or not registered
|
//do not receive chat messages from clients that are too young or not registered
|
||||||
if(net.server() && player != null && player.con != null && (Time.timeSinceMillis(player.con.connectTime) < 500 || !player.con.hasConnected || !player.isAdded())) return;
|
if(net.server() && player != null && player.con != null && (Time.timeSinceMillis(player.con.connectTime) < 500 || !player.con.hasConnected || !player.isAdded())) return;
|
||||||
|
|
||||||
|
//detect and kick for foul play
|
||||||
|
if(player != null && player.con != null && !player.con.chatRate.allow(2000, 20)){
|
||||||
|
player.con.kick(KickReason.kick);
|
||||||
|
netServer.admins.blacklistDos(player.con.address);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(message.length() > maxTextLength){
|
if(message.length() > maxTextLength){
|
||||||
throw new ValidateException(player, "Player has sent a message above the text limit.");
|
throw new ValidateException(player, "Player has sent a message above the text limit.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public class Administration{
|
|||||||
public Seq<ChatFilter> chatFilters = new Seq<>();
|
public Seq<ChatFilter> chatFilters = new Seq<>();
|
||||||
public Seq<ActionFilter> actionFilters = new Seq<>();
|
public Seq<ActionFilter> actionFilters = new Seq<>();
|
||||||
public Seq<String> subnetBans = new Seq<>();
|
public Seq<String> subnetBans = new Seq<>();
|
||||||
|
public ObjectSet<String> dosBlacklist = new ObjectSet<>();
|
||||||
public ObjectMap<String, Long> kickedIPs = new ObjectMap<>();
|
public ObjectMap<String, Long> kickedIPs = new ObjectMap<>();
|
||||||
|
|
||||||
/** All player info. Maps UUIDs to info. This persists throughout restarts. Do not access directly. */
|
/** All player info. Maps UUIDs to info. This persists throughout restarts. Do not access directly. */
|
||||||
@@ -83,6 +84,14 @@ public class Administration{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void blacklistDos(String address){
|
||||||
|
dosBlacklist.add(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean isDosBlacklisted(String address){
|
||||||
|
return dosBlacklist.contains(address);
|
||||||
|
}
|
||||||
|
|
||||||
/** @return time at which a player would be pardoned for a kick (0 means they were never kicked) */
|
/** @return time at which a player would be pardoned for a kick (0 means they were never kicked) */
|
||||||
public long getKickTime(String uuid, String ip){
|
public long getKickTime(String uuid, String ip){
|
||||||
return Math.max(getInfo(uuid).lastKicked, kickedIPs.get(ip, 0L));
|
return Math.max(getInfo(uuid).lastKicked, kickedIPs.get(ip, 0L));
|
||||||
@@ -162,7 +171,7 @@ public class Administration{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getPlayerLimit(){
|
public int getPlayerLimit(){
|
||||||
return Core.settings.getInt("playerlimit", 0);
|
return Core.settings.getInt("playerlimit", headless ? 30 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayerLimit(int limit){
|
public void setPlayerLimit(int limit){
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import arc.util.*;
|
|||||||
import arc.util.Log.*;
|
import arc.util.Log.*;
|
||||||
import arc.util.io.*;
|
import arc.util.io.*;
|
||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
|
import mindustry.game.EventType.*;
|
||||||
import mindustry.net.Net.*;
|
import mindustry.net.Net.*;
|
||||||
import mindustry.net.Packets.*;
|
import mindustry.net.Packets.*;
|
||||||
import net.jpountz.lz4.*;
|
import net.jpountz.lz4.*;
|
||||||
@@ -19,7 +20,6 @@ import java.io.*;
|
|||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
import java.nio.channels.*;
|
import java.nio.channels.*;
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
@@ -35,6 +35,8 @@ public class ArcNetProvider implements NetProvider{
|
|||||||
private static final LZ4FastDecompressor decompressor = LZ4Factory.fastestInstance().fastDecompressor();
|
private static final LZ4FastDecompressor decompressor = LZ4Factory.fastestInstance().fastDecompressor();
|
||||||
private static final LZ4Compressor compressor = LZ4Factory.fastestInstance().fastCompressor();
|
private static final LZ4Compressor compressor = LZ4Factory.fastestInstance().fastCompressor();
|
||||||
|
|
||||||
|
private volatile int playerLimitCache;
|
||||||
|
|
||||||
public ArcNetProvider(){
|
public ArcNetProvider(){
|
||||||
ArcNet.errorHandler = e -> {
|
ArcNet.errorHandler = e -> {
|
||||||
if(Log.level == LogLevel.debug){
|
if(Log.level == LogLevel.debug){
|
||||||
@@ -42,6 +44,11 @@ public class ArcNetProvider implements NetProvider{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//fetch this in the main thread to prevent threading issues
|
||||||
|
Events.run(Trigger.update, () -> {
|
||||||
|
playerLimitCache = netServer.admins.getPlayerLimit();
|
||||||
|
});
|
||||||
|
|
||||||
client = new Client(8192, 8192, new PacketSerializer());
|
client = new Client(8192, 8192, new PacketSerializer());
|
||||||
client.setDiscoveryPacket(packetSupplier);
|
client.setDiscoveryPacket(packetSupplier);
|
||||||
client.addListener(new NetListener(){
|
client.addListener(new NetListener(){
|
||||||
@@ -94,6 +101,12 @@ public class ArcNetProvider implements NetProvider{
|
|||||||
public void connected(Connection connection){
|
public void connected(Connection connection){
|
||||||
String ip = connection.getRemoteAddressTCP().getAddress().getHostAddress();
|
String ip = connection.getRemoteAddressTCP().getAddress().getHostAddress();
|
||||||
|
|
||||||
|
//kill connections above the limit to prevent spam
|
||||||
|
if((playerLimitCache > 0 && server.getConnections().length > playerLimitCache) || netServer.admins.isDosBlacklisted(ip)){
|
||||||
|
connection.close(DcReason.closed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ArcConnection kn = new ArcConnection(ip, connection);
|
ArcConnection kn = new ArcConnection(ip, connection);
|
||||||
|
|
||||||
Connect c = new Connect();
|
Connect c = new Connect();
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ public abstract class NetConnection{
|
|||||||
public long lastReceivedClientTime;
|
public long lastReceivedClientTime;
|
||||||
/** Build requests that have been recently rejected. This is cleared every snapshot. */
|
/** Build requests that have been recently rejected. This is cleared every snapshot. */
|
||||||
public Seq<BuildPlan> rejectedRequests = new Seq<>();
|
public Seq<BuildPlan> rejectedRequests = new Seq<>();
|
||||||
|
/** Handles chat spam rate limits. */
|
||||||
|
public Ratekeeper chatRate = new Ratekeeper();
|
||||||
|
|
||||||
public boolean hasConnected, hasBegunConnecting, hasDisconnected;
|
public boolean hasConnected, hasBegunConnecting, hasDisconnected;
|
||||||
public float viewWidth, viewHeight, viewX, viewY;
|
public float viewWidth, viewHeight, viewX, viewY;
|
||||||
|
|||||||
Reference in New Issue
Block a user