Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: C:/Users/George/Desktop/Workspace/Game/java/com/l2js/gameserver/model/actor/L2Npc.java
- ===================================================================
- --- C:/Users/George/Desktop/Workspace/Game/java/com/l2js/gameserver/model/actor/L2Npc.java (revision 183)
- +++ C:/Users/George/Desktop/Workspace/Game/java/com/l2js/gameserver/model/actor/L2Npc.java (working copy)
- @@ -39,16 +40,7 @@
- import com.l2jserver.gameserver.model.L2Spawn;
- import com.l2jserver.gameserver.model.L2World;
- import com.l2jserver.gameserver.model.L2WorldRegion;
- import com.l2jserver.gameserver.model.actor.instance.L2ClanHallManagerInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2DoormenInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2FestivalGuideInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2FishermanInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2TeleporterInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2TrainerInstance;
- import com.l2jserver.gameserver.model.actor.instance.L2WarehouseInstance;
- +import com.l2jserver.gameserver.model.actor.instance.L2SummonInstance;
- +import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
- import com.l2jserver.gameserver.model.actor.knownlist.NpcKnownList;
- import com.l2jserver.gameserver.model.actor.stat.NpcStat;
- import com.l2jserver.gameserver.model.actor.status.NpcStatus;
- @@ -74,6 +66,21 @@
- import com.l2jserver.gameserver.util.Broadcast;
- import com.l2jserver.util.Rnd;
- import com.l2jserver.util.StringUtil;
- +import gov.nasa.worldwind.formats.dds.DDSConverter;
- +
- +import java.awt.Color;
- +import java.awt.Font;
- +import java.awt.FontMetrics;
- +import java.awt.Graphics2D;
- +import java.awt.geom.AffineTransform;
- +import java.awt.image.BufferedImage;
- +import java.io.File;
- +import javax.imageio.ImageIO;
- +import com.l2jserver.gameserver.idfactory.IdFactory;
- +import com.l2jserver.gameserver.model.L2World;
- +import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
- +import com.l2jserver.gameserver.network.serverpackets.PledgeCrest;
- +import com.l2jserver.gameserver.skills.AbnormalEffect;
- /**
- * This class represents a Non-Player-Character in the world. It can be a monster or a friendly character.
- @@ -1388,6 +1398,98 @@
- return (int) (getTemplate().rewardSp * Config.RATE_SP);
- }
- + public static StringBuilder finalString = new StringBuilder();
- + NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
- + private static BufferedImage generateCaptcha()
- + {
- + Color textColor = new Color(98, 213, 43);
- + Color circleColor = new Color(98, 213, 43);
- + Font textFont = new Font("comic sans ms", Font.BOLD, 24);
- + int charsToPrint = 5;
- + int width = 256;
- + int height = 64;
- + int circlesToDraw = 8;
- + float horizMargin = 20.0f;
- + double rotationRange = 0.7; // this is radians
- + BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
- +
- + Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
- +
- + //Draw an oval
- + g.setColor(new Color(30,31,31));
- + g.fillRect(0, 0, width, height);
- +
- + // lets make some noisey circles
- + g.setColor(circleColor);
- + for ( int i = 0; i < circlesToDraw; i++ ) {
- + int circleRadius = (int) (Math.random() * height / 2.0);
- + int circleX = (int) (Math.random() * width - circleRadius);
- + int circleY = (int) (Math.random() * height - circleRadius);
- + g.drawOval(circleX, circleY, circleRadius * 2, circleRadius * 2);
- + }
- +
- + g.setColor(textColor);
- + g.setFont(textFont);
- +
- + FontMetrics fontMetrics = g.getFontMetrics();
- + int maxAdvance = fontMetrics.getMaxAdvance();
- + int fontHeight = fontMetrics.getHeight();
- +
- + // Suggestions ----------------------------------------------------------------------
- + // i removed 1 and l and i because there are confusing to users...
- + // Z, z, and N also get confusing when rotated
- + // 0, O, and o are also confusing...
- + // lowercase G looks a lot like a 9 so i killed it
- + // this should ideally be done for every language...
- + // i like controlling the characters though because it helps prevent confusion
- + // So recommended chars are:
- + // String elegibleChars = "ABCDEFGHJKLMPQRSTUVWXYabcdefhjkmnpqrstuvwxy23456789";
- + // Suggestions ----------------------------------------------------------------------
- + String elegibleChars = "ABCDEFGHJKLMPQRSTUVWXYZ";
- + char[] chars = elegibleChars.toCharArray();
- +
- + float spaceForLetters = -horizMargin * 2 + width;
- + float spacePerChar = spaceForLetters / (charsToPrint - 1.0f);
- +
- + for ( int i = 0; i < charsToPrint; i++ ) {
- + double randomValue = Math.random();
- + int randomIndex = (int) Math.round(randomValue * (chars.length - 1));
- + char characterToShow = chars[randomIndex];
- + finalString.append(characterToShow);
- +
- + // this is a separate canvas used for the character so that
- + // we can rotate it independently
- + int charWidth = fontMetrics.charWidth(characterToShow);
- + int charDim = Math.max(maxAdvance, fontHeight);
- + int halfCharDim = (charDim / 2);
- +
- + BufferedImage charImage = new BufferedImage(charDim, charDim, BufferedImage.TYPE_INT_ARGB);
- + Graphics2D charGraphics = charImage.createGraphics();
- + charGraphics.translate(halfCharDim, halfCharDim);
- + double angle = (Math.random() - 0.5) * rotationRange;
- + charGraphics.transform(AffineTransform.getRotateInstance(angle));
- + charGraphics.translate(-halfCharDim,-halfCharDim);
- + charGraphics.setColor(textColor);
- + charGraphics.setFont(textFont);
- +
- + int charX = (int) (0.5 * charDim - 0.5 * charWidth);
- + charGraphics.drawString("" + characterToShow, charX,
- + ((charDim - fontMetrics.getAscent())
- + / 2 + fontMetrics.getAscent()));
- +
- + float x = horizMargin + spacePerChar * (i) - charDim / 2.0f;
- + int y = ((height - charDim) / 2);
- + g.drawImage(charImage, (int) x, y, charDim, charDim, null, null);
- +
- + charGraphics.dispose();
- + }
- +
- + g.dispose();
- +
- + return bufferedImage;
- + }
- +
- +
- /**
- * Kill the L2NpcInstance (the corpse disappeared after 7 seconds).<BR><BR>
- *
- @@ -1409,6 +1511,47 @@
- @Override
- public boolean doDie(L2Character killer)
- {
- + //If killer instanceof L2PetInstance or instanceof L2SummonInstance, this is going to get the player that controls the killer.
- + L2PcInstance player = null;
- + player = killer.getActingPlayer();
- +
- + //ANTIBOT - Start
- + if(getNpcId() == 10012 && (killer instanceof L2PcInstance) || (killer instanceof L2PetInstance) || (killer instanceof L2SummonInstance))
- + {
- + //+1 to mobcounter
- + player.setKills(player.getKills() + 1);
- +
- + //Checks the mobcounter
- + if(player.getKills() == 220 || player.getKills() == 0)
- + {
- + //Random image file name
- + int imgId = IdFactory.getInstance().getNextId();
- + //Convertion from .png to .dds, and crest packed send
- + try
- + {
- + File captcha = new File("data/captcha/captcha.png");
- + ImageIO.write(generateCaptcha(), "png", captcha);
- + PledgeCrest packet = new PledgeCrest(imgId, DDSConverter.convertToDDS(captcha).array()); //Convertion to DDS where is antybot
- + player.sendPacket(packet);
- + }
- + catch (Exception e)
- + {
- + _log.warning(e.getMessage());
- + }
- + //Paralyze, abnormal effect, invul, html with captcha output and start of the 1 min counter
- + player.startAbnormalEffect(AbnormalEffect.REAL_TARGET);
- + player.setIsParalyzed(true);
- + player.setIsInvul(true);
- + 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>");
- + player.sendPacket(adminReply);
- + player.setCode(finalString);
- + ThreadPoolManager.getInstance().scheduleGeneral(new CaptchaTimer(player), 180000);//180sec
- + player.setCodeRight(false);
- + finalString.replace(0, 5, "");
- + }
- + }
- + //ANTIBOT - End
- +
- if (!super.doDie(killer))
- return false;
- @@ -1748,4 +1896,27 @@
- {
- return this._hidedName;
- }
- + //3 Mins Counter and the event that happens
- + class CaptchaTimer implements Runnable{
- + L2PcInstance activeChar;
- + public CaptchaTimer(L2PcInstance player){
- + activeChar = player;
- + }
- + public void run(){
- + //here will be code that will run after 1 min
- + if(!activeChar.isCodeRight()){
- + activeChar.setTries(3);
- + //here will run method with jailing player after 1 min
- + activeChar.stopAbnormalEffect(AbnormalEffect.REAL_TARGET);
- + NpcHtmlMessage npcHtmlMessage = new NpcHtmlMessage(0);
- + 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>");
- + if (activeChar.isFlyingMounted())
- + activeChar.untransform();
- + activeChar.setPunishLevel(L2PcInstance.PunishLevel.JAIL, 1);
- + activeChar.setIsInvul(false);
- + activeChar.setIsParalyzed(false);
- + activeChar.sendPacket(npcHtmlMessage);
- + }
- + }
- + }
- }
Advertisement
Add Comment
Please, Sign In to add comment