Thread: Taking Screenshot when Reporting Player

Page 1 of 5 123 ... LastLast
Results 1 to 10 of 41
  1. #1 Taking Screenshot when Reporting Player 
    Registered Member

    Join Date
    Jun 2007
    Posts
    2,237
    Thanks given
    267
    Thanks received
    411
    Rep Power
    1283
    Description: WRites a report for the Player into an XML file and takes a screen shot

    Difficulty: 1.

    Assumed Knowledge: Knowledge of XML is helpful but not needed

    Tested Server: Winterloves.

    Files/Classes Modified: Client.java, Misc.java

    Procedure
    Step 1: Open misc and add inside
    Code:
     public static final char validCharacters[] = {
            '_', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
            'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0',
            '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '@', '#', '$', '%',
            '^', '&', '*', '(', ')', '-', '+', '=', ':', ';', '.', '>', '<', ',',
            '"', '[', ']', '|', '?', '/', '`'};
    
        public static String longToString(long l) {
            int i = 0;
            char ac[] = new char[12];
    
            while (l != 0L) {
                long l1 = l;
    
                l /= 37L;
                ac[11 - i++] = validCharacters[(int) (l1 - l * 37L)];
            }
            return new String(ac, 12 - i, i);
        }
    .

    Step 2: Next open Client and add
    Code:
    private ReportScreenShots shots = ReportScreenShots.getInstance();
    
        /**
         * Writes a log to XML file of the player been Reported
         * @param player the name of the player been reported
         * @param rule the rule the offending player broke
         */
        public final void reportPlayer(final String player, final int rule) {
            final String date = Calendar.DATE + "-" + Calendar.HOUR + "-" + Calendar.MINUTE;
            try {
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                Document document = db.newDocument();
                Element em = document.createElement("reported-player");
                em.setAttribute("player", player);
                em.setAttribute("date", date);
                Node reportedBy = document.createTextNode("reported-by");
                reportedBy.setNodeValue(playerName);
                em.appendChild(reportedBy);
                Node ruleBroken = document.createTextNode("rule");
                ruleBroken.setNodeValue(Integer.toString(rule));
                TransformerFactory tFactory = TransformerFactory.newInstance();
                Transformer transformer = tFactory.newTransformer();
                DOMSource source = new DOMSource(document);
                StreamResult result = new StreamResult(new FileOutputStream("./report/Reported-Players.xml"));
                transformer.transform(source, result);
            } catch (ParserConfigurationException pce) {
                System.err.println(pce);
            } catch (TransformerConfigurationException tce) {
                System.err.println(tce);
            } catch (TransformerException te) {
                System.err.println(te);
            } catch (FileNotFoundException e) {
                System.err.println(e);
            }
        }
    .

    Step 3: Add this with your other Packets:
    Code:
    case 218:
                    final String REPORTED_PLAYER = misc.longToString(inStream.readQWord());
                    final int RULE = inStream.readUnsignedByte();
                    final String DATE = Calendar.DATE + "-" + Calendar.HOUR + "-" + Calendar.MINUTE;
                    try {
                        Toolkit toolkit = Toolkit.getDefaultToolkit();
                        Dimension screenSize = toolkit.getScreenSize();
                        Rectangle screenShape = new Rectangle(0, 0, screenSize.width, screenSize.height);
                        Robot robot = new Robot();
                        BufferedImage image = robot.createScreenCapture(screenShape);
                        File file = new File("/reports/" + REPORTED_PLAYER + " " + DATE + ".png");
                        reportPlayer(REPORTED_PLAYER, RULE);
                        shots.addImage(image, file);                    
                    } catch (AWTException awt) {
                        System.err.println(awt);
                    }
                    break;
    Step 4 Finally with you imports add
    Code:
    import java.awt.AWTException;
    import java.awt.Dimension;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.Toolkit;
    import java.awt.image.BufferedImage;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Calendar;
    import javax.imageio.ImageIO;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    Step 5 add this class as ReportScreenShots
    Code:
    
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;
    import javax.imageio.ImageIO;
    
    public class ReportScreenShots {
    
        private static ReportScreenShots instance;
        private Map<BufferedImage, File> image = new HashMap<BufferedImage, File>();
    
        public static ReportScreenShots getInstance() {
            if (instance == null) {
                instance = new ReportScreenShots();
            }
            return instance;
        }
    
        public Map<BufferedImage, File> getImages() {
            return image;
        }
    
        public synchronized void addImage(final BufferedImage i, final File f) {
            image.put(i, f);
        }
    
        public int size() {
            return image.size();
        }
    
        public void clear() {
            image.clear();
        }
        
    
        static {
            long start = System.currentTimeMillis();
            ReportScreenShots shots = ReportScreenShots.getInstance();
            if (System.currentTimeMillis() >= 10000000) {
                for (BufferedImage bi : shots.getImages().keySet()) {
                    for (File f : shots.getImages().values()) {
                        try {
                            ImageIO.write(bi, "png", f);
                        } catch (IOException e) {
                            System.err.println(e);
                        }
                    }
                }
            }
            start = System.currentTimeMillis();
        }
    }
    Credits: Surfer25.

    If you need any help add:
    [Only registered and activated users can see links. ]
    Don't worry, Be happy.
     

  2. #2  
    Banned

    Join Date
    Oct 2007
    Age
    28
    Posts
    2,733
    Thanks given
    32
    Thanks received
    53
    Rep Power
    0
    oh wow, very nice job
     

  3. #3  
    Donator

    Evan's Avatar
    Join Date
    Aug 2007
    Age
    25
    Posts
    1,028
    Thanks given
    1
    Thanks received
    3
    Rep Power
    134
    Good job
    Gone...
     

  4. #4  
    Warmly
    Guest
    Very good job, I really like this.

    Edit: I bet some people will get error that says something like, missing Class File and OutputFormat.
     

  5. #5  
    Registered Member

    Join Date
    Jun 2007
    Posts
    2,237
    Thanks given
    267
    Thanks received
    411
    Rep Power
    1283
    Then they should fix it shouldn't they
    Don't worry, Be happy.
     

  6. #6  
    Warmly
    Guest
    Haha, you're right it's a pretty easy fix.
     

  7. #7  
    Registered Member

    Join Date
    Jun 2007
    Posts
    2,237
    Thanks given
    267
    Thanks received
    411
    Rep Power
    1283
    If you've used this replace the reportPlayer method with the new one.
    Don't worry, Be happy.
     

  8. #8  
    Registered Member

    Join Date
    Jun 2008
    Posts
    734
    Thanks given
    8
    Thanks received
    14
    Rep Power
    148
    very nice man its clean and ownage
    S Quare Quxx: Raul > paladin end of the story
     

  9. #9  
    Warmly
    Guest
    Ahhgg, I did something stupid, now I can't seem to fix the File problem ..
     

  10. #10  
    Registered Member

    Join Date
    Jun 2007
    Posts
    2,237
    Thanks given
    267
    Thanks received
    411
    Rep Power
    1283
    I've changed it a fair bit.
    Now instead of straight off saving, it will load into a Map then save after a set time.

    EDIT:

    Sorry Guys, When i edited i fucked everything up.
    It should all be fixed now.
    Don't worry, Be happy.
     

Page 1 of 5 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •