Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 4014)
- +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (working copy)
- @@ -193,7 +193,7 @@
- import net.sf.l2j.gameserver.templates.L2Weapon;
- import net.sf.l2j.gameserver.templates.L2WeaponType;
- import net.sf.l2j.gameserver.util.Broadcast;
- -import net.sf.l2j.gameserver.util.FloodProtector;
- +import net.sf.l2j.gameserver.util.FloodProtectors;
- import net.sf.l2j.util.Point3D;
- import net.sf.l2j.util.Rnd;
- @@ -331,6 +331,9 @@
- protected int _baseClass;
- protected int _activeClass;
- protected int _classIndex = 0;
- +
- + /** Flood Protector **/
- + private final FloodProtectors _floodProtectors = new FloodProtectors(this);
- /** The list of sub-classes this character has. */
- private Map<Integer, SubClass> _subClasses;
- @@ -9389,9 +9392,6 @@
- // Close the connection with the client
- closeNetConnection();
- - // remove from flood protector
- - FloodProtector.getInstance().removePlayer(getObjectId());
- -
- if (getClanId() > 0)
- getClan().broadcastToOtherOnlineMembers(new PledgeShowMemberListUpdate(this), this);
- //ClanTable.getInstance().getClan(getClanId()).broadcastToOnlineMembers(new PledgeShowMemberListAdd(this));
- @@ -10215,4 +10215,8 @@
- {
- _forceBuff = fb;
- }
- + public FloodProtectors getFloodProtectors()
- + {
- + return _floodProtectors;
- + }
- }
- Index: java/net/sf/l2j/gameserver/handler/itemhandlers/Firework.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/itemhandlers/Firework.java (revision 4014)
- +++ java/net/sf/l2j/gameserver/handler/itemhandlers/Firework.java (working copy)
- @@ -27,7 +27,6 @@
- import net.sf.l2j.gameserver.network.SystemMessageId;
- import net.sf.l2j.gameserver.serverpackets.MagicSkillUser;
- import net.sf.l2j.gameserver.serverpackets.SystemMessage;
- -import net.sf.l2j.gameserver.util.FloodProtector;
- /**
- * This class ...
- @@ -46,7 +45,7 @@
- L2PcInstance activeChar = (L2PcInstance)playable;
- int itemId = item.getItemId();
- - if (!FloodProtector.getInstance().tryPerformAction(activeChar.getObjectId(), FloodProtector.PROTECTED_FIREWORK))
- + if (!activeChar.getFloodProtectors().getFirework().tryPerformAction("firework use"))
- {
- SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANNOT_BE_USED);
- sm.addItemName(itemId);
- Index: java/net/sf/l2j/gameserver/clientpackets/UseItem.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/clientpackets/UseItem.java (revision 4014)
- +++ java/net/sf/l2j/gameserver/clientpackets/UseItem.java (working copy)
- @@ -36,7 +36,6 @@
- import net.sf.l2j.gameserver.templates.L2Item;
- import net.sf.l2j.gameserver.templates.L2Weapon;
- import net.sf.l2j.gameserver.templates.L2WeaponType;
- -import net.sf.l2j.gameserver.util.FloodProtector;
- /**
- * This class ...
- @@ -66,8 +65,11 @@
- return;
- // Flood protect UseItem
- - if (!FloodProtector.getInstance().tryPerformAction(activeChar.getObjectId(), FloodProtector.PROTECTED_USEITEM))
- + if (!activeChar.getFloodProtectors().getUseItem().tryPerformAction("use item"))
- + {
- + activeChar.sendMessage("You cannot use items so fast. Try again latter !");
- return;
- + }
- if (activeChar.getPrivateStoreType() != 0)
- {
- Index: java/net/sf/l2j/gameserver/handler/itemhandlers/RollingDice.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/itemhandlers/RollingDice.java (revision 4014)
- +++ java/net/sf/l2j/gameserver/handler/itemhandlers/RollingDice.java (working copy)
- @@ -27,7 +27,6 @@
- import net.sf.l2j.gameserver.serverpackets.Dice;
- import net.sf.l2j.gameserver.serverpackets.SystemMessage;
- import net.sf.l2j.gameserver.util.Broadcast;
- -import net.sf.l2j.gameserver.util.FloodProtector;
- import net.sf.l2j.util.Rnd;
- @@ -82,7 +81,11 @@
- private int rollDice(L2PcInstance player)
- {
- // Check if the dice is ready
- - if ( !FloodProtector.getInstance().tryPerformAction(player.getObjectId(), FloodProtector.PROTECTED_ROLLDICE) ) return 0;
- + if (!player.getFloodProtectors().getRollDice().tryPerformAction("dice use"))
- + {
- + player.sendMessage("You can't roll dice so fast");
- + return 0;
- + }
- return Rnd.get(1, 6);
- }
- Index: java/net/sf/l2j/gameserver/clientpackets/EnterWorld.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/clientpackets/EnterWorld.java (revision 4014)
- +++ java/net/sf/l2j/gameserver/clientpackets/EnterWorld.java (working copy)
- @@ -71,7 +71,6 @@
- import net.sf.l2j.gameserver.serverpackets.SignsSky;
- import net.sf.l2j.gameserver.serverpackets.SystemMessage;
- import net.sf.l2j.gameserver.serverpackets.UserInfo;
- -import net.sf.l2j.gameserver.util.FloodProtector;
- /**
- * Enter World Packet Handler<p>
- * <p>
- @@ -106,9 +105,6 @@
- return;
- }
- - // Register in flood protector
- - FloodProtector.getInstance().registerNewPlayer(activeChar.getObjectId());
- -
- if (L2World.getInstance().findObject(activeChar.getObjectId()) != null)
- {
- if(Config.DEBUG)
- Index: java/net/sf/l2j/gameserver/clientpackets/Say2.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/clientpackets/Say2.java (revision 4014)
- +++ java/net/sf/l2j/gameserver/clientpackets/Say2.java (working copy)
- @@ -35,7 +35,6 @@
- import net.sf.l2j.gameserver.network.SystemMessageId;
- import net.sf.l2j.gameserver.serverpackets.CreatureSay;
- import net.sf.l2j.gameserver.serverpackets.SystemMessage;
- -import net.sf.l2j.gameserver.util.FloodProtector;
- /**
- * This class ...
- @@ -313,7 +312,7 @@
- case HERO_VOICE:
- if (activeChar.isHero())
- {
- - if (!FloodProtector.getInstance().tryPerformAction(activeChar.getObjectId(), FloodProtector.PROTECTED_HEROVOICE))
- + if (!activeChar.getFloodProtectors().getHeroVoice().tryPerformAction("hero chat"))
- {
- activeChar.sendMessage("Action failed. Heroes are only able to speak in the global channel once every 10 seconds.");
- return;
- Index: java/net/sf/l2j/gameserver/util/StringUtil.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/util/StringUtil.java (revision 0)
- +++ java/net/sf/l2j/gameserver/util/StringUtil.java (revision 0)
- @@ -0,0 +1,297 @@
- +/*
- + * $Header$
- + *
- + * $Author: fordfrog $ $Date$ $Revision$ $Log$
- + *
- + *
- + * 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 net.sf.l2j.gameserver.util;
- +
- +/**
- + * String utilities optimized for the best performance.
- + *
- + * <h1>How to Use It</h1> <h2>concat() or append()</h2> If concatenating strings
- + * in single call, use StringUtil.concat(), otherwise use StringUtil.append()
- + * and its variants. <h2>Minimum Calls</h2> Bad:
- + *
- + * <pre>
- + * final StringBuilder sbString = new StringBuilder();
- + * StringUtil.append(sbString, "text 1", String.valueOf(npcId));
- + * StringUtil.append("text 2");
- + * </pre>
- + *
- + * Good:
- + *
- + * <pre>
- + * final StringBuilder sbString = new StringBuilder();
- + * StringUtil.append(sbString, "text 1", String.valueOf(npcId), "text 2");
- + * </pre>
- + *
- + * Why?<br/>
- + * Because the less calls you do, the less memory re-allocations have to be done
- + * so the whole text fits into the memory and less array copy tasks has to be
- + * performed. So if using less calls, less memory is used and string
- + * concatenation is faster. <h2>Size Hints for Loops</h2> Bad:
- + *
- + * <pre>
- + * final StringBuilder sbString = new StringBuilder();
- + * StringUtil.append(sbString, "header start", someText, "header end");
- + * for (int i = 0; i < 50; i++)
- + * {
- + * StringUtil.append(sbString, "text 1", stringArray[i], "text 2");
- + * }
- + * </pre>
- + *
- + * Good:
- + *
- + * <pre>
- + * final StringBuilder sbString = StringUtil.startAppend(1300, "header start", someText, "header end");
- + * for (int i = 0; i < 50; i++)
- + * {
- + * StringUtil.append(sbString, "text 1", stringArray[i], "text 2");
- + * }
- + * </pre>
- + *
- + * Why?<br/>
- + * When using StringUtil.append(), memory is only allocated to fit in the
- + * strings in method argument. So on each loop new memory for the string has to
- + * be allocated and old string has to be copied to the new string. With size
- + * hint, even if the size hint is above the needed memory, memory is saved
- + * because new memory has not to be allocated on each cycle. Also it is much
- + * faster if no string copy tasks has to be performed. So if concatenating
- + * strings in a loop, count approximately the size and set it as the hint for
- + * the string builder size. It's better to make the size hint little bit larger
- + * rather than smaller.<br/>
- + * In case there is no text appended before the cycle, just use <code>new
- + * StringBuilder(1300)</code>. <h2>Concatenation and Constants</h2> Bad:
- + *
- + * <pre>
- + * StringUtil.concat("text 1 ", "text 2", String.valueOf(npcId));
- + * </pre>
- + *
- + * Good:
- + *
- + * <pre>
- + * StringUtil.concat("text 1 " + "text 2", String.valueOf(npcId));
- + * </pre>
- + *
- + * or
- + *
- + * <pre>
- + * StringUtil.concat("text 1 text 2", String.valueOf(npcId));
- + * </pre>
- + *
- + * Why?<br/>
- + * It saves some cycles when determining size of memory that needs to be
- + * allocated because less strings are passed to concat() method. But do not use
- + * + for concatenation of non-constant strings, that degrades performance and
- + * makes extra memory allocations needed. <h2>Concatenation and Constant
- + * Variables</h2> Bad:
- + *
- + * <pre>
- + * String glue = "some glue";
- + * StringUtil.concat("text 1", glue, "text 2", glue, String.valueOf(npcId));
- + * </pre>
- + *
- + * Good:
- + *
- + * <pre>
- + * final String glue = "some glue";
- + * StringUtil.concat("text 1" + glue + "text2" + glue, String.valueOf(npcId));
- + * </pre>
- + *
- + * Why? Because when using <code>final</code> keyword, the <code>glue</code> is
- + * marked as constant string and compiler treats it as a constant string so it
- + * is able to create string "text1some gluetext2some glue" during the
- + * compilation. But this only works in case the value is known at compilation
- + * time, so this cannot be used for cases like
- + * <code>final String objectIdString =
- + * String.valueOf(getObjectId)</code>. <h2>StringBuilder Reuse</h2> Bad:
- + *
- + * <pre>
- + * final StringBuilder sbString1 = new StringBuilder();
- + * StringUtil.append(sbString1, "text 1", String.valueOf(npcId), "text 2");
- + * ... // output of sbString1, it is no more needed
- + * final StringBuilder sbString2 = new StringBuilder();
- + * StringUtil.append(sbString2, "text 3", String.valueOf(npcId), "text 4");
- + * </pre>
- + *
- + * Good:
- + *
- + * <pre>
- + * final StringBuilder sbString = new StringBuilder();
- + * StringUtil.append(sbString, "text 1", String.valueOf(npcId), "text 2");
- + * ... // output of sbString, it is no more needed
- + * sbString.setLength(0);
- + * StringUtil.append(sbString, "text 3", String.valueOf(npcId), "text 4");
- + * </pre>
- + *
- + * Why?</br> In first case, new memory has to be allocated for the second
- + * string. In second case already allocated memory is reused, but only in case
- + * the new string is not longer than the previously allocated string. Anyway,
- + * the second way is better because the string either fits in the memory and
- + * some memory is saved, or it does not fit in the memory, and in that case it
- + * works as in the first case. <h2>Primitives to Strings</h2> To convert
- + * primitives to string, use String.valueOf(). <h2>How much faster is it?</h2>
- + * Here are some results of my tests. Count is number of strings concatenated.
- + * Don't take the numbers as 100% true as the numbers are affected by other
- + * programs running on my computer at the same time. Anyway, from the results it
- + * is obvious that using StringBuilder with predefined size is the fastest (and
- + * also most memory efficient) solution. It is about 5 times faster when
- + * concatenating 7 strings, compared to TextBuilder. Also, with more strings
- + * concatenated, the difference between StringBuilder and TextBuilder gets
- + * larger. In code, there are many cases, where there are concatenated 50+
- + * strings so the time saving is even greater.
- + *
- + * <pre>
- + * Count: 2
- + * TextBuilder: 1893
- + * TextBuilder with size: 1703
- + * String: 1033
- + * StringBuilder: 993
- + * StringBuilder with size: 1024
- + * Count: 3
- + * TextBuilder: 1973
- + * TextBuilder with size: 1872
- + * String: 2583
- + * StringBuilder: 1633
- + * StringBuilder with size: 1156
- + * Count: 4
- + * TextBuilder: 2188
- + * TextBuilder with size: 2229
- + * String: 4207
- + * StringBuilder: 1816
- + * StringBuilder with size: 1444
- + * Count: 5
- + * TextBuilder: 9185
- + * TextBuilder with size: 9464
- + * String: 6937
- + * StringBuilder: 2745
- + * StringBuilder with size: 1882
- + * Count: 6
- + * TextBuilder: 9785
- + * TextBuilder with size: 10082
- + * String: 9471
- + * StringBuilder: 2889
- + * StringBuilder with size: 1857
- + * Count: 7
- + * TextBuilder: 10169
- + * TextBuilder with size: 10528
- + * String: 12746
- + * StringBuilder: 3081
- + * StringBuilder with size: 2139
- + * </pre>
- + *
- + * @author fordfrog
- + */
- +public final class StringUtil
- +{
- +
- + private StringUtil()
- + {
- + }
- +
- + /**
- + * Concatenates strings.
- + *
- + * @param strings
- + * strings to be concatenated
- + *
- + * @return concatenated string
- + *
- + * @see StringUtil
- + */
- + public static String concat(final String... strings)
- + {
- + final StringBuilder sbString = new StringBuilder(getLength(strings));
- +
- + for (final String string : strings)
- + {
- + sbString.append(string);
- + }
- +
- + return sbString.toString();
- + }
- +
- + /**
- + * Creates new string builder with size initializated to
- + * <code>sizeHint</code>, unless total length of strings is greater than
- + * <code>sizeHint</code>.
- + *
- + * @param sizeHint
- + * hint for string builder size allocation
- + * @param strings
- + * strings to be appended
- + *
- + * @return created string builder
- + *
- + * @see StringUtil
- + */
- + public static StringBuilder startAppend(final int sizeHint, final String... strings)
- + {
- + final int length = getLength(strings);
- + final StringBuilder sbString = new StringBuilder(sizeHint > length ? sizeHint : length);
- +
- + for (final String string : strings)
- + {
- + sbString.append(string);
- + }
- +
- + return sbString;
- + }
- +
- + /**
- + * Appends strings to existing string builder.
- + *
- + * @param sbString
- + * string builder
- + * @param strings
- + * strings to be appended
- + *
- + * @see StringUtil
- + */
- + public static void append(final StringBuilder sbString, final String... strings)
- + {
- + sbString.ensureCapacity(sbString.length() + getLength(strings));
- +
- + for (final String string : strings)
- + {
- + sbString.append(string);
- + }
- + }
- +
- + /**
- + * Counts total length of all the strings.
- + *
- + * @param strings
- + * array of strings
- + *
- + * @return total length of all the strings
- + */
- + private static int getLength(final String[] strings)
- + {
- + int length = 0;
- +
- + for (final String string : strings)
- + {
- + if (string == null)
- + length += 4;
- + else
- + length += string.length();
- + }
- +
- + return length;
- + }
- +}
- Index: java/net/sf/l2j/gameserver/GameServer.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/GameServer.java (revision 4014)
- +++ java/net/sf/l2j/gameserver/GameServer.java (working copy)
- @@ -227,7 +227,6 @@
- import net.sf.l2j.gameserver.script.faenor.FaenorScriptEngine;
- import net.sf.l2j.gameserver.taskmanager.TaskManager;
- import net.sf.l2j.gameserver.util.DynamicExtension;
- -import net.sf.l2j.gameserver.util.FloodProtector;
- import net.sf.l2j.status.Status;
- import com.l2jserver.mmocore.network.SelectorServerConfig;
- @@ -646,7 +645,6 @@
- _log.log(Level.WARNING, "DynamicExtension could not be loaded and initialized", ex);
- }
- - FloodProtector.getInstance();
- TvTManager.getInstance();
- System.gc();
- // maxMemory is the upper limit the jvm can use, totalMemory the size of the current allocation pool, freeMemory the unused memory in the allocation pool
- Index: java/net/sf/l2j/gameserver/handler/itemhandlers/SummonItems.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/handler/itemhandlers/SummonItems.java (revision 4014)
- +++ java/net/sf/l2j/gameserver/handler/itemhandlers/SummonItems.java (working copy)
- @@ -45,7 +45,6 @@
- import net.sf.l2j.gameserver.serverpackets.Ride;
- import net.sf.l2j.gameserver.serverpackets.SystemMessage;
- import net.sf.l2j.gameserver.templates.L2NpcTemplate;
- -import net.sf.l2j.gameserver.util.FloodProtector;
- public class SummonItems implements IItemHandler
- {
- @@ -59,7 +58,11 @@
- L2PcInstance activeChar = (L2PcInstance)playable;
- - if ( !FloodProtector.getInstance().tryPerformAction(activeChar.getObjectId(), FloodProtector.PROTECTED_ITEMPETSUMMON) ) return;
- + if (!activeChar.getFloodProtectors().getItemPetSummon().tryPerformAction("summon item"))
- + {
- + activeChar.sendMessage("You can't summon items so fast");
- + return;
- + }
- if(activeChar.isSitting())
- {
- Index: java/net/sf/l2j/gameserver/util/FloodProtectorConfig.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/util/FloodProtectorConfig.java (revision 0)
- +++ java/net/sf/l2j/gameserver/util/FloodProtectorConfig.java (revision 0)
- @@ -0,0 +1,59 @@
- +/*
- + * 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 net.sf.l2j.gameserver.util;
- +
- +/**
- + * Flood protector configuration
- + *
- + * @author fordfrog
- + */
- +public final class FloodProtectorConfig
- +{
- +
- + /**
- + * Type used for identification of logging output.
- + */
- + public String FLOOD_PROTECTOR_TYPE;
- + /**
- + * Flood protection interval in game ticks.
- + */
- + public int FLOOD_PROTECTION_INTERVAL;
- + /**
- + * Whether flooding should be logged.
- + */
- + public boolean LOG_FLOODING;
- + /**
- + * If specified punishment limit is exceeded, punishment is applied.
- + */
- + public int PUNISHMENT_LIMIT;
- + /**
- + * Punishment type. Either 'none', 'kick', 'ban' or 'jail'.
- + */
- + public String PUNISHMENT_TYPE;
- + /**
- + * For how long should the char/account be punished.
- + */
- + public int PUNISHMENT_TIME;
- +
- + /**
- + * Creates new instance of FloodProtectorConfig.
- + *
- + * @param floodProtectorType
- + * {@link #FLOOD_PROTECTOR_TYPE}
- + */
- + public FloodProtectorConfig(final String floodProtectorType)
- + {
- + super();
- + FLOOD_PROTECTOR_TYPE = floodProtectorType;
- + }
- +}
- \ No newline at end of file
- Index: java/net/sf/l2j/gameserver/util/FloodProtectorAction.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/util/FloodProtectorAction.java (revision 0)
- +++ java/net/sf/l2j/gameserver/util/FloodProtectorAction.java (revision 0)
- @@ -0,0 +1,172 @@
- +/*
- + * 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 net.sf.l2j.gameserver.util;
- +
- +import java.util.concurrent.atomic.AtomicInteger;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +import net.sf.l2j.gameserver.GameTimeController;
- +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +
- +/**
- + * Flood protector implementation.
- + *
- + * @author fordfrog
- + */
- +public final class FloodProtectorAction
- +{
- +
- + /**
- + * Logger
- + */
- + private static final Logger _log = Logger.getLogger(FloodProtectorAction.class.getName());
- + /**
- + * Player for this instance of flood protector.
- + */
- + private final L2PcInstance _player;
- + /**
- + * Configuration of this instance of flood protector.
- + */
- + private final FloodProtectorConfig _config;
- + /**
- + * Next game tick when new request is allowed.
- + */
- + private volatile int _nextGameTick = GameTimeController.getGameTicks();
- + /**
- + * Request counter.
- + */
- + private AtomicInteger _count = new AtomicInteger(0);
- + /**
- + * Flag determining whether exceeding request has been logged.
- + */
- + private boolean _logged;
- + /**
- + * Flag determining whether punishment application is in progress so that we do not apply
- + * punisment multiple times (flooding).
- + */
- + private volatile boolean _punishmentInProgress;
- +
- + /**
- + * Creates new instance of FloodProtectorAction.
- + *
- + * @param player
- + * player for which flood protection is being created
- + * @param config
- + * flood protector configuration
- + */
- + public FloodProtectorAction(final L2PcInstance player, final FloodProtectorConfig config)
- + {
- + super();
- + _player = player;
- + _config = config;
- + }
- +
- + /**
- + * Checks whether the request is flood protected or not.
- + *
- + * @param command
- + * command issued or short command description
- + *
- + * @return true if action is allowed, otherwise false
- + */
- + public boolean tryPerformAction(final String command)
- + {
- + final int curTick = GameTimeController.getGameTicks();
- +
- + if (curTick < _nextGameTick || _punishmentInProgress)
- + {
- + if (_config.LOG_FLOODING && !_logged && _log.isLoggable(Level.WARNING))
- + {
- + _log.warning(StringUtil.concat(_config.FLOOD_PROTECTOR_TYPE, ": Player [", _player.getName(), "] called command [", command, "] [~", String.valueOf((_config.FLOOD_PROTECTION_INTERVAL - (_nextGameTick - curTick)) * GameTimeController.MILLIS_IN_TICK), " ms] after previous command"));
- + _logged = true;
- + }
- +
- + _count.incrementAndGet();
- +
- + if (!_punishmentInProgress && _config.PUNISHMENT_LIMIT > 0 && _count.get() > _config.PUNISHMENT_LIMIT && _config.PUNISHMENT_TYPE != null)
- + {
- + _punishmentInProgress = true;
- +
- + if ("kick".equals(_config.PUNISHMENT_TYPE))
- + {
- + kickPlayer();
- + }
- + else if ("ban".equals(_config.PUNISHMENT_TYPE))
- + {
- + banAccount();
- + }
- + else if ("jail".equals(_config.PUNISHMENT_TYPE))
- + {
- + jailChar();
- + }
- +
- + _punishmentInProgress = false;
- + }
- +
- + return false;
- + }
- +
- + if (_count.get() > 0)
- + {
- + if (_config.LOG_FLOODING && _log.isLoggable(Level.WARNING))
- + {
- + _log.warning(StringUtil.concat(_config.FLOOD_PROTECTOR_TYPE, ": Player [", _player.getName(), "] issued [", String.valueOf(_count), "] extra requests within [~", String.valueOf(_config.FLOOD_PROTECTION_INTERVAL * GameTimeController.MILLIS_IN_TICK), " ms]"));
- + }
- + }
- +
- + _nextGameTick = curTick + _config.FLOOD_PROTECTION_INTERVAL;
- + _logged = false;
- + _count.set(0);
- +
- + return true;
- + }
- +
- + /**
- + * Kick player from game (close network connection).
- + */
- + private void kickPlayer()
- + {
- + _player.closeNetConnection();
- +
- + if (_log.isLoggable(Level.WARNING))
- + {
- + _log.warning(StringUtil.concat(_config.FLOOD_PROTECTOR_TYPE, ": Account [", _player.getAccountName(), "] kicked for flooding [char ", _player.getName(), "]"));
- + }
- + }
- +
- + /**
- + * Bans char account and logs out the char.
- + */
- + private void banAccount()
- + {
- + _player.setAccountAccesslevel(-100);
- +
- + if (_log.isLoggable(Level.WARNING))
- + _log.warning(StringUtil.concat(_config.FLOOD_PROTECTOR_TYPE, ": Account [", _player.getAccountName(), "] banned for flooding [char ", _player.getName(), "] ", _config.PUNISHMENT_TIME <= 0 ? "forever" : "for " + _config.PUNISHMENT_TIME + " mins"));
- +
- + _player.logout();
- + }
- +
- + /**
- + * Jails char.
- + */
- + private void jailChar()
- + {
- + _player.setInJail(true, _config.PUNISHMENT_TIME);
- +
- + if (_log.isLoggable(Level.WARNING))
- + {
- + _log.warning(StringUtil.concat(_config.FLOOD_PROTECTOR_TYPE, ": Player [", _player.getName(), "] jailed for flooding [char ", _player.getName(), "] ", _config.PUNISHMENT_TIME <= 0 ? "forever" : "for " + _config.PUNISHMENT_TIME + " mins"));
- + }
- + }
- +}
- \ No newline at end of file
- Index: java/net/sf/l2j/Config.java
- ===================================================================
- --- java/net/sf/l2j/Config.java (revision 4014)
- +++ java/net/sf/l2j/Config.java (working copy)
- @@ -30,6 +30,8 @@
- import javolution.util.FastList;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +import net.sf.l2j.gameserver.util.FloodProtectorConfig;
- +import net.sf.l2j.gameserver.util.StringUtil;
- /**
- * This class contains global server configuration.<br>
- @@ -711,6 +713,7 @@
- public static final String SEVENSIGNS_FILE = "./config/sevensigns.properties";
- public static final String CLANHALL_CONFIG_FILE = "./config/clanhall.properties";
- public static final String L2JMOD_CONFIG_FILE = "./config/l2jmods.properties";
- + public static final String FLOODPROTECTOR_CONFIG_FILE = "./config/FloodProtector.properties";
- public static int MAX_ITEM_IN_PACKET;
- public static boolean CHECK_KNOWN;
- @@ -881,6 +884,32 @@
- public static boolean L2JMOD_WEDDING_SAMESEX;
- public static boolean L2JMOD_WEDDING_FORMALWEAR;
- public static int L2JMOD_WEDDING_DIVORCE_COSTS;
- +
- + //--------------------------------------------------
- + // FloodProtector Settings
- + //--------------------------------------------------
- + public static final FloodProtectorConfig FLOOD_PROTECTOR_USE_ITEM =
- + new FloodProtectorConfig("UseItemFloodProtector");
- + public static final FloodProtectorConfig FLOOD_PROTECTOR_ROLL_DICE =
- + new FloodProtectorConfig("RollDiceFloodProtector");
- + public static final FloodProtectorConfig FLOOD_PROTECTOR_FIREWORK =
- + new FloodProtectorConfig("FireworkFloodProtector");
- + public static final FloodProtectorConfig FLOOD_PROTECTOR_ITEM_PET_SUMMON =
- + new FloodProtectorConfig("ItemPetSummonFloodProtector");
- + public static final FloodProtectorConfig FLOOD_PROTECTOR_HERO_VOICE =
- + new FloodProtectorConfig("HeroVoiceFloodProtector");
- + public static final FloodProtectorConfig FLOOD_PROTECTOR_GLOBAL_CHAT =
- + new FloodProtectorConfig("GlobalChatFloodProtector");
- + public static final FloodProtectorConfig FLOOD_PROTECTOR_SUBCLASS =
- + new FloodProtectorConfig("SubclassFloodProtector");
- + public static final FloodProtectorConfig FLOOD_PROTECTOR_DROP_ITEM =
- + new FloodProtectorConfig("DropItemFloodProtector");
- + public static final FloodProtectorConfig FLOOD_PROTECTOR_SERVER_BYPASS =
- + new FloodProtectorConfig("ServerBypassFloodProtector");
- + public static final FloodProtectorConfig FLOOD_PROTECTOR_MULTISELL =
- + new FloodProtectorConfig("MultiSellFloodProtector");
- + public static final FloodProtectorConfig FLOOD_PROTECTOR_TRANSACTION =
- + new FloodProtectorConfig("TransactionFloodProtector");
- // Packet information
- /** Count the amount of packets per minute ? */
- @@ -1963,6 +1992,24 @@
- e.printStackTrace();
- throw new Error("Failed to Load "+L2JMOD_CONFIG_FILE+" File.");
- }
- +
- + // Actions FloodProtector
- + try
- + {
- + Properties FloodProtector = new Properties();
- + InputStream is = new FileInputStream(new File(FLOODPROTECTOR_CONFIG_FILE));
- + FloodProtector.load(is);
- + is.close();
- +
- + loadFloodProtectorConfigs(FloodProtector);
- +
- + }
- + catch (Exception e)
- + {
- + e.printStackTrace();
- + throw new Error("Failed to Load "+FLOODPROTECTOR_CONFIG_FILE+" File.");
- + }
- +
- // pvp config
- try
- {
- @@ -2164,6 +2211,44 @@
- }
- }
- +
- + /**
- + * Loads single flood protector configuration.
- + *
- + * @param properties
- + * properties file reader
- + * @param config
- + * flood protector configuration instance
- + * @param configString
- + * flood protector configuration string that determines for which flood protector
- + * configuration should be read
- + * @param defaultInterval
- + * default flood protector interval
- + */
- + private static void loadFloodProtectorConfig(final Properties properties, final FloodProtectorConfig config, final String configString, final String defaultInterval)
- + {
- + config.FLOOD_PROTECTION_INTERVAL = Integer.parseInt(properties.getProperty(StringUtil.concat("FloodProtector", configString, "Interval"), defaultInterval));
- + config.LOG_FLOODING = Boolean.parseBoolean(properties.getProperty(StringUtil.concat("FloodProtector", configString, "LogFlooding"), "False"));
- + config.PUNISHMENT_LIMIT = Integer.parseInt(properties.getProperty(StringUtil.concat("FloodProtector", configString, "PunishmentLimit"), "0"));
- + config.PUNISHMENT_TYPE = properties.getProperty(StringUtil.concat("FloodProtector", configString, "PunishmentType"), "none");
- + config.PUNISHMENT_TIME = Integer.parseInt(properties.getProperty(StringUtil.concat("FloodProtector", configString, "PunishmentTime"), "0"));
- + }
- +
- +
- + private static void loadFloodProtectorConfigs(final Properties properties)
- + {
- + loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_USE_ITEM, "UseItem", "4");
- + loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_ROLL_DICE, "RollDice", "42");
- + loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_FIREWORK, "Firework", "42");
- + loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_ITEM_PET_SUMMON, "ItemPetSummon", "16");
- + loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_HERO_VOICE, "HeroVoice", "100");
- + loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_GLOBAL_CHAT, "GlobalChat", "5");
- + loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_SUBCLASS, "Subclass", "20");
- + loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_DROP_ITEM, "DropItem", "10");
- + loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_SERVER_BYPASS, "ServerBypass", "5");
- + loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_MULTISELL, "MultiSell", "1");
- + loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_TRANSACTION, "Transaction", "10");
- + }
- /**
- * Set a new value to a game parameter from the admin console.
- Index: java/net/sf/l2j/gameserver/util/FloodProtectors.java
- ===================================================================
- --- java/net/sf/l2j/gameserver/util/FloodProtectors.java (revision 0)
- +++ java/net/sf/l2j/gameserver/util/FloodProtectors.java (revision 0)
- @@ -0,0 +1,204 @@
- +/*
- +/*
- + * 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 net.sf.l2j.gameserver.util;
- +
- +import net.sf.l2j.Config;
- +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- +
- +/**
- + * Collection of flood protectors for single player.
- + *
- + * @author fordfrog
- + */
- +public final class FloodProtectors
- +{
- +
- + /**
- + * Use-item flood protector.
- + */
- + private final FloodProtectorAction _useItem;
- + /**
- + * Roll-dice flood protector.
- + */
- + private final FloodProtectorAction _rollDice;
- + /**
- + * Firework flood protector.
- + */
- + private final FloodProtectorAction _firework;
- + /**
- + * Item-pet-summon flood protector.
- + */
- + private final FloodProtectorAction _itemPetSummon;
- + /**
- + * Hero-voice flood protector.
- + */
- + private final FloodProtectorAction _heroVoice;
- + /**
- + * Global-chat flood protector.
- + */
- + private final FloodProtectorAction _globalChat;
- + /**
- + * Subclass flood protector.
- + */
- + private final FloodProtectorAction _subclass;
- + /**
- + * Drop-item flood protector.
- + */
- + private final FloodProtectorAction _dropItem;
- + /**
- + * Server-bypass flood protector.
- + */
- + private final FloodProtectorAction _serverBypass;
- + /**
- + * Multisell flood protector.
- + */
- + private final FloodProtectorAction _multiSell;
- + /**
- + * Transaction flood protector.
- + */
- + private final FloodProtectorAction _transaction;
- +
- + /**
- + * Creates new instance of FloodProtectors.
- + *
- + * @param player
- + * player for which the collection of flood protectors is being created.
- + */
- + public FloodProtectors(final L2PcInstance player)
- + {
- + super();
- + _useItem = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_USE_ITEM);
- + _rollDice = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_ROLL_DICE);
- + _firework = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_FIREWORK);
- + _itemPetSummon = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_ITEM_PET_SUMMON);
- + _heroVoice = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_HERO_VOICE);
- + _globalChat = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_GLOBAL_CHAT);
- + _subclass = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_SUBCLASS);
- + _dropItem = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_DROP_ITEM);
- + _serverBypass = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_SERVER_BYPASS);
- + _multiSell = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_MULTISELL);
- + _transaction = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_TRANSACTION);
- + }
- +
- + /**
- + * Returns {@link #_useItem}.
- + *
- + * @return {@link #_useItem}
- + */
- + public FloodProtectorAction getUseItem()
- + {
- + return _useItem;
- + }
- +
- + /**
- + * Returns {@link #_rollDice}.
- + *
- + * @return {@link #_rollDice}
- + */
- + public FloodProtectorAction getRollDice()
- + {
- + return _rollDice;
- + }
- +
- + /**
- + * Returns {@link #_firework}.
- + *
- + * @return {@link #_firework}
- + */
- + public FloodProtectorAction getFirework()
- + {
- + return _firework;
- + }
- +
- + /**
- + * Returns {@link #_itemPetSummon}.
- + *
- + * @return {@link #_itemPetSummon}
- + */
- + public FloodProtectorAction getItemPetSummon()
- + {
- + return _itemPetSummon;
- + }
- +
- + /**
- + * Returns {@link #_heroVoice}.
- + *
- + * @return {@link #_heroVoice}
- + */
- + public FloodProtectorAction getHeroVoice()
- + {
- + return _heroVoice;
- + }
- +
- + /**
- + * Returns {@link #_globalChat}.
- + *
- + * @return {@link #_globalChat}
- + */
- + public FloodProtectorAction getGlobalChat()
- + {
- + return _globalChat;
- + }
- +
- + /**
- + * Returns {@link #_subclass}.
- + *
- + * @return {@link #_subclass}
- + */
- + public FloodProtectorAction getSubclass()
- + {
- + return _subclass;
- + }
- +
- + /**
- + * Returns {@link #_dropItem}.
- + *
- + * @return {@link #_dropItem}
- + */
- + public FloodProtectorAction getDropItem()
- + {
- + return _dropItem;
- + }
- +
- + /**
- + * Returns {@link #_serverBypass}.
- + *
- + * @return {@link #_serverBypass}
- + */
- + public FloodProtectorAction getServerBypass()
- + {
- + return _serverBypass;
- + }
- +
- + /**
- + * Returns {@link #_multisell}.
- + *
- + * @return {@link #_multisell}
- + */
- + public FloodProtectorAction getMultiSell()
- + {
- + return _multiSell;
- + }
- +
- + /**
- + * Returns {@link #_transaction}.
- + *
- + * @return {@link #_transaction}
- + */
- + public FloodProtectorAction getTransaction()
- + {
- + return _transaction;
- + }
- +
- +}
- \ No newline at end of file
- Index: java/config/FloodProtector.properties
- ===================================================================
- --- java/config/FloodProtector.properties (revision 0)
- +++ java/config/FloodProtector.properties (revision 0)
- @@ -0,0 +1,86 @@
- +# ---------------------------------------------------------------------------
- +# Floodprotector Options
- +# ---------------------------------------------------------------------------
- +# The following settings can be applied to each feature:
- +# Interval - interval in gameserver ticks (1 tick = 100ms) in which only one request is allowed
- +# LogFlooding - whether flooding should be logged (only first ocurrance of flooding and total count of flood requests is logged)
- +# PunishmentLimit - if number of requests within single interval exceeds specified number then the specified punishment is applied (0 = disables punishment feature)
- +# PunishmentType - type of the punishment ('none', 'kick', 'ban', 'jail'), valid only if PunishmentLimit is greater than 0
- +# PunishmentTime - for how many minutes should the player(jail)/account(ban) be punished (0 = forever), valid only for PunishmentType 'jail' or 'ban'
- +
- +# UseItem - item usage flooding
- +FloodProtectorUseItemInterval = 4
- +FloodProtectorUseItemLogFlooding = False
- +FloodProtectorUseItemPunishmentLimit = 0
- +FloodProtectorUseItemPunishmentType = none
- +FloodProtectorUseItemPunishmentTime = 0
- +
- +# RollDice - rolling dice flooding
- +FloodProtectorRollDiceInterval = 42
- +FloodProtectorRollDiceLogFlooding = False
- +FloodProtectorRollDicePunishmentLimit = 0
- +FloodProtectorRollDicePunishmentType = none
- +FloodProtectorRollDicePunishmentTime = 0
- +
- +# Firework - firework flooding
- +FloodProtectorFireworkInterval = 42
- +FloodProtectorFireworkLogFlooding = False
- +FloodProtectorFireworkPunishmentLimit = 0
- +FloodProtectorFireworkPunishmentType = none
- +FloodProtectorFireworkPunishmentTime = 0
- +
- +# ItemPetSummon - item summonning and pet mounting flooding
- +FloodProtectorItemPetSummonInterval = 16
- +FloodProtectorItemPetSummonLogFlooding = False
- +FloodProtectorItemPetSummonPunishmentLimit = 0
- +FloodProtectorItemPetSummonPunishmentType = none
- +FloodProtectorItemPetSummonPunishmentTime = 0
- +
- +# HeroVoice - hero voice flooding
- +FloodProtectorHeroVoiceInterval = 100
- +FloodProtectorHeroVoiceLogFlooding = False
- +FloodProtectorHeroVoicePunishmentLimit = 0
- +FloodProtectorHeroVoicePunishmentType = none
- +FloodProtectorHeroVoicePunishmentTime = 0
- +
- +# GlobalChat - global chat flooding
- +FloodProtectorGlobalChatInterval = 5
- +FloodProtectorGlobalChatLogFlooding = False
- +FloodProtectorGlobalChatPunishmentLimit = 0
- +FloodProtectorGlobalChatPunishmentType = none
- +FloodProtectorGlobalChatPunishmentTime = 0
- +
- +# Subclass - subclass flooding
- +FloodProtectorSubclassInterval = 20
- +FloodProtectorSubclassLogFlooding = False
- +FloodProtectorSubclassPunishmentLimit = 0
- +FloodProtectorSubclassPunishmentType = none
- +FloodProtectorSubclassPunishmentTime = 0
- +
- +# DropItem - drop item flooding
- +FloodProtectorDropItemInterval = 10
- +FloodProtectorDropItemLogFlooding = False
- +FloodProtectorDropItemPunishmentLimit = 0
- +FloodProtectorDropItemPunishmentType = none
- +FloodProtectorDropItemPunishmentTime = 0
- +
- +# ServerBypass - server bypass flooding
- +FloodProtectorServerBypassInterval = 5
- +FloodProtectorServerBypassLogFlooding = False
- +FloodProtectorServerBypassPunishmentLimit = 0
- +FloodProtectorServerBypassPunishmentType = none
- +FloodProtectorServerBypassPunishmentTime = 0
- +
- +# ServerBypass - multisell list request flooding
- +FloodProtectorMultiSellInterval = 1
- +FloodProtectorMultiSellLogFlooding = False
- +FloodProtectorMultiSellPunishmentLimit = 0
- +FloodProtectorMultiSellPunishmentType = none
- +FloodProtectorMultiSellPunishmentTime = 0
- +
- +# All kind of other transactions - to/from pet, private store, warehouse, destroy
- +FloodProtectorTransactionInterval = 10
- +FloodProtectorTransactionLogFlooding = False
- +FloodProtectorTransactionPunishmentLimit = 0
- +FloodProtectorTransactionPunishmentType = none
- +FloodProtectorTransactionPunishmentTime = 0
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment