SRL Archive - Web Development

dynamic signature


Scaper

2010-04-16 13:48:36

ok well im making a dynamic sig and basicaly imphp noob i got the image already but dont have the php coding etc iv tried and failed

here is the image i was just wondering if someone can help me with the coding part pleaseeeee


http://scaper.php0h.com/sig/picture.png

thanks in advance

Frement

2010-04-16 13:56:30

I can code it for you, where do you get the data?

Scaper

2010-04-16 13:59:45

im wanting it for a ibot script so i want it to send data to a file then read it from there??? if that makes any sense??

id would really appreciate it if you coulkd hlp me

Frement

2010-04-16 14:02:14

From: Scaper
im wanting it for a ibot script so i want it to send data to a file then read it from there??? if that makes any sense??

id would really appreciate it if you coulkd hlp me


Well, can you post data to a site with the iBot?

Like i have site: www.domain.com/script_stats.php
And you post:
"running": 50024
"natures": 2004
And whatever else you need.

What im meaning is that can you post like in scar?

Scaper

2010-04-16 14:04:52

umm im not sure im hosting on my ow domain take a look at what this guy did in his script

import impsoft.bots.ColorBot;
import impsoft.bots.reflection.Entity;
import impsoft.bots.reflection.GroundItem;
import impsoft.bots.reflection.NPCIterator;
import impsoft.bots.reflection.PhysicalObject;
import impsoft.bots.reflection.NPC;
import impsoft.scripting.ibot.aryanweb.PlayerTeleport;
import impsoft.scripting.ibot.enums.Skill;
import impsoft.scripting.ibot.enums.WalkingOptions;
import impsoft.scripting.ibot.interfaces.AutoPaint;
import impsoft.scripting.ibot.interfaces.ChatListener;
import impsoft.scripting.ibot.objects.WalkingPath;
import impsoft.scripting.ibot.interfaces.HumanMouseListener;
import impsoft.scripting.ibot.interfaces.InventoryMonitor;
import impsoft.scripting.ibot.structs.AryanTile;
import impsoft.scripting.ibot.structs.AryanTileZone;
import impsoft.scripting.ibot.structs.XY;
import impsoft.bots.reflection.Player;
import impsoft.bots.reflection.PlayerIterator;
import impsoft.scripting.ibot.builtin.itemrec.BankReflectionItemSlot;
import impsoft.scripting.ibot.builtin.itemrec.IdentifiedItem;
import impsoft.scripting.ibot.builtin.itemrec.InventoryReflectionItemSlot;
import impsoft.scripting.ibot.builtin.itemrec.Item;
import impsoft.scripting.ibot.builtin.itemrec.ItemSlot;
import impsoft.scripting.types.parallel.scriptjobs.ScriptJob;
import impsoft.scripting.types.parallel.scriptjobs.WorldObjectClickingScriptJob;
import impsoft.scripting.types.ColorScript;
import impsoft.utils.general.Timer;
import impsoft.utils.ibot.ReflectionUtils;
import impsoft.utils.ibot.Sorting;
import impsoft.values.constant.Areas;
import impsoft.scripting.ibot.itemrec.ItemNameExact;
import impsoft.utils.uber.*;

import rodney.*;

import java.security.Security;
import java.util.StringTokenizer;
import java.util.EnumSet;
import java.util.HashMap;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.*;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.awt.*;
import java.io.*;
import java.awt.event.ActionEvent;
import java.net.*;
import java.util.Iterator;
import java.util.Scanner;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import SoundPlayer.SoundPlayer;
import bergCoder.BergUtils;
import bergCoder.LootItem;
import bergCoder.LootTable;
import bergCoder.Object3D;

