2016-06-02 20:14:09 +02:00
|
|
|
/*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2015-11-24 06:35:58 +01:00
|
|
|
package fr.neatmonster.nocheatplus.checks.net;
|
2015-11-16 12:29:39 +01:00
|
|
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import fr.neatmonster.nocheatplus.actions.ParameterName;
|
|
|
|
import fr.neatmonster.nocheatplus.checks.Check;
|
|
|
|
import fr.neatmonster.nocheatplus.checks.CheckType;
|
|
|
|
import fr.neatmonster.nocheatplus.checks.ViolationData;
|
[BROKEN] Data storage overhaul (basics). (+)
(SAFETY COMMIT)
Largely breaking change.
* Interfaces in front of data types (and 'managers'), some interfaces
removed.
* Data and configuration fetching.
* Check activation checking (config flags, isEnabled, hasBypass).
* CheckType (activation checks, factories removed).
* Lots of collateral signature changes, including IPlayerData.
The (I)WorldDataManager stores per-world data (+ per world per check
type).
* Raw configurations.
* Typical flags: check activation, debug, lag adaption.
* Generic data, such as check configurations or per world check data.
The (I)PlayerDataManager stores per player data.
* Check Data.
* Typical flags: debug
* Exemption
* Check data (and config cache).
* Further mappings and later OfflinePlayerData.
* The registration interface will allow defining, how instances are
handled for registered types (factory, proxy, what on world change, what
on logout, global removal handler, per player removal handler).
(I)PlayerData is intended to be/become the central access point.
* External interface is IPlayerData now.
* Per player debug flags, exemptions.
* Fetching configuration and data: local cache, relaying fetching to
registered factories and proxy-registries/storage (e.g. fetching
configuration from per world storage).
Other fixes/changes:
(+) Extend the debug player command (set true/false, reset to world
default, arbitrary check types).
(+) PlayerData maintains a currentWorldIdentifier (to be used instead of
ChatData in future).
(+) The WorldConfigProvider getAll implementation returns a
LinkedHashSet now, avoiding duplicates.
(+) Move DefaultGenericInstanceRegistry to NCPCore.
(+) Thread-safety considerations for DefaultGenericInstanceRegistry.
(+) Don't log errors on hasBypass checking. TBD: Instead intercept
during listener methods (or even as a feature within the listener node:
e.g. @ThreadContext(primaryThread=true, skipOffContext=true,
cancelOffContext=true).
(+) Add fight.wrongturn permissions to plugin.yml.
(+) Missing GPLv3 headers.
Broken/Missing:
* WorldData inheritance from default: propagate all changes done
directly to the default config to children (all worlds that don't have
an explicit world_config.yml set) - possibly add an OverrideState or
similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if
coming from the default. Calling override on the default WorldData is
not to be confused with calling override for WorldDataManager (override
for all worlds as EXPLICIT).
* Organize overriding for special circumstances (version dependent
activation and the like). Might want to add registered override
handlers to be called on reload automatically.
* Store generic per check type per world data in the WorldDataManager,
such as configurations and per-world check data. TBD: Factories, cleanup
(!).
* Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?).
* All the registry stuff (see PlayerData).
* Use interfaces for auto registry (and a flag within
RegistrationContext?) - world unload, world change, player join / leave.
* (Data expiration handling including transition to IOfflinePlayerData,
because now data is a little heavier.)
* Further details.
2018-02-13 15:15:23 +01:00
|
|
|
import fr.neatmonster.nocheatplus.players.IPlayerData;
|
2015-11-16 12:59:22 +01:00
|
|
|
import fr.neatmonster.nocheatplus.utilities.TickTask;
|
2015-11-16 12:29:39 +01:00
|
|
|
|
|
|
|
public class AttackFrequency extends Check {
|
|
|
|
|
|
|
|
public AttackFrequency() {
|
|
|
|
super(CheckType.NET_ATTACKFREQUENCY);
|
|
|
|
}
|
|
|
|
|
[BROKEN] Data storage overhaul (basics). (+)
(SAFETY COMMIT)
Largely breaking change.
* Interfaces in front of data types (and 'managers'), some interfaces
removed.
* Data and configuration fetching.
* Check activation checking (config flags, isEnabled, hasBypass).
* CheckType (activation checks, factories removed).
* Lots of collateral signature changes, including IPlayerData.
The (I)WorldDataManager stores per-world data (+ per world per check
type).
* Raw configurations.
* Typical flags: check activation, debug, lag adaption.
* Generic data, such as check configurations or per world check data.
The (I)PlayerDataManager stores per player data.
* Check Data.
* Typical flags: debug
* Exemption
* Check data (and config cache).
* Further mappings and later OfflinePlayerData.
* The registration interface will allow defining, how instances are
handled for registered types (factory, proxy, what on world change, what
on logout, global removal handler, per player removal handler).
(I)PlayerData is intended to be/become the central access point.
* External interface is IPlayerData now.
* Per player debug flags, exemptions.
* Fetching configuration and data: local cache, relaying fetching to
registered factories and proxy-registries/storage (e.g. fetching
configuration from per world storage).
Other fixes/changes:
(+) Extend the debug player command (set true/false, reset to world
default, arbitrary check types).
(+) PlayerData maintains a currentWorldIdentifier (to be used instead of
ChatData in future).
(+) The WorldConfigProvider getAll implementation returns a
LinkedHashSet now, avoiding duplicates.
(+) Move DefaultGenericInstanceRegistry to NCPCore.
(+) Thread-safety considerations for DefaultGenericInstanceRegistry.
(+) Don't log errors on hasBypass checking. TBD: Instead intercept
during listener methods (or even as a feature within the listener node:
e.g. @ThreadContext(primaryThread=true, skipOffContext=true,
cancelOffContext=true).
(+) Add fight.wrongturn permissions to plugin.yml.
(+) Missing GPLv3 headers.
Broken/Missing:
* WorldData inheritance from default: propagate all changes done
directly to the default config to children (all worlds that don't have
an explicit world_config.yml set) - possibly add an OverrideState or
similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if
coming from the default. Calling override on the default WorldData is
not to be confused with calling override for WorldDataManager (override
for all worlds as EXPLICIT).
* Organize overriding for special circumstances (version dependent
activation and the like). Might want to add registered override
handlers to be called on reload automatically.
* Store generic per check type per world data in the WorldDataManager,
such as configurations and per-world check data. TBD: Factories, cleanup
(!).
* Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?).
* All the registry stuff (see PlayerData).
* Use interfaces for auto registry (and a flag within
RegistrationContext?) - world unload, world change, player join / leave.
* (Data expiration handling including transition to IOfflinePlayerData,
because now data is a little heavier.)
* Further details.
2018-02-13 15:15:23 +01:00
|
|
|
public boolean check(final Player player, final long time,
|
|
|
|
final NetData data, final NetConfig cc, final IPlayerData pData) {
|
2015-11-16 12:29:39 +01:00
|
|
|
// Update frequency.
|
|
|
|
data.attackFrequencySeconds.add(time, 1f);
|
|
|
|
double maxVL = 0.0;
|
|
|
|
float maxLimit = 0f;
|
|
|
|
String tags = null;
|
|
|
|
// TODO: option to normalize the vl / stats to per second?
|
|
|
|
// HALF
|
|
|
|
float sum = data.attackFrequencySeconds.bucketScore(0); // HALF
|
|
|
|
float limit = cc.attackFrequencyLimitSecondsHalf;
|
|
|
|
if (sum - limit > maxVL) {
|
|
|
|
maxVL = sum - limit;
|
|
|
|
maxLimit = limit;
|
|
|
|
tags = "sec_half";
|
|
|
|
}
|
|
|
|
// ONE (update sum).
|
|
|
|
sum += data.attackFrequencySeconds.bucketScore(1);
|
|
|
|
limit = cc.attackFrequencyLimitSecondsOne;
|
|
|
|
if (sum - limit > maxVL) {
|
|
|
|
maxVL = sum - limit;
|
|
|
|
maxLimit = limit;
|
|
|
|
tags = "sec_one";
|
|
|
|
}
|
|
|
|
// TWO (update sum).
|
|
|
|
sum += data.attackFrequencySeconds.sliceScore(2, 4, 1f);
|
|
|
|
limit = cc.attackFrequencyLimitSecondsTwo;
|
|
|
|
if (sum - limit > maxVL) {
|
|
|
|
maxVL = sum - limit;
|
|
|
|
maxLimit = limit;
|
|
|
|
tags = "sec_two";
|
|
|
|
}
|
|
|
|
// FOUR (update sum).
|
|
|
|
sum += data.attackFrequencySeconds.sliceScore(4, 8, 1f);
|
|
|
|
limit = cc.attackFrequencyLimitSecondsFour;
|
|
|
|
if (sum - limit > maxVL) {
|
|
|
|
maxVL = sum - limit;
|
|
|
|
maxLimit = limit;
|
|
|
|
tags = "sec_four";
|
|
|
|
}
|
|
|
|
// EIGHT (update sum).
|
|
|
|
sum += data.attackFrequencySeconds.sliceScore(8, 16, 1f);
|
|
|
|
limit = cc.attackFrequencyLimitSecondsEight;
|
|
|
|
if (sum - limit > maxVL) {
|
|
|
|
maxVL = sum - limit;
|
|
|
|
maxLimit = limit;
|
|
|
|
tags = "sec_eight";
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (data.debug) {
|
|
|
|
// player.sendMessage("AttackFrequency: " + data.attackFrequencySeconds.toLine());
|
|
|
|
// }
|
|
|
|
|
|
|
|
boolean cancel = false;
|
|
|
|
if (maxVL > 0.0) {
|
|
|
|
// Trigger a violation.
|
|
|
|
final ViolationData vd = new ViolationData(this, player, maxVL, 1.0, cc.attackFrequencyActions);
|
[BROKEN] Data storage overhaul (basics). (+)
(SAFETY COMMIT)
Largely breaking change.
* Interfaces in front of data types (and 'managers'), some interfaces
removed.
* Data and configuration fetching.
* Check activation checking (config flags, isEnabled, hasBypass).
* CheckType (activation checks, factories removed).
* Lots of collateral signature changes, including IPlayerData.
The (I)WorldDataManager stores per-world data (+ per world per check
type).
* Raw configurations.
* Typical flags: check activation, debug, lag adaption.
* Generic data, such as check configurations or per world check data.
The (I)PlayerDataManager stores per player data.
* Check Data.
* Typical flags: debug
* Exemption
* Check data (and config cache).
* Further mappings and later OfflinePlayerData.
* The registration interface will allow defining, how instances are
handled for registered types (factory, proxy, what on world change, what
on logout, global removal handler, per player removal handler).
(I)PlayerData is intended to be/become the central access point.
* External interface is IPlayerData now.
* Per player debug flags, exemptions.
* Fetching configuration and data: local cache, relaying fetching to
registered factories and proxy-registries/storage (e.g. fetching
configuration from per world storage).
Other fixes/changes:
(+) Extend the debug player command (set true/false, reset to world
default, arbitrary check types).
(+) PlayerData maintains a currentWorldIdentifier (to be used instead of
ChatData in future).
(+) The WorldConfigProvider getAll implementation returns a
LinkedHashSet now, avoiding duplicates.
(+) Move DefaultGenericInstanceRegistry to NCPCore.
(+) Thread-safety considerations for DefaultGenericInstanceRegistry.
(+) Don't log errors on hasBypass checking. TBD: Instead intercept
during listener methods (or even as a feature within the listener node:
e.g. @ThreadContext(primaryThread=true, skipOffContext=true,
cancelOffContext=true).
(+) Add fight.wrongturn permissions to plugin.yml.
(+) Missing GPLv3 headers.
Broken/Missing:
* WorldData inheritance from default: propagate all changes done
directly to the default config to children (all worlds that don't have
an explicit world_config.yml set) - possibly add an OverrideState or
similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if
coming from the default. Calling override on the default WorldData is
not to be confused with calling override for WorldDataManager (override
for all worlds as EXPLICIT).
* Organize overriding for special circumstances (version dependent
activation and the like). Might want to add registered override
handlers to be called on reload automatically.
* Store generic per check type per world data in the WorldDataManager,
such as configurations and per-world check data. TBD: Factories, cleanup
(!).
* Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?).
* All the registry stuff (see PlayerData).
* Use interfaces for auto registry (and a flag within
RegistrationContext?) - world unload, world change, player join / leave.
* (Data expiration handling including transition to IOfflinePlayerData,
because now data is a little heavier.)
* Further details.
2018-02-13 15:15:23 +01:00
|
|
|
if (pData.isDebugActive(type) || vd.needsParameters()) {
|
2015-11-16 12:29:39 +01:00
|
|
|
vd.setParameter(ParameterName.PACKETS, Integer.toString((int) sum));
|
|
|
|
vd.setParameter(ParameterName.LIMIT, Integer.toString((int) maxLimit));
|
|
|
|
vd.setParameter(ParameterName.TAGS, tags);
|
|
|
|
}
|
[BREAKING][BLEEDING] Adjust the API to the upcoming penalty framework.
This is a first step in, which doesn't change the default behavior,
however it might break plugins that rely on certain internals.
PenaltyAction allows to do something with probabilities to consider,
including the possibility to select the first applicable penalty or
applying several penalties. There will be player-specific penalties,
which are applied during ViolationData.executeActions always, and there
will be input-specific penalties, e.g. for applying within the event
listener.
Potentially breaking:
* Return value of executeActions is now void for Action + ViolationData.
* Return value of Check.executeActions is ViolationData now.
* CancelAction is now extending PenaltyAction.
* CancelPenalty may cancel, but might not, due to probability.
* IViolationInfo.hasCancel -> deprecated, now returns willCancel().
* IViolationInfo.willCancel is now used, applicable penalties are
estimated on creation of ViolationData.
* Custom actions can no longer be used to cause cancel. Only penalties
can do so now (due to the return type change). CancelAction is still
there to keep a simple action for canceling.
Not yet:
* InputSpecificPenalty support for fight checks and using them in the
default actions.
* Configuration for penalties (currently only a plugin could override
the action factories, later penalties may have a probability to apply,
reference each other, allow first match, apply several at once).
2016-02-10 00:05:11 +01:00
|
|
|
if (executeActions(vd).willCancel()) {
|
2015-11-16 12:29:39 +01:00
|
|
|
cancel = true;
|
|
|
|
}
|
2015-11-16 12:59:22 +01:00
|
|
|
// Feed Improbable.
|
|
|
|
TickTask.requestImprobableUpdate(player.getUniqueId(), 2f);
|
2015-11-16 12:29:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|