Addition of player action flood protector.

This commit is contained in:
MobiusDevelopment
2021-11-08 15:52:50 +00:00
parent 1c6d57c355
commit 259fa858f6
214 changed files with 1376 additions and 3796 deletions

View File

@ -610,6 +610,7 @@ public class Config
public static FloodProtectorConfig FLOOD_PROTECTOR_SENDMAIL;
public static FloodProtectorConfig FLOOD_PROTECTOR_CHARACTER_SELECT;
public static FloodProtectorConfig FLOOD_PROTECTOR_ITEM_AUCTION;
public static FloodProtectorConfig FLOOD_PROTECTOR_PLAYER_ACTION;
// --------------------------------------------------
// NPC Settings
@ -1400,6 +1401,7 @@ public class Config
FLOOD_PROTECTOR_SENDMAIL = new FloodProtectorConfig("SendMailFloodProtector");
FLOOD_PROTECTOR_CHARACTER_SELECT = new FloodProtectorConfig("CharacterSelectFloodProtector");
FLOOD_PROTECTOR_ITEM_AUCTION = new FloodProtectorConfig("ItemAuctionFloodProtector");
FLOOD_PROTECTOR_PLAYER_ACTION = new FloodProtectorConfig("PlayerActionFloodProtector");
final PropertiesParser serverSettings = new PropertiesParser(SERVER_CONFIG_FILE);
GAMESERVER_HOSTNAME = serverSettings.getString("GameserverHostname", "0.0.0.0");
@ -3765,6 +3767,7 @@ public class Config
loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_SENDMAIL, "SendMail", 100);
loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_CHARACTER_SELECT, "CharacterSelect", 30);
loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_ITEM_AUCTION, "ItemAuction", 9);
loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_PLAYER_ACTION, "PlayerAction", 3);
}
/**

View File

@ -37,7 +37,7 @@ import org.l2jmobius.gameserver.network.clientpackets.friend.RequestSendFriendMs
public enum IncomingPackets implements IIncomingPackets<GameClient>
{
LOGOUT(0x00, Logout::new, ConnectionState.AUTHENTICATED, ConnectionState.IN_GAME),
ATTACK(0x01, Attack::new, ConnectionState.IN_GAME),
ATTACK(0x01, AttackRequest::new, ConnectionState.IN_GAME),
REQUEST_START_PLEDGE_WAR(0x03, RequestStartPledgeWar::new, ConnectionState.IN_GAME),
REQUEST_REPLY_START_PLEDGE(0x04, RequestReplyStartPledgeWar::new, ConnectionState.IN_GAME),
REQUEST_STOP_PLEDGE_WAR(0x05, RequestStopPledgeWar::new, ConnectionState.IN_GAME),

View File

@ -54,6 +54,11 @@ public class Action implements IClientIncomingPacket
@Override
public void run(GameClient client)
{
if (!client.getFloodProtectors().getPlayerAction().tryPerformAction("PlayerAction"))
{
return;
}
// Get the current PlayerInstance of the player
final PlayerInstance player = client.getPlayer();
if (player == null)

View File

@ -1,139 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* 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/>.
*/
package org.l2jmobius.gameserver.network.clientpackets;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.enums.PrivateStoreType;
import org.l2jmobius.gameserver.model.PlayerCondOverride;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.WorldObject;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
import org.l2jmobius.gameserver.model.skills.AbnormalType;
import org.l2jmobius.gameserver.model.skills.BuffInfo;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.SystemMessageId;
import org.l2jmobius.gameserver.network.serverpackets.ActionFailed;
/**
* TODO: This class is a copy of AttackRequest, we should get proper structure for both.
*/
public class Attack implements IClientIncomingPacket
{
// cddddc
private int _objectId;
@SuppressWarnings("unused")
private int _originX;
@SuppressWarnings("unused")
private int _originY;
@SuppressWarnings("unused")
private int _originZ;
@SuppressWarnings("unused")
private int _attackId;
@Override
public boolean read(GameClient client, PacketReader packet)
{
_objectId = packet.readD();
_originX = packet.readD();
_originY = packet.readD();
_originZ = packet.readD();
_attackId = packet.readC(); // 0 for simple click 1 for shift-click
return true;
}
@Override
public void run(GameClient client)
{
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
// Avoid Attacks in Boat.
if (player.isPlayable() && player.isInBoat())
{
player.sendPacket(SystemMessageId.THIS_IS_NOT_ALLOWED_WHILE_RIDING_A_FERRY_OR_BOAT);
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
final BuffInfo info = player.getEffectList().getFirstBuffInfoByAbnormalType(AbnormalType.BOT_PENALTY);
if (info != null)
{
for (AbstractEffect effect : info.getEffects())
{
if (!effect.checkCondition(-1))
{
player.sendPacket(SystemMessageId.YOU_HAVE_BEEN_REPORTED_AS_AN_ILLEGAL_PROGRAM_USER_SO_YOUR_ACTIONS_HAVE_BEEN_RESTRICTED);
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
}
}
// avoid using expensive operations if not needed
final WorldObject target;
if (player.getTargetId() == _objectId)
{
target = player.getTarget();
}
else
{
target = World.getInstance().findObject(_objectId);
}
if (target == null)
{
return;
}
if ((!target.isTargetable() || player.isTargetingDisabled()) && !player.canOverrideCond(PlayerCondOverride.TARGET_ALL))
{
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
// Players can't attack objects in the other instances
else if (target.getInstanceWorld() != player.getInstanceWorld())
{
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
// Only GMs can directly attack invisible characters
else if (!target.isVisibleFor(player))
{
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
player.onActionRequest();
if (player.getTarget() != target)
{
target.onAction(player);
}
else if ((target.getObjectId() != player.getObjectId()) && (player.getPrivateStoreType() == PrivateStoreType.NONE) && (player.getActiveRequester() == null))
{
target.onForcedAttack(player);
}
else
{
player.sendPacket(ActionFailed.STATIC_PACKET);
}
}
}

View File

@ -56,12 +56,25 @@ public class AttackRequest implements IClientIncomingPacket
@Override
public void run(GameClient client)
{
if (!client.getFloodProtectors().getPlayerAction().tryPerformAction("PlayerAction"))
{
return;
}
final PlayerInstance player = client.getPlayer();
if (player == null)
{
return;
}
// Avoid Attacks in Boat.
if (player.isPlayable() && player.isInBoat())
{
player.sendPacket(SystemMessageId.THIS_IS_NOT_ALLOWED_WHILE_RIDING_A_FERRY_OR_BOAT);
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
final BuffInfo info = player.getEffectList().getFirstBuffInfoByAbnormalType(AbnormalType.BOT_PENALTY);
if (info != null)
{
@ -92,7 +105,8 @@ public class AttackRequest implements IClientIncomingPacket
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
else if ((!target.isTargetable() || player.isTargetingDisabled()) && !player.canOverrideCond(PlayerCondOverride.TARGET_ALL))
if ((!target.isTargetable() || player.isTargetingDisabled()) && !player.canOverrideCond(PlayerCondOverride.TARGET_ALL))
{
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
@ -110,6 +124,8 @@ public class AttackRequest implements IClientIncomingPacket
return;
}
player.onActionRequest();
if (player.getTarget() != target)
{
target.onAction(player);

View File

@ -40,6 +40,11 @@ public class RequestTargetActionMenu implements IClientIncomingPacket
@Override
public void run(GameClient client)
{
if (!client.getFloodProtectors().getPlayerAction().tryPerformAction("PlayerAction"))
{
return;
}
final PlayerInstance player = client.getPlayer();
if ((player == null) || player.isTargetingDisabled())
{

View File

@ -87,12 +87,12 @@ public class FloodProtectorAction
*/
public boolean tryPerformAction(String command)
{
final int curTick = GameTimeTaskManager.getInstance().getGameTicks();
if ((_client.getPlayer() != null) && _client.getPlayer().canOverrideCond(PlayerCondOverride.FLOOD_CONDITIONS))
{
return true;
}
final int curTick = GameTimeTaskManager.getInstance().getGameTicks();
if ((curTick < _nextGameTick) || _punishmentInProgress)
{
if (_config.LOG_FLOODING && !_logged && LOGGER.isLoggable(Level.WARNING))

View File

@ -89,6 +89,10 @@ public class FloodProtectors
* Item Auction
*/
private final FloodProtectorAction _itemAuction;
/**
* Player Action
*/
private final FloodProtectorAction _playerAction;
/**
* Creates new instance of FloodProtectors.
@ -113,6 +117,7 @@ public class FloodProtectors
_sendMail = new FloodProtectorAction(client, Config.FLOOD_PROTECTOR_SENDMAIL);
_characterSelect = new FloodProtectorAction(client, Config.FLOOD_PROTECTOR_CHARACTER_SELECT);
_itemAuction = new FloodProtectorAction(client, Config.FLOOD_PROTECTOR_ITEM_AUCTION);
_playerAction = new FloodProtectorAction(client, Config.FLOOD_PROTECTOR_PLAYER_ACTION);
}
/**
@ -257,4 +262,13 @@ public class FloodProtectors
{
return _itemAuction;
}
/**
* Returns {@link #_playerAction}.
* @return {@link #_playerAction}
*/
public FloodProtectorAction getPlayerAction()
{
return _playerAction;
}
}