Guest User

Untitled

a guest
Jun 11th, 2017
590
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 47.56 KB | None | 0 0
  1. package quests.AntiBotPW;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.FontMetrics;
  6. import java.awt.Graphics2D;
  7. import java.awt.RenderingHints;
  8. import java.awt.geom.Rectangle2D.Float;
  9. import java.awt.image.BufferedImage;
  10. import java.awt.image.ColorModel;
  11. import java.io.File;
  12. import java.io.FileInputStream;
  13. import java.io.FileWriter;
  14. import java.io.IOException;
  15. import java.io.InputStream;
  16. import java.io.PrintStream;
  17. import java.nio.ByteBuffer;
  18. import java.nio.ByteOrder;
  19. import java.sql.PreparedStatement;
  20. import java.sql.ResultSet;
  21. import java.sql.SQLException;
  22. import java.util.HashMap;
  23. import java.util.Iterator;
  24. import java.util.Properties;
  25. import java.util.Random;
  26. import java.util.concurrent.ScheduledFuture;
  27. import java.util.logging.Logger;
  28. import javolution.util.FastList;
  29. import net.sf.l2j.Config;
  30. import net.sf.l2j.L2DatabaseFactory;
  31. import net.sf.l2j.gameserver.ThreadPoolManager;
  32. import net.sf.l2j.gameserver.model.L2Character;
  33. import net.sf.l2j.gameserver.model.L2Object;
  34. import net.sf.l2j.gameserver.model.L2Skill;
  35. import net.sf.l2j.gameserver.model.L2Skill.SkillType;
  36. import net.sf.l2j.gameserver.model.L2Summon;
  37. import net.sf.l2j.gameserver.model.actor.instance.L2GrandBossInstance;
  38. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  39. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  40. import net.sf.l2j.gameserver.model.actor.instance.L2RaidBossInstance;
  41. import net.sf.l2j.gameserver.model.quest.Quest;
  42. import net.sf.l2j.gameserver.network.SystemMessageId;
  43. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUser;
  44. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  45. import net.sf.l2j.gameserver.network.serverpackets.PledgeCrest;
  46. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  47. import net.sf.l2j.gameserver.util.Util;
  48. import net.sf.l2j.mysql.Close;
  49. import net.sf.l2j.mysql.Connect;
  50. import net.sf.l2j.util.Rnd;
  51. import scripts.commands.IVoicedCommandHandler;
  52. import scripts.commands.VoicedCommandHandler;
  53. import scripts.skills.ISkillHandler;
  54. import scripts.skills.SkillHandler;
  55.  
  56. public class AntiBotPW
  57.   extends Quest
  58. {
  59.   public static boolean AntiBotPWCaptchaEnable;
  60.   public static int AntiBotPWCaptchaMode;
  61.   public static boolean AntiBotPWCaptchaEnableNpc;
  62.   public static boolean AntiBotPWCaptchaEnableCmd;
  63.   public static boolean AntiBotPWCaptchaEnableSkill;
  64.   public static String MONSTERSs;
  65.   public static FastList<Integer> MONSTERS = new FastList();
  66.   public static int AntiBotPWTriggerChance;
  67.   public static int AntiBotPWLVL;
  68.   public static int CaptchaAntiBotPWKick;
  69.   public static int[] CaptchaAntiBotPWLoc = { 82543, 149221, 62068 };
  70.   public static int AntiBotPWReCheckInterval;
  71.   public static int AntiBotPWReCheckEndingInterval;
  72.   public static boolean AntiBotPWReCheckEndingGM;
  73.   public static int CaptchaCountError;
  74.   public static boolean AntiBotPWCaptchaNoble;
  75.   public static boolean AntiBotPWCaptchaHero;
  76.   public static boolean AntiBotPWCaptchaPremium;
  77.   public static boolean AntiBotPWNewCore;
  78.   public static int AntiBotPWCMDPlayerLVL;
  79.   public static int AntiBotPWCMDTargetLVL;
  80.   public static int AntiBotPWCMDSkill;
  81.   public static boolean AntiBotPWLog;
  82.   private static final Logger _log = Logger.getLogger(AntiBotPW.class.getName());
  83.   private HashMap<L2PcInstance, BotResults> _players;
  84.   private HashMap<L2PcInstance, String> _codes;
  85.   private HashMap<L2PcInstance, Integer> _errors;
  86.   private HashMap<L2PcInstance, Integer> _recheckending;
  87.   protected HashMap<L2PcInstance, BotEye> _activeEyes;
  88.   private static final String qn = "AntiBotPW";
  89.  
  90.   public AntiBotPW()
  91.   {
  92.     super(-1, "AntiBotPW", "custom");
  93.    
  94.     loadAntiBotPWCfg();
  95.     if (AntiBotPWCaptchaEnable)
  96.     {
  97.       for (Iterator localIterator = MONSTERS.iterator(); localIterator.hasNext();)
  98.       {
  99.         int mobs = ((Integer)localIterator.next()).intValue();
  100.         addKillId(mobs);
  101.       }
  102.       _log.info("-------------------------------------------");
  103.       _log.info("##########     AntiBot: PWsoft   ##########");
  104.       _log.info("##########  Developer: ncs.SpawN ##########");
  105.       _log.info("##########  Share: gvb ICQ: 685308391 #####");
  106.       _log.info("##########     Site: L2CODE.RU    #########");
  107.       _log.info("-------------------------------------------");
  108.       this._players = new HashMap();
  109.       this._codes = new HashMap();
  110.       this._errors = new HashMap();
  111.       this._recheckending = new HashMap();
  112.       this._activeEyes = new HashMap();
  113.       new SecurityCode();
  114.       new AntiBotPWSkillTP1();
  115.     }
  116.   }
  117.  
  118.   public static void loadAntiBotPWCfg()
  119.   {
  120.     try
  121.     {
  122.       Properties AntiBotPWSettings = new Properties();
  123.       InputStream is = new FileInputStream(new File("./config/AntiBotPW.cfg"));
  124.       AntiBotPWSettings.load(is);
  125.       is.close();
  126.       AntiBotPWCaptchaEnable = Boolean.valueOf(AntiBotPWSettings.getProperty("CaptchaEnable", "true")).booleanValue();
  127.       AntiBotPWCaptchaMode = Integer.parseInt(AntiBotPWSettings.getProperty("CaptchaMode", "2"));
  128.       AntiBotPWCaptchaEnableNpc = Boolean.valueOf(AntiBotPWSettings.getProperty("CaptchaEnableNpc", "true")).booleanValue();
  129.       AntiBotPWCaptchaEnableCmd = Boolean.valueOf(AntiBotPWSettings.getProperty("CaptchaEnableCmd", "true")).booleanValue();
  130.       AntiBotPWCaptchaEnableSkill = Boolean.valueOf(AntiBotPWSettings.getProperty("CaptchaEnableSkill", "true")).booleanValue();
  131.       String[] propertySplit = AntiBotPWSettings.getProperty("Loc", "82543,149221,-3468").split(",");
  132.       CaptchaAntiBotPWLoc[0] = Integer.parseInt(propertySplit[0]);
  133.       CaptchaAntiBotPWLoc[1] = Integer.parseInt(propertySplit[1]);
  134.       CaptchaAntiBotPWLoc[2] = Integer.parseInt(propertySplit[2]);
  135.      
  136.       MONSTERSs = AntiBotPWSettings.getProperty("MONSTERS", "2375,3500,3501,3502,4422,4423,4424,4425,6648,6649,6650,9882");
  137.       MONSTERS = new FastList();
  138.       for (String id : MONSTERSs.trim().split(",")) {
  139.         MONSTERS.add(Integer.valueOf(Integer.parseInt(id.trim())));
  140.       }
  141.       AntiBotPWTriggerChance = Integer.parseInt(AntiBotPWSettings.getProperty("TriggerChance", "10"));
  142.      
  143.       AntiBotPWLVL = Integer.parseInt(AntiBotPWSettings.getProperty("LVL", "76"));
  144.       CaptchaAntiBotPWKick = Integer.parseInt(AntiBotPWSettings.getProperty("Kick", "3"));
  145.       AntiBotPWReCheckInterval = Integer.parseInt(AntiBotPWSettings.getProperty("ReCheckInterval", "300"));
  146.       AntiBotPWReCheckEndingInterval = Integer.parseInt(AntiBotPWSettings.getProperty("ReCheckEndingInterval", "5"));
  147.       AntiBotPWReCheckEndingGM = Boolean.valueOf(AntiBotPWSettings.getProperty("ReCheckEndingGM", "true")).booleanValue();
  148.       CaptchaCountError = Integer.parseInt(AntiBotPWSettings.getProperty("CountError", "3"));
  149.       AntiBotPWCaptchaNoble = Boolean.valueOf(AntiBotPWSettings.getProperty("CaptchaNoble", "true")).booleanValue();
  150.       AntiBotPWCaptchaHero = Boolean.valueOf(AntiBotPWSettings.getProperty("CaptchaHero", "true")).booleanValue();
  151.       AntiBotPWCaptchaPremium = Boolean.valueOf(AntiBotPWSettings.getProperty("CaptchaPremium ", "true")).booleanValue();
  152.       AntiBotPWNewCore = Boolean.valueOf(AntiBotPWSettings.getProperty("NewCore", "true")).booleanValue();
  153.       AntiBotPWCMDPlayerLVL = Integer.parseInt(AntiBotPWSettings.getProperty("CMDPlayerLVL", "76"));
  154.       AntiBotPWCMDTargetLVL = Integer.parseInt(AntiBotPWSettings.getProperty("CMDTargetLVL", "76"));
  155.       AntiBotPWCMDSkill = Integer.parseInt(AntiBotPWSettings.getProperty("CMDSkill", "7100"));
  156.       AntiBotPWLog = Boolean.valueOf(AntiBotPWSettings.getProperty("Log", "true")).booleanValue();
  157.     }
  158.     catch (Exception e)
  159.     {
  160.       e.printStackTrace();
  161.       throw new Error("Failed to Load ./config/AntiBotPW.cfg File.");
  162.     }
  163.   }
  164.  
  165.   public String onKill(L2NpcInstance npc, L2PcInstance player, boolean isPet)
  166.   {
  167.     L2Character character = player;
  168.     L2Object target = character != null ? character.getTarget() : null;
  169.     if ((character instanceof L2PcInstance)) {
  170.       player = character.getPlayer();
  171.     } else if ((character instanceof L2Summon)) {
  172.       player = character.getPlayer();
  173.     }
  174.     if (player == null)
  175.     {
  176.       _log.info("AntiBotPW: #onKill for null.");
  177.       return null;
  178.     }
  179.     if (((target instanceof L2RaidBossInstance)) || ((target instanceof L2GrandBossInstance))) {
  180.       return null;
  181.     }
  182.     if (((target instanceof L2PcInstance)) || ((target instanceof L2Summon))) {
  183.       return null;
  184.     }
  185.     if ((!AntiBotPWCaptchaEnableNpc) || (player.getLevel() < AntiBotPWLVL)) {
  186.       return null;
  187.     }
  188.     if ((!AntiBotPWCaptchaPremium) && (player.isPremium())) {
  189.       return null;
  190.     }
  191.     if ((!AntiBotPWCaptchaHero) && (player.isHero())) {
  192.       return null;
  193.     }
  194.     if ((!AntiBotPWCaptchaNoble) && (player.isNoble())) {
  195.       return null;
  196.     }
  197.     if ((Rnd.get(100) < AntiBotPWTriggerChance) && (!this._activeEyes.containsKey(player)))
  198.     {
  199.       int current_time = (int)(System.currentTimeMillis() / 1000L);
  200.       int player_time = 0;
  201.       if (this._recheckending.containsKey(player)) {
  202.         player_time = ((Integer)this._recheckending.get(player)).intValue();
  203.       }
  204.       if (player_time > current_time)
  205.       {
  206.         int last_sec = ((Integer)this._recheckending.get(player)).intValue() - current_time;
  207.         player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("???? ???: ? ??????? " + last_sec + " ?????? ???????? ??? ??? ?????????."));
  208.         return null;
  209.       }
  210.       player.broadcastPacket(new MagicSkillUser(player, player, 1427, 1, 10, 0));
  211.       int counterrors = CaptchaCountError;
  212.       this._errors.put(player, Integer.valueOf(counterrors));
  213.       timer(player);
  214.       triggerCaptcha(player, true);
  215.     }
  216.     return null;
  217.   }
  218.  
  219.   private void writeLog(L2PcInstance activeChar)
  220.   {
  221.     String name = activeChar.getName();
  222.     String ip = activeChar.getIP();
  223.     String account = activeChar.getAccountName();
  224.     new File("log/AntiBotPW").mkdirs();
  225.     try
  226.     {
  227.       File file = new File("log/AntiBotPW/AntiBotPW.txt");
  228.       FileWriter save = new FileWriter(file, true);
  229.       String out = "Player: " + name + " Account: " + account + " IP: " + ip + " Not check the captcha!\n";
  230.       save.write(out);
  231.       save.flush();
  232.       save.close();
  233.       save = null;
  234.       file = null;
  235.     }
  236.     catch (IOException e)
  237.     {
  238.       _log.warning("AntiBotPW: Error create log ./log/AntiBotPW/AntiBotPW.txt");
  239.       e.printStackTrace();
  240.     }
  241.   }
  242.  
  243.   private void triggerCaptcha(L2PcInstance player, boolean setEffect)
  244.   {
  245.     int id = 0;
  246.     if (AntiBotPWCaptchaMode == 1)
  247.     {
  248.       id = (int)(Math.random() * 1000.0D + 1.0D);
  249.       if (id < 10) {
  250.         id += 10;
  251.       }
  252.     }
  253.     else
  254.     {
  255.       Random rndoms = new Random();
  256.       id = rndoms.nextInt(12);
  257.     }
  258.     String code = String.valueOf(id);
  259.     this._codes.put(player, code);
  260.     id = (int)(Math.random() * 100000.0D + 1.0D);
  261.     if (id < 1000) {
  262.       id += 1000;
  263.     }
  264.     sendImage(player, id, generateImage(code));
  265.     NpcHtmlMessage htmll = NpcHtmlMessage.id(0);
  266.     int seconds = AntiBotPWReCheckInterval;
  267.     String html;
  268.     String html;
  269.     if (AntiBotPWCaptchaMode == 1) {
  270.       html = "<html><title>???? ???</title><body><center><br><img src=\"Crest.crest_" + Config.SERVER_ID + "_" + id + "\" width=128 height=64><br><edit width=100 var=\"code\"><br><button action=\"bypass -h " + CheckCore() + "ag_code $code\" value=\"??????????\" width=75 height=21 back=\"L2UI_ch3.Btn1_normalOn\" fore=\"L2UI_ch3.Btn1_normal\"><br><br>???? ?? ???????? ??? ????, ??????????? ???????<br1> <font color=\"EEEEEE\">.code</font><br1>? ??? ???? <font color=\"EEEEEE\">" + seconds + " ??????</font> ???? ?????? ????????? ?????!<br><a action=\"bypass -h " + CheckCore() + "ag_refresh\"><font color=\"EEEEEE\">???????? ?????</font></a></center></body></html>";
  271.     } else {
  272.       html = "<html><title>???? ???</title><body><center><br><img src=\"Crest.crest_" + Config.SERVER_ID + "_" + id + "\" width=128 height=64><br><table border=\"0\" width=\"290\" cellpadding=\"3\" cellspacing=\"0\"><tr><td align=\"center\" width=\"75\"><a action=\"bypass -h " + CheckCore() + "ag_code 0\"><font color=\"3030DD\">???????</font></a></td><td align=\"center\" width=\"75\"><a action=\"bypass -h " + CheckCore() + "ag_code 1\"><font color=\"00DD00\">???????</font></a></td><td align=\"center\" width=\"75\"><a action=\"bypass -h " + CheckCore() + "ag_code 2\"><font color=\"DD0000\">???????</font></a></td><td align=\"center\" width=\"75\"><a action=\"bypass -h " + CheckCore() + "ag_code 3\"><font color=\"DDDD00\">???????</font></a></td></tr><tr><td align=\"center\" width=\"75\"><a action=\"bypass -h " + CheckCore() + "ag_code 4\"><font color=\"3030DD\">????</font></a></td><td align=\"center\" width=\"75\"><a action=\"bypass -h " + CheckCore() + "ag_code 5\"><font color=\"00DD00\">????</font></a></td><td align=\"center\" width=\"75\"><a action=\"bypass -h " + CheckCore() + "ag_code 6\"><font color=\"DD0000\">????</font></a></td><td align=\"center\" width=\"75\"><a action=\"bypass -h " + CheckCore() + "ag_code 7\"><font color=\"DDDD00\">????</font></a></td></tr><tr><td align=\"center\" width=\"75\"><a action=\"bypass -h " + CheckCore() + "ag_code 8\"><font color=\"3030DD\">???????????</font></a></td><td align=\"center\" width=\"75\"><a action=\"bypass -h " + CheckCore() + "ag_code 9\"><font color=\"00DD00\">???????????</font></a></td><td align=\"center\" width=\"75\"><a action=\"bypass -h " + CheckCore() + "ag_code 10\"><font color=\"DD0000\">???????????</font></a></td><td align=\"center\" width=\"75\"><a action=\"bypass -h " + CheckCore() + "ag_code 11\"><font color=\"DDDD00\">???????????</font></a></td></tr></table><br><br>???? ?? ???????? ??? ????, ??????????? ???????<br1> <font color=\"EEEEEE\">.code</font><br1>? ??? ???? <font color=\"EEEEEE\">" + seconds + " ??????</font> ???? ?????? ????????? ?????!<br><a action=\"bypass -h " + CheckCore() + "ag_refresh\"><font color=\"EEEEEE\">???????? ?????</font></a></center></body></html>";
  273.     }
  274.     htmll.setHtml(html);
  275.     player.sendPacket(htmll);
  276.     if (setEffect)
  277.     {
  278.       player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("???? ???: .code"));
  279.       player.startAbnormalEffect(524288);
  280.       player.startAbnormalEffect(1024);
  281.       player.setIsParalyzed(true);
  282.       player.setIsInvul(true);
  283.       this._activeEyes.put(player, new BotEye(player, seconds));
  284.     }
  285.   }
  286.  
  287.   public static AntiBotPW getInstance()
  288.   {
  289.     return SingletonHolder._instance;
  290.   }
  291.  
  292.   public String CheckCore()
  293.   {
  294.     String result = "";
  295.     if (AntiBotPWNewCore) {
  296.       result = "vch_";
  297.     }
  298.     return result;
  299.   }
  300.  
  301.   public void validate(L2PcInstance player, String code)
  302.   {
  303.     code = code.trim();
  304.     if ((code == null) || (code.equalsIgnoreCase("ag_refresh")))
  305.     {
  306.       triggerCaptcha(player, false);
  307.       return;
  308.     }
  309.     String valid = (String)this._codes.get(player);
  310.     if ((valid != null) && (valid.equalsIgnoreCase(code)))
  311.     {
  312.       player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("???? ???: ???????????! ?? ?????? ???????????."));
  313.       player.stopAbnormalEffect(524288);
  314.       player.stopAbnormalEffect(1024);
  315.       player.setIsParalyzed(false);
  316.       player.setIsInvul(false);
  317.       timer(player);
  318.       player.setCurrentHp(player.getMaxHp());
  319.       if (this._activeEyes.containsKey(player)) {
  320.         ((BotEye)this._activeEyes.remove(player)).cancel();
  321.       }
  322.     }
  323.     else
  324.     {
  325.       int validerrors = ((Integer)this._errors.get(player)).intValue();
  326.       if (validerrors >= 1)
  327.       {
  328.         validerrors--;
  329.         this._errors.put(player, Integer.valueOf(validerrors));
  330.         player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("???? ???: ???????????! ???????? (" + validerrors + ") ???????. ?????????? ??? ???."));
  331.         triggerCaptcha(player, false);
  332.       }
  333.       else if (CaptchaAntiBotPWKick == 1)
  334.       {
  335.         Util.handleIllegalPlayerAction(player, "Player " + player.getName() + " did not enter the AntiBotPW captcha intime.", 2);
  336.         if (AntiBotPWLog) {
  337.           writeLog(player);
  338.         }
  339.       }
  340.       else
  341.       {
  342.         player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("???? ???: ???????????! ?? ?????? ???????????."));
  343.         player.stopAbnormalEffect(524288);
  344.         player.stopAbnormalEffect(1024);
  345.         player.setIsParalyzed(false);
  346.         player.setIsInvul(false);
  347.         timer(player);
  348.         player.setCurrentHp(player.getMaxHp());
  349.         if (this._activeEyes.containsKey(player)) {
  350.           ((BotEye)this._activeEyes.remove(player)).cancel();
  351.         }
  352.         if (CaptchaAntiBotPWKick == 2) {
  353.           player.teleToClosestTown();
  354.         } else {
  355.           player.teleToLocation(CaptchaAntiBotPWLoc[0], CaptchaAntiBotPWLoc[1], CaptchaAntiBotPWLoc[2]);
  356.         }
  357.         if (AntiBotPWLog) {
  358.           writeLog(player);
  359.         }
  360.       }
  361.     }
  362.   }
  363.  
  364.   private void teleportOfflinePlayer(String name, int xxx, int yyy, int zzz)
  365.   {
  366.     Connect con = null;
  367.     PreparedStatement st = null;
  368.     ResultSet rs = null;
  369.     try
  370.     {
  371.       con = L2DatabaseFactory.get();
  372.       con.setTransactionIsolation(1);
  373.       settp(con, name, xxx, yyy, zzz);
  374.     }
  375.     catch (SQLException e)
  376.     {
  377.       System.out.println("[ERROR] AntiBotPW 1, settp() error: " + e);
  378.     }
  379.     finally
  380.     {
  381.       Close.CSR(con, st, rs);
  382.     }
  383.   }
  384.  
  385.   private void settp(Connect con, String name, int xxx, int yyy, int zzz)
  386.   {
  387.     PreparedStatement st = null;
  388.     ResultSet rs = null;
  389.     try
  390.     {
  391.       st = con.prepareStatement("UPDATE characters SET x=?, y=?, z=? WHERE char_name=?");
  392.       st.setInt(1, xxx);
  393.       st.setInt(2, yyy);
  394.       st.setInt(3, zzz);
  395.       st.setString(4, name);
  396.       st.execute();
  397.     }
  398.     catch (SQLException e)
  399.     {
  400.       System.out.println("[ERROR] AntiBotPW 2, settp() error: " + e);
  401.     }
  402.     finally
  403.     {
  404.       Close.SR(st, rs);
  405.     }
  406.   }
  407.  
  408.   private boolean checkmob(int int_mobs)
  409.   {
  410.     boolean result = false;
  411.     for (Iterator localIterator = MONSTERS.iterator(); localIterator.hasNext();)
  412.     {
  413.       int mobs = ((Integer)localIterator.next()).intValue();
  414.       if (mobs == int_mobs) {
  415.         result = true;
  416.       }
  417.     }
  418.     return result;
  419.   }
  420.  
  421.   private void timer(L2PcInstance player)
  422.   {
  423.     if (this._recheckending.containsKey(player)) {
  424.       this._recheckending.remove(player);
  425.     }
  426.     int current_time = (int)(System.currentTimeMillis() / 1000L);
  427.     int last_time = current_time + AntiBotPWReCheckEndingInterval;
  428.     this._recheckending.put(player, Integer.valueOf(last_time));
  429.   }
  430.  
  431.   public static ByteBuffer convertToDDS(BufferedImage bufferedimage)
  432.   {
  433.     if (bufferedimage == null) {
  434.       return null;
  435.     }
  436.     if (bufferedimage.getColorModel().hasAlpha()) {
  437.       return convertToDxt3(bufferedimage);
  438.     }
  439.     return convertToDxt1NoTransparency(bufferedimage);
  440.   }
  441.  
  442.   public static ByteBuffer convertToDxt1NoTransparency(BufferedImage bufferedimage)
  443.   {
  444.     if (bufferedimage == null) {
  445.       return null;
  446.     }
  447.     int[] ai = new int[16];
  448.     int i = 128 + bufferedimage.getWidth() * bufferedimage.getHeight() / 2;
  449.     ByteBuffer bytebuffer = ByteBuffer.allocate(i);
  450.     bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
  451.     buildHeaderDxt1(bytebuffer, bufferedimage.getWidth(), bufferedimage.getHeight());
  452.     int j = bufferedimage.getWidth() / 4;
  453.     int k = bufferedimage.getHeight() / 4;
  454.     for (int l = 0; l < k; l++) {
  455.       for (int i2 = 0; i2 < j; i2++)
  456.       {
  457.         BufferedImage bufferedimage2 = bufferedimage.getSubimage(i2 * 4, l * 4, 4, 4);
  458.         bufferedimage2.getRGB(0, 0, 4, 4, ai, 0, 4);
  459.         Color[] acolor = getColors888(ai);
  460.         for (int j2 = 0; j2 < ai.length; j2++)
  461.         {
  462.           ai[j2] = getPixel565(acolor[j2]);
  463.           acolor[j2] = getColor565(ai[j2]);
  464.         }
  465.         int[] ai2 = determineExtremeColors(acolor);
  466.         if (ai[ai2[0]] < ai[ai2[1]])
  467.         {
  468.           int k2 = ai2[0];
  469.           ai2[0] = ai2[1];
  470.           ai2[1] = k2;
  471.         }
  472.         bytebuffer.putShort((short)ai[ai2[0]]);
  473.         bytebuffer.putShort((short)ai[ai2[1]]);
  474.         long l2 = computeBitMask(acolor, ai2);
  475.         bytebuffer.putInt((int)l2);
  476.       }
  477.     }
  478.     return bytebuffer;
  479.   }
  480.  
  481.   public static ByteBuffer convertToDxt3(BufferedImage bufferedimage)
  482.   {
  483.     if (bufferedimage == null) {
  484.       return null;
  485.     }
  486.     if (!bufferedimage.getColorModel().hasAlpha()) {
  487.       return convertToDxt1NoTransparency(bufferedimage);
  488.     }
  489.     int[] ai = new int[16];
  490.     int i = 128 + bufferedimage.getWidth() * bufferedimage.getHeight();
  491.     ByteBuffer bytebuffer = ByteBuffer.allocate(i);
  492.     bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
  493.     buildHeaderDxt3(bytebuffer, bufferedimage.getWidth(), bufferedimage.getHeight());
  494.     int j = bufferedimage.getWidth() / 4;
  495.     int k = bufferedimage.getHeight() / 4;
  496.     for (int l = 0; l < k; l++) {
  497.       for (int i2 = 0; i2 < j; i2++)
  498.       {
  499.         BufferedImage bufferedimage2 = bufferedimage.getSubimage(i2 * 4, l * 4, 4, 4);
  500.         bufferedimage2.getRGB(0, 0, 4, 4, ai, 0, 4);
  501.         Color[] acolor = getColors888(ai);
  502.         for (int j2 = 0; j2 < ai.length; j2 += 2) {
  503.           bytebuffer.put((byte)(ai[j2] >>> 28 | ai[(j2 + 1)] >>> 24));
  504.         }
  505.         for (int k2 = 0; k2 < ai.length; k2++)
  506.         {
  507.           ai[k2] = getPixel565(acolor[k2]);
  508.           acolor[k2] = getColor565(ai[k2]);
  509.         }
  510.         int[] ai2 = determineExtremeColors(acolor);
  511.         if (ai[ai2[0]] < ai[ai2[1]])
  512.         {
  513.           int l2 = ai2[0];
  514.           ai2[0] = ai2[1];
  515.           ai2[1] = l2;
  516.         }
  517.         bytebuffer.putShort((short)ai[ai2[0]]);
  518.         bytebuffer.putShort((short)ai[ai2[1]]);
  519.         long l3 = computeBitMask(acolor, ai2);
  520.         bytebuffer.putInt((int)l3);
  521.       }
  522.     }
  523.     return bytebuffer;
  524.   }
  525.  
  526.   protected static void buildHeaderDxt1(ByteBuffer bytebuffer, int i, int j)
  527.   {
  528.     bytebuffer.rewind();
  529.     bytebuffer.put((byte)68);
  530.     bytebuffer.put((byte)68);
  531.     bytebuffer.put((byte)83);
  532.     bytebuffer.put((byte)32);
  533.     bytebuffer.putInt(124);
  534.     int k = 659463;
  535.     bytebuffer.putInt(659463);
  536.     bytebuffer.putInt(j);
  537.     bytebuffer.putInt(i);
  538.     bytebuffer.putInt(i * j / 2);
  539.     bytebuffer.putInt(0);
  540.     bytebuffer.putInt(0);
  541.     bytebuffer.position(bytebuffer.position() + 44);
  542.     bytebuffer.putInt(32);
  543.     bytebuffer.putInt(4);
  544.     bytebuffer.put((byte)68);
  545.     bytebuffer.put((byte)88);
  546.     bytebuffer.put((byte)84);
  547.     bytebuffer.put((byte)49);
  548.     bytebuffer.putInt(0);
  549.     bytebuffer.putInt(0);
  550.     bytebuffer.putInt(0);
  551.     bytebuffer.putInt(0);
  552.     bytebuffer.putInt(0);
  553.     bytebuffer.putInt(4096);
  554.     bytebuffer.putInt(0);
  555.     bytebuffer.position(bytebuffer.position() + 12);
  556.   }
  557.  
  558.   protected static void buildHeaderDxt3(ByteBuffer bytebuffer, int i, int j)
  559.   {
  560.     bytebuffer.rewind();
  561.     bytebuffer.put((byte)68);
  562.     bytebuffer.put((byte)68);
  563.     bytebuffer.put((byte)83);
  564.     bytebuffer.put((byte)32);
  565.     bytebuffer.putInt(124);
  566.     int k = 659463;
  567.     bytebuffer.putInt(659463);
  568.     bytebuffer.putInt(j);
  569.     bytebuffer.putInt(i);
  570.     bytebuffer.putInt(i * j);
  571.     bytebuffer.putInt(0);
  572.     bytebuffer.putInt(0);
  573.     bytebuffer.position(bytebuffer.position() + 44);
  574.     bytebuffer.putInt(32);
  575.     bytebuffer.putInt(4);
  576.     bytebuffer.put((byte)68);
  577.     bytebuffer.put((byte)88);
  578.     bytebuffer.put((byte)84);
  579.     bytebuffer.put((byte)51);
  580.     bytebuffer.putInt(0);
  581.     bytebuffer.putInt(0);
  582.     bytebuffer.putInt(0);
  583.     bytebuffer.putInt(0);
  584.     bytebuffer.putInt(0);
  585.     bytebuffer.putInt(4096);
  586.     bytebuffer.putInt(0);
  587.     bytebuffer.position(bytebuffer.position() + 12);
  588.   }
  589.  
  590.   protected static int[] determineExtremeColors(Color[] acolor)
  591.   {
  592.     int i = Integer.MIN_VALUE;
  593.     int[] ai = new int[2];
  594.     for (int j = 0; j < acolor.length - 1; j++) {
  595.       for (int k = j + 1; k < acolor.length; k++)
  596.       {
  597.         int l = distance(acolor[j], acolor[k]);
  598.         if (l > i)
  599.         {
  600.           i = l;
  601.           ai[0] = j;
  602.           ai[1] = k;
  603.         }
  604.       }
  605.     }
  606.     return ai;
  607.   }
  608.  
  609.   protected static long computeBitMask(Color[] acolor, int[] ai)
  610.   {
  611.     Color[] acolor2 = { null, null, new Color(), new Color() };
  612.     acolor2[0] = acolor[ai[0]];
  613.     acolor2[1] = acolor[ai[1]];
  614.     if (acolor2[0].equals(acolor2[1])) {
  615.       return 0L;
  616.     }
  617.     acolor2[2].r = ((2 * acolor2[0].r + acolor2[1].r + 1) / 3);
  618.     acolor2[2].g = ((2 * acolor2[0].g + acolor2[1].g + 1) / 3);
  619.     acolor2[2].b = ((2 * acolor2[0].b + acolor2[1].b + 1) / 3);
  620.     acolor2[3].r = ((acolor2[0].r + 2 * acolor2[1].r + 1) / 3);
  621.     acolor2[3].g = ((acolor2[0].g + 2 * acolor2[1].g + 1) / 3);
  622.     acolor2[3].b = ((acolor2[0].b + 2 * acolor2[1].b + 1) / 3);
  623.     long l = 0L;
  624.     for (int i = 0; i < acolor.length; i++)
  625.     {
  626.       int j = Integer.MAX_VALUE;
  627.       int k = 0;
  628.       for (int i2 = 0; i2 < acolor2.length; i2++)
  629.       {
  630.         int j2 = distance(acolor[i], acolor2[i2]);
  631.         if (j2 < j)
  632.         {
  633.           j = j2;
  634.           k = i2;
  635.         }
  636.       }
  637.       l |= k << i * 2;
  638.     }
  639.     return l;
  640.   }
  641.  
  642.   protected static int getPixel565(Color color)
  643.   {
  644.     int i = color.r >> 3;
  645.     int j = color.g >> 2;
  646.     int k = color.b >> 3;
  647.     return i << 11 | j << 5 | k;
  648.   }
  649.  
  650.   protected static Color getColor565(int i)
  651.   {
  652.     Color color = new Color();
  653.     color.r = ((int)(i & 0xF800) >> 11);
  654.     color.g = ((int)(i & 0x7E0) >> 5);
  655.     color.b = ((int)(i & 0x1F));
  656.     return color;
  657.   }
  658.  
  659.   protected static Color[] getColors888(int[] ai)
  660.   {
  661.     Color[] acolor = new Color[ai.length];
  662.     for (int i = 0; i < ai.length; i++)
  663.     {
  664.       acolor[i] = new Color();
  665.       acolor[i].r = ((int)(ai[i] & 0xFF0000) >> 16);
  666.       acolor[i].g = ((int)(ai[i] & 0xFF00) >> 8);
  667.       acolor[i].b = ((int)(ai[i] & 0xFF));
  668.     }
  669.     return acolor;
  670.   }
  671.  
  672.   protected static int distance(Color color, Color color1)
  673.   {
  674.     return (color1.r - color.r) * (color1.r - color.r) + (color1.g - color.g) * (color1.g - color.g) + (color1.b - color.b) * (color1.b - color.b);
  675.   }
  676.  
  677.   public static BufferedImage scaleImage(BufferedImage img, int width, int height, Color background)
  678.   {
  679.     int imgWidth = img.getWidth();
  680.     int imgHeight = img.getHeight();
  681.     if (imgWidth * height < imgHeight * width) {
  682.       width = imgWidth * height / imgHeight;
  683.     } else {
  684.       height = imgHeight * width / imgWidth;
  685.     }
  686.     BufferedImage newImage = new BufferedImage(width, height, 1);
  687.     Graphics2D g = newImage.createGraphics();
  688.     try
  689.     {
  690.       g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
  691.       g.setBackground(background);
  692.       g.clearRect(0, 0, width, height);
  693.       g.drawImage(img, 0, 0, width, height, null);
  694.     }
  695.     finally
  696.     {
  697.       g.dispose();
  698.     }
  699.     return newImage;
  700.   }
  701.  
  702.   public static BufferedImage generateImage(String text)
  703.   {
  704.     BufferedImage img = new BufferedImage(128, 64, 1);
  705.     Color bgColor = new Color(100, 100, 100);
  706.     Color textColor = new Color(160, 160, 160);
  707.     Color noiseColor = new Color(130, 130, 130);
  708.     Random rnd = new Random();
  709.     if (AntiBotPWCaptchaMode == 1) {
  710.       switch (rnd.nextInt(10))
  711.       {
  712.       case 0:
  713.       case 1:
  714.         bgColor = new Color(0, 100, 0);
  715.         textColor = new Color(0, 150, 0);
  716.         noiseColor = new Color(0, 125, 0);
  717.         break;
  718.       case 2:
  719.       case 3:
  720.         bgColor = new Color(0, 0, 100);
  721.         textColor = new Color(0, 0, 170);
  722.         noiseColor = new Color(0, 0, 125);
  723.         break;
  724.       case 4:
  725.       case 5:
  726.         bgColor = new Color(100, 0, 100);
  727.         textColor = new Color(150, 0, 150);
  728.         noiseColor = new Color(125, 0, 125);
  729.       }
  730.     } else {
  731.       bgColor = new Color(0, 0, 0);
  732.     }
  733.     Graphics2D backColor = img.createGraphics();
  734.     backColor.setPaint(bgColor);
  735.     backColor.fillRect(0, 0, img.getWidth(), img.getHeight());
  736.     backColor.dispose();
  737.     if (AntiBotPWCaptchaMode == 1)
  738.     {
  739.       for (int i = 0; i < 20; i++)
  740.       {
  741.         Graphics2D g = img.createGraphics();
  742.         g.setColor(noiseColor);
  743.         int radius = rnd.nextInt(10) + 4;
  744.         int x = rnd.nextInt(128) + 1;
  745.         int y = rnd.nextInt(64) + 1;
  746.         g.fillOval(x, y, radius, radius);
  747.       }
  748.     }
  749.     else
  750.     {
  751.       Graphics2D g2 = img.createGraphics();
  752.       g2.setColor(new Color(0, 100, 0));
  753.       int sw = Integer.parseInt(text);
  754.       switch (sw)
  755.       {
  756.       case 0:
  757.         textColor = new Color(0, 0, 170);
  758.         g2.setColor(textColor);
  759.         g2.fill(new Rectangle2D.Float(42.0F, 10.0F, 45.0F, 45.0F));
  760.         break;
  761.       case 1:
  762.         textColor = new Color(0, 150, 0);
  763.         g2.setColor(textColor);
  764.         g2.fill(new Rectangle2D.Float(42.0F, 10.0F, 45.0F, 45.0F));
  765.         break;
  766.       case 2:
  767.         textColor = new Color(170, 0, 0);
  768.         g2.setColor(textColor);
  769.         g2.fill(new Rectangle2D.Float(42.0F, 10.0F, 45.0F, 45.0F));
  770.         break;
  771.       case 3:
  772.         textColor = new Color(170, 170, 0);
  773.         g2.setColor(textColor);
  774.         g2.fill(new Rectangle2D.Float(42.0F, 10.0F, 45.0F, 45.0F));
  775.         break;
  776.       case 4:
  777.         textColor = new Color(0, 0, 170);
  778.         g2.setColor(textColor);
  779.         g2.fillOval(42, 10, 45, 45);
  780.         break;
  781.       case 5:
  782.         textColor = new Color(0, 150, 0);
  783.         g2.setColor(textColor);
  784.         g2.fillOval(42, 10, 45, 45);
  785.         break;
  786.       case 6:
  787.         textColor = new Color(170, 0, 0);
  788.         g2.setColor(textColor);
  789.         g2.fillOval(42, 10, 45, 45);
  790.         break;
  791.       case 7:
  792.         textColor = new Color(170, 170, 0);
  793.         g2.setColor(textColor);
  794.         g2.fillOval(42, 10, 45, 45);
  795.         break;
  796.       case 8:
  797.         textColor = new Color(0, 0, 170);
  798.         g2.setColor(textColor);
  799.         g2.fillPolygon(new int[] { 42, 67, 90 }, new int[] { 50, 10, 50 }, 3);
  800.         break;
  801.       case 9:
  802.         textColor = new Color(0, 150, 0);
  803.         g2.setColor(textColor);
  804.         g2.fillPolygon(new int[] { 42, 67, 90 }, new int[] { 50, 10, 50 }, 3);
  805.         break;
  806.       case 10:
  807.         textColor = new Color(170, 0, 0);
  808.         g2.setColor(textColor);
  809.         g2.fillPolygon(new int[] { 42, 67, 90 }, new int[] { 50, 10, 50 }, 3);
  810.         break;
  811.       case 11:
  812.         textColor = new Color(170, 170, 0);
  813.         g2.setColor(textColor);
  814.         g2.fillPolygon(new int[] { 42, 67, 90 }, new int[] { 50, 10, 50 }, 3);
  815.       }
  816.     }
  817.     Graphics2D g2d = img.createGraphics();
  818.     g2d.drawImage(img, 0, 0, null);
  819.     g2d.setPaint(textColor);
  820.     int fontSize = 0;
  821.     if (AntiBotPWCaptchaMode == 1) {
  822.       fontSize = rnd.nextInt(10) + 35;
  823.     } else {
  824.       fontSize = 36;
  825.     }
  826.     g2d.setFont(new Font("Serif", 1, fontSize));
  827.     FontMetrics fm = g2d.getFontMetrics();
  828.     int y2;
  829.     if (AntiBotPWCaptchaMode == 1)
  830.     {
  831.       int x2 = img.getWidth() - fm.stringWidth(text) - rnd.nextInt(100 - fontSize);
  832.       if (fontSize < 35) {
  833.         fontSize = 35;
  834.       }
  835.       int y2 = fm.getHeight() - fontSize / 8;
  836.       g2d.drawString(text, x2, y2);
  837.     }
  838.     else
  839.     {
  840.       int x2 = img.getWidth() - fm.stringWidth(text) - (70 - fontSize);
  841.       y2 = fm.getHeight() - fontSize / 8;
  842.     }
  843.     g2d.dispose();
  844.     return img;
  845.   }
  846.  
  847.   public static void sendImage(L2PcInstance player, int id, BufferedImage image)
  848.   {
  849.     try
  850.     {
  851.       PledgeCrest packet = new PledgeCrest(id, convertToDDS(image).array());
  852.       player.sendPacket(packet);
  853.     }
  854.     catch (Exception localException) {}
  855.   }
  856.  
  857.   public static void main(String[] args)
  858.   {
  859.     new AntiBotPW();
  860.   }
  861.  
  862.   private static class SingletonHolder
  863.   {
  864.     protected static final AntiBotPW _instance = new AntiBotPW();
  865.   }
  866.  
  867.   public class AntiBotPWSkillTP1
  868.     implements ISkillHandler
  869.   {
  870.     private final L2Skill.SkillType[] SKILL_IDS;
  871.    
  872.     public AntiBotPWSkillTP1()
  873.     {
  874.       this.SKILL_IDS = new L2Skill.SkillType[] { L2Skill.SkillType.NOTDONE };
  875.       SkillHandler.getInstance().registerSkillHandler(this);
  876.     }
  877.    
  878.     public void useSkill(L2Character activeChar, L2Skill skill, FastList<L2Object> targets)
  879.     {
  880.       L2PcInstance player = null;
  881.       L2PcInstance target = null;
  882.       L2Character Character_target = null;
  883.       if (activeChar.isPlayer()) {
  884.         player = (L2PcInstance)activeChar;
  885.       }
  886.       L2Object targetz = player != null ? player.getTarget() : null;
  887.       int leveltarget = 0;
  888.       if ((targetz instanceof L2PcInstance))
  889.       {
  890.         Character_target = (L2Character)targetz;
  891.         target = (L2PcInstance)Character_target;
  892.         leveltarget = target.getLevel();
  893.       }
  894.       if (player != null)
  895.       {
  896.         int levelchar = player.getLevel();
  897.         if (!AntiBotPW.AntiBotPWCaptchaEnableSkill)
  898.         {
  899.           if (skill.getId() == AntiBotPW.AntiBotPWCMDSkill) {
  900.             player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("??????? ??????? ???????? ????? ????? ????????? ??????????????!"));
  901.           }
  902.         }
  903.         else if (levelchar < AntiBotPW.AntiBotPWCMDPlayerLVL)
  904.         {
  905.           if (skill.getId() == AntiBotPW.AntiBotPWCMDSkill) {
  906.             player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?? ?? ?????? ???????????? ??????? ???????? ???? ?? ?????????? " + AntiBotPW.AntiBotPWCMDPlayerLVL + " ??????"));
  907.           }
  908.         }
  909.         else if (target == null)
  910.         {
  911.           if (skill.getId() == AntiBotPW.AntiBotPWCMDSkill) {
  912.             player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?? ?? ?????? ???????????? ??????? ???????? ???? ? ??? ???????????? ??????"));
  913.           }
  914.         }
  915.         else if (leveltarget < AntiBotPW.AntiBotPWCMDTargetLVL)
  916.         {
  917.           if (skill.getId() == AntiBotPW.AntiBotPWCMDSkill) {
  918.             player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?? ?? ?????? ???????????? ??????? ???????? ?? " + target.getName() + " ???? ?? ?? ????????? " + AntiBotPW.AntiBotPWCMDTargetLVL + " ??????"));
  919.           }
  920.         }
  921.         else if (skill.getId() == AntiBotPW.AntiBotPWCMDSkill)
  922.         {
  923.           if ((!AntiBotPW.AntiBotPWReCheckEndingGM) || (!player.isGM()))
  924.           {
  925.             if ((!AntiBotPW.AntiBotPWCaptchaPremium) && (target.isPremium()))
  926.             {
  927.               player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?????? ??????? ???????? ? " + target.getName() + " ????????!"));
  928.               return;
  929.             }
  930.             if ((!AntiBotPW.AntiBotPWCaptchaHero) && (target.isHero()))
  931.             {
  932.               player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?????? ??????? ???????? ? " + target.getName() + " ????????!"));
  933.               return;
  934.             }
  935.             if ((!AntiBotPW.AntiBotPWCaptchaNoble) && (target.isNoble()))
  936.             {
  937.               player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?????? ??????? ???????? ? " + target.getName() + " ????????!"));
  938.               return;
  939.             }
  940.             L2Object targetx = target != null ? target.getTarget() : null;
  941.             int int_targetx = 0;
  942.             if ((targetx instanceof L2NpcInstance))
  943.             {
  944.               L2NpcInstance npc_targetx = (L2NpcInstance)targetx;
  945.               int_targetx = npc_targetx.getNpcId();
  946.             }
  947.             if (!AntiBotPW.this.checkmob(int_targetx))
  948.             {
  949.               player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?????????! ? ?????? " + target.getName() + " ?????? ???? ? ??????? ?????? ?? ???????? ???????????????? ????????! ?????????? ??? ???..."));
  950.               return;
  951.             }
  952.             int current_time = (int)(System.currentTimeMillis() / 1000L);
  953.             int player_time = 0;
  954.             if (AntiBotPW.this._recheckending.containsKey(target)) {
  955.               player_time = ((Integer)AntiBotPW.this._recheckending.get(target)).intValue();
  956.             }
  957.             if (player_time > current_time)
  958.             {
  959.               int last_sec = ((Integer)AntiBotPW.this._recheckending.get(target)).intValue() - current_time;
  960.               player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("??????? ???????? ? " + target.getName() + " ??? ????????!"));
  961.               target.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("???? ???: ? ??????? " + last_sec + " ?????? ???????? ??? ??? ?????????."));
  962.               return;
  963.             }
  964.           }
  965.           if (!AntiBotPW.this._activeEyes.containsKey(target))
  966.           {
  967.             player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?????? ??????? ???????? ? " + target.getName() + "!"));
  968.             if ((!AntiBotPW.AntiBotPWReCheckEndingGM) || (!player.isGM())) {
  969.               target.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("????? " + player.getName() + " ???????? ? ??? ??????? ????????!"));
  970.             } else {
  971.               target.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("??? ????????? ??????? ????????!"));
  972.             }
  973.             target.broadcastPacket(new MagicSkillUser(target, target, 1427, 1, 10, 0));
  974.             player.broadcastPacket(new MagicSkillUser(player, player, 1427, 1, 10, 0));
  975.             int counterrors = AntiBotPW.CaptchaCountError;
  976.             AntiBotPW.this._errors.put(target, Integer.valueOf(counterrors));
  977.             AntiBotPW.this.triggerCaptcha(target, true);
  978.           }
  979.           else
  980.           {
  981.             player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("??????? ???????? ? " + target.getName() + " ??? ????????!"));
  982.           }
  983.         }
  984.       }
  985.     }
  986.    
  987.     public L2Skill.SkillType[] getSkillIds()
  988.     {
  989.       return this.SKILL_IDS;
  990.     }
  991.   }
  992.  
  993.   public static final class BotResults
  994.   {
  995.     public final int _success;
  996.     public final int _fails;
  997.    
  998.     public BotResults(int success, int fails)
  999.     {
  1000.       this._success = success;
  1001.       this._fails = fails;
  1002.     }
  1003.   }
  1004.  
  1005.   public void useVoicedCommand2(String command, L2PcInstance player, String target)
  1006.   {
  1007.     if ((command.startsWith("ag_code")) && (this._activeEyes.containsKey(player)))
  1008.     {
  1009.       String flag = command.substring(7).trim();
  1010.       validate(player, flag);
  1011.     }
  1012.     if ((command.equalsIgnoreCase("ag_refresh")) && (this._activeEyes.containsKey(player))) {
  1013.       validate(player, command);
  1014.     }
  1015.   }
  1016.  
  1017.   public class SecurityCode
  1018.     implements IVoicedCommandHandler
  1019.   {
  1020.     private final String[] VOICED_COMMANDS;
  1021.    
  1022.     public SecurityCode()
  1023.     {
  1024.       this.VOICED_COMMANDS = new String[] { "code", "check" };
  1025.       VoicedCommandHandler.getInstance().registerVoicedCommandHandler(this);
  1026.     }
  1027.    
  1028.     public boolean useVoicedCommand(String command, L2PcInstance player, String target)
  1029.     {
  1030.       if ((command.equalsIgnoreCase("code")) && (AntiBotPW.this._activeEyes.containsKey(player))) {
  1031.         AntiBotPW.this.validate(player, "ag_refresh");
  1032.       }
  1033.       if (command.equalsIgnoreCase("check"))
  1034.       {
  1035.         L2PcInstance target_cp = null;
  1036.         L2Character Character_target = null;
  1037.         L2Object targetz = player != null ? player.getTarget() : null;
  1038.         int leveltarget = 0;
  1039.         if ((targetz instanceof L2PcInstance))
  1040.         {
  1041.           Character_target = (L2Character)targetz;
  1042.           target_cp = (L2PcInstance)Character_target;
  1043.           leveltarget = target_cp.getLevel();
  1044.         }
  1045.         if (player != null)
  1046.         {
  1047.           int levelchar = player.getLevel();
  1048.           if (!AntiBotPW.AntiBotPWCaptchaEnableCmd)
  1049.           {
  1050.             player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("??????? ??????? ???????? ????? .check ????????? ??????????????!"));
  1051.           }
  1052.           else if (levelchar < AntiBotPW.AntiBotPWCMDPlayerLVL)
  1053.           {
  1054.             player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?? ?? ?????? ???????????? ??????? ???????? ???? ?? ?????????? " + AntiBotPW.AntiBotPWCMDPlayerLVL + " ??????"));
  1055.           }
  1056.           else if (target_cp == null)
  1057.           {
  1058.             player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?? ?? ?????? ???????????? ??????? ???????? ???? ? ??? ???????????? ??????"));
  1059.           }
  1060.           else if (leveltarget < AntiBotPW.AntiBotPWCMDTargetLVL)
  1061.           {
  1062.             player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?? ?? ?????? ???????????? ??????? ???????? ?? " + target_cp.getName() + " ???? ?? ?? ????????? " + AntiBotPW.AntiBotPWCMDTargetLVL + " ??????"));
  1063.           }
  1064.           else
  1065.           {
  1066.             if ((!AntiBotPW.AntiBotPWReCheckEndingGM) || (!player.isGM()))
  1067.             {
  1068.               if ((!AntiBotPW.AntiBotPWCaptchaPremium) && (target_cp.isPremium()))
  1069.               {
  1070.                 player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?????? ??????? ???????? ? " + target_cp.getName() + " ????????!"));
  1071.                 return true;
  1072.               }
  1073.               if ((!AntiBotPW.AntiBotPWCaptchaHero) && (target_cp.isHero()))
  1074.               {
  1075.                 player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?????? ??????? ???????? ? " + target_cp.getName() + " ????????!"));
  1076.                 return true;
  1077.               }
  1078.               if ((!AntiBotPW.AntiBotPWCaptchaNoble) && (target_cp.isNoble()))
  1079.               {
  1080.                 player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?????? ??????? ???????? ? " + target_cp.getName() + " ????????!"));
  1081.                 return true;
  1082.               }
  1083.               L2Object targetx = target_cp != null ? target_cp.getTarget() : null;
  1084.               int int_targetx = 0;
  1085.               if ((targetx instanceof L2NpcInstance))
  1086.               {
  1087.                 L2NpcInstance npc_targetx = (L2NpcInstance)targetx;
  1088.                 int_targetx = npc_targetx.getNpcId();
  1089.               }
  1090.               if (!AntiBotPW.this.checkmob(int_targetx))
  1091.               {
  1092.                 player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?????????! ? ?????? " + target_cp.getName() + " ?????? ???? ? ??????? ?????? ?? ???????? ???????????????? ????????! ?????????? ??? ???..."));
  1093.                 return true;
  1094.               }
  1095.               int current_time = (int)(System.currentTimeMillis() / 1000L);
  1096.               int player_time = 0;
  1097.               if (AntiBotPW.this._recheckending.containsKey(target_cp)) {
  1098.                 player_time = ((Integer)AntiBotPW.this._recheckending.get(target_cp)).intValue();
  1099.               }
  1100.               if (player_time > current_time)
  1101.               {
  1102.                 int last_sec = ((Integer)AntiBotPW.this._recheckending.get(target_cp)).intValue() - current_time;
  1103.                 player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("??????? ???????? ? " + target_cp.getName() + " ??? ????????!"));
  1104.                 target_cp.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("???? ???: ? ??????? " + last_sec + " ?????? ???????? ??? ??? ?????????."));
  1105.                 return true;
  1106.               }
  1107.             }
  1108.             if (!AntiBotPW.this._activeEyes.containsKey(target_cp))
  1109.             {
  1110.               player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("?????? ??????? ???????? ? " + target_cp.getName() + "!"));
  1111.               if ((!AntiBotPW.AntiBotPWReCheckEndingGM) || (!player.isGM())) {
  1112.                 target_cp.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("????? " + player.getName() + " ???????? ? ??? ??????? ????????!"));
  1113.               } else {
  1114.                 target_cp.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("??? ????????? ??????? ????????!"));
  1115.               }
  1116.               target_cp.broadcastPacket(new MagicSkillUser(target_cp, target_cp, 1427, 1, 10, 0));
  1117.               player.broadcastPacket(new MagicSkillUser(player, player, 1427, 1, 10, 0));
  1118.               int counterrors = AntiBotPW.CaptchaCountError;
  1119.               AntiBotPW.this._errors.put(target_cp, Integer.valueOf(counterrors));
  1120.               AntiBotPW.this.triggerCaptcha(target_cp, true);
  1121.             }
  1122.             else
  1123.             {
  1124.               player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("??????? ???????? ? " + target_cp.getName() + " ??? ????????!"));
  1125.             }
  1126.           }
  1127.         }
  1128.       }
  1129.       return true;
  1130.     }
  1131.    
  1132.     public String[] getVoicedCommandList()
  1133.     {
  1134.       return this.VOICED_COMMANDS;
  1135.     }
  1136.   }
  1137.  
  1138.   private final class BotEye
  1139.     implements Runnable
  1140.   {
  1141.     private ScheduledFuture<?> _task;
  1142.     private int _delay;
  1143.     private L2PcInstance _player;
  1144.    
  1145.     public BotEye(L2PcInstance player, int delay)
  1146.     {
  1147.       this._task = null;
  1148.       this._player = player;
  1149.       this._delay = delay;
  1150.       run();
  1151.     }
  1152.    
  1153.     public void run()
  1154.     {
  1155.       if ((this._delay < 1) || (this._player.isOnline() == 0))
  1156.       {
  1157.         if (AntiBotPW.CaptchaAntiBotPWKick == 1)
  1158.         {
  1159.           String valid = (String)AntiBotPW.this._codes.get(this._player);
  1160.           AntiBotPW.this.validate(this._player, valid);
  1161.           Util.handleIllegalPlayerAction(this._player, "Player " + this._player.getName() + " did not enter the AntiBotPW captcha intime.", 2);
  1162.           if (this._player.isOnline() == 0) {
  1163.             AntiBotPW.this.teleportOfflinePlayer(this._player.getName(), 82737, 148571, 62066);
  1164.           }
  1165.           if (AntiBotPW.AntiBotPWLog) {
  1166.             AntiBotPW.this.writeLog(this._player);
  1167.           }
  1168.         }
  1169.         else
  1170.         {
  1171.           String valid = (String)AntiBotPW.this._codes.get(this._player);
  1172.           AntiBotPW.this.validate(this._player, valid);
  1173.           if (this._player.isOnline() == 0) {
  1174.             AntiBotPW.this.teleportOfflinePlayer(this._player.getName(), 82737, 148571, 62066);
  1175.           } else if (AntiBotPW.CaptchaAntiBotPWKick == 2) {
  1176.             this._player.teleToClosestTown();
  1177.           } else {
  1178.             this._player.teleToLocation(AntiBotPW.CaptchaAntiBotPWLoc[0], AntiBotPW.CaptchaAntiBotPWLoc[1], AntiBotPW.CaptchaAntiBotPWLoc[2]);
  1179.           }
  1180.           if (AntiBotPW.AntiBotPWLog) {
  1181.             AntiBotPW.this.writeLog(this._player);
  1182.           }
  1183.         }
  1184.         return;
  1185.       }
  1186.       handleTick();
  1187.       this._task = ThreadPoolManager.getInstance().scheduleGeneral(this, 1000L);
  1188.       this._delay -= 1;
  1189.     }
  1190.    
  1191.     public void cancel()
  1192.     {
  1193.       if (this._task != null) {
  1194.         this._task.cancel(true);
  1195.       }
  1196.     }
  1197.    
  1198.     private void handleTick()
  1199.     {
  1200.       switch (this._delay)
  1201.       {
  1202.       case 1:
  1203.       case 2:
  1204.       case 3:
  1205.       case 4:
  1206.       case 5:
  1207.       case 10:
  1208.       case 15:
  1209.       case 30:
  1210.       case 45:
  1211.       case 60:
  1212.       case 120:
  1213.       case 180:
  1214.       case 240:
  1215.       case 300:
  1216.         this._player.sendPacket(SystemMessage.id(SystemMessageId.GM_S1).addString("???? ???: ? ??? ???????? " + this._delay + " ?????? ?? ??????????? ????? ?????."));
  1217.       }
  1218.     }
  1219.   }
  1220.  
  1221.   protected static class Color
  1222.   {
  1223.     protected int r;
  1224.     protected int g;
  1225.     protected int b;
  1226.    
  1227.     public boolean equals(Object obj)
  1228.     {
  1229.       if (this == obj) {
  1230.         return true;
  1231.       }
  1232.       if ((obj == null) || (getClass() != obj.getClass())) {
  1233.         return false;
  1234.       }
  1235.       Color color = (Color)obj;
  1236.       return (this.b == color.b) && (this.g == color.g) && (this.r == color.r);
  1237.     }
  1238.    
  1239.     public int hashCode()
  1240.     {
  1241.       int i = this.r;
  1242.       i = 29 * i + this.g;
  1243.       i = 29 * i + this.b;
  1244.       return i;
  1245.     }
  1246.    
  1247.     public Color()
  1248.     {
  1249.       boolean z = false;
  1250.       this.b = 0;
  1251.       this.g = 0;
  1252.       this.r = 0;
  1253.     }
  1254.    
  1255.     public Color(int i, int j, int k)
  1256.     {
  1257.       this.r = i;
  1258.       this.g = j;
  1259.       this.b = k;
  1260.     }
  1261.   }
  1262. }
Advertisement
Add Comment
Please, Sign In to add comment