diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java b/src/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java index 8bb807ca..7433e49a 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/ChatConfig.java @@ -127,6 +127,7 @@ public class ChatConfig extends AsyncCheckConfig { public final int loginsSeconds; public final int loginsLimit; public final String loginsKickMessage; + public final long loginsStartupDelay; public final boolean opInConsoleOnly; @@ -214,6 +215,7 @@ public class ChatConfig extends AsyncCheckConfig { loginsSeconds = config.getInt(ConfPaths.CHAT_LOGINS_SECONDS); loginsLimit = config.getInt(ConfPaths.CHAT_LOGINS_LIMIT); loginsKickMessage = config.getString(ConfPaths.CHAT_LOGINS_KICKMESSAGE); + loginsStartupDelay = config.getInt(ConfPaths.CHAT_LOGINS_STARTUPDELAY) * 1000; relogCheck = config.getBoolean(ConfPaths.CHAT_RELOG_CHECK); relogKickMessage = config.getString(ConfPaths.CHAT_RELOG_KICKMESSAGE); diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/Logins.java b/src/fr/neatmonster/nocheatplus/checks/chat/Logins.java index 716240b2..aa929dd5 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/Logins.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/Logins.java @@ -8,6 +8,7 @@ import org.bukkit.entity.Player; import fr.neatmonster.nocheatplus.checks.Check; import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.utilities.ActionFrequency; +import fr.neatmonster.nocheatplus.utilities.TickTask; 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) { + 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. final long durBucket = 1000L * cc.loginsSeconds / 6; final ActionFrequency freq = getActionFrequency(player.getWorld().getName(), 6, durBucket, cc.loginsPerWorldCount); - final long now = System.currentTimeMillis(); freq.update(now); final boolean cancel = freq.getScore(1f) > cc.loginsLimit; if (!cancel) freq.add(now, 1f); diff --git a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java index 4bb1eae1..5cf182fd 100644 --- a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -278,6 +278,7 @@ public abstract class ConfPaths { 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_KICKMESSAGE = CHAT_LOGINS + "kickmessage"; + public static final String CHAT_LOGINS_STARTUPDELAY = CHAT_LOGINS + "startupdelay"; private static final String CHAT_RELOG = CHAT + "relog."; public static final String CHAT_RELOG_CHECK = CHAT_RELOG + "active"; diff --git a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java index 128c7c3b..f638ebdc 100644 --- a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -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"); // Logins set(ConfPaths.CHAT_LOGINS_CHECK, true); + set(ConfPaths.CHAT_LOGINS_STARTUPDELAY, 300); set(ConfPaths.CHAT_LOGINS_PERWORLDCOUNT, false); set(ConfPaths.CHAT_LOGINS_SECONDS, 10); set(ConfPaths.CHAT_LOGINS_LIMIT, 6); diff --git a/src/fr/neatmonster/nocheatplus/utilities/TickTask.java b/src/fr/neatmonster/nocheatplus/utilities/TickTask.java index 30ee491a..3e171de6 100644 --- a/src/fr/neatmonster/nocheatplus/utilities/TickTask.java +++ b/src/fr/neatmonster/nocheatplus/utilities/TickTask.java @@ -56,6 +56,8 @@ public class TickTask implements Runnable { protected static int tick = 0; + protected static long timeStart = 0; + ////////////////////////////////////////////////////////////// // Special static methods, usually not called from outside. @@ -131,6 +133,14 @@ public class TickTask implements Runnable { return tick; } + /** + * Get the time at which the task was started. + * @return + */ + public static final long getTimeStart(){ + return timeStart; + } + //////////////////////////////////////// // Public methods for internal use. //////////////////////////////////////// @@ -138,6 +148,7 @@ public class TickTask implements Runnable { public static int start(final NoCheatPlus plugin){ cancel(); taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new TickTask(), 1, 1); + if (taskId != -1) timeStart = System.currentTimeMillis(); return taskId; }