<?php
	$ok = true;
	require("./spravca.php");
	mysql_con();

	$datum = date("d-m-Y H:i:s", time());
	$fo = fopen("./cron.log", "a+");
	fwrite($fo, "[ $datum ]");

	$query = mysql_query("SELECT * FROM games");

	/* ===== Kontrola scriptfiles pre SAMP ===== */
	while($lnk = mysql_fetch_array($query))
	{
		$pocet = 0;
		$port = $lnk["port"];
		if($port == "0") continue;	
		if(is_dir("./SAMP/svrs/$port/scriptfiles"))
		{
			$dirr = opendir("./SAMP/svrs/$port/scriptfiles");	
			while($dir = readdir($dirr)) $pocet++;
		}
		if($pocet >= 1002)
		{
			mysql_query("UPDATE games SET `lock` = '3' WHERE port = '$port'");
			exec("pkill samp03svr$port");
		}

		if($pocet >= 1002) fwrite($fo, "\n $port | $pocet | BANNED!!!!!!!!");
		else fwrite($fo, "\n $port | $pocet");

		if(is_dir("./SAMP/svrs/$port"))
		{
			if(echo("pidof samp03svr$port")) continue;
			if(file_exists("./SAMP/svrs/$port/automat.wtf")) exec("cd SAMP/svrs/$port/; ./samp03svr$port > /dev/null &");
		}
	}
	fwrite($fo, "\n");
	fclose($fo);

?>
		