public class KazFighter extends ColorScript implements AutoPaint {

public KazFighter(ColorBot bot, String cmd, String args[])
{
super(bot);
}

//Script info
public static String author = "Kaz";
public static String description = "The simplest way to be 'the best'";
public static String Version = "1.05";
public static String Credits = "Kaz";

//Utils
BergUtils util = new BergUtils(this);

//GUI Variables
boolean guiIsDone;
ArrayList<NPC> nearbyMonstersArray = new ArrayList<NPC>();
ArrayList<NPC> proggyArray = new ArrayList<NPC>();
ArrayList<String> currentMonstersArrayList = new ArrayList<String>();
ArrayList<String> usedLoot = new ArrayList<String>();
ArrayList<String> beforeLoot = new ArrayList<String>();
NPC[] currentMonstersArray = {};
NPC nearbyNPC[] = {};
ArrayList<String> nearbyNPCInfo = new ArrayList<String>();
ArrayList<String> currentNPCInfo = new ArrayList<String>();
DefaultListModel nearbyListModel;
DefaultListModel currentMonstersModel;
ArrayList<String> LootItemsList = new ArrayList<String>();
int currentLoot = 0;
boolean breaks = false;
int intervalMin;
int intervalMax;
int breakTimeMax;
int breakTimeMin;
File[] files = {};

//NPC variables
int numb;
String[] monsterNames = {};
int[] monsterTypes = {};

//Food variables
String food = null;
int healthNumber = 0;
int foodAmount = 0;
boolean useFood = true;
boolean useBank = true;
boolean logOff = false;
boolean useStyle = false;

//Item variables
String[] itemList = {};
boolean buryBones = false;
float profitMade = 0;

//Tile variables
AryanTile startTile;
int tileDistance = 0;

//Fight variables
WorldObjectClickingScriptJob sj;
int npcKills = 0;
String attackStyle;
boolean longWait = false;

double health;

boolean currentBreak = true;

boolean breakTimer = false;
Timer interval = new Timer(random((intervalMin * 1000 * 60), (intervalMax * 1000 * 60)));

//Paint variables
Timer timer = new Timer(0);
int startEXPAttack = 1;
int startEXPStrength = 1;
int startEXPDefence = 1;
int startEXPHitpoints = 1;
int startLevelAttack = 1;
int startLevelStrength = 1;
int startLevelDefence = 1;
int startLevelHitpoints = 1;
int TotalExp;
int sigXP = 0;
int sigKills = 0;

Timer t = new Timer(random(300000, 480000));

String userString;

public void script() throws InterruptedException, Exception, IOException
{
try{
if(!new File("KazFighter").exists() || !new File("KazFighter/Data").exists() || !new File("KazFighter/Data/LootFile.txt").exists() ||
!new File("KazFighter/SaveFiles").exists() || !new File("KazFighter/ScreenShots/").exists())
{
createDirectory();
}
startGUI();
while(!theLoggedInTest.isLoggedIn())
{
sleep(500);
}
startEXPAttack = theTabs.Statistics.getStatExperience(Skill.ATTACK);
startEXPStrength = theTabs.Statistics.getStatExperience(Skill.STRENGTH);
startEXPDefence = theTabs.Statistics.getStatExperience(Skill.DEFENSE);
startEXPHitpoints = theTabs.Statistics.getStatExperience(Skill.HITPOINTS);
startLevelAttack = theTabs.Statistics.getStatBottom(Skill.ATTACK);
startLevelStrength = theTabs.Statistics.getStatBottom(Skill.STRENGTH);
startLevelDefence = theTabs.Statistics.getStatBottom(Skill.DEFENSE);
startLevelHitpoints = theTabs.Statistics.getStatBottom(Skill.HITPOINTS);
startTile = getLocation();
checkAttackStyle();
while(true && currentBreak)
{
stopRandom("Login");
if(t.isUp())
{
updateSignature(userString);
updateSignature("TotalUsage");
t.reset();
}
walkToSpot();
checkRun();
if(theTabs.Inventory.count(food) < 4 || theTabs.Inventory.isFull())
{
bank();
}
fightMonster();
}
}
catch(InterruptedException e)
{
e.printStackTrace();
BufferedImage proggy = screenshotOfProgress();
File file = new File("KazFighter/ScreenShots");
File[] countfiles = file.listFiles();
File outputfile = new File("KazFighter/ScreenShots/" + countfiles.length + ".png");
ImageIO.write(proggy, "png", outputfile);

}
}

public void updateSignature(String username) throws IOException
{
checkURLFile(username);

log("Updating signature");
BufferedReader reader = new BufferedReader(new InputStreamReader(new URL("http://www.pyritebomb.co.uk/signature/" + username + "time.txt").openStream()));
BufferedReader reader2 = new BufferedReader(new InputStreamReader(new URL("http://www.pyritebomb.co.uk/signature/" + username + "xp.txt").openStream()));
BufferedReader reader3 = new BufferedReader(new InputStreamReader(new URL("http://www.pyritebomb.co.uk/signature/" + username + "kills.txt").openStream()));

String line;
String line2;
String line3;

String str1 = null;
String str2 = null;
String str3 = null;

String time = "";
String xp = "";
String kills = "";

while((line = reader.readLine()) != null)
{
str1 = line;
}
int index = str1.indexOf(":");
int seg1 = Integer.parseInt(str1.substring(0, index));
int seg2 = Integer.parseInt(str1.substring(index+1, index+3));
int seg3 = Integer.parseInt(str1.substring(index+4, str1.length()));
String currentTime = t.timePassedStr();
int index2 = currentTime.indexOf(":");
int seg4 = Integer.parseInt(currentTime.substring(0, index2));
int seg5 = Integer.parseInt(currentTime.substring(index2+1, index2+3));
int seg6 = Integer.parseInt(currentTime.substring(index2+4, currentTime.length()));

//Seconds
String int3 = "0";
if((seg3 + seg6) > 59 && (seg3 + seg6) < 70)
{
seg5++;
int3 = "0" + (seg3 + seg6 - 60);
}
else if((seg3 + seg6) > 70)
{
seg5++;
int3 = "" + (seg3 + seg6 - 60);
}
else if((seg3 + seg6) < 10)
int3 = "0" + (seg3 + seg6);
else
int3 = "" + (seg3 + seg6);

//Minutes
String int2 = "0";
if((seg2 + seg5) > 59 && (seg2 + seg5) < 70)
{
seg4++;
int2 = "0" + (seg2 + seg5 - 60);
}
else if((seg2 + seg5) > 70)
{
seg4++;
int2 = "" + (seg2 + seg5 - 60);
}
else if((seg2 + seg5) < 10)
int2 = "0" + (seg2 + seg5);
else
int2 = "" + (seg2 + seg5);

//Hours
String int1 = "0";
if((seg1 + seg4) < 10)
int1 = "0" + (seg1 + seg4);
else
int1 = "" + (seg1 + seg4);

time = System.getProperty("line.separator") + int1 + ":" + int2 + ":" + int3;

while((line2 = reader2.readLine()) != null)
{
str2 = line2;
}

int i = Integer.parseInt(str2);
xp = System.getProperty("line.separator") + (i + (TotalExp - sigXP));
sigXP = TotalExp;

while((line3 = reader3.readLine()) != null)
{
str3 = line3;
}

int d = Integer.parseInt(str3);
kills = System.getProperty("line.separator") + ((npcKills - sigKills) + d);

sigKills = npcKills;


connectToUrl(username, time, xp, kills);
}

public void checkURLFile(String username) throws MalformedURLException, UnsupportedEncodingException, IOException
{
URL url = new URL("http://www.pyritebomb.co.uk/signature/checkfile.php?user=" + URLEncoder.encode(username, "UTF-8"));
url.openConnection();
Scanner scan = new Scanner(url.openStream());
while (scan.hasNext()) {
String line = scan.nextLine();
System.out.print(line);
}
}

public void connectToUrl(String username, String time, String xp, String kills) throws IOException
{
URL url = null;
try {
url = new URL("http://www.pyritebomb.co.uk/signature/makesig.php?user=" + URLEncoder.encode(username, "UTF-8") + "&time=" + URLEncoder.encode(time, "UTF-8") + "&xp=" + URLEncoder.encode(xp, "UTF-8") + "&kills=" + URLEncoder.encode(kills, "UTF-8"));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
url.openConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Scanner scan = new Scanner(url.openStream());
while (scan.hasNext()) {
String line = scan.nextLine();
System.out.print(line);
}
}

public BufferedImage screenshotOfProgress(){
BufferedImage bi = theClientScreenGrabber.getDebugBufferedImage(0);
synchronized (bi) {
return bi.getSubimage(7, 345, 505, 130);
}
}

public void checkAttackStyle() throws InterruptedException
{
theTabs.Attack.setSelected();
theTabs.Attack.setRetaliate(true);
}

public void checkRun() throws InterruptedException
{
if(theMiniMapIndicators.getEnergy() < 80)
setRunning(true);
}

public void startGUI() throws InterruptedException, IOException {
JFrame GUI = new GUI();
try {
while (!guiIsDone) {
sleep(4000);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}

public void bank() throws InterruptedException
{
if(useBank)
{
theBank.open();
if(theTabs.Inventory.getCount() > 0)
theBank.doDepositAll();
if(theTabs.Inventory.count(food) <= foodAmount)
{
theBank.doWithDrawX(food, foodAmount);
}
else
{
theTabs.Logout.click();
theTabs.Logout.clickLogOut();
}
checkRun();
walkToSpot();
}
}

public void fightMonster() throws InterruptedException
{
if(breaks){
if(interval.isUp())
{
breaker();
}
}
checkTabs();
NPC monster = findBestMonster();
if(monster != null)
{
sj = theParallelWorldObjectActions.clickAttackNPC(monster);
sleep(500);
if(isClicking())
sleep(2000,3000);
while(getAnimation() != -1)
if(useFood)
{
String statBottom = "0." + healthNumber;
health = Double.parseDouble(statBottom);
if(theMiniMapIndicators.getHealthPoints() < theTabs.Statistics.getStatBottom(Skill.HITPOINTS) * health)
{
theTabs.Inventory.doAction(food, "Eat", 1, true);
}
sleep(400,500);
}
if(longWait)
{
while (monster.inCombat() || monster.isInteractingWithMyPlayer())
{
sleep(400);
}
}
if (!monster.inCombat() || !monster.isInteractingWithMyPlayer()) {
getLoot();
npcKills++;
}
}
}

public void breaker() throws InterruptedException
{
int time = random(breakTimeMin, breakTimeMax);
int realTime = (time * 1000 * 60);
log("Breaking for " + time + "minutes");
theTabs.Logout.click();
theTabs.Logout.clickLogOut();
Timer breakTime = new Timer(realTime);
while(breakTime.isNotUp())
{
sleep(2000);
}
if(breakTime.isUp())
{
startRandom("Login");
log("Returning to script");
breakTimer = false;
breakTime.reset();
currentBreak = true;
}
}

public boolean clickMonster(NPC npc) throws InterruptedException
{
int type = npc.getType();
String name = npc.getName();
AryanTile monsterTile = npc.getLocation();
Object3D Bounds = new Object3D(-15, 15, -15, 15, 75, 160, false);
if(name == null)
return false;
if(npc.inCombat())
return false;
if(npc.getLocation() != monsterTile)
{
monsterTile = npc.getLocation();
if(npc == null)
return false;
}
return false;
}

public void checkTabs() throws InterruptedException
{
if(!theTabs.Inventory.isSelected())
theTabs.Inventory.click();
}

public void getLoot() throws InterruptedException
{
GroundItem[] item = getAllGroundItems();
for(int i = 0; i < item.length; i++)
{
for(int b = 0; b < usedLoot.size(); b++)
{
if(usedLoot.get(b).toLowerCase().equals(item[i].getName().toLowerCase()))
{
util.clickGroundItem(item[i].getID(), item[i].getName());
sleep(500);
while(isMoving())
{
sleep(400, 500);
}
if(buryBones)
{
if(item[i].getName().toLowerCase().contains("bones"));
theTabs.Inventory.doAction(item[i].getName(), "Bury", 1, true);
int price = item[i].getGrandExchangeValue();
profitMade = profitMade + price;
}
}
}
}
}

public void walkToSpot() throws InterruptedException
{
if(getLocation().distanceTo(startTile) > tileDistance)
{
util.walkExact(startTile);
}
}

public NPC findBestMonster()
{
for(int i = 0; i < currentMonstersArrayList.size(); i++)
{
NPC monster = util.getNPCByName(currentMonstersArrayList.get(i));
return monster;
}
return null;
}

public boolean isClicking(){
if(sj == null) return false;
return !sj.isDone();
}


public void writeFile(StringBuilder string) throws IOException
{
File file = new File("KazFighter/Data/LootFile.txt");
FileWriter fileWriter = new FileWriter(file);
BufferedWriter writer = new BufferedWriter(fileWriter);
writer.write(string.toString());
writer.close();
}

public void createDirectory() throws IOException
{
File file = new File("KazFighter");
File file2 = new File("KazFighter/Data");
File file3 = new File("KazFighter/Data/LootFile.txt");
File file4 = new File("KazFighter/SaveFiles");
File file5 = new File("KazFighter/ScreenShots");
File file6 = new File("KazFighter/SaveFiles/0.txt");
File file7 = new File("KazFighter/Data/ProggyName.txt");
file.mkdir();
file2.mkdir();
file3.createNewFile();
file4.mkdir();
file5.mkdir();
file6.createNewFile();
file7.createNewFile();

URL url = new URL("http://www.pyritebomb.co.uk/LootFile.txt");
InputStreamReader in = new InputStreamReader(url.openStream());
BufferedReader reader = new BufferedReader(in);

String line = null;
StringBuilder string = new StringBuilder();

log("Updating Loot list");

while((line = reader.readLine()) != null)
{

string.append(line + System.getProperty("line.separator"));
}

writeFile(string);
}

public void getNearbyMonsters()
{
nearbyMonstersArray.clear();
for (NPCIterator iterator = getNPCIterator(); iterator.hasNext();) {
NPC npc = iterator.next();
Polygon p = npc.getGameScreenLocation();
if (p != null) {
if(npc.getLevel() > 0)
{
nearbyMonstersArray.add(npc);
}
}
}
}

public void paint(Graphics g)
{
try{
g.setColor(new Color(38, 38, 38));
g.fillRoundRect(7, 345, 505, 130, 0, 0);
g.setColor(Color.BLACK);
g.drawRoundRect(7, 345, 505, 25, 0, 0);
g.drawRoundRect(7, 345, 505, 130, 0, 0);
g.setColor(Color.white);
g.drawString("KazFighter v" + Version, 200, 360);
int TotalXpAttack = theTabs.Statistics.getStatExperience(Skill.ATTACK) - startEXPAttack;
int TotalXpStrength = theTabs.Statistics.getStatExperience(Skill.STRENGTH) - startEXPStrength;
int TotalXpDefence = theTabs.Statistics.getStatExperience(Skill.DEFENSE) - startEXPDefence;
int TotalXpHitpoints = theTabs.Statistics.getStatExperience(Skill.HITPOINTS) - startEXPHitpoints;
int currentLevelAttack = theTabs.Statistics.getStatBottom(Skill.ATTACK);
int currentLevelStrength = theTabs.Statistics.getStatBottom(Skill.STRENGTH);
int currentLevelDefence = theTabs.Statistics.getStatBottom(Skill.DEFENSE);
int currentLevelHitpoints = theTabs.Statistics.getStatBottom(Skill.HITPOINTS);
long xpphAttack = (TotalXpAttack * 60 * 60) / (timer.getTimeElapsed() / 1000);
long xpphStrength = (TotalXpStrength * 60 * 60) / (timer.getTimeElapsed() / 1000);
long xpphDefence = (TotalXpDefence * 60 * 60) / (timer.getTimeElapsed() / 1000);
long xpphHitpoints = (TotalXpHitpoints * 60 * 60) / (timer.getTimeElapsed() / 1000);
TotalExp = (TotalXpAttack + TotalXpStrength + TotalXpDefence + TotalXpHitpoints);
float TotalProfit = (profitMade / 1000);
g.drawString("Time ran - " + timer.toStringTimeElapsed(), 15, 385);
g.drawString("Monsters killed - " + npcKills, 15, 400);
g.drawString("Total xp - " + (TotalXpAttack + TotalXpStrength + TotalXpDefence + TotalXpHitpoints) + " - " + (xpphAttack + xpphStrength + xpphDefence + xpphHitpoints) + " xp/h", 15, 415);
g.drawString("Profit Made - " + TotalProfit + "k", 270, 385);
g.drawString("Attack - " + currentLevelAttack + " - " + xpphAttack + " xp/h", 15, 445);
g.drawString("Strength - " + currentLevelStrength + " - " + xpphStrength + " xp/h", 15, 460);
g.drawString("Defence - " + currentLevelDefence + " - " + xpphDefence + " xp/h", 270, 445);
g.drawString("Hitpoints - " + currentLevelHitpoints + " - " + xpphHitpoints + " xp/h", 270, 460);
getNearbyMonsters();
for(int i = 0; i < nearbyMonstersArray.size(); i++)
{
NPC npc = nearbyMonstersArray.get(i);
if(npc != null)
{
if(npc.getGameScreenLocation() != null)
{
g.drawPolygon(npc.getGameScreenLocation());
}
}
int ratio;
if(npc.inCombat())
{
ratio = (int)(npc.getHPRatio() / 2.55);
}
else
{
ratio = 100;
}
double x = npc.getGameScreenLocation().getBounds().getCenterX();
double y = npc.getGameScreenLocation().getBounds().getCenterY();
g.setFont(new Font("Arial", Font.PLAIN, 10));
g.setColor(new Color(60,60,60,70));
g.fillRect((int)x, (int)y, 80, 20);
g.setColor(new Color(160,160,160,70));
g.fillRect((int)x+80, (int)y, 40, 20);
g.setColor(Color.black);
g.drawRect((int)x, (int)y, 120, 20);
g.setColor(Color.white);
g.drawString(npc.getName(), (int)x+5, (int)y+15);
g.drawString(ratio + "%", (int)x+85, (int)y+15);
}
}
catch(Exception e)
{

}
}


class GUI extends JFrame implements ActionListener, ChangeListener{
public GUI() throws IOException
{
super();
doGUI();
this.setVisible(true);
}

//Monsters Tab
int nearbyMonsters = nearbyMonstersArray.size();
int currentMonsters = currentMonstersArray.length;

JList nearbyMonsterList;
JLabel nearbyMonsterLabel;

JButton monsterRefresh;

JList currentMonsterList;

JButton toButton;
JButton fromButton;
JButton clearButton;

//Main GUI
JButton startScript;
JTextField username;

//Food panel
JTextField foodType;
JLabel foodLabel;
JSpinner foodCount;

JSlider healthPercent;

JCheckBox bankOption;
JCheckBox titleOption;
JCheckBox logOffFoodOption;

SpinnerModel foodNumbers;

//Loot Panel
JButton searchButton;

JTextField itemSearch;
DefaultListModel ItemsListModel;
DefaultListModel usedItemListModel;

JButton lootInButton;
JButton lootOutButton;
JButton clearLootButton;

JList usedLootList;
JList lootList;

JButton lootSaveButton;

//General Tab
JComboBox attackStyleSelection;
JCheckBox useAttackStyle;

JComboBox profileSelection;
JButton profileButton;
String[] GeneralProfiles;

SpinnerModel tileNumbers;
JSpinner tileCount;

JCheckBox useBreaks;

JTextField breakBoxMax;
JTextField breakBoxMin;
JTextField intervalBoxMax;
JTextField intervalBoxMin;

JTextField profileSaveField;

//Misc Panel
JCheckBox buryBonesBox;

JCheckBox waitUntilDeath;

public void doGUI() throws IOException
{
setVisible(true);
setResizable(false);
setAlwaysOnTop(true);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


JPanel contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);

//Tabs
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.setBounds(10, 100, 475, 360);

JLabel Title = new JLabel("KazFighter v" + Version);
Title.setBounds(120, 10, 300, 60);
Title.setForeground(Color.ORANGE);

Font font = Title.getFont();
Title.setFont(new Font(font.getFontName(), font.getStyle(), 35));

//Button
startScript = new JButton("Start Script");
startScript.setBounds(10, 460, 475, 30);
startScript.addActionListener(this);

JLabel usernameLabel = new JLabel("Your signature username:");
usernameLabel.setBounds(100, 70, 150, 20);

String usernameString = getUserName();

username = new JTextField(usernameString);
username.setBounds(250, 70, 100, 20);

tabbedPane.addTab("General", makeGeneralPanel());
tabbedPane.addTab("Food", makeFoodPanel());
tabbedPane.addTab("Monsters", makeMonstersPanel());
tabbedPane.addTab("Loot", makeLootPanel());
tabbedPane.addTab("Misc", makeMiscPanel());

contentPane.add(tabbedPane);
contentPane.add(startScript);
contentPane.add(Title);
contentPane.add(usernameLabel);
contentPane.add(username);

this.setTitle("KazFighter v1.0");
this.setLocation(new Point(275, 88));
this.setSize(new Dimension(500, 525));
}

protected JComponent makeGeneralPanel() {
JPanel panel = new JPanel(null);

JPanel panel1 = new JPanel(null);
panel1.setBounds(20, 20, 430, 100);
panel1.setBorder(BorderFactory.createTitledBorder("Profile"));

JLabel profileLabel = new JLabel("Choose your profile:");
profileLabel.setBounds(20, 20, 200, 20);

GeneralProfiles = getFoldersFiles();

profileSelection = new JComboBox(GeneralProfiles);
profileSelection.setBounds(180, 20, 200, 20);
profileSelection.addActionListener(this);

profileButton = new JButton("Save Options");
profileButton.setBounds(140, 50, 260, 20);
profileButton.addActionListener(this);

profileSaveField = new JTextField();
profileSaveField.setBounds(20, 50, 100, 20);

tileNumbers = new SpinnerNumberModel(15, 1, 30, 1);

tileCount = new JSpinner(tileNumbers);
tileCount.setBounds(200, 125, 50, 20);

JLabel tileLabel = new JLabel("Fight within ");
tileLabel.setBounds(70, 125, 200, 20);

JLabel tileLabel2 = new JLabel("tiles");
tileLabel2.setBounds(270, 125, 200, 20);

JPanel panel2 = new JPanel(null);
panel2.setBounds(20, 220, 430, 100);
panel2.setBorder(BorderFactory.createTitledBorder("Breaks"));

useBreaks = new JCheckBox("Use Breaks");
useBreaks.setBounds(20, 20, 200, 20);

JLabel breaksLabel = new JLabel("Time between breaks");
breaksLabel.setBounds(40, 40, 200, 20);

intervalBoxMax = new JTextField("90");
intervalBoxMax.setBounds(200, 40, 50, 20);

JLabel intervalLabel = new JLabel("Min/Max");
intervalLabel.setBounds(275, 40, 90, 20);

intervalBoxMin = new JTextField("60");
intervalBoxMin.setBounds(350, 40, 50, 20);

JLabel breaksLabel2 = new JLabel("Length of breaks");
breaksLabel2.setBounds(40, 60, 100, 20);

breakBoxMax = new JTextField("15");
breakBoxMax.setBounds(200, 60, 50, 20);

JLabel breakLabel = new JLabel("Min/Max");
breakLabel.setBounds(275, 60, 90, 20);

breakBoxMin = new JTextField("30");
breakBoxMin.setBounds(350, 60, 50, 20);

panel1.add(profileLabel);
panel1.add(profileSelection);
panel1.add(profileSaveField);
panel.add(tileCount);
panel.add(tileLabel);
panel.add(tileLabel2);
panel1.add(profileButton);
panel2.add(useBreaks);
panel2.add(breaksLabel);
panel2.add(breaksLabel2);
panel2.add(intervalBoxMax);
panel2.add(intervalBoxMin);
panel2.add(breakBoxMax);
panel2.add(breakBoxMin);
panel2.add(intervalLabel);
panel2.add(breakLabel);
panel.add(panel1);
panel.add(panel2);

return panel;
}

protected JComponent makeMiscPanel() {
JPanel panel = new JPanel(null);

buryBonesBox = new JCheckBox("Bury bones on pickup");
buryBonesBox.setBounds(20, 20, 150, 20);

waitUntilDeath = new JCheckBox("Wait until monster is dead");
waitUntilDeath.setBounds(20, 40, 150, 20);

panel.add(buryBonesBox);
panel.add(waitUntilDeath);

return panel;
}

protected JComponent makeLootPanel() {
JPanel panel = new JPanel(null);

ItemsListModel = new DefaultListModel();

lootList = new JList(ItemsListModel);
lootList.setLayoutOrientation(JList.VERTICAL);
lootList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
lootList.setAlignmentX(LEFT_ALIGNMENT);

JScrollPane itemPane = new JScrollPane(lootList);
itemPane.setBounds(20, 32, 150, 240);

usedItemListModel = new DefaultListModel();

usedLootList = new JList(usedItemListModel);
lootList.setLayoutOrientation(JList.VERTICAL);
lootList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
lootList.setAlignmentX(LEFT_ALIGNMENT);

JScrollPane usedItemPane = new JScrollPane(usedLootList);
usedItemPane.setBounds(300, 32, 150, 240);

itemSearch = new JTextField();
itemSearch.setBounds(100, 10, 70, 20);

JLabel searchLabel = new JLabel("Search:");
searchLabel.setBounds(20, 10, 50, 20);

searchButton = new JButton("Search");
searchButton.setBounds(20, 290, 150, 25);
searchButton.addActionListener(this);

lootInButton = new JButton("Move Right");
lootInButton.setBounds(185, 50, 100, 30);
lootInButton.addActionListener(this);

lootOutButton = new JButton("Move Left");
lootOutButton.setBounds(185, 90, 100, 30);
lootOutButton.addActionListener(this);

clearLootButton = new JButton("Clear Lists");
clearLootButton.setBounds(185, 130, 100, 30);
clearLootButton.addActionListener(this);

panel.add(itemPane);
panel.add(itemSearch);
panel.add(searchButton);
panel.add(searchLabel);
panel.add(usedItemPane);
panel.add(lootInButton);
panel.add(lootOutButton);
panel.add(clearLootButton);
//panel.add(lootSaveButton);

return panel;
}

protected JComponent makeFoodPanel() {
JPanel panel = new JPanel(null);

foodLabel = new JLabel("Choice of food:");
foodLabel.setBounds(20, 25, 150, 28);

JLabel foodLabel2 = new JLabel("(Eg. lobster)");
foodLabel2.setBounds(260, 25, 150, 28);

foodType = new JTextField();
foodType.setBounds(100, 28, 150, 20);

foodNumbers = new SpinnerNumberModel(15, 1, 28, 1);

foodCount = new JSpinner(foodNumbers);
foodCount.setBounds(330, 28, 50, 20);

JPanel panel2 = new JPanel(null);
panel2.setBounds(20, 80, 430, 80);
panel2.setBorder(BorderFactory.createTitledBorder("Health percent"));

healthPercent = new JSlider(JSlider.HORIZONTAL, 0, 100, 30);
healthPercent.setMajorTickSpacing(20);
healthPercent.setMinorTickSpacing(5);
healthPercent.setPaintTicks(true);
healthPercent.setPaintLabels(true);
healthPercent.setBounds(30, 20, 350, 40);
healthPercent.addChangeListener(this);

bankOption = new JCheckBox("Run to the bank when food has run out");
bankOption.setBounds(20, 190, 250, 20);

titleOption = new JCheckBox("Use food");
titleOption.setBounds(20, 170, 250, 20);

logOffFoodOption = new JCheckBox("Log off if out of food");
logOffFoodOption.setBounds(20, 210, 250, 20);

bankOption.setSelected(true);
titleOption.setSelected(true);

panel.add(foodType);
panel.add(foodLabel);
panel.add(foodCount);
panel.add(foodLabel2);
panel.add(bankOption);
panel.add(titleOption);
panel.add(panel2);
panel2.add(healthPercent);
panel.add(logOffFoodOption);

return panel;
}

protected JComponent makeMonstersPanel() {
JPanel panel = new JPanel(null);

nearbyListModel = new DefaultListModel();

nearbyMonsterList = new JList(nearbyListModel);
nearbyMonsterList.setLayoutOrientation(JList.VERTICAL);
nearbyMonsterList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
nearbyMonsterList.setAlignmentX(LEFT_ALIGNMENT);


JScrollPane nearbyMonsterPane = new JScrollPane(nearbyMonsterList);
nearbyMonsterPane.setBounds(20, 32, 150, 250);

nearbyMonsterLabel = new JLabel("Nearby Monsters");
nearbyMonsterLabel.setBounds(20, 10, 150, 28);

monsterRefresh = new JButton("Refresh");
monsterRefresh.setBounds(20, 290, 150, 30);
monsterRefresh.addActionListener(this);

currentMonstersModel = new DefaultListModel();

currentMonsterList = new JList(currentMonstersModel);
currentMonsterList.setLayoutOrientation(JList.VERTICAL);
currentMonsterList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
currentMonsterList.setAlignmentX(LEFT_ALIGNMENT);

JScrollPane currentMonsterPane = new JScrollPane(currentMonsterList);
currentMonsterPane.setBounds(300, 32, 150, 250);

JLabel currentMonsterLabel = new JLabel("Hunted Monsters");
currentMonsterLabel.setBounds(300, 10, 150, 28);

toButton = new JButton("Move Right");
toButton.setBounds(185, 50, 100, 30);
toButton.addActionListener(this);

fromButton = new JButton("Move Left");
fromButton.setBounds(185, 90, 100, 30);
fromButton.addActionListener(this);

clearButton = new JButton("Clear Lists");
clearButton.setBounds(185, 130, 100, 30);
clearButton.addActionListener(this);

panel.add(nearbyMonsterPane);
panel.add(nearbyMonsterLabel);
panel.add(monsterRefresh);
panel.add(currentMonsterPane);
panel.add(currentMonsterLabel);
panel.add(toButton);
panel.add(fromButton);
panel.add(clearButton);

return panel;
}

public void moveMonstersTo()
{
Object selectedElement = nearbyMonsterList.getSelectedValue();
int selectedItem = nearbyMonsterList.getSelectedIndex();
currentMonstersArrayList.add(nearbyMonstersArray.get(selectedItem).getName());
currentMonstersModel.addElement(selectedElement);
nearbyListModel.removeElement(selectedElement);
}

public void moveMonstersFrom()
{
Object selectedElement = currentMonsterList.getSelectedValue();
int selectedItem = currentMonsterList.getSelectedIndex();
currentMonstersArrayList.remove(nearbyMonstersArray.get(selectedItem));
nearbyListModel.addElement(selectedElement);
currentMonstersModel.removeElement(selectedElement);
}

public void moveLootTo()
{
Object selectedElement = lootList.getSelectedValue();
int selectedItem = lootList.getSelectedIndex();
usedLoot.add(beforeLoot.get(selectedItem));
usedItemListModel.addElement(selectedElement);
ItemsListModel.removeElement(selectedElement);
}

public void moveLootFrom()
{
Object selectedElement = usedLootList.getSelectedValue();
int selectedItem = usedLootList.getSelectedIndex();
usedLoot.remove(beforeLoot.get(selectedItem));
ItemsListModel.addElement(selectedElement);
usedItemListModel.removeElement(selectedElement);
}

public String[] getFoldersFiles()
{
File file = new File("KazFighter/SaveFiles");
String[] filesName = file.list();
filesName[0] = "";
return filesName;
}

public String getUserName() throws IOException
{
File file = new File("KazFighter/Data/ProggyName.txt");
FileReader w = new FileReader(file);
BufferedReader reader = new BufferedReader(w);

String line = null;
String name = "";

while((line = reader.readLine()) != null)
{
name = line;
}
return name;
}

public void writeUserName() throws IOException
{
File file = new File("KazFighter/Data/ProggyName.txt");

FileWriter w = new FileWriter(file);
BufferedWriter writer = new BufferedWriter(w);

writer.write(username.getText() + System.getProperty("line.separator"));
writer.close();
}

public void saveGeneralTab() throws IOException
{
File file = new File("KazFighter/SaveFiles/" + profileSaveField.getText() + ".txt");
file.createNewFile();

FileWriter w = new FileWriter(file);
BufferedWriter writer = new BufferedWriter(w);

writer.write(" --KazFighter Save File--" + System.getProperty("line.separator") + System.getProperty("line.separator"));

writer.write("[General Tab]"+ System.getProperty("line.separator") + System.getProperty("line.separator"));

SpinnerModel model2 = tileCount.getModel();
Integer d = (Integer)model2.getValue();
writer.write("Tiles Away = " + d.intValue() + System.getProperty("line.separator"));

String breaksString;
if(useBreaks.isSelected())
breaksString = "true";
else
breaksString = "false";
writer.write("Use Breaks = " + breaksString + System.getProperty("line.separator"));

writer.write("Min Length = " + Integer.parseInt(breakBoxMin.getText()) + System.getProperty("line.separator"));

writer.write("Max Length = " + Integer.parseInt(breakBoxMin.getText()) + System.getProperty("line.separator"));

writer.write("Min Interval = " + Integer.parseInt(intervalBoxMin.getText()) + System.getProperty("line.separator"));

writer.write("Min Interval = " + Integer.parseInt(intervalBoxMax.getText()) + System.getProperty("line.separator") + System.getProperty("line.separator"));

writer.write("[Food Tab]"+ System.getProperty("line.separator") + System.getProperty("line.separator"));

writer.write("Food Type = " + foodType.getText() + System.getProperty("line.separator"));

SpinnerModel model = foodCount.getModel();
Integer i = (Integer)model.getValue();
writer.write("Food Amount = " + i.intValue() + System.getProperty("line.separator"));

writer.write("Food Percent = " + healthPercent.getValue() + System.getProperty("line.separator"));

String useFoodString;
if (titleOption.isSelected())
{
useFoodString = "true";
}
else
useFoodString = "false";
writer.write("Use Food = " + useFoodString + System.getProperty("line.separator"));

String useBankString;
if (bankOption.isSelected())
{
useBankString = "true";
}
else
useBankString = "false";
writer.write("Run to Bank = " + useBankString + System.getProperty("line.separator"));

String logOffString;
if (logOffFoodOption.isSelected())
{
logOffString = "true";
}
else
logOffString = "false";
writer.write("Log Off = " + logOffString + System.getProperty("line.separator") + System.getProperty("line.separator"));

writer.write("[Loot Tab]" + System.getProperty("line.separator") + System.getProperty("line.separator"));

for(int x = 0; x < usedLoot.size(); x++)
{
writer.write("Items = " + usedLoot.get(x) + System.getProperty("line.separator"));
}

writer.write("[Monster Tab]" + System.getProperty("line.separator") + System.getProperty("line.separator"));

for(int y = 0; y < currentMonstersArrayList.size(); y++)
{
writer.write("Monsters = " + currentMonstersArrayList.get(y) + System.getProperty("line.separator"));
}

writer.write(System.getProperty("line.separator") + "[Misc Tab]"+ System.getProperty("line.separator") + System.getProperty("line.separator"));

String buryBonesString;
if (buryBonesBox.isSelected())
{
buryBonesString = "true";
}
else
buryBonesString = "false";
writer.write("Bury Bones = " + buryBonesString);

String waitTilDeathString;
if (waitUntilDeath.isSelected())
{
waitTilDeathString = "true";
}
else
waitTilDeathString = "false";
writer.write("Loot after death = " + waitTilDeathString);

writer.close();
}

public void readGeneralSave(String str) throws IOException
{
File file = new File("KazFighter/SaveFiles/" + str);
FileReader r = new FileReader(file);
BufferedReader reader = new BufferedReader(r);

String line = null;

while((line = reader.readLine()) != null)
{
int i = line.indexOf("=");
if(line.contains("Tiles Away"))
{
int tiles = Integer.parseInt(line.substring(i+2, line.length()));
tileCount.setValue(new Integer(tiles));
}
if(line.contains("Use Breaks = true"))
{
useBreaks.setSelected(true);
}
if(line.contains("Use Breaks = false"))
{
useBreaks.setSelected(false);
}
if(line.contains("Min Length"))
{
int length = Integer.parseInt(line.substring(i+2, line.length()));
breakBoxMin.setText("" + length);
}
if(line.contains("Max Length"))
{
int length = Integer.parseInt(line.substring(i+2, line.length()));
breakBoxMax.setText("" + length);
}
if(line.contains("Min Interval"))
{
int length = Integer.parseInt(line.substring(i+2, line.length()));
intervalBoxMin.setText("" + length);
}
if(line.contains("Max Interval"))
{
int length = Integer.parseInt(line.substring(i+2, line.length()));
intervalBoxMax.setText("" + length);
}
if(line.contains("Food Type"))
{
String foodItem = String.valueOf(line.substring(i+2, line.length()));
foodType.setText(foodItem);
}
if(line.contains("Food Amount"))
{
int amount = Integer.parseInt(line.substring(i+2, line.length()));
foodCount.setValue(new Integer(amount));
}
if(line.contains("Food Percent"))
{
int percent = Integer.parseInt(line.substring(i+2, line.length()));
healthPercent.setValue(percent);
}
if(line.contains("Use Food = true"))
{
titleOption.setSelected(true);
}
if(line.contains("Use Food = false"))
{
titleOption.setSelected(false);
}
if(line.contains("Run to Bank = true"))
{
bankOption.setSelected(true);
}
if(line.contains("Run to Bank = false"))
{
bankOption.setSelected(false);
}
if(line.contains("Log Off = true"))
{
logOffFoodOption.setSelected(true);
}
if(line.contains("Log Off = false"))
{
logOffFoodOption.setSelected(false);
}
if(line.contains("Items"))
{
String lootItem = String.valueOf(line.substring(i+2, line.length()));
usedItemListModel.addElement(lootItem);
usedLoot.add(lootItem);
}
if(line.contains("Monsters ="))
{
String monster = String.valueOf(line.substring(i+2, line.length()));
currentMonstersModel.addElement(monster);
currentMonstersArrayList.add(monster);
}
if(line.contains("Bury Bones = true"))
{
buryBonesBox.setSelected(true);
}
if(line.contains("BuryBones = false"))
{
buryBonesBox.setSelected(false);
}
if(line.contains("Loot after death = true"))
{
waitUntilDeath.setSelected(true);
}
if(line.contains("Loot after death = false"))
{
waitUntilDeath.setSelected(false);
}
}
}

public void actionPerformed(ActionEvent e) {
Object button = e.getSource();
if(button == profileSelection)
{
try {
readGeneralSave(GeneralProfiles[profileSelection.getSelectedIndex()]);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(button == toButton)
{
moveMonstersTo();
}
if(button == fromButton)
{
moveMonstersFrom();
}
if(button == lootInButton)
{
moveLootTo();
}
if(button == lootOutButton)
{
moveLootFrom();
}
if(button == clearButton)
{
nearbyListModel.clear();
currentMonstersModel.clear();
}
if(button == clearLootButton)
{
ItemsListModel.clear();
usedItemListModel.clear();
}
if(button == monsterRefresh)
{
nearbyListModel.clear();
getNearbyMonsters();
nearbyMonsters = 0;
for(Iterator iterator = nearbyMonstersArray.iterator();iterator.hasNext();)
{
nearbyNPCInfo.add(nearbyMonstersArray.get(nearbyMonsters).getName() + " - ID: " + nearbyMonstersArray.get(nearbyMonsters).getType() + " - Level:" + nearbyMonstersArray.get(nearbyMonsters).getLevel());
nearbyListModel.addElement(nearbyNPCInfo.get(nearbyMonsters));
nearbyMonsters++;
}
nearbyMonsterLabel = new JLabel("Nearby Monsters: " + nearbyMonsters);
}
if(button == startScript)
{
if(!guiIsDone)
{
log("Starting script");
}
else
log("Applying script");
food = foodType.getText();
healthNumber = healthPercent.getValue();
SpinnerModel model = foodCount.getModel();
Integer i = (Integer)model.getValue();
foodAmount = i.intValue();
if (bankOption.isSelected())
{
useBank = true;
}
else
useBank = false;
if (titleOption.isSelected())
{
useFood = true;
}
else
useFood = false;
if (logOffFoodOption.isSelected())
{
logOff = true;
}
else
logOff = false;
SpinnerModel model2 = tileCount.getModel();
Integer d = (Integer)model2.getValue();
tileDistance = d.intValue();
if(useBreaks.isSelected())
breaks = true;
else
breaks= false;
if(buryBonesBox.isSelected())
buryBones = true;
else
buryBones= false;
if(waitUntilDeath.isSelected())
longWait = true;
else
longWait= false;
userString = username.getText();
breakTimeMax = Integer.parseInt(breakBoxMax.getText());
breakTimeMin = Integer.parseInt(breakBoxMin.getText());
intervalMax = Integer.parseInt(intervalBoxMax.getText());
intervalMax = Integer.parseInt(intervalBoxMin.getText());
try {
writeUserName();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
guiIsDone = true;
}
if(button == searchButton)
{
try {
ItemsListModel.clear();
log("Reading file");
ReadLootFile(itemSearch.getText());
for(int i = 0; i < LootItemsList.size(); i++)
{
ItemsListModel.addElement(LootItemsList.get(i));
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if(button == profileButton)
{
try {
saveGeneralTab();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}

public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider)e.getSource();
healthNumber = source.getValue();
}

public void ReadLootFile(String s) throws FileNotFoundException, IOException
{
File LootFile = new File("KazFighter/Data/LootFile.txt");
FileReader reader = new FileReader(LootFile);
BufferedReader in = new BufferedReader(reader);

LootItemsList.clear();
beforeLoot.clear();

String line = null;
while((line = in.readLine()) != null)
{
if(line.toLowerCase().contains(s))
{
LootItemsList.add(line);
beforeLoot.add(line);
}
}
log(beforeLoot.size());
}
}
}

public void updateSignature(String username) throws IOException
{
checkURLFile(username);

log("Updating signature");
BufferedReader reader = new BufferedReader(new InputStreamReader(new URL("http://www.pyritebomb.co.uk/signature/" + username + "time.txt").openStream()));
BufferedReader reader2 = new BufferedReader(new InputStreamReader(new URL("http://www.pyritebomb.co.uk/signature/" + username + "xp.txt").openStream()));
BufferedReader reader3 = new BufferedReader(new InputStreamReader(new URL("http://www.pyritebomb.co.uk/signature/" + username + "kills.txt").openStream()));

String line;
String line2;
String line3;

String str1 = null;
String str2 = null;
String str3 = null;

String time = "";
String xp = "";
String kills = "";

while((line = reader.readLine()) != null)
{
str1 = line;
}
int index = str1.indexOf(":");
int seg1 = Integer.parseInt(str1.substring(0, index));
int seg2 = Integer.parseInt(str1.substring(index+1, index+3));
int seg3 = Integer.parseInt(str1.substring(index+4, str1.length()));
String currentTime = t.timePassedStr();
int index2 = currentTime.indexOf(":");
int seg4 = Integer.parseInt(currentTime.substring(0, index2));
int seg5 = Integer.parseInt(currentTime.substring(index2+1, index2+3));
int seg6 = Integer.parseInt(currentTime.substring(index2+4, currentTime.length()));

//Seconds
String int3 = "0";
if((seg3 + seg6) > 59 && (seg3 + seg6) < 70)
{
seg5++;
int3 = "0" + (seg3 + seg6 - 60);
}
else if((seg3 + seg6) > 70)
{
seg5++;
int3 = "" + (seg3 + seg6 - 60);
}
else if((seg3 + seg6) < 10)
int3 = "0" + (seg3 + seg6);
else
int3 = "" + (seg3 + seg6);

//Minutes
String int2 = "0";
if((seg2 + seg5) > 59 && (seg2 + seg5) < 70)
{
seg4++;
int2 = "0" + (seg2 + seg5 - 60);
}
else if((seg2 + seg5) > 70)
{
seg4++;
int2 = "" + (seg2 + seg5 - 60);
}
else if((seg2 + seg5) < 10)
int2 = "0" + (seg2 + seg5);
else
int2 = "" + (seg2 + seg5);

//Hours
String int1 = "0";
if((seg1 + seg4) < 10)
int1 = "0" + (seg1 + seg4);
else
int1 = "" + (seg1 + seg4);

time = System.getProperty("line.separator") + int1 + ":" + int2 + ":" + int3;

while((line2 = reader2.readLine()) != null)
{
str2 = line2;
}

int i = Integer.parseInt(str2);
xp = System.getProperty("line.separator") + (i + (TotalExp - sigXP));
sigXP = TotalExp;

while((line3 = reader3.readLine()) != null)
{
str3 = line3;
}

int d = Integer.parseInt(str3);
kills = System.getProperty("line.separator") + ((npcKills - sigKills) + d);

sigKills = npcKills;


connectToUrl(username, time, xp, kills);
}

Scaper

2010-04-16 14:06:04

also look at part 1 on here

http://www.rscheata.net/forum/index.php/topic,66851.0.html

Frement

2010-04-16 14:17:31

I can host on my site, but i really dont know anything about java really (or something yes).

If you can get your script to post the data to my site, then i can code the php for you.

To test, this will return everything you post:
http://www.frement.net/srl/scaper/test.php

Scaper

2010-04-16 14:54:45

here you go here is what you need

http://www.rscheata.net/forum/index.php/topic,95063.new.html#new

Frement

2010-04-16 14:58:39

From: Scaper
here you go here is what you need

http://www.rscheata.net/forum/index.php/topic,95063.new.html#new


I dont have account on there :/

EDIT: I tried to make the java code, here:
public void UpdateStats(String str_value, String str_value_2, String str_value_3) {
String data = URLEncoder.encode(varname, "UTF-8") + "=" + URLEncoder.encode(str_value, "UTF-8");
data += "&" + URLEncoder.encode(varname_2, "UTF-8") + "=" + URLEncoder.encode(str_value_2, "UTF-8");
data += "&" + URLEncoder.encode(varname_3, "UTF-8") + "=" + URLEncoder.encode(str_value_3, "UTF-8");
data += "&" + URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode("SCAPER123", "UTF-8");
URL url = new URL("http://www.frement.net/srl/scaper/update_stats.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes(data);
wr.flush();
wr.close();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
if(!line.contains("Failed")) {
log("Successful");
} else {
log("Failed");
}
}
rd.close();
} catch (Exception e) {
log("PHP Communication Failed");
}
}

str_value = Time running
str_value_2 = What was the second you wanted?
str_value_3 = What was the third you wanted?

The image you uploaded doesnt work anymore, its not a valid url.

Scaper

2010-04-16 15:02:35


First you need a mySql database with the structure shown below.
Make a php script which you execute using java.

Replace: IP OR localhost, USERNAME, PASSWORD, DATABASE, TABLE, 666666

Fields are named:

upload.php

<?php
mysql_connect("IP OR localhost", "USERNAME", "PASSWORD") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("DATABASE") or die(mysql_error());
echo "Connected to Database<br />";

if(intval($_GET['key'])==666666){
$user = trim($_GET['user']);
$result = mysql_query("SELECT * FROM TABLE
WHERE user='$user'") or die(mysql_error());
if(mysql_num_rows($result)){
echo "User exists.";
$row = mysql_fetch_array( $result );
$timer = doubleVal($row['timeran']);
$experience = doubleVal($row['experience']);
$loot = doubleVal($row['loot']);
$kills = doubleVal($row['kills']);

$version = '1.0';
$seconds = intval($timer)+intval($_GET['seconds']);
$experience = intval($experience)+intval($_GET['experience']);
$loot = intval($loot)+intval($_GET['loot']);
$kills = intval($kills)+intval($_GET['kills']);

$result = mysql_query("UPDATE TABLE SET fversion='$version' WHERE user='$user'")
or die(mysql_error());
$result = mysql_query("UPDATE TABLE SET timeran=$seconds WHERE user='$user'")
or die(mysql_error());
$result = mysql_query("UPDATE TABLE SET experience=$experience WHERE user='$user'")
or die(mysql_error());
$result = mysql_query("UPDATE TABLE SET loot=$loot WHERE user='$user'")
or die(mysql_error());
$result = mysql_query("UPDATE TABLE SET kills=$kills WHERE user='$user'")
or die(mysql_error());
} else {
echo "User doesnt exist, creating new row.</br>";
$version = floatval($_GET['fversion']);
$seconds = doubleVal($_GET['seconds']);
$experience = doubleVal($_GET['experience']);
$loot = doubleVal($_GET['loot']);
$kills = doubleVal($_GET['kills']);
echo "Sending query.</br>";
mysql_query("INSERT INTO TABLE
(fversion, timeran, experience, loot, kills, user) VALUES ('$version', $seconds, $experience, $loot, $kills, '$user')")
or die(mysql_error());
}
} else echo "Invalid query, try again later.";
?>

Then you call it in java:

String upload_folder = "http://exampleadress.com/"

public Signature upload(Signature sign, long seconds, long experience,
long loot, long kills) {
long u_seconds = seconds - sign.seconds;
long u_experience = experience - sign.experience;
long u_loot = loot - sign.loot;
long u_kills = kills - sign.kills;

try {
flog("Uploading statistics to [" + "upload.php] @ " + time);
URL url = new URL(upload_folder + "upload.php?user="
+ sign.user + "&seconds=" + u_seconds + "&experience="
+ u_experience + "&loot=" + u_loot + "&kills="
+ u_kills + "&key=" + 666666);
URLConnection con = url.openConnection();
con.getContent();
return new Signature(sign.user, sign.version, seconds,
experience, loot, kills);
} catch (Exception e) {
e.printStackTrace();
}
return sign;
}

there thats what i just got need anything else

Frement

2010-04-16 15:05:36

From: Scaper
there thats what i just got need anything else


Could you check if the code i edited in my last post compiles? If it does we can test it soon.

EDIT: I added you on MSN also.

Scaper

2010-04-16 15:09:59

ok ill test now

str_value = Time running
str_value_2 = Natures Made
str_value_3 = Xp Gained

remeber there is my png

http://scaper.php0h.com/sig/picture.png

Frement

2010-04-16 15:12:42

From: Scaper
ok ill test now

str_value = Time running
str_value_2 = Natures Made
str_value_3 = Xp Gained

remeber there is my png

http://scaper.php0h.com/sig/picture.png


Ok, ill be back in 10mins.

Scaper

2010-04-16 15:18:05

he has added more info


First you need a mySql database with the structure shown below.
Make a php script which you execute using java.

Replace: IP OR localhost, USERNAME, PASSWORD, DATABASE, TABLE, 666666

Fields are named:

upload.php

<?php
mysql_connect("IP OR localhost", "USERNAME", "PASSWORD") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("DATABASE") or die(mysql_error());
echo "Connected to Database<br />";

if(intval($_GET['key'])==666666){
$user = trim($_GET['user']);
$result = mysql_query("SELECT * FROM TABLE
WHERE user='$user'") or die(mysql_error());
if(mysql_num_rows($result)){
echo "User exists.";
$row = mysql_fetch_array( $result );
$timer = doubleVal($row['timeran']);
$experience = doubleVal($row['experience']);
$loot = doubleVal($row['loot']);
$kills = doubleVal($row['kills']);

$version = '1.0';
$seconds = intval($timer)+intval($_GET['seconds']);
$experience = intval($experience)+intval($_GET['experience']);
$loot = intval($loot)+intval($_GET['loot']);
$kills = intval($kills)+intval($_GET['kills']);

$result = mysql_query("UPDATE TABLE SET fversion='$version' WHERE user='$user'")
or die(mysql_error());
$result = mysql_query("UPDATE TABLE SET timeran=$seconds WHERE user='$user'")
or die(mysql_error());
$result = mysql_query("UPDATE TABLE SET experience=$experience WHERE user='$user'")
or die(mysql_error());
$result = mysql_query("UPDATE TABLE SET loot=$loot WHERE user='$user'")
or die(mysql_error());
$result = mysql_query("UPDATE TABLE SET kills=$kills WHERE user='$user'")
or die(mysql_error());
} else {
echo "User doesnt exist, creating new row.</br>";
$version = floatval($_GET['fversion']);
$seconds = doubleVal($_GET['seconds']);
$experience = doubleVal($_GET['experience']);
$loot = doubleVal($_GET['loot']);
$kills = doubleVal($_GET['kills']);
echo "Sending query.</br>";
mysql_query("INSERT INTO TABLE
(fversion, timeran, experience, loot, kills, user) VALUES ('$version', $seconds, $experience, $loot, $kills, '$user')")
or die(mysql_error());
}
} else echo "Invalid query, try again later.";
?>
Then you call it in java:

I instance the class capitalized as I use it as a static class (before I knew why)

Signature Signature = new Signature();
String upload_folder = "http://exampleadress.com/"

public class Signature {
public String user;
public double version;
public long seconds;
public long experience;
public long loot;
public long kills;

public Signature(String user, double version, long seconds,
long experience, long loot, long kills) {
this.user = user;
this.version = version;
this.seconds = seconds;
this.experience = experience;
this.loot = loot;
this.kills = kills;
}

public Signature upload(Signature sign, long seconds, long experience,
long loot, long kills) {
long u_seconds = seconds - sign.seconds;
long u_experience = experience - sign.experience;
long u_loot = loot - sign.loot;
long u_kills = kills - sign.kills;

try {
flog("Uploading statistics to [" + "upload.php] @ " + time);
URL url = new URL(upload_folder + "upload.php?user="
+ sign.user + "&seconds=" + u_seconds + "&experience="
+ u_experience + "&loot=" + u_loot + "&kills="
+ u_kills + "&key=" + 666666);
URLConnection con = url.openConnection();
con.getContent();
return new Signature(sign.user, sign.version, seconds,
experience, loot, kills);
} catch (Exception e) {
e.printStackTrace();
}
return sign;
}
}


To actually upload, you also need to make a thread which will keep track of how much experience we've uploaded, and to make it time based.


Timer upload = new Timer(60000 * 5); // 5 minute timer, increase?
SignatureUploader su = new SignatureUploader();

// In script initialization (ie right before entering main loop)
su.start();
Signature = new Signature(username, version, (long) timeran.timePassed() / 1000, 0, 0, 0);
upload = new Timer(60000 * 5);
The thread will, when time is up, upload the difference between the last uploaded data, then replace our last uploaded data with the new.

public class SignatureUploader extends Thread {
public void run() {
while(getHandler().isScriptRunning()) {
try {
if (upload.isUp()) {
Signature = Signature
.upload(
Signature,
(long) timeran.timePassed() / 1000,
(experience.getTotalExperience() - start_experience
.getTotalExperience()),
looted, kills);
upload.reset();
}
} catch (Throwable t) {
}
sleep(100);
}
}
}

Frement

2010-04-16 15:19:55

From: Scaper
he has added more info


I really dont understand java that well, the code i pasted, did you test it? Did it compile?

Scaper

2010-04-16 15:26:31

ok yea that works fine i added it into my script in eclipse and no errors aprt from here

String data = URLEncoder.encode([B]varname[/B], "UTF-8") + "=" + URLEncoder.encode(str_value, "UTF-8");
data += "&" + URLEncoder.encode([B]varname_2[/B], "UTF-8") + "=" + URLEncoder.encode(str_value_2, "UTF-8");
data += "&" + URLEncoder.encode([B]varname_3[/B], "UTF-8") + "=" + URLEncoder.encode(str_value_3, "UTF-8");
data += "&" + URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode("SCAPER123", "UTF-8");

what should i do there add to my ins

varname = null;?

Frement

2010-04-16 15:28:10

From: Scaper
ok yea that works fine i added it into my script in eclipse and no errors aprt from here

String data = URLEncoder.encode([B]varname[/B], "UTF-8") + "=" + URLEncoder.encode(str_value, "UTF-8");
data += "&" + URLEncoder.encode([B]varname_2[/B], "UTF-8") + "=" + URLEncoder.encode(str_value_2, "UTF-8");
data += "&" + URLEncoder.encode([B]varname_3[/B], "UTF-8") + "=" + URLEncoder.encode(str_value_3, "UTF-8");
data += "&" + URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode("SCAPER123", "UTF-8");

what should i do there add to my ins

varname = null;?


What errors did you exactly get?

Scaper

2010-04-16 15:31:18

no errors just i havent declared the variables

varname
varname_2
varname_3

should i declare them as

String varname;
String vrname_2 etc?

ZaSz

2010-04-16 15:43:06

Pretty sure declare as String.

And lets say you want to post xp=12;

Set the first Varname to xp

(varname = "xp";)

and make String str_value = ""+12;

Scaper

2010-04-16 15:49:05

ok got ths now

public void UpdateStats(String str_value, String str_value_2, String str_value_3) {
try {
String data = URLEncoder.encode(TimeRunning, "UTF-8") + "=" + URLEncoder.encode(str_value, "UTF-8");
data += "&" + URLEncoder.encode(NatsMade, "UTF-8") + "=" + URLEncoder.encode(str_value_2, "UTF-8");
final String xpGained;
data += "&" + URLEncoder.encode(xpGained, "UTF-8") + "=" + URLEncoder.encode(str_value_3, "UTF-8");
data += "&" + URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode("SCAPER123", "UTF-8");
URL url = new URL("http://www.frement.net/srl/scaper/update_stats.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes(data);
wr.flush();
wr.close();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
if(!line.contains("Failed")) {
log("Successful");
} else {
log("Failed");
}
}
rd.close();
} catch (Exception e) {
log("PHP Communication Failed");
}
}

Frement

2010-04-16 16:06:00

From: Scaper
ok got ths now

public void UpdateStats(String str_value, String str_value_2, String str_value_3) {
try {
String data = URLEncoder.encode(TimeRunning, "UTF-8") + "=" + URLEncoder.encode(str_value, "UTF-8");
data += "&" + URLEncoder.encode(NatsMade, "UTF-8") + "=" + URLEncoder.encode(str_value_2, "UTF-8");
final String xpGained;
data += "&" + URLEncoder.encode(xpGained, "UTF-8") + "=" + URLEncoder.encode(str_value_3, "UTF-8");
data += "&" + URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode("SCAPER123", "UTF-8");
URL url = new URL("http://www.frement.net/srl/scaper/update_stats.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes(data);
wr.flush();
wr.close();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
if(!line.contains("Failed")) {
log("Successful");
} else {
log("Failed");
}
}
rd.close();
} catch (Exception e) {
log("PHP Communication Failed");
}
}


You cant have it like that, you must have them like varname varname_2 varname_3 because my PHP reads those.

How about this:
public void UpdateStats(String str_value, String str_value_2, String str_value_3) {
try {
String data = URLEncoder.encode("varname", "UTF-8") + "=" + URLEncoder.encode(str_value, "UTF-8");
data += "&" + URLEncoder.encode("varname_2", "UTF-8") + "=" + URLEncoder.encode(str_value_2, "UTF-8");
final String xpGained;
data += "&" + URLEncoder.encode("varname_3", "UTF-8") + "=" + URLEncoder.encode(str_value_3, "UTF-8");
data += "&" + URLEncoder.encode("key", "UTF-8") + "=" + URLEncoder.encode("SCAPER123", "UTF-8");
URL url = new URL("http://www.frement.net/srl/scaper/update_stats.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes(data);
wr.flush();
wr.close();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
if(!line.contains("Failed")) {
log("Successful");
} else {
log("Failed");
}
}
rd.close();
} catch (Exception e) {
log("PHP Communication Failed");
}
}

Usage like:
UpdateStats(TimeRunning, NatsMade, xpGained);

Scaper

2010-04-16 16:24:54

yea no errors with that

Frement

2010-04-16 16:38:53

From: Scaper
yea no errors with that


Ok, try updating the stats now. Oh and the time running, insert seconds to that.

Scaper

2010-04-17 15:53:24

ok iv run the script and nothjing seems to of updated

Frement

2010-04-17 15:58:47

From: Scaper
ok iv run the script and nothjing seems to of updated


Add me on msn, alot faster in there.

Scaper

2010-04-17 16:02:42

i cant use msn on this comp it laggs it out to detah and i end up crashing :/

Frement

2010-04-17 16:16:45

From: Scaper
i cant use msn on this comp it laggs it out to detah and i end up crashing :/


Well, does it say "Success" or "Failed"? The java part.

I shall make some debugs to the PHP part in a min, i have a LoL match atm.

EDIT: Ok, you may test it now.

EDIT2: It would help if you could give me some java app that i can use to update the stats.