mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-02 08:40:01 +01:00
Exempt commands from all nopwnage checks but speed and first.
This commit is contained in:
parent
45951b5013
commit
568314770c
@ -61,7 +61,7 @@ public class ChatListener implements Listener {
|
||||
event.setMessage(color.check(player, event.getMessage(), false));
|
||||
|
||||
// Then the no pwnage check.
|
||||
if (noPwnage.check(player, event.getMessage(), false))
|
||||
if (noPwnage.check(player, event.getMessage(), false, false))
|
||||
event.setCancelled(true);
|
||||
else if (globalChat.check(player, event.getMessage(), (ICaptcha) noPwnage, false))
|
||||
// Only check those that got through.
|
||||
@ -93,6 +93,9 @@ public class ChatListener implements Listener {
|
||||
* |_|
|
||||
*/
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
// Trim is necessary because the server accepts leading spaces with commands.
|
||||
// TODO: Maybe: only remove the leading whitespace or spaces.
|
||||
final String command = event.getMessage().trim().split(" ")[0].substring(1).toLowerCase();
|
||||
|
||||
final ChatConfig cc = ChatConfig.getConfig(player);
|
||||
@ -119,11 +122,13 @@ public class ChatListener implements Listener {
|
||||
|
||||
// First the color check.
|
||||
event.setMessage(color.check(player, event.getMessage(), true));
|
||||
|
||||
|
||||
final boolean handleAsChat = cc.globalChatCommands.contains(command) || cc.globalChatCommands.contains("/"+command);
|
||||
|
||||
// Then the no pwnage check.
|
||||
if (noPwnage.check(player, event.getMessage(), true))
|
||||
if (noPwnage.check(player, event.getMessage(), !handleAsChat, true))
|
||||
event.setCancelled(true);
|
||||
else if ((cc.globalChatCommands.contains(command) || cc.globalChatCommands.contains("/"+command)) && globalChat.check(player, event.getMessage(), noPwnage, true))
|
||||
else if (handleAsChat && globalChat.check(player, event.getMessage(), noPwnage, true))
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,8 @@ public class NoPwnage extends Check implements ICaptcha{
|
||||
* is the thread the main thread
|
||||
* @return If to cancel the event.
|
||||
*/
|
||||
public boolean check(final Player player, final String message, final boolean isMainThread) {
|
||||
public boolean check(final Player player, final String message, final boolean isCommand,
|
||||
final boolean isMainThread) {
|
||||
if (isMainThread && !isEnabled(player))
|
||||
return false;
|
||||
|
||||
@ -72,7 +73,7 @@ public class NoPwnage extends Check implements ICaptcha{
|
||||
|
||||
// Keep related to ChatData/NoPwnage/Color used lock.
|
||||
synchronized (data) {
|
||||
return unsafeCheck(player, message, isMainThread, cc, data);
|
||||
return unsafeCheck(player, message, isCommand, isMainThread, cc, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,8 +125,8 @@ public class NoPwnage extends Check implements ICaptcha{
|
||||
* the data
|
||||
* @return If to cancel the event.
|
||||
*/
|
||||
private boolean unsafeCheck(final Player player, final String message, final boolean isMainThread,
|
||||
final ChatConfig cc, final ChatData data) {
|
||||
private boolean unsafeCheck(final Player player, final String message, final boolean isCommand,
|
||||
final boolean isMainThread, final ChatConfig cc, final ChatData data) {
|
||||
boolean cancel = false;
|
||||
|
||||
// Don't not check excluded messages/commands.
|
||||
@ -147,7 +148,7 @@ public class NoPwnage extends Check implements ICaptcha{
|
||||
int suspicion = 0;
|
||||
// NoPwnage will remember the last message that caused someone to get banned. If a player repeats that
|
||||
// message within "timeout" milliseconds, the suspicion will be increased by "weight".
|
||||
if (cc.noPwnageBannedCheck && now - lastBanCausingMessageTime < cc.noPwnageBannedTimeout
|
||||
if (!isCommand && cc.noPwnageBannedCheck && now - lastBanCausingMessageTime < cc.noPwnageBannedTimeout
|
||||
&& CheckUtils.isSimilar(message, lastBanCausingMessage, 0.8f))
|
||||
suspicion += cc.noPwnageBannedWeight;
|
||||
|
||||
@ -158,7 +159,7 @@ public class NoPwnage extends Check implements ICaptcha{
|
||||
|
||||
// NoPwnage will check if a player repeats a message that has been sent by another player just before,
|
||||
// within "timeout". If he does, suspicion will be increased by "weight".
|
||||
if (cc.noPwnageGlobalCheck && now - lastGlobalMessageTime < cc.noPwnageGlobalTimeout
|
||||
if (!isCommand && cc.noPwnageGlobalCheck && now - lastGlobalMessageTime < cc.noPwnageGlobalTimeout
|
||||
&& CheckUtils.isSimilar(message, lastGlobalMessage, 0.8f))
|
||||
suspicion += cc.noPwnageGlobalWeight;
|
||||
|
||||
@ -169,13 +170,13 @@ public class NoPwnage extends Check implements ICaptcha{
|
||||
|
||||
// NoPwnage will check if a player repeats his messages within the "timeout" timeframe. Even if the message
|
||||
// is a bit different, it will be counted as being a repetition. The suspicion is increased by "weight".
|
||||
if (cc.noPwnageRepeatCheck && now - data.noPwnageLastMessageTime < cc.noPwnageRepeatTimeout
|
||||
if (!isCommand && cc.noPwnageRepeatCheck && now - data.noPwnageLastMessageTime < cc.noPwnageRepeatTimeout
|
||||
&& CheckUtils.isSimilar(message, data.noPwnageLastMessage, 0.8f))
|
||||
suspicion += cc.noPwnageRepeatWeight;
|
||||
|
||||
// NoPwnage will check if a player moved within the "timeout" timeframe. If he did not move, the suspicion will
|
||||
// be increased by "weight" value.
|
||||
if (cc.noPwnageMoveCheck && now - data.noPwnageLastMovedTime > cc.noPwnageMoveTimeout)
|
||||
if (!isCommand && cc.noPwnageMoveCheck && now - data.noPwnageLastMovedTime > cc.noPwnageMoveTimeout)
|
||||
suspicion += cc.noPwnageMoveWeight;
|
||||
|
||||
// Should a player that reaches the "warnLevel" get a text message telling him that he is under suspicion of
|
||||
|
Loading…
Reference in New Issue
Block a user