Php Scripts
These are a collection of Php scripts.
/ShowPlayers: this script will display online players in the server's status page.
/VaultManager: A web interface to the Vault.
NOTE: it would be cool if we could build a common library used by all scripts, to avoid duplicating basic functions.
--- Submitted by - KhouFou
Added by Gav (Meeting Place)
This script will produce a .csv file showing who, how long and when! (Run it to see what I mean). The code will need editing to fit your setup. See the comments in file.
<?php
// NOTE: You may need to change the path in the shebang in line 1 above.
// NOTE: You will need to edit the four lines below.
$user=""; //Enter the MySQL user name that plasma uses here.
$host=""; //Enter the hostname of the MySQL server here (often localhost).
$password=""; //Enter the password for the aforementioned user account here.
define ("VAULT", "vaultdb_test"); //Enter the vault database name here.
// Begin functions taken from highvaultage.inc by Gav (a work in progress)
function getdata($database,$query)
{
mysql_select_db($database);
$query = stripSlashes($query);
$result = mysql_query($query);
if ($result==0) exit("<b>Error in functions.inc (".mysql_errno()."): ".mysql_error()."</b>");
return $result;
}
function durationphp ($seconds, $suffix=FALSE) // This function by moritz at barafranca dot com, taken from uk.php.net/time
{
$takes_time = array(604800,86400,3600,60,0);
$suffixes = array("Week","Day","Hour","Minute","Second");
$delimeter = array(" W ", " D ", ":",":","");
$output = "";
foreach ($takes_time as $key=>$val)
{
${$suffixes[$key]} = ($val == 0) ? $seconds : floor(($seconds/$val));
$seconds -= ${$suffixes[$key]} * $val;
if (${$suffixes[$key]} > 0 || (!empty($output) && $suffix == FALSE))
{
if ($val == 0 && $suffix == FALSE && empty($output))
{
$output .= "00:";
}
$output .= ($key > 1 && strlen(${$suffixes[$key]}) == 1 && $suffix == FALSE) ? "0".${$suffixes[$key]} : ${$suffixes[$key]};
if ($suffix == "short")
{
$output .= substr($suffixes[$key],0,1)." ";
}
elseif ($suffix == "long")
{
$output .= (${$suffixes[$key]} > 1) ? " ".$suffixes[$key]."s " : " ".$suffixes[$key]." ";
}
else
{
$output .= $delimeter[$key];
}
}
}
return $output;
}
function dttm2unixtime($dttm2timestamp_in) // This function also from the uk.php.net
{
$date_time = explode(" ", $dttm2timestamp_in);
$date = explode("-",$date_time[0]);
$time = explode(":",$date_time[1]);
unset($date_time);
list($year, $month, $day)=$date;
list($hour,$minute,$second)=$time;
return mktime(intval($hour), intval($minute), intval($second), intval($month), intval($day), intval($year));
}
// End of functions taken from highvaultage.inc by Gav (a work in progress)
//Program mainline: Produces a CSV separated output. Execute it from a shell on your server and redirect it's output to a file.
//Example: ./guids.php > stuff.csv
mysql_connect($host,$user,$password);
$guids = getdata(VAULT, 'Select IString64_2, Idx, UInt32_2 from Nodes where NodeType=2 order by IString64_2');
if (@mysql_num_rows($guids)!=0)
{
$numberofavatars=mysql_num_rows($guids);
for ($i=0;$i < mysql_num_rows($guids);$i++)
{
$row = mysql_fetch_row($guids);
$plrtime[$i]=$row[2];
$plrnode[$i]=$row[1];
$plrguid[$i]=$row[0];
}
for ($i=0;$i < $numberofavatars; $i++)
{
$refs = getdata(VAULT, 'select ChildIdx from NodeRefs where ParentIdx='.$plrnode[$i].' and ParentIdx!=SaverIdx order by ChildIdx limit 1');
$row = mysql_fetch_row($refs);
$infnode[$i]=$row[0];
}
echo "Count, GUID, Player NODE#, Player INFO NODE#, Avatar Name, Day, Date, Time, Time Online (seconds), Time Online (human readable)\n";
for ($i=0;$i < $numberofavatars;$i++)
{
$avatar = getdata(VAULT, 'select IString64_1, UNIX_TIMESTAMP(AutoTime) from Nodes where Idx='.$infnode[$i]);
$row = mysql_fetch_row($avatar);
echo $i.",".
$plrguid[$i].",".
$plrnode[$i].",".
$infnode[$i].",".
$row[0].",".
gmstrftime ("%A,%d-%b-%y,%T",$row[1]).",".
$plrtime[$i].",".
durationphp($plrtime[$i],'long')."\n";
}
}
else echo "***BOOOM*** It's all gone pear shaped.\n";
?>Ignore the word wrapping - select it all and copy it, and paste it into your editor of choice. Should be OK.