use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class NoCheatPlus method postEnable.
/**
* Actions to be done after enable of all plugins. This aims at reloading mainly.
*/
private void postEnable(final Player[] onlinePlayers) {
logManager.info(Streams.INIT, "Post-enable running...");
// Update permission registry internals for permissions preferred to be updated.
// (By now checks should have noted what they want.)
permissionRegistry.arrangePreferKeepUpdated();
final ConfigFile config = ConfigManager.getConfigFile();
try {
// Command protection feature.
if (config.getBoolean(ConfPaths.PROTECT_PLUGINS_HIDE_ACTIVE)) {
setupCommandProtection();
}
} catch (Throwable t) {
logManager.severe(Streams.INIT, "Failed to apply command protection: " + t.getClass().getSimpleName());
logManager.severe(Streams.INIT, t);
}
// TODO: This should be a registered handler.
for (final Player player : onlinePlayers) {
final IPlayerData pData = DataManager.getPlayerData(player);
if (player.isSleeping()) {
pData.getGenericInstance(CombinedData.class).wasInBed = true;
}
}
if (onlinePlayers.length > 0) {
logManager.info(Streams.INIT, "Updated data for " + onlinePlayers.length + " players (post-enable).");
}
// Finished.
logManager.info(Streams.INIT, "Post-enable finished.");
// Log version to file (queued).
logManager.info(Streams.DEFAULT_FILE, StringUtil.join(VersionCommand.getVersionInfo(), "\n"));
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class NoCheatPlus method onJoinLow.
private void onJoinLow(final Player player) {
final String playerName = player.getName();
final IPlayerData data = DataManager.getPlayerData(player);
if (data.hasPermission(Permissions.NOTIFY, player)) {
// Inconsistent config version.
if (configProblemsChat != null && ConfigManager.getConfigFile().getBoolean(ConfPaths.CONFIGVERSION_NOTIFY)) {
// Could use custom prefix from logging, however ncp should be mentioned then.
sendMessageOnTick(playerName, ChatColor.RED + "NCP: " + ChatColor.WHITE + configProblemsChat);
}
// Message if notify is turned off.
if (data.getNotifyOff()) {
sendMessageOnTick(playerName, MSG_NOTIFY_OFF);
}
}
// JoinLeaveListenerS: Do update comment in NoCheatPlusAPI with changing event priority.
for (final JoinLeaveListener jlListener : joinLeaveListeners) {
try {
jlListener.playerJoins(player);
} catch (Throwable t) {
logManager.severe(Streams.INIT, "JoinLeaveListener(" + jlListener.getClass().getName() + ") generated an exception (join): " + t.getClass().getSimpleName());
logManager.severe(Streams.INIT, t);
}
}
// Mod message (left on low instead of lowest to allow some permissions plugins compatibility).
ModUtil.motdOnJoin(player);
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class CatchAllAdapter method onPacketReceiving.
@Override
public void onPacketReceiving(PacketEvent event) {
final Player player = event.getPlayer();
if (player == null) {
counters.add(ProtocolLibComponent.idNullPlayer, 1);
// TODO: Is this a problem, as the server has the player so it could break a block)?
return;
}
final IPlayerData pData = DataManager.getPlayerData(player);
if (packetFrequency.isEnabled(player, pData)) {
final NetConfig cc = pData.getGenericInstance(NetConfig.class);
final NetData data = pData.getGenericInstance(NetData.class);
if (packetFrequency.check(player, data, cc)) {
event.setCancelled(true);
}
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class MovingFlying method onFlyingPacket.
private void onFlyingPacket(final PacketEvent event) {
// TODO: Code review protocol plugin :p.
final boolean primaryThread = Bukkit.isPrimaryThread();
counters.add(idFlying, 1, primaryThread);
if (event.isAsync() == primaryThread) {
counters.add(ProtocolLibComponent.idInconsistentIsAsync, 1, primaryThread);
}
if (!primaryThread) {
// Count all asynchronous events extra.
counters.addSynchronized(idAsyncFlying, 1);
// TODO: Detect game phase for the player?
}
final long time = System.currentTimeMillis();
final Player player = event.getPlayer();
if (player == null) {
// TODO: Need config?
counters.add(ProtocolLibComponent.idNullPlayer, 1, primaryThread);
event.setCancelled(true);
return;
}
final IPlayerData pData = DataManager.getPlayerData(player);
// Always update last received time.
final NetData data = pData.getGenericInstance(NetData.class);
// Update without much of a contract.
data.lastKeepAliveTime = time;
// TODO: Leniency options too (packet order inversion). -> current: flyingQueue is fetched.
final IWorldData worldData = pData.getCurrentWorldDataSafe();
if (!worldData.isCheckActive(CheckType.NET_FLYINGFREQUENCY)) {
return;
}
final NetConfig cc = pData.getGenericInstance(NetConfig.class);
boolean cancel = false;
// Interpret the packet content.
final DataPacketFlying packetData = interpretPacket(event, time);
// Early return tests, if the packet can be interpreted.
boolean skipFlyingFrequency = false;
if (packetData != null) {
// Prevent processing packets with obviously malicious content.
if (isInvalidContent(packetData)) {
// TODO: extra actions: log and kick (cancel state is not evaluated)
event.setCancelled(true);
if (pData.isDebugActive(this.checkType)) {
debug(player, "Incoming packet, cancel due to malicious content: " + packetData.toString());
}
return;
}
switch(data.teleportQueue.processAck(packetData)) {
case WAITING:
{
if (pData.isDebugActive(this.checkType)) {
debug(player, "Incoming packet, still waiting for ACK on outgoing position.");
}
if (confirmTeleportType != null && cc.supersededFlyingCancelWaiting) {
// Don't add to the flying queue for now (assumed invalid).
final AckReference ackReference = data.teleportQueue.getLastAckReference();
if (ackReference.lastOutgoingId != Integer.MIN_VALUE && ackReference.lastOutgoingId != ackReference.maxConfirmedId) {
// Still waiting for a 'confirm teleport' packet. More or less safe to cancel this out.
/*
* TODO: The actual issue with this, apart from
* potential freezing, also concerns gameplay experience
* in case of minor set backs, which also could be
* caused by the server, e.g. with 'moved wrongly' or
* setting players outside of blocks. In this case the
* moves sent before teleport ack would still be valid
* after the teleport, because distances are small. The
* actual solution should still be to a) not have false
* positives b) somehow get rid all the
* position-correction teleporting the server does, for
* the cases a plugin can handle.
*/
// TODO: Timeout -> either skip cancel or schedule a set back (to last valid pos or other).
// TODO: Config?
cancel = true;
}
}
break;
}
case ACK:
{
// Skip processing ACK packets, no cancel.
skipFlyingFrequency = true;
if (pData.isDebugActive(this.checkType)) {
debug(player, "Incoming packet, interpret as ACK for outgoing position.");
}
}
default:
{
// Continue.
// TODO: Not the optimal position, perhaps.
data.addFlyingQueue(packetData);
}
}
// Add as valid packet (exclude invalid coordinates etc. for now).
validContent.add(packetData.getSimplifiedContentType());
}
// TODO: Consider using the NetStatic check.
if (!cancel && !skipFlyingFrequency && !pData.hasBypass(CheckType.NET_FLYINGFREQUENCY, player) && flyingFrequency.check(player, packetData, time, data, cc, pData)) {
cancel = true;
}
// Process cancel and debug log.
if (cancel) {
event.setCancelled(true);
}
if (pData.isDebugActive(this.checkType)) {
debug(player, (packetData == null ? "(Incompatible data)" : packetData.toString()) + (event.isCancelled() ? " CANCEL" : ""));
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class OutgoingPosition method onPacketSending.
@Override
public void onPacketSending(PacketEvent event) {
if (event.isCancelled()) {
return;
}
final long time = System.currentTimeMillis();
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
// TODO: In future multiple checks might use this (!)
if (pData.isCheckActive(CheckType.NET_FLYINGFREQUENCY, player)) {
interpretPacket(player, event.getPacket(), time, pData.getGenericInstance(NetData.class), pData.isDebugActive(CheckType.NET_FLYINGFREQUENCY));
}
}
Aggregations