Advertisement
Guest User

Flood Rework

a guest
Jan 24th, 2010
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 31.71 KB | None | 0 0
  1. Index: /trunk/Eclipse/java/config/Custom/FloodProtector.properties.properties
  2. ===================================================================
  3. --- /trunk/Eclipse/java/config/Custom/FloodProtector.properties.properties (revision 422)
  4. +++ /trunk/Eclipse/java/config/Custom/FloodProtector.properties.properties (revision 422)
  5. @@ -0,0 +1,114 @@
  6. +###########################################################
  7. +##   Following settings can be applied to each feature:  ##
  8. +###########################################################
  9. +# Interval - interval in gameserver ticks (10 = 1 second)
  10. +# LogFlooding - whether flooding should be logged
  11. +# PunishmentLimit - if number of requests within single interval exceeds (0 - disables punishment feature)
  12. +# PunishmentType - type of the punishment ('none', 'ban', 'jail'), used only, if PunishmentLimit is greater than zero
  13. +# PunishmentTime - for how many minutes should be the player/account punished, player is punished in case of 'jail', account is punishedin case of 'ban' (0 = forever)
  14. +
  15. +FloodProtectorUseItemInterval = 4
  16. +FloodProtectorUseItemLogFlooding = False
  17. +FloodProtectorUseItemPunishmentLimit = 0
  18. +FloodProtectorUseItemPunishmentType = none
  19. +FloodProtectorUseItemPunishmentTime = 0
  20. +
  21. +FloodProtectorRollDiceInterval = 42
  22. +FloodProtectorRollDiceLogFlooding = False
  23. +FloodProtectorRollDicePunishmentLimit = 0
  24. +FloodProtectorRollDicePunishmentType = none
  25. +FloodProtectorRollDicePunishmentTime = 0
  26. +
  27. +FloodProtectorFireworkInterval = 42
  28. +FloodProtectorFireworkLogFlooding = False
  29. +FloodProtectorFireworkPunishmentLimit = 0
  30. +FloodProtectorFireworkPunishmentType = none
  31. +FloodProtectorFireworkPunishmentTime = 0
  32. +
  33. +FloodProtectorItemPetSummonInterval = 16
  34. +FloodProtectorItemPetSummonLogFlooding = False
  35. +FloodProtectorItemPetSummonPunishmentLimit = 0
  36. +FloodProtectorItemPetSummonPunishmentType = none
  37. +FloodProtectorItemPetSummonPunishmentTime = 0
  38. +
  39. +FloodProtectorHeroVoiceInterval = 100
  40. +FloodProtectorHeroVoiceLogFlooding = False
  41. +FloodProtectorHeroVoicePunishmentLimit = 0
  42. +FloodProtectorHeroVoicePunishmentType = none
  43. +FloodProtectorHeroVoicePunishmentTime = 0
  44. +
  45. +FloodProtectorSubclassInterval = 200
  46. +FloodProtectorSubclassLogFlooding = False
  47. +FloodProtectorSubclassPunishmentLimit = 0
  48. +FloodProtectorSubclassPunishmentType = none
  49. +FloodProtectorSubclassPunishmentTime = 0
  50. +
  51. +FloodProtectorDropItemInterval = 10
  52. +FloodProtectorDropItemLogFlooding = False
  53. +FloodProtectorDropItemPunishmentLimit = 0
  54. +FloodProtectorDropItemPunishmentType = none
  55. +FloodProtectorDropItemPunishmentTime = 0
  56. +
  57. +FloodProtectorServerBypassInterval = 5
  58. +FloodProtectorServerBypassLogFlooding = False
  59. +FloodProtectorServerBypassPunishmentLimit = 0
  60. +FloodProtectorServerBypassPunishmentType = none
  61. +FloodProtectorServerBypassPunishmentTime = 0
  62. +
  63. +FloodProtectorUnkPacketsInterval = 5
  64. +FloodProtectorUnkPacketsLogFlooding = False
  65. +FloodProtectorUnkPacketsPunishmentLimit = 0
  66. +FloodProtectorUnkPacketsPunishmentType = none
  67. +FloodProtectorUnkPacketsPunishmentTime = 0
  68. +
  69. +FloodProtectorBufferInterval = 5
  70. +FloodProtectorBufferLogFlooding = False
  71. +FloodProtectorBufferPunishmentLimit = 0
  72. +FloodProtectorBufferPunishmentType = none
  73. +FloodProtectorBufferPunishmentTime = 0
  74. +
  75. +FloodProtectorCraftInterval = 5
  76. +FloodProtectorCraftLogFlooding = False
  77. +FloodProtectorCraftPunishmentLimit = 0
  78. +FloodProtectorCraftPunishmentType = none
  79. +FloodProtectorCraftPunishmentTime = 0
  80. +
  81. +FloodProtectorMultisellInterval = 30
  82. +FloodProtectorMultisellLogFlooding = False
  83. +FloodProtectorMultisellPunishmentLimit = 0
  84. +FloodProtectorMultisellPunishmentType = none
  85. +FloodProtectorMultisellPunishmentTime = 0
  86. +
  87. +FloodProtectorBankingSystemInterval = 30
  88. +FloodProtectorBankingSystemLogFlooding = False
  89. +FloodProtectorBankingSystemPunishmentLimit = 0
  90. +FloodProtectorBankingSystemPunishmentType = none
  91. +FloodProtectorBankingSystemPunishmentTime = 0
  92. +
  93. +FloodProtectorWerehouseInterval = 10
  94. +FloodProtectorWerehouseLogFlooding = False
  95. +FloodProtectorWerehousePunishmentLimit = 0
  96. +FloodProtectorWerehousePunishmentType = none
  97. +FloodProtectorWerehousePunishmentTime = 0
  98. +
  99. +FloodProtectorMiscInterval = 10
  100. +FloodProtectorMiscLogFlooding = False
  101. +FloodProtectorMiscPunishmentLimit = 0
  102. +FloodProtectorMiscPunishmentType = none
  103. +FloodProtectorMiscPunishmentTime = 0
  104. +
  105. +FloodProtectorChatInterval = 10
  106. +FloodProtectorChatLogFlooding = False
  107. +FloodProtectorChatPunishmentLimit = 0
  108. +FloodProtectorChatPunishmentType = none
  109. +FloodProtectorChatPunishmentTime = 0
  110. +
  111. +FloodProtectorGlobalInterval = 10
  112. +FloodProtectorGlobalLogFlooding = False
  113. +FloodProtectorGlobalPunishmentLimit = 0
  114. +FloodProtectorGlobalPunishmentType = none
  115. +FloodProtectorGlobalPunishmentTime = 0
  116. Index: /trunk/Eclipse/java/net/sf/l2j/Config.java
  117. ===================================================================
  118. --- /trunk/Eclipse/java/net/sf/l2j/Config.java (revision 421)
  119. +++ /trunk/Eclipse/java/net/sf/l2j/Config.java (revision 422)
  120. @@ -27,4 +27,7 @@
  121.  import javolution.util.FastList;
  122.  import javolution.util.FastMap;
  123. +
  124. +import net.sf.l2j.gameserver.util.FloodProtectorConfig;
  125. +import net.sf.l2j.gameserver.util.StringUtil;
  126.  
  127.  /**
  128. @@ -90,4 +93,23 @@
  129.     public static String SERVER_BUILD_DATE;
  130.     public static String DATAPACK_VERSION;
  131. +  
  132. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector");
  133. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector");
  134. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_FIREWORK = new FloodProtectorConfig("FireworkFloodProtector");
  135. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_ITEM_PET_SUMMON = new FloodProtectorConfig("ItemPetSummonFloodProtector");
  136. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_HERO_VOICE = new FloodProtectorConfig("HeroVoiceFloodProtector");
  137. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_SUBCLASS = new FloodProtectorConfig("SubclassFloodProtector");
  138. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_DROP_ITEM = new FloodProtectorConfig("DropItemFloodProtector");
  139. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_SERVER_BYPASS = new FloodProtectorConfig("ServerBypassFloodProtector");
  140. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_UNK_PACKETS = new FloodProtectorConfig("UnkPacketsFloodProtector");
  141. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_BUFFER = new FloodProtectorConfig("BufferFloodProtector");
  142. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_CRAFT = new FloodProtectorConfig("CraftFloodProtector");
  143. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_MULTISELL = new FloodProtectorConfig("MultiSellFloodProtector");
  144. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_BANKING_SYSTEM = new FloodProtectorConfig("BankingSystemFloodProtector");
  145. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_WEREHOUSE = new FloodProtectorConfig("WerehouseFloodProtector");
  146. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_MISC = new FloodProtectorConfig("MiscFloodProtector");
  147. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_CHAT = new FloodProtectorConfig("ChatFloodProtector");
  148. +   public static final FloodProtectorConfig FLOOD_PROTECTOR_GLOBAL = new FloodProtectorConfig("GlobalFloodProtector");
  149.     /** Start AltSettings.properties */
  150.     // Auto loots configs
  151. @@ -1682,7 +1704,6 @@
  152.                 FloodProtector.load(is);
  153.                 is.close();
  154. -              
  155. -               // Flood Tipos
  156. -              
  157. +               loadFloodProtectorConfigs(FloodProtector);
  158. +               _log.info("# " + FLOODPROTECTOR_CONFIG_FILE + " Sucessfully LOADED #");
  159.             }
  160.             catch (Exception e)
  161. @@ -1691,5 +1712,4 @@
  162.                 throw new Error("Failed to Load " + FLOODPROTECTOR_CONFIG_FILE + " File.");
  163.             }
  164. -           // access levels
  165.             try
  166.             {
  167. @@ -4019,4 +4039,33 @@
  168.         return true;
  169.     }
  170. +  
  171. +   private static void loadFloodProtectorConfigs(final Properties properties)
  172. +   {
  173. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_USE_ITEM, "UseItem", "4");
  174. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_ROLL_DICE, "RollDice", "42");
  175. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_FIREWORK, "Firework", "42");
  176. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_ITEM_PET_SUMMON, "ItemPetSummon", "16");
  177. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_HERO_VOICE, "HeroVoice", "100");
  178. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_SUBCLASS, "Subclass", "20");
  179. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_DROP_ITEM, "DropItem", "10");
  180. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_SERVER_BYPASS, "ServerBypass", "5");
  181. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_UNK_PACKETS, "UnkPackets", "5");
  182. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_BUFFER, "Buffer", "5");
  183. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_CRAFT, "Craft", "10");
  184. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_MULTISELL, "MultiSell", "30");
  185. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_WEREHOUSE, "Werehouse", "10");
  186. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_MISC, "Misc", "10");
  187. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_CHAT, "Chat", "10");
  188. +       loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_GLOBAL, "Global", "500");
  189. +   }
  190. +
  191. +   private static void loadFloodProtectorConfig(final Properties properties, final FloodProtectorConfig config, final String configString, final String defaultInterval)
  192. +   {
  193. +       config.FLOOD_PROTECTION_INTERVAL = Integer.parseInt(properties.getProperty(StringUtil.concat("FloodProtector", configString, "Interval"), defaultInterval));
  194. +       config.LOG_FLOODING = Boolean.parseBoolean(properties.getProperty(StringUtil.concat("FloodProtector", configString, "LogFlooding"), "False"));
  195. +       config.PUNISHMENT_LIMIT = Integer.parseInt(properties.getProperty(StringUtil.concat("FloodProtector", configString, "PunishmentLimit"), "0"));
  196. +       config.PUNISHMENT_TYPE = properties.getProperty(StringUtil.concat("FloodProtector", configString, "PunishmentType"), "none");
  197. +       config.PUNISHMENT_TIME = Integer.parseInt(properties.getProperty(StringUtil.concat("FloodProtector", configString, "PunishmentTime"), "0"));
  198. +   }
  199.  
  200.     /*
  201. Index: /trunk/Eclipse/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  202. ===================================================================
  203. --- /trunk/Eclipse/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 421)
  204. +++ /trunk/Eclipse/java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 422)
  205. @@ -201,4 +201,5 @@
  206.  import net.sf.l2j.gameserver.templates.L2WeaponType;
  207.  import net.sf.l2j.gameserver.util.Broadcast;
  208. +import net.sf.l2j.gameserver.util.FloodProtectors;
  209.  import net.sf.l2j.util.Point3D;
  210.  import net.sf.l2j.util.Rnd;
  211. @@ -382,4 +383,35 @@
  212.     private long _jailTimer = 0;
  213.     private ScheduledFuture<?> _jailTask;
  214. +  
  215. +   /** PunishLevel by Danielmwx **/
  216. +   private PunishLevel _punishLevel = PunishLevel.NONE; // TODO Clean up, delete old methods and add this one...
  217. +   private long _punishTimer = 0;
  218. +   private ScheduledFuture<?> _punishTask;
  219. +
  220. +   public enum PunishLevel
  221. +   {
  222. +       NONE(0, ""), CHAT(1, "chat banned"), JAIL(2, "jailed"), CHAR(3, "banned"), ACC(4, "banned");
  223. +       private int punValue;
  224. +       private String punString;
  225. +
  226. +       PunishLevel(int value, String string)
  227. +       {
  228. +           punValue = value;
  229. +           punString = string;
  230. +       }
  231. +
  232. +       public int value()
  233. +       {
  234. +           return punValue;
  235. +       }
  236. +
  237. +       public String string()
  238. +       {
  239. +           return punString;
  240. +       }
  241. +   }
  242. +
  243. +   private final FloodProtectors _floodProtectors = new FloodProtectors(this);
  244. +  
  245.     /** character away mode **/
  246.     private boolean _isAway = false;
  247. @@ -9174,4 +9206,16 @@
  248.     }
  249.  
  250. +   public L2Object _saymode = null;
  251. +
  252. +   public L2Object getSayMode()
  253. +   {
  254. +       return _saymode;
  255. +   }
  256. +
  257. +   public void setSayMode(L2Object say)
  258. +   {
  259. +       _saymode = say;
  260. +   }
  261. +
  262.     public boolean isChatBanned()
  263.     {
  264. @@ -12200,3 +12244,234 @@
  265.         _gatesRequest.setTarget(null);
  266.     }
  267. +   /**
  268. +    * returns punishment level of player
  269. +    *
  270. +    * @return
  271. +    */
  272. +   public PunishLevel getPunishLevel()
  273. +   {
  274. +       return _punishLevel;
  275. +   }
  276. +
  277. +   /**
  278. +    * @return True if player is jailed
  279. +    */
  280. +   @Deprecated
  281. +   public boolean isInJail_()
  282. +   {
  283. +       return _punishLevel == PunishLevel.JAIL;
  284. +   }
  285. +
  286. +   // TODO clean up please...
  287. +   /**
  288. +    * @return True if player is chat banned
  289. +    */
  290. +   @Deprecated
  291. +   public boolean isChatBanned_()
  292. +   {
  293. +       return _punishLevel == PunishLevel.CHAT;
  294. +   }
  295. +
  296. +   public void setPunishLevel(int state)
  297. +   {
  298. +       switch (state)
  299. +       {
  300. +           case 0:
  301. +           {
  302. +               _punishLevel = PunishLevel.NONE;
  303. +               break;
  304. +           }
  305. +           case 1:
  306. +           {
  307. +               _punishLevel = PunishLevel.CHAT;
  308. +               break;
  309. +           }
  310. +           case 2:
  311. +           {
  312. +               _punishLevel = PunishLevel.JAIL;
  313. +               break;
  314. +           }
  315. +           case 3:
  316. +           {
  317. +               _punishLevel = PunishLevel.CHAR;
  318. +               break;
  319. +           }
  320. +           case 4:
  321. +           {
  322. +               _punishLevel = PunishLevel.ACC;
  323. +               break;
  324. +           }
  325. +       }
  326. +   }
  327. +
  328. +   /**
  329. +    * Sets punish level for player based on delay
  330. +    *
  331. +    * @param state
  332. +    * @param delayInMinutes
  333. +    *            0 - Indefinite
  334. +    */
  335. +   public void setPunishLevel(PunishLevel state, int delayInMinutes)
  336. +   {
  337. +       long delayInMilliseconds = delayInMinutes * 60000L;
  338. +       switch (state)
  339. +       {
  340. +           case NONE: // Remove Punishments
  341. +           {
  342. +               switch (_punishLevel)
  343. +               {
  344. +                   case CHAT:
  345. +                   {
  346. +                       _punishLevel = state;
  347. +                       stopPunishTask(true);
  348. +                       sendPacket(new EtcStatusUpdate(this));
  349. +                       sendMessage("Your Chat ban has been lifted");
  350. +                       break;
  351. +                   }
  352. +                   case JAIL:
  353. +                   {
  354. +                       _punishLevel = state;
  355. +                       // Open a Html message to inform the player
  356. +                       NpcHtmlMessage htmlMsg = new NpcHtmlMessage(0);
  357. +                       String jailInfos = HtmCache.getInstance().getHtm("data/html/jail_out.htm");
  358. +                       if (jailInfos != null)
  359. +                           htmlMsg.setHtml(jailInfos);
  360. +                       else
  361. +                           htmlMsg.setHtml("<html><body>You are free for now, respect server rules!</body></html>");
  362. +                       sendPacket(htmlMsg);
  363. +                       stopPunishTask(true);
  364. +                       teleToLocation(17836, 170178, -3507, true); // Floran
  365. +                       break;
  366. +                   }
  367. +               }
  368. +               break;
  369. +           }
  370. +           case CHAT: // Chat Ban
  371. +           {
  372. +               _punishLevel = state;
  373. +               _punishTimer = 0;
  374. +               sendPacket(new EtcStatusUpdate(this));
  375. +               // Remove the task if any
  376. +               stopPunishTask(false);
  377. +               if (delayInMinutes > 0)
  378. +               {
  379. +                   _punishTimer = delayInMilliseconds;
  380. +                   // start the countdown
  381. +                   _punishTask = ThreadPoolManager.getInstance().scheduleGeneral(new PunishTask(this), _punishTimer);
  382. +                   sendMessage("You are chat banned for " + delayInMinutes + " minutes.");
  383. +               }
  384. +               else
  385. +                   sendMessage("You have been chat banned");
  386. +               break;
  387. +           }
  388. +           case JAIL: // Jail Player
  389. +           {
  390. +               _punishLevel = state;
  391. +               _punishTimer = 0;
  392. +               // Remove the task if any
  393. +               stopPunishTask(false);
  394. +               if (delayInMinutes > 0)
  395. +               {
  396. +                   _punishTimer = delayInMilliseconds;
  397. +                   // start the countdown
  398. +                   _punishTask = ThreadPoolManager.getInstance().scheduleGeneral(new PunishTask(this), _punishTimer);
  399. +                   sendMessage("You are in jail for " + delayInMinutes + " minutes.");
  400. +               }
  401. +               // Open a Html message to inform the player
  402. +               NpcHtmlMessage htmlMsg = new NpcHtmlMessage(0);
  403. +               String jailInfos = HtmCache.getInstance().getHtm("data/html/jail_in.htm");
  404. +               if (jailInfos != null)
  405. +                   htmlMsg.setHtml(jailInfos);
  406. +               else
  407. +                   htmlMsg.setHtml("<html><body>You have been put in jail by an admin.</body></html>");
  408. +               sendPacket(htmlMsg);
  409. +               setInstanceId(0);
  410. +               teleToLocation(-114356, -249645, -2984, false); // Jail
  411. +               break;
  412. +           }
  413. +           case CHAR: // Ban Character
  414. +           case ACC: // Ban Account
  415. +           default:
  416. +           {
  417. +               _punishLevel = state;
  418. +               break;
  419. +           }
  420. +       }
  421. +       // store in database
  422. +       storeCharBase();
  423. +   }
  424. +
  425. +   public long getPunishTimer()
  426. +   {
  427. +       return _punishTimer;
  428. +   }
  429. +
  430. +   public void setPunishTimer(long time)
  431. +   {
  432. +       _punishTimer = time;
  433. +   }
  434. +
  435. +   @Deprecated
  436. +   @SuppressWarnings("unused")
  437. +   private void updatePunishState()// TODO Next clean up this shood be active
  438. +   {
  439. +       if (getPunishLevel() != PunishLevel.NONE)
  440. +       {
  441. +           // If punish timer exists, restart punishtask.
  442. +           if (_punishTimer > 0)
  443. +           {
  444. +               _punishTask = ThreadPoolManager.getInstance().scheduleGeneral(new PunishTask(this), _punishTimer);
  445. +               sendMessage("You are still " + getPunishLevel().string() + " for " + Math.round(_punishTimer / 60000) + " minutes.");
  446. +           }
  447. +           if (getPunishLevel() == PunishLevel.JAIL)
  448. +           {
  449. +               // If player escaped, put him back in jail
  450. +               if (!isInsideZone(ZONE_JAIL))
  451. +                   teleToLocation(-114356, -249645, -2984, true);
  452. +           }
  453. +       }
  454. +   }
  455. +
  456. +   public void stopPunishTask(boolean save)
  457. +   {
  458. +       if (_punishTask != null)
  459. +       {
  460. +           if (save)
  461. +           {
  462. +               long delay = _punishTask.getDelay(TimeUnit.MILLISECONDS);
  463. +               if (delay < 0)
  464. +                   delay = 0;
  465. +               setPunishTimer(delay);
  466. +           }
  467. +           _punishTask.cancel(false);
  468. +           _punishTask = null;
  469. +       }
  470. +   }
  471. +
  472. +   private class PunishTask implements Runnable
  473. +   {
  474. +       L2PcInstance _player;
  475. +       protected long _startedAt;
  476. +
  477. +       protected PunishTask(L2PcInstance player)
  478. +       {
  479. +           _player = player;
  480. +           _startedAt = System.currentTimeMillis();
  481. +       }
  482. +
  483. +       public void run()
  484. +       {
  485. +           _player.setPunishLevel(PunishLevel.NONE, 0);
  486. +       }
  487. +   }
  488. +
  489. +   public FloodProtectors getFloodProtectors()
  490. +   {
  491. +       return _floodProtectors;
  492. +   }
  493. +
  494. +   public void systemSendMessage(SystemMessageId id)
  495. +   {
  496. +       sendPacket(new SystemMessage(id));
  497. +   }
  498.  }
  499. Index: /trunk/Eclipse/java/net/sf/l2j/gameserver/util/FloodProtectorAction.java
  500. ===================================================================
  501. --- /trunk/Eclipse/java/net/sf/l2j/gameserver/util/FloodProtectorAction.java (revision 422)
  502. +++ /trunk/Eclipse/java/net/sf/l2j/gameserver/util/FloodProtectorAction.java (revision 422)
  503. @@ -0,0 +1,145 @@
  504. +/*
  505. + * This program is free software: you can redistribute it and/or modify it under
  506. + * the terms of the GNU General Public License as published by the Free Software
  507. + * Foundation, either version 3 of the License, or (at your option) any later
  508. + * version.
  509. + *
  510. + * This program is distributed in the hope that it will be useful, but WITHOUT
  511. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  512. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  513. + * details.
  514. + *
  515. + * You should have received a copy of the GNU General Public License along with
  516. + * this program. If not, see <http://www.gnu.org/licenses/>.
  517. + */
  518. +package net.sf.l2j.gameserver.util;
  519. +
  520. +import java.util.concurrent.atomic.AtomicInteger;
  521. +import java.util.logging.Level;
  522. +import java.util.logging.Logger;
  523. +
  524. +import net.sf.l2j.gameserver.GameTimeController;
  525. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  526. +
  527. +public final class FloodProtectorAction
  528. +{
  529. +   /**
  530. +    * Logger
  531. +    */
  532. +   private static final Logger _log = Logger.getLogger(FloodProtectorAction.class.getName());
  533. +   /**
  534. +    * Player for this instance of flood protector.
  535. +    */
  536. +   private final L2PcInstance _player;
  537. +   /**
  538. +    * Configuration of this instance of flood protector.
  539. +    */
  540. +   private final FloodProtectorConfig _config;
  541. +   /**
  542. +    * Next game tick when new request is allowed.
  543. +    */
  544. +   private volatile int _nextGameTick = GameTimeController.getGameTicks();
  545. +   /**
  546. +    * Request counter.
  547. +    */
  548. +   private AtomicInteger _count = new AtomicInteger(0);
  549. +   /**
  550. +    * Flag determining whether exceeding request has been logged.
  551. +    */
  552. +   private boolean _logged;
  553. +   /**
  554. +    * Flag determining whether punishment application is in progress so that we do not apply punisment multiple times (flooding).
  555. +    */
  556. +   private volatile boolean _punishmentInProgress;
  557. +
  558. +   /**
  559. +    * Creates new instance of FloodProtectorAction.
  560. +    *
  561. +    * @param player
  562. +    *            player for which flood protection is being created
  563. +    * @param config
  564. +    *            flood protector configuration
  565. +    */
  566. +   public FloodProtectorAction(final L2PcInstance player, final FloodProtectorConfig config)
  567. +   {
  568. +       super();
  569. +       _player = player;
  570. +       _config = config;
  571. +   }
  572. +
  573. +   /**
  574. +    * Checks whether the request is flood protected or not.
  575. +    *
  576. +    * @param command
  577. +    *            command issued or short command description
  578. +    * @return true if action is allowed, otherwise false
  579. +    */
  580. +   public boolean tryPerformAction(final String command)
  581. +   {
  582. +       final int curTick = GameTimeController.getGameTicks();
  583. +       if (curTick < _nextGameTick || _punishmentInProgress)
  584. +       {
  585. +           if (_config.LOG_FLOODING && !_logged && _log.isLoggable(Level.WARNING))
  586. +           {
  587. +               _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"));
  588. +               _logged = true;
  589. +           }
  590. +           _count.incrementAndGet();
  591. +           if (!_punishmentInProgress && _config.PUNISHMENT_LIMIT > 0 && _count.get() > _config.PUNISHMENT_LIMIT && _config.PUNISHMENT_TYPE != null)
  592. +           {
  593. +               _punishmentInProgress = true;
  594. +               if ("ban".equals(_config.PUNISHMENT_TYPE))
  595. +               {
  596. +                   banAccount();
  597. +               }
  598. +               else if ("jail".equals(_config.PUNISHMENT_TYPE))
  599. +               {
  600. +                   jailChar();
  601. +               }
  602. +               _punishmentInProgress = false;
  603. +           }
  604. +           return false;
  605. +       }
  606. +       if (_count.get() > 0)
  607. +       {
  608. +           if (_config.LOG_FLOODING && _log.isLoggable(Level.WARNING))
  609. +           {
  610. +               _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]"));
  611. +           }
  612. +       }
  613. +       _nextGameTick = curTick + _config.FLOOD_PROTECTION_INTERVAL;
  614. +       _logged = false;
  615. +       _count.set(0);
  616. +       return true;
  617. +   }
  618. +
  619. +   /**
  620. +    * Bans char account and logs out the char.
  621. +    */
  622. +   private void banAccount()
  623. +   {
  624. +       _player.setPunishLevel(L2PcInstance.PunishLevel.ACC, _config.PUNISHMENT_TIME);
  625. +       if (_log.isLoggable(Level.WARNING))
  626. +       {
  627. +           _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"));
  628. +       }
  629. +       _player.logout();
  630. +   }
  631. +
  632. +   /**
  633. +    * Jails char.
  634. +    */
  635. +   private void jailChar()
  636. +   {
  637. +       _player.setPunishLevel(L2PcInstance.PunishLevel.JAIL, _config.PUNISHMENT_TIME);
  638. +       if (_log.isLoggable(Level.WARNING))
  639. +       {
  640. +           _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"));
  641. +       }
  642. +   }
  643. +}
  644. Index: /trunk/Eclipse/java/net/sf/l2j/gameserver/util/FloodProtectors.java
  645. ===================================================================
  646. --- /trunk/Eclipse/java/net/sf/l2j/gameserver/util/FloodProtectors.java
  647. +++ /trunk/Eclipse/java/net/sf/l2j/gameserver/util/FloodProtectors.java
  648. @@ -0,0 +1,293 @@
  649. +/*
  650. + * This program is free software: you can redistribute it and/or modify it under
  651. + * the terms of the GNU General Public License as published by the Free Software
  652. + * Foundation, either version 3 of the License, or (at your option) any later
  653. + * version.
  654. + *
  655. + * This program is distributed in the hope that it will be useful, but WITHOUT
  656. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  657. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  658. + * details.
  659. + *
  660. + * You should have received a copy of the GNU General Public License along with
  661. + * this program. If not, see <http://www.gnu.org/licenses/>.
  662. + */
  663. +package net.sf.l2j.gameserver.util;
  664. +
  665. +import net.sf.l2j.Config;
  666. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  667. +
  668. +public final class FloodProtectors
  669. +{
  670. +   /**
  671. +    * Use-item flood protector.
  672. +    */
  673. +   private final FloodProtectorAction _useItem;
  674. +   /**
  675. +    * Roll-dice flood protector.
  676. +    */
  677. +   private final FloodProtectorAction _rollDice;
  678. +   /**
  679. +    * Firework flood protector.
  680. +    */
  681. +   private final FloodProtectorAction _firework;
  682. +   /**
  683. +    * Item-pet-summon flood protector.
  684. +    */
  685. +   private final FloodProtectorAction _itemPetSummon;
  686. +   /**
  687. +    * Hero-voice flood protector.
  688. +    */
  689. +   private final FloodProtectorAction _heroVoice;
  690. +   /**
  691. +    * Subclass flood protector.
  692. +    */
  693. +   private final FloodProtectorAction _subclass;
  694. +   /**
  695. +    * Drop-item flood protector.
  696. +    */
  697. +   private final FloodProtectorAction _dropItem;
  698. +   /**
  699. +    * Wnk flood protector.
  700. +    */
  701. +   private final FloodProtectorAction _wnk;
  702. +   /**
  703. +    * Server-bypass flood protector.
  704. +    */
  705. +   private final FloodProtectorAction _serverBypass;
  706. +   /**
  707. +    * Buffer flood protector.
  708. +    */
  709. +   private final FloodProtectorAction _buffer;
  710. +   /**
  711. +    * Craft flood protector.
  712. +    */
  713. +   private final FloodProtectorAction _craft;
  714. +   /**
  715. +    * Multisell flood protector.
  716. +    */
  717. +   private final FloodProtectorAction _multisell;
  718. +   /**
  719. +    * Banking System Flood Protector.
  720. +    */
  721. +   private final FloodProtectorAction _BankingSystem;
  722. +   /**
  723. +    * Werehouse Flood Protector.
  724. +    */
  725. +   private final FloodProtectorAction _werehouse;
  726. +   /**
  727. +    * Misc Flood Protector.
  728. +    */
  729. +   private final FloodProtectorAction _misc;
  730. +   /**
  731. +    * Chat Flood Protector.
  732. +    */
  733. +   private final FloodProtectorAction _chat;
  734. +   /**
  735. +    * Chat Global Flood Protector.
  736. +    */
  737. +   private final FloodProtectorAction _global;
  738. +
  739. +   /**
  740. +    * Creates new instance of FloodProtectors.
  741. +    *
  742. +    * @param player
  743. +    *            player for which the collection of flood protectors is being created.
  744. +    */
  745. +   public FloodProtectors(final L2PcInstance player)
  746. +   {
  747. +       super();
  748. +       _useItem = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_USE_ITEM);
  749. +       _rollDice = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_ROLL_DICE);
  750. +       _firework = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_FIREWORK);
  751. +       _itemPetSummon = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_ITEM_PET_SUMMON);
  752. +       _heroVoice = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_HERO_VOICE);
  753. +       _subclass = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_SUBCLASS);
  754. +       _dropItem = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_DROP_ITEM);
  755. +       _wnk = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_UNK_PACKETS);
  756. +       _serverBypass = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_SERVER_BYPASS);
  757. +       _buffer = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_BUFFER);
  758. +       _craft = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_CRAFT);
  759. +       _multisell = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_MULTISELL);
  760. +       _BankingSystem = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_BANKING_SYSTEM);
  761. +       _werehouse = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_WEREHOUSE);
  762. +       _misc = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_MISC);
  763. +       _chat = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_CHAT);
  764. +       _global = new FloodProtectorAction(player, Config.FLOOD_PROTECTOR_GLOBAL);
  765. +   }
  766. +
  767. +   /**
  768. +    * Returns {@link #_useItem}.
  769. +    *
  770. +    * @return {@link #_useItem}
  771. +    */
  772. +   public FloodProtectorAction getUseItem()
  773. +   {
  774. +       return _useItem;
  775. +   }
  776. +
  777. +   /**
  778. +    * Returns {@link #_rollDice}.
  779. +    *
  780. +    * @return {@link #_rollDice}
  781. +    */
  782. +   public FloodProtectorAction getRollDice()
  783. +   {
  784. +       return _rollDice;
  785. +   }
  786. +
  787. +   /**
  788. +    * Returns {@link #_firework}.
  789. +    *
  790. +    * @return {@link #_firework}
  791. +    */
  792. +   public FloodProtectorAction getFirework()
  793. +   {
  794. +       return _firework;
  795. +   }
  796. +
  797. +   /**
  798. +    * Returns {@link #_itemPetSummon}.
  799. +    *
  800. +    * @return {@link #_itemPetSummon}
  801. +    */
  802. +   public FloodProtectorAction getItemPetSummon()
  803. +   {
  804. +       return _itemPetSummon;
  805. +   }
  806. +
  807. +   /**
  808. +    * Returns {@link #_heroVoice}.
  809. +    *
  810. +    * @return {@link #_heroVoice}
  811. +    */
  812. +   public FloodProtectorAction getHeroVoice()
  813. +   {
  814. +       return _heroVoice;
  815. +   }
  816. +
  817. +   /**
  818. +    * Returns {@link #_subclass}.
  819. +    *
  820. +    * @return {@link #_subclass}
  821. +    */
  822. +   public FloodProtectorAction getSubclass()
  823. +   {
  824. +       return _subclass;
  825. +   }
  826. +
  827. +   /**
  828. +    * Returns {@link #_dropItem}.
  829. +    *
  830. +    * @return {@link #_dropItem}
  831. +    */
  832. +   public FloodProtectorAction getDropItem()
  833. +   {
  834. +       return _dropItem;
  835. +   }
  836. +  
  837. +   /**
  838. +    * Returns {@link #_wnk}.
  839. +    *
  840. +    * @return {@link #_wnk}
  841. +    */
  842. +   public FloodProtectorAction getWnk()
  843. +   {
  844. +       return _wnk;
  845. +   }
  846. +
  847. +   /**
  848. +    * Returns {@link #_serverBypass}.
  849. +    *
  850. +    * @return {@link #_serverBypass}
  851. +    */
  852. +   public FloodProtectorAction getServerBypass()
  853. +   {
  854. +       return _serverBypass;
  855. +   }
  856. +
  857. +   /**
  858. +    * Returns {@link #_buffer}.
  859. +    *
  860. +    * @return {@link #_buffer}
  861. +    */
  862. +   public FloodProtectorAction getBuffer()
  863. +   {
  864. +       return _buffer;
  865. +   }
  866. +
  867. +   /**
  868. +    * Returns {@link #_craft}.
  869. +    *
  870. +    * @return {@link #_craft}
  871. +    */
  872. +   public FloodProtectorAction getCraft()
  873. +   {
  874. +       return _craft;
  875. +   }
  876. +
  877. +   /**
  878. +    * Returns {@link #_multisell}.
  879. +    *
  880. +    * @return {@link #_multisell}
  881. +    */
  882. +   public FloodProtectorAction getMultisell()
  883. +   {
  884. +       return _multisell;
  885. +   }
  886. +
  887. +   /**
  888. +    * Returns {@link #_BankingSystem}.
  889. +    *
  890. +    * @return {@link #_BankingSystem}
  891. +    */
  892. +   public FloodProtectorAction getBankingSystem()
  893. +   {
  894. +       return _BankingSystem;
  895. +   }
  896. +
  897. +   /**
  898. +    * Returns {@link #_werehouse}.
  899. +    *
  900. +    * @return {@link #_werehouse}
  901. +    */
  902. +   public FloodProtectorAction getWerehouse()
  903. +   {
  904. +       return _werehouse;
  905. +   }
  906. +
  907. +   /**
  908. +    * Returns {@link #_misc}.
  909. +    *
  910. +    * @return {@link #_misc}
  911. +    */
  912. +   public FloodProtectorAction getMisc()
  913. +   {
  914. +       return _misc;
  915. +   }
  916. +
  917. +   /**
  918. +    * Returns {@link #_chat}.
  919. +    *
  920. +    * @return {@link #_chat}
  921. +    */
  922. +   public FloodProtectorAction getChat()
  923. +   {
  924. +       return _chat;
  925. +   }
  926. +
  927. +   /**
  928. +    * Returns {@link #_global}.
  929. +    *
  930. +    * @return {@link #_global}
  931. +    */
  932. +   public FloodProtectorAction getGlobal()
  933. +   {
  934. +       return _global;
  935. +   }
  936. +}
  937. Index: /trunk/Eclipse/java/net/sf/l2j/gameserver/util/FloodProtectorConfig.java
  938. ===================================================================
  939. --- /trunk/Eclipse/java/net/sf/l2j/gameserver/util/FloodProtectorConfig.java
  940. +++ /trunk/Eclipse/java/net/sf/l2j/gameserver/util/FloodProtectorConfig.java
  941. @@ -0,0 +1,60 @@
  942. +/*
  943. + * This program is free software: you can redistribute it and/or modify it under
  944. + * the terms of the GNU General Public License as published by the Free Software
  945. + * Foundation, either version 3 of the License, or (at your option) any later
  946. + * version.
  947. + *
  948. + * This program is distributed in the hope that it will be useful, but WITHOUT
  949. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  950. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  951. + * details.
  952. + *
  953. + * You should have received a copy of the GNU General Public License along with
  954. + * this program. If not, see <http://www.gnu.org/licenses/>.
  955. + */
  956. +package net.sf.l2j.gameserver.util;
  957. +
  958. +public final class FloodProtectorConfig
  959. +{
  960. +   /**
  961. +    * Type used for identification of logging output.
  962. +    */
  963. +   public String FLOOD_PROTECTOR_TYPE;
  964. +   /**
  965. +    * Flood protection interval in game ticks.
  966. +    */
  967. +   public int FLOOD_PROTECTION_INTERVAL;
  968. +   /**
  969. +    * Whether flooding should be logged.
  970. +    */
  971. +   public boolean LOG_FLOODING;
  972. +   /**
  973. +    * If specified punishment limit is exceeded, punishment is applied.
  974. +    */
  975. +   public int PUNISHMENT_LIMIT;
  976. +   /**
  977. +    * Punishment type. Either 'none', 'ban' or 'jail'.
  978. +    */
  979. +   public String PUNISHMENT_TYPE;
  980. +   /**
  981. +    * For how long should the char/account be punished.
  982. +    */
  983. +   public int PUNISHMENT_TIME;
  984. +
  985. +   /**
  986. +    * Creates new instance of FloodProtectorConfig.
  987. +    *
  988. +    * @param floodProtectorType
  989. +    *            {@link #FLOOD_PROTECTOR_TYPE}
  990. +    */
  991. +   public FloodProtectorConfig(final String floodProtectorType)
  992. +   {
  993. +       super();
  994. +       FLOOD_PROTECTOR_TYPE = floodProtectorType;
  995. +   }
  996. +}
  997.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement