mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-07 03:02:11 +01:00
Add startupdelay to Logins check.
This commit is contained in:
parent
b2d6608eaa
commit
efabd0536b
@ -127,6 +127,7 @@ public class ChatConfig extends AsyncCheckConfig {
|
|||||||
public final int loginsSeconds;
|
public final int loginsSeconds;
|
||||||
public final int loginsLimit;
|
public final int loginsLimit;
|
||||||
public final String loginsKickMessage;
|
public final String loginsKickMessage;
|
||||||
|
public final long loginsStartupDelay;
|
||||||
|
|
||||||
public final boolean opInConsoleOnly;
|
public final boolean opInConsoleOnly;
|
||||||
|
|
||||||
@ -214,6 +215,7 @@ public class ChatConfig extends AsyncCheckConfig {
|
|||||||
loginsSeconds = config.getInt(ConfPaths.CHAT_LOGINS_SECONDS);
|
loginsSeconds = config.getInt(ConfPaths.CHAT_LOGINS_SECONDS);
|
||||||
loginsLimit = config.getInt(ConfPaths.CHAT_LOGINS_LIMIT);
|
loginsLimit = config.getInt(ConfPaths.CHAT_LOGINS_LIMIT);
|
||||||
loginsKickMessage = config.getString(ConfPaths.CHAT_LOGINS_KICKMESSAGE);
|
loginsKickMessage = config.getString(ConfPaths.CHAT_LOGINS_KICKMESSAGE);
|
||||||
|
loginsStartupDelay = config.getInt(ConfPaths.CHAT_LOGINS_STARTUPDELAY) * 1000;
|
||||||
|
|
||||||
relogCheck = config.getBoolean(ConfPaths.CHAT_RELOG_CHECK);
|
relogCheck = config.getBoolean(ConfPaths.CHAT_RELOG_CHECK);
|
||||||
relogKickMessage = config.getString(ConfPaths.CHAT_RELOG_KICKMESSAGE);
|
relogKickMessage = config.getString(ConfPaths.CHAT_RELOG_KICKMESSAGE);
|
||||||
|
@ -8,6 +8,7 @@ import org.bukkit.entity.Player;
|
|||||||
import fr.neatmonster.nocheatplus.checks.Check;
|
import fr.neatmonster.nocheatplus.checks.Check;
|
||||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||||
import fr.neatmonster.nocheatplus.utilities.ActionFrequency;
|
import fr.neatmonster.nocheatplus.utilities.ActionFrequency;
|
||||||
|
import fr.neatmonster.nocheatplus.utilities.TickTask;
|
||||||
|
|
||||||
public class Logins extends Check {
|
public class Logins extends Check {
|
||||||
|
|
||||||
@ -27,10 +28,12 @@ public class Logins extends Check {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean check(final Player player, final ChatConfig cc, final ChatData data) {
|
public boolean check(final Player player, final ChatConfig cc, final ChatData data) {
|
||||||
|
final long now = System.currentTimeMillis();
|
||||||
|
// Skip if is too close to the startup time.
|
||||||
|
if (now - TickTask.getTimeStart() < cc.loginsStartupDelay) return false;
|
||||||
// Split into 6 buckets always.
|
// Split into 6 buckets always.
|
||||||
final long durBucket = 1000L * cc.loginsSeconds / 6;
|
final long durBucket = 1000L * cc.loginsSeconds / 6;
|
||||||
final ActionFrequency freq = getActionFrequency(player.getWorld().getName(), 6, durBucket, cc.loginsPerWorldCount);
|
final ActionFrequency freq = getActionFrequency(player.getWorld().getName(), 6, durBucket, cc.loginsPerWorldCount);
|
||||||
final long now = System.currentTimeMillis();
|
|
||||||
freq.update(now);
|
freq.update(now);
|
||||||
final boolean cancel = freq.getScore(1f) > cc.loginsLimit;
|
final boolean cancel = freq.getScore(1f) > cc.loginsLimit;
|
||||||
if (!cancel) freq.add(now, 1f);
|
if (!cancel) freq.add(now, 1f);
|
||||||
|
@ -278,6 +278,7 @@ public abstract class ConfPaths {
|
|||||||
public static final String CHAT_LOGINS_SECONDS = CHAT_LOGINS + "seconds";
|
public static final String CHAT_LOGINS_SECONDS = CHAT_LOGINS + "seconds";
|
||||||
public static final String CHAT_LOGINS_LIMIT = CHAT_LOGINS + "limit";
|
public static final String CHAT_LOGINS_LIMIT = CHAT_LOGINS + "limit";
|
||||||
public static final String CHAT_LOGINS_KICKMESSAGE = CHAT_LOGINS + "kickmessage";
|
public static final String CHAT_LOGINS_KICKMESSAGE = CHAT_LOGINS + "kickmessage";
|
||||||
|
public static final String CHAT_LOGINS_STARTUPDELAY = CHAT_LOGINS + "startupdelay";
|
||||||
|
|
||||||
private static final String CHAT_RELOG = CHAT + "relog.";
|
private static final String CHAT_RELOG = CHAT + "relog.";
|
||||||
public static final String CHAT_RELOG_CHECK = CHAT_RELOG + "active";
|
public static final String CHAT_RELOG_CHECK = CHAT_RELOG + "active";
|
||||||
|
@ -219,6 +219,7 @@ public class DefaultConfig extends ConfigFile {
|
|||||||
set(ConfPaths.CHAT_RELOG_ACTIONS, "log:relog:0:10:cf cancel vl>20 log:relog:0:10:cf cancel cmd:tempkick5");
|
set(ConfPaths.CHAT_RELOG_ACTIONS, "log:relog:0:10:cf cancel vl>20 log:relog:0:10:cf cancel cmd:tempkick5");
|
||||||
// Logins
|
// Logins
|
||||||
set(ConfPaths.CHAT_LOGINS_CHECK, true);
|
set(ConfPaths.CHAT_LOGINS_CHECK, true);
|
||||||
|
set(ConfPaths.CHAT_LOGINS_STARTUPDELAY, 300);
|
||||||
set(ConfPaths.CHAT_LOGINS_PERWORLDCOUNT, false);
|
set(ConfPaths.CHAT_LOGINS_PERWORLDCOUNT, false);
|
||||||
set(ConfPaths.CHAT_LOGINS_SECONDS, 10);
|
set(ConfPaths.CHAT_LOGINS_SECONDS, 10);
|
||||||
set(ConfPaths.CHAT_LOGINS_LIMIT, 6);
|
set(ConfPaths.CHAT_LOGINS_LIMIT, 6);
|
||||||
|
@ -56,6 +56,8 @@ public class TickTask implements Runnable {
|
|||||||
|
|
||||||
protected static int tick = 0;
|
protected static int tick = 0;
|
||||||
|
|
||||||
|
protected static long timeStart = 0;
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
// Special static methods, usually not called from outside.
|
// Special static methods, usually not called from outside.
|
||||||
@ -131,6 +133,14 @@ public class TickTask implements Runnable {
|
|||||||
return tick;
|
return tick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the time at which the task was started.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static final long getTimeStart(){
|
||||||
|
return timeStart;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
// Public methods for internal use.
|
// Public methods for internal use.
|
||||||
////////////////////////////////////////
|
////////////////////////////////////////
|
||||||
@ -138,6 +148,7 @@ public class TickTask implements Runnable {
|
|||||||
public static int start(final NoCheatPlus plugin){
|
public static int start(final NoCheatPlus plugin){
|
||||||
cancel();
|
cancel();
|
||||||
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new TickTask(), 1, 1);
|
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new TickTask(), 1, 1);
|
||||||
|
if (taskId != -1) timeStart = System.currentTimeMillis();
|
||||||
return taskId;
|
return taskId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user