Guest User

L2Npc.java Antibot v2

a guest
Jun 17th, 2011
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.25 KB | None | 0 0
  1. Index: C:/Users/George/Desktop/Workspace/Game/java/com/l2js/gameserver/model/actor/L2Npc.java
  2. ===================================================================
  3. --- C:/Users/George/Desktop/Workspace/Game/java/com/l2js/gameserver/model/actor/L2Npc.java (revision 183)
  4. +++ C:/Users/George/Desktop/Workspace/Game/java/com/l2js/gameserver/model/actor/L2Npc.java (working copy)
  5. @@ -39,16 +40,7 @@
  6. import com.l2jserver.gameserver.model.L2Spawn;
  7. import com.l2jserver.gameserver.model.L2World;
  8. import com.l2jserver.gameserver.model.L2WorldRegion;
  9. import com.l2jserver.gameserver.model.actor.instance.L2ClanHallManagerInstance;
  10. import com.l2jserver.gameserver.model.actor.instance.L2DoormenInstance;
  11. import com.l2jserver.gameserver.model.actor.instance.L2FestivalGuideInstance;
  12. import com.l2jserver.gameserver.model.actor.instance.L2FishermanInstance;
  13. import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance;
  14. import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
  15. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  16. import com.l2jserver.gameserver.model.actor.instance.L2TeleporterInstance;
  17. import com.l2jserver.gameserver.model.actor.instance.L2TrainerInstance;
  18. import com.l2jserver.gameserver.model.actor.instance.L2WarehouseInstance;
  19. +import com.l2jserver.gameserver.model.actor.instance.L2SummonInstance;
  20. +import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  21. import com.l2jserver.gameserver.model.actor.knownlist.NpcKnownList;
  22. import com.l2jserver.gameserver.model.actor.stat.NpcStat;
  23. import com.l2jserver.gameserver.model.actor.status.NpcStatus;
  24. @@ -74,6 +66,21 @@
  25. import com.l2jserver.gameserver.util.Broadcast;
  26. import com.l2jserver.util.Rnd;
  27. import com.l2jserver.util.StringUtil;
  28. +import gov.nasa.worldwind.formats.dds.DDSConverter;
  29. +
  30. +import java.awt.Color;
  31. +import java.awt.Font;
  32. +import java.awt.FontMetrics;
  33. +import java.awt.Graphics2D;
  34. +import java.awt.geom.AffineTransform;
  35. +import java.awt.image.BufferedImage;
  36. +import java.io.File;
  37. +import javax.imageio.ImageIO;
  38. +import com.l2jserver.gameserver.idfactory.IdFactory;
  39. +import com.l2jserver.gameserver.model.L2World;
  40. +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  41. +import com.l2jserver.gameserver.network.serverpackets.PledgeCrest;
  42. +import com.l2jserver.gameserver.skills.AbnormalEffect;
  43.  
  44. /**
  45. * This class represents a Non-Player-Character in the world. It can be a monster or a friendly character.
  46. @@ -1388,6 +1398,98 @@
  47. return (int) (getTemplate().rewardSp * Config.RATE_SP);
  48. }
  49.  
  50. + public static StringBuilder finalString = new StringBuilder();
  51. + NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  52. + private static BufferedImage generateCaptcha()
  53. + {
  54. + Color textColor = new Color(98, 213, 43);
  55. + Color circleColor = new Color(98, 213, 43);
  56. + Font textFont = new Font("comic sans ms", Font.BOLD, 24);
  57. + int charsToPrint = 5;
  58. + int width = 256;
  59. + int height = 64;
  60. + int circlesToDraw = 8;
  61. + float horizMargin = 20.0f;
  62. + double rotationRange = 0.7; // this is radians
  63. + BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
  64. +
  65. + Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
  66. +
  67. + //Draw an oval
  68. + g.setColor(new Color(30,31,31));
  69. + g.fillRect(0, 0, width, height);
  70. +
  71. + // lets make some noisey circles
  72. + g.setColor(circleColor);
  73. + for ( int i = 0; i < circlesToDraw; i++ ) {
  74. + int circleRadius = (int) (Math.random() * height / 2.0);
  75. + int circleX = (int) (Math.random() * width - circleRadius);
  76. + int circleY = (int) (Math.random() * height - circleRadius);
  77. + g.drawOval(circleX, circleY, circleRadius * 2, circleRadius * 2);
  78. + }
  79. +
  80. + g.setColor(textColor);
  81. + g.setFont(textFont);
  82. +
  83. + FontMetrics fontMetrics = g.getFontMetrics();
  84. + int maxAdvance = fontMetrics.getMaxAdvance();
  85. + int fontHeight = fontMetrics.getHeight();
  86. +
  87. + // Suggestions ----------------------------------------------------------------------
  88. + // i removed 1 and l and i because there are confusing to users...
  89. + // Z, z, and N also get confusing when rotated
  90. + // 0, O, and o are also confusing...
  91. + // lowercase G looks a lot like a 9 so i killed it
  92. + // this should ideally be done for every language...
  93. + // i like controlling the characters though because it helps prevent confusion
  94. + // So recommended chars are:
  95. + // String elegibleChars = "ABCDEFGHJKLMPQRSTUVWXYabcdefhjkmnpqrstuvwxy23456789";
  96. + // Suggestions ----------------------------------------------------------------------
  97. + String elegibleChars = "ABCDEFGHJKLMPQRSTUVWXYZ";
  98. + char[] chars = elegibleChars.toCharArray();
  99. +
  100. + float spaceForLetters = -horizMargin * 2 + width;
  101. + float spacePerChar = spaceForLetters / (charsToPrint - 1.0f);
  102. +
  103. + for ( int i = 0; i < charsToPrint; i++ ) {
  104. + double randomValue = Math.random();
  105. + int randomIndex = (int) Math.round(randomValue * (chars.length - 1));
  106. + char characterToShow = chars[randomIndex];
  107. + finalString.append(characterToShow);
  108. +
  109. + // this is a separate canvas used for the character so that
  110. + // we can rotate it independently
  111. + int charWidth = fontMetrics.charWidth(characterToShow);
  112. + int charDim = Math.max(maxAdvance, fontHeight);
  113. + int halfCharDim = (charDim / 2);
  114. +
  115. + BufferedImage charImage = new BufferedImage(charDim, charDim, BufferedImage.TYPE_INT_ARGB);
  116. + Graphics2D charGraphics = charImage.createGraphics();
  117. + charGraphics.translate(halfCharDim, halfCharDim);
  118. + double angle = (Math.random() - 0.5) * rotationRange;
  119. + charGraphics.transform(AffineTransform.getRotateInstance(angle));
  120. + charGraphics.translate(-halfCharDim,-halfCharDim);
  121. + charGraphics.setColor(textColor);
  122. + charGraphics.setFont(textFont);
  123. +
  124. + int charX = (int) (0.5 * charDim - 0.5 * charWidth);
  125. + charGraphics.drawString("" + characterToShow, charX,
  126. + ((charDim - fontMetrics.getAscent())
  127. + / 2 + fontMetrics.getAscent()));
  128. +
  129. + float x = horizMargin + spacePerChar * (i) - charDim / 2.0f;
  130. + int y = ((height - charDim) / 2);
  131. + g.drawImage(charImage, (int) x, y, charDim, charDim, null, null);
  132. +
  133. + charGraphics.dispose();
  134. + }
  135. +
  136. + g.dispose();
  137. +
  138. + return bufferedImage;
  139. + }
  140. +
  141. +
  142. /**
  143. * Kill the L2NpcInstance (the corpse disappeared after 7 seconds).<BR><BR>
  144. *
  145. @@ -1409,6 +1511,47 @@
  146. @Override
  147. public boolean doDie(L2Character killer)
  148. {
  149. + //If killer instanceof L2PetInstance or instanceof L2SummonInstance, this is going to get the player that controls the killer.
  150. + L2PcInstance player = null;
  151. + player = killer.getActingPlayer();
  152. +
  153. + //ANTIBOT - Start
  154. + if(getNpcId() == 10012 && (killer instanceof L2PcInstance) || (killer instanceof L2PetInstance) || (killer instanceof L2SummonInstance))
  155. + {
  156. + //+1 to mobcounter
  157. + player.setKills(player.getKills() + 1);
  158. +
  159. + //Checks the mobcounter
  160. + if(player.getKills() == 220 || player.getKills() == 0)
  161. + {
  162. + //Random image file name
  163. + int imgId = IdFactory.getInstance().getNextId();
  164. + //Convertion from .png to .dds, and crest packed send
  165. + try
  166. + {
  167. + File captcha = new File("data/captcha/captcha.png");
  168. + ImageIO.write(generateCaptcha(), "png", captcha);
  169. + PledgeCrest packet = new PledgeCrest(imgId, DDSConverter.convertToDDS(captcha).array()); //Convertion to DDS where is antybot
  170. + player.sendPacket(packet);
  171. + }
  172. + catch (Exception e)
  173. + {
  174. + _log.warning(e.getMessage());
  175. + }
  176. + //Paralyze, abnormal effect, invul, html with captcha output and start of the 1 min counter
  177. + player.startAbnormalEffect(AbnormalEffect.REAL_TARGET);
  178. + player.setIsParalyzed(true);
  179. + player.setIsInvul(true);
  180. + adminReply.setHtml("<html><title>Captcha Antibot System</title><body><center>Enter the 5-digits code below and click Confirm.<br><img src=\"Crest.crest_" + Config.SERVER_ID + "_" + imgId + "\" width=256 height=64><br><font color=\"888888\">(There are only english uppercase letters.)</font><br1><font color=\"FF0000\">Tries Left: " + player.getTries() +"</font><br><edit var=\"antibot\" width=110><br><button value=\"Confirm\" action=\"bypass -h voice .antibot $antibot\" width=80 height=26 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\"><br>If you close by mistake this window,<br1>you can re-open it by typing \".captcha\" on Chat.<br1>You have 3 minutes to answer or you<br1>will get jailed.<br1>You have 3 tries, if you will<br1>answer wrong to all of them you<br1>will get punished.</center></body></html>");
  181. + player.sendPacket(adminReply);
  182. + player.setCode(finalString);
  183. + ThreadPoolManager.getInstance().scheduleGeneral(new CaptchaTimer(player), 180000);//180sec
  184. + player.setCodeRight(false);
  185. + finalString.replace(0, 5, "");
  186. + }
  187. + }
  188. + //ANTIBOT - End
  189. +
  190. if (!super.doDie(killer))
  191. return false;
  192. @@ -1748,4 +1896,27 @@
  193. {
  194. return this._hidedName;
  195. }
  196. + //3 Mins Counter and the event that happens
  197. + class CaptchaTimer implements Runnable{
  198. + L2PcInstance activeChar;
  199. + public CaptchaTimer(L2PcInstance player){
  200. + activeChar = player;
  201. + }
  202. + public void run(){
  203. + //here will be code that will run after 1 min
  204. + if(!activeChar.isCodeRight()){
  205. + activeChar.setTries(3);
  206. + //here will run method with jailing player after 1 min
  207. + activeChar.stopAbnormalEffect(AbnormalEffect.REAL_TARGET);
  208. + NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
  209. + npcHtmlMessage.setHtml("<html><title>Captcha Antibot System</title><body><center><font color=\"FF0000\">3 minutes passed.<br><br></font><font color=\"66FF00\"><center></font><font color=\"FF0000\">You will be jailed.</font><br><button value=\"Exit\" action=\"bypass -h npc_%objectId%_Quest\" width=45 height=25 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_ct1.button_df\"></center></body></html>");
  210. + if (activeChar.isFlyingMounted())
  211. + activeChar.untransform();
  212. + activeChar.setPunishLevel(L2PcInstance.PunishLevel.JAIL, 1);
  213. + activeChar.setIsInvul(false);
  214. + activeChar.setIsParalyzed(false);
  215. + activeChar.sendPacket(npcHtmlMessage);
  216. + }
  217. + }
  218. + }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment