[Release] PHP Script for bot pickups

01/20/2009 00:13 kodosai#1
***NOTE*** This is a PHP script, it will only work if you run it on a webserver with PHP enabled.

***DISCLAIMER***
If you don't know what PHP is, or a webserver, this tool is not for you.


**Edited 1/20/09**
Fixed an ordering issue on parsing so that equipment with the word "Gold" in it would not appear in the gold section.

Took "Elixirs" out of the items.txt file so they would no longer show up under equipment.
Links and source updated.
On to the meat:

The tool basically allows you to select your console logs from AGBot and view the parsed out files to show what and how many of each your bot has picked up during that bot session.

There is no javascript, there is no pretty. All it does is work.

The script will attempt to create 1 (one) file: "pickups.ini" in the same directory as itself to retain the path to the log files only.

Here's the link (which contains the script and an items.txt file:
[Only registered and activated users can see links. Click Here To Register...]

Just in case you're bored or whatever and somehow think PHP is going to "ZOMG ITS A TROJANZ IT HAXx0R3D MY COMPUTARZz!!!1111ONE!!ELEVEN!!"
Here's the source for the script itself:

Code:
<title>Pickups</title>
<title>Pickups</title>
<?php
/*
Created By: IGotArrows 
On: 1/19/08
Version: 1.0
Credits: The Rev6 AGBot Team for the original raw data file for the items list which the item names were parsed out of for the equipment portion of this script.
*/
if($_GET[submit] == 'Save' && $_GET[dir] <> ''){ #checking for valid form and non-empty
	$fp = fopen('pickups.ini','w');
	fwrite($fp,$_GET[dir]);	
	fclose($fp);
}
if(file_exists('pickups.ini') !== true){ # Checking for ini
	echo '<form method=get action=pickups.php>';
	echo '<b>Type in the complete path to the folder of your console logs.</b><p>';
	echo '<input type=text name=dir><br>';
	echo '<input type=submit name=submit value=Save>';
	echo '</form>';
	die;
}
$fini = file('pickups.ini'); # Read ini for location of logs.
$dir = $fini[0];
# $dir = 'c:\documents and settings\owner\desktop\silkroad\agbot';
$dirhandle = opendir($dir) or die('Unable to open directory.');
echo '<form method=get action=pickups.php>';
echo '<select name=log><option value="">Select File</a>';
while (false !== ($file = readdir($dirhandle))) { # Reading list of log files.
	if (strpos($file, 'LogConsol') !== false){
		# echo "<a href=\"chat.php?log=$dir\\$file\">" . $file . "</a><br>";
		echo "<option value=\"$dir\\$file\">$file</option>";
	}	
}
echo '</select>';
echo '<input type=submit name=submit value="View Log">';
echo '</form>';
?>
<?php
# Generating item hash.
$file = $_GET[log];
$raw = file($file) or die('Unable to open file.');
$itemdata = file('items.txt');
foreach($itemdata as $val){
	$items[trim($val)] = 1;
}
# Separate each "pickup" in to its own category.
foreach($raw as $val){
	if(strpos($val,'Pick up Item :') !== false){
	 	$temp = explode(': ',$val);
	 	$val = trim($temp[2]);
	 	if(array_key_exists(trim($val),$items)){
				$myitems[] = $val;
		}
	 	elseif(preg_match("/Gold /",$val)){
			$gold[] = $val;
		}
		elseif(preg_match("/HP Recovery /",$val)){
			$pots[] = $val;
		}
		elseif(preg_match("/Intensifing Elixir/",$val)){
			$elixers[] = $val;
		}
		elseif(preg_match("/Jade tablet of /",$val)){
			$tabs[] = $val;
		}
		elseif(preg_match("/MP Recovery /",$val)){
			$pots[] = $val;
		}
		elseif(preg_match("/Ruby tablet of /",$val)){
			$tabs[] = $val;
		}
		elseif(preg_match("/Vigor Recovery /",$val)){
			$pots[] = $val;
		}
		elseif(preg_match("/Universal Pill /",$val)){
			$pots[] = $val;
		}
		else{
			$misc[] = $val;
		}
		$full[] = $val;
	}
}
# Sorting and creating hash tables for categories. 
natcasesort($gold);
natcasesort($pots);
natcasesort($elixers);
natcasesort($tabs);
natcasesort($misc);
natcasesort($myitems);
$uniquegold = array_unique($gold);
$uniquepots = array_unique($pots);
$uniqueelixers = array_unique($elixers);
$uniquetabs = array_unique($tabs);
$uniquemyitems = array_unique($myitems);
$uniquemisc = array_unique($misc);
/* OUTPUT FUNCTIONS BELOW THIS */
# GOLD
$tdcount = 0;
foreach($gold as $val){
	$uniquegold[$val] = ++$uniquegold[$val];
}
echo '<table  width=100% border=1><tr><caption>Gold</caption></tr><tr>';
foreach($uniquegold as $key => $val){
 	if (is_numeric($key) === false){
 	 	if($tdcount < 3){
			echo "<td><b>$key: </b>$val</td>";
			++$tdcount;
		}
		else{
			echo "</tr><tr><td><b>$key: </b>$val</td>";
			$tdcount = 1;
		}
	}
}
echo '</tr></table><p>';
# EQUIPMENT
$tdcount = 0;
foreach($myitems as $val){
	$uniquemyitems[$val] = ++$uniquemyitems[$val];
}
echo '<table  width=100% border=1><tr><caption>Equipment</caption></tr><tr>';
foreach($uniquemyitems as $key => $val){
 	if (is_numeric($key) === false){
 	 	if($tdcount < 3){
			echo "<td><b>$key: </b>$val</td>";
			++$tdcount;
		}
		else{
			echo "</tr><tr><td><b>$key: </b>$val</td>";
			$tdcount = 1;
		}
	}
}
echo '</tr></table><p>';
# POTS
$tdcount = 0;
foreach($pots as $val){
	$uniquepots[$val] = ++$uniquepots[$val];
}
echo '<table width=100% border=1><tr><caption>Pots</caption></tr><tr>';
foreach($uniquepots as $key => $val){
 	if (is_numeric($key) === false){
 	 	if($tdcount < 3){
			echo "<td><b>$key: </b>$val</td>";
			++$tdcount;
		}
		else{
			echo "</tr><tr><td><b>$key: </b>$val</td>";
			$tdcount = 1;
		}
	}
}
echo '</tr></table><p>';
# Elixers
$tdcount = 0;
foreach($elixers as $val){
	$uniqueelixers[$val] = ++$uniqueelixers[$val];
}
echo '<table width=100% border=1><tr><caption>Elixers</caption></tr><tr>';
foreach($uniqueelixers as $key => $val){
 	if (is_numeric($key) === false){
 	 	if($tdcount < 3){
			echo "<td><b>$key: </b>$val</td>";
			++$tdcount;
		}
		else{
			echo "</tr><tr><td><b>$key: </b>$val</td>";
			$tdcount = 1;
		}
	}
}
echo '</tr></table><p>';
# TABS
$tdcount = 0;
foreach($tabs as $val){
	$uniquetabs[$val] = ++$uniquetabs[$val];
}
echo '<table width=100% border=1><tr><caption>Tabs</caption></tr><tr>';
foreach($uniquetabs as $key => $val){
 	if (is_numeric($key) === false){
 	 	if($tdcount < 3){
			echo "<td><b>$key: </b>$val</td>";
			++$tdcount;
		}
		else{
			echo "</tr><tr><td><b>$key: </b>$val</td>";
			$tdcount = 1;
		}
	}
}
echo '</tr></table><p>';
# MISC
$tdcount = 0;
foreach($misc as $val){
	$uniquemisc[$val] = ++$uniquemisc[$val];
}
echo '<table width=100% border=1><tr><caption>Ingredients/Items</caption></tr><tr>';
foreach($uniquemisc as $key => $val){
 	if (is_numeric($key) === false){
 	 	if($tdcount < 3){
			echo "<td><b>$key: </b>$val</td>";
			++$tdcount;
		}
		else{
			echo "</tr><tr><td><b>$key: </b>$val</td>";
			$tdcount = 1;
		}
	}
}
echo '</tr></table><p>';
?>
01/20/2009 11:36 necro_3#2
Thnx but this tool isn't for me :((

i don't know php :handsdown:
01/20/2009 14:16 maxbot#3
You could atleast add some CSS style to the tables ;p
01/20/2009 15:29 wopa#4
damn I would like to see something like this for sbot when it's clientless
01/20/2009 17:09 kodosai#5
Quote:
You could atleast add some CSS style to the tables ;p
I provide the scripting, if someone wants "pretty", they're more than welcome to make it the way they want it to look. I only care about the data honestly. If I wanted a pretty internet, I'd use AOL and be a friendwhxre on myspace.

Quote:
Originally Posted by wopa View Post
damn I would like to see something like this for sbot when it's clientless
If it has logfiles, pm me a link to the logfiles that you want parsed and I'll see what I can whip up for you.
01/20/2009 17:14 theoneofgod#6
Quote:
Originally Posted by kodosai View Post
If it has logfiles, pm me a link and I'll see what I can whip up for you.
there are no logs....
01/20/2009 17:30 kodosai#7
Quote:
Originally Posted by theoneofgod View Post
there are no logs....
A program with no logging? WTH? I somewhere remember reading that sbot has output at some point because it switches from verbose to minimal output depending on whether it's clientless or not. Perhaps the data is not as detailed as AG's though, still I would like to see it at least match up (maybe not logging every attack string as that would be good usually only for debugging. S'why I like free and opensource stuff, typically they *want* you to know what's going on, as opposed to commercially available products.
01/21/2009 11:17 dj30324#8
well i ran this on my site as well [Only registered and activated users can see links. Click Here To Register...] . and now what it asked me to type the console maybe u could tell me or show us demonstration on what server are u running it on.

btw what ami suppose to put ont he pickups.ini on the webserver.
01/23/2009 21:39 kodosai#9
Quote:
Originally Posted by dj30324 View Post
well i ran this on my site as well [Only registered and activated users can see links. Click Here To Register...] . and now what it asked me to type the console maybe u could tell me or show us demonstration on what server are u running it on.

btw what ami suppose to put ont he pickups.ini on the webserver.
The pickups.ini is automatically created if it's not there. You chose not to read what the script asked of you when you first ran it.

It specifically states: "Type in the complete path to the folder of your console logs." You chose to enter "agbot" as the full path, which is not correct.

Your full path is always going to start with a drive letter, and go from there.

For example: Say I put a folder called agbot in my silkroad folder (default install), then the full path to the log files would be c:\Program Files\Silkroad\agbot
01/24/2009 13:14 SpInKsTaR#10
There is logging in Sbot but it does not get output to a file
It wouldnt be hard to grab that data and output it with an external app tho

[Only registered and activated users can see links. Click Here To Register...]