- Joined
- Sep 3, 2011
- Messages
- 150
- Reaction score
- 94
Its just script to calculate kills and save to MySQL.
Table structure:
table name: kills
PHP file which saves to MySQL:
saver.php
Sh file which reads logs:
rank.sh
eg for crontab:
If u set if right, ull get all kills saved in database.
It also remembers last kill date so it works even if you remove old log files.
Table structure:
table name: kills
Code:
CREATE TABLE IF NOT EXISTS `kills` (
`time` int(11) NOT NULL,
`corpseid` int(22) NOT NULL,
`killerid` int(22) NOT NULL,
`type` tinyint(4) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
PHP file which saves to MySQL:
saver.php
Code:
<?php
mysql_connect("localhost","user","pass"); //to change
mysql_select_db("db"); //to change
$tmp=mysql_query("SELECT `time` FROM `kills` ORDER BY `time` DESC LIMIT 1");
$last_time=mysql_fetch_row($tmp);
$file = file("/home/rain/logs/kills.formatlog"); //logs folder
foreach($file as $f){
$a = strpos($f, "die:roleid")+11;
$time=substr($f,0,19);
$time=explode(' ',$time);
$tim1=explode('-',$time[0]);
$tim2=explode(':',$time[1]);
$tim=mktime($tim2[0], $tim2[1], $tim2[2], $tim1[1], $tim1[2], $tim1[0]);
$data=substr($f,$a);
$data=str_replace('type=','',$data);
$data=str_replace('attacker=','',$data);
$data=explode(':',$data);
if($data[1]==2) $data[2]=0;
if($tim>$last_time[0]) mysql_query("INSERT INTO `kills` (`time`, `corpseid`,`killerid`,`type`) VALUES ('$tim', '$data[0]','$data[2]','$data[1]')");
}
?>
Sh file which reads logs:
rank.sh
Code:
#!/bin/sh
cd /home/rain/logs
grep -e ':die:' world2.formatlog > kills.formatlog
chmod 777 kills.formatlog
/opt/lampp/bin/php -f /root/saver.php >> ranklogfile.txt 2>&1
rm kills.formatlog
eg for crontab:
Code:
0 * * * * root /auto60/rank.sh
If u set if right, ull get all kills saved in database.
It also remembers last kill date so it works even if you remove old log files.