Jump to content

Welcome to Pure Warfare - The #1 Community for Pures

Welcome to Pure Warfare - The #1 Community for Pures, like most online communities you must register to view or post in our community, but don't worry this is a simple free process that requires minimal information for you to signup. Be apart of Pure Warfare - The #1 Community for Pures by signing in or creating an account.
  • Start new topics and reply to others
  • Subscribe to topics and forums to get email updates
  • Get your own profile page and make new friends
  • Send personal messages to other members.

Small half of a program.


Mythic

Recommended Posts

Well, I need some freaking posts so I can talk in clan discussion, so I decided to post here.

 

I had a little script for a certain unnamed bot that would keep track of world populations and print out when a clan probably hopped to another world(determined by differences in a world's population). Well, the day after I shared it with a rank in my clan and helped him set it up, he hopped to FOE! *points to Adam*

 

Now that I remade it without the need for that certain botting program, I have to make it a little less leak-able, which is why I made a client/server program so I can determine who gets to see the data. The server keeps track of all the good stuff, and basically just sends it all to the client, where the client would display it.

 

Now, I can give it to my fellow scouts without fear of it ever being leaked because even if what I give them is leaked, whoever has it can't actually see the good stuff! I'm posting it here just to prove that point.

 

Discuss! (btw I'm still a bit away from 25 posts, so ask questions if you have any).

 

edit: and just in case you haven't realized, this is only the client!

 

import java.io.Serializable;
public class WorldInfo implements Serializable
{
    private static final long serialVersionUID = 5264138554224340984L;
    private int iWorld, iBefore, iAfter;
    
    public WorldInfo(int iWorld, int iBefore, int iAfter)
    {
        this.iWorld = iWorld;
        this.iBefore = iBefore;
        this.iAfter = iAfter;
    }
    
    public int getWorld() { return iWorld; }
    public int getBefore() { return iBefore; }
    public int getAfter() { return iAfter; }
    
    public void setWorld(int iNewWorld) { iWorld = iNewWorld; }
    public void setBefore(int iNewBefore) { iWorld = iBefore; }
    public void setAfter(int iNewAfter) { iWorld = iAfter; }

    public int getDifference() { return iAfter - iBefore; }
    
    public String toString()
    {
        return iWorld + ":\t" + iBefore + "\t" + iAfter + "\t" + getDifference(); 
    }
}

import java.io.Serializable;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;

public class WorldMessage implements Serializable
{
    private static final long serialVersionUID = -6621944895174293618L;
    private static final DateFormat dfFormat = DateFormat.getDateTimeInstance();
    private static int iPacketNum = 0;
    private long lTime;
    private ArrayList<WorldInfo> alNewWorldInfo, alOldWorldInfo;
    
    public WorldMessage()
    {
        iPacketNum++;
        lTime = System.currentTimeMillis();
        alNewWorldInfo = new ArrayList<WorldInfo>();
        alOldWorldInfo = new ArrayList<WorldInfo>();
    }
    
    public void addNewWorldInfo(WorldInfo wiWorld)
    {
        alNewWorldInfo.add(wiWorld);
    }
    
    public void addOldWorldInfo(WorldInfo wiWorld)
    {
        alOldWorldInfo.add(wiWorld);
    }
    
    @SuppressWarnings("unchecked")
    public ArrayList<WorldInfo> getNewWorldInfo()
    {
        return (ArrayList<WorldInfo>) alNewWorldInfo.clone();
    }
    
    @SuppressWarnings("unchecked")
    public ArrayList<WorldInfo> getOldWorldInfo()
    {
        return (ArrayList<WorldInfo>) alOldWorldInfo.clone();
    }
    
    public String toString()
    {
        StringBuffer sbOut = new StringBuffer();
        sbOut.append("Message Number: ");
        sbOut.append(iPacketNum);
        sbOut.append("\nTime: ");
        sbOut.append(dfFormat.format(new Date(lTime)));
        
        sbOut.append("\n\n=============== Current Hopping =================\n");
        for (WorldInfo wi : alNewWorldInfo)
        {
            sbOut.append(wi.toString());
            sbOut.append("\n");
        }
        
        sbOut.append("\n=============== Past Hopping =================\n");
        for (WorldInfo wi : alOldWorldInfo)
        {
            sbOut.append(wi.toString());
            sbOut.append("\n");
        }
        
        return sbOut.toString();
    }
}

import java.awt.Dimension;
import java.io.ObjectInputStream;
import java.io.PrintWriter;
import java.net.Socket;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class WorldClient implements Runnable
{
    private Socket sSock = null;
    private ObjectInputStream oisInput = null;
    private PrintWriter pwWriter = null;

    private JFrame jfMain = null;
    private JTextArea jtaText = null;
    
    public WorldClient(String sLogin, String sHost, int iPort)
    {
        try {
            sSock = new Socket(sHost, iPort);
            oisInput = new ObjectInputStream(sSock.getInputStream());
            pwWriter = new PrintWriter(sSock.getOutputStream(), true);
            
            pwWriter.println(sLogin);
        } catch (Exception e)
        {
            // Not going to waste time handling different exceptions, just kill the program
            JOptionPane.showMessageDialog(null, "Could not connect to server! Program is closing");
            System.exit(1);
        }
        
        initGUI();
    }
    
    private void initGUI()
    {
        jfMain = new JFrame("World Tracker Client");
        jtaText = new JTextArea();
        jfMain.add(new JScrollPane(jtaText));
        jfMain.setPreferredSize(new Dimension(300, 600));
        jfMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jfMain.setVisible(true);
    }
    
    public void run()
    {
        while (true)
        {
            try {
                Object oReceived = oisInput.readObject();
                jtaText.setText(oReceived.toString());
            } catch (Exception e)
            {
                JOptionPane.showMessageDialog(null, "Communication error! Program is closing");
                System.exit(1);
            }
        }
    }
    
    public static void main(String[] args)
    {
        String sHost = JOptionPane.showInputDialog("Host to connect to?");
        String sPort = JOptionPane.showInputDialog("Port to connect to?");
        String sLogin = JOptionPane.showInputDialog("Login?");
        
        int iPort = -1;
        
        try {
            iPort = Integer.parseInt(sPort);
        } catch(NumberFormatException nfe) {
            JOptionPane.showMessageDialog(null, "Invalid port entry! Program is closing");
            System.exit(1);
        }

        WorldClient wc = new WorldClient(sLogin, sHost, iPort);
        new Thread(wc).start();
    }
}

Link to comment
Share on other sites

Spies and leaks take too much time and are too expensive!

 

Except if I want one from Z, ofc (lol)

 

edit: @Father, from several places. Books, classes, the internet. It really depends on the person. Some people are decent programmers, but others just don't think like programmers and its harder for them to learn. Of course, to be fair, its hard for everyone to learn their first language.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
  • Create New...