3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php #if ($_SESSION['uid'] == null) header("Location: index.php"); ###!/usr/bin/php #echo mysql_error(); error_reporting(E_ALL); // демон, запускающий волны $names = array("Слуга хаоса","Котельщик","Зомби-Надсмотрщик","Адский палач", "Бродячий Труп", "Демон Хаоса", "Проклятье Хаоса", "Предводитель Хаоса"); $bots = array(22,23,26,87,90,20759,11154); $shema = array ( "22" => 2, "23" => 1, "26" => 1, "87" => 1, "90" => 1, "20759" => 1, "11154" => 1 ); // подключаем конфиг include ('/var/www/localhost/htdocs/connect.php'); // подключаем функции include ('/var/www/localhost/htdocs/functions.php'); // циклим демона while(1) { // итерация // есть ли конект с базой $test = mysql_fetch_array(mysql_query("SELECT 1;")); if($test[1]!=1) { include ('/var/www/localhost/htdocs/connect.php'); } // выбираем все походы $pohs = mysql_query("SELECT `owner`,`volna`, `id`, `win` FROM `hellround_pohod` WHERE `end` = 0;"); while ($poh = mysql_fetch_array($pohs)) { // проверяем на живность $u = mysql_fetch_array(mysql_query("SELECT `hp`, `win`, `battle`, `maxhp` FROM `users` WHERE `id` = '".$poh['owner']."' LIMIT 1;")); if($u['hp'] <= 0) { // удаляем ресурсы mysql_query("DELETE FROM `inventory` WHERE `owner` = '".$poh['owner']."' AND `bs` = 1;"); ##mysql_query("UPDATE `hellround_pohod` SET `end` = 1, `date_out` = NOW( ) WHERE `id` = ".$poh['id']." AND `end` = 0;"); addchp ('<font color=red>Внимание!</font> Вы потерпели поражение в борьбе с Хаосом...<BR>\'; top.frames[\'main\'].location=\'main.php\'; var z = \' ','{[]}'.nick7 ($poh['owner']).'{[]}'); ##echo "USER: ".$poh['owner']." live trip.\n"; } else { // забираем последний бой, может пора запускать волну? Проверяем что победа одержена win = 3 #$last_a = mysql_fetch_array(mysql_query("SELECT `id` FROM `battle` WHERE `t1` = '".$poh['owner']."' AND `win` = 3 ORDER by `id` DESC LIMIT 1;")); #$last_b = mysql_fetch_array(mysql_query("SELECT `to1` FROM `battle` WHERE `t1` = '".$poh['owner']."' AND `win` <> 3 ORDER by `id` DESC LIMIT 1;")); // забираем последний бой, может пора запускать волну? Все равно, пробедили или нет... $last_a = mysql_fetch_array(mysql_query("SELECT `id` FROM `battle` WHERE `t1` = '".$poh['owner']."' ORDER by `id` DESC LIMIT 1;")); $last_b = mysql_fetch_array(mysql_query("SELECT `to1` FROM `battle` WHERE `t1` = '".$poh['owner']."' ORDER by `id` DESC LIMIT 1;")); $last_b = $last_b[0]; $last_a = $last_a[0]; // echo $last_a." ".$last_b." ".$poh['owner']."\n"; // проверяем, запускаем ботов if ((time()-$last_b) >= 10 && $last_a == 0) { if ((time()-$last_b) >= 30 && $u['battle']==0 && $u['hp'] > $u['maxhp']/2) { // если прошло больше минуты, стартуем волну $nextvolna = $poh['volna']+1; $bot[1] = $shema[$bots[0]]*$nextvolna; $bot[2] = $shema[$bots[1]]*$nextvolna; $bot[3] = $shema[$bots[2]]*$nextvolna; if ($nextvolna >= 10) { $bot[4] = $shema[$bots[3]]*$nextvolna; $bot[5] = $shema[$bots[4]]*$nextvolna; $bot[6] = $shema[$bots[5]]*$nextvolna; } if ($nextvolna >= 25) { $bot[7] = $shema[$bots[6]]*$nextvolna; $bot[8] = $shema[$bots[7]]*$nextvolna; $bot[9] = $shema[$bots[8]]*$nextvolna; } // делаем массив с айдишниками ботов for($n = 1; $n <= 9; $n++) { for($i = 1; $i <= (int)$bot[$n]; $i++){ $botz = mysql_fetch_array(mysql_query("SELECT `maxhp`,`id` FROM `users` WHERE `id` = '".$bots[$n-1]."' LIMIT 1;")); mysql_query("INSERT INTO `bots` ( `name`,`prototype`,`battle`,`hp`, `for_id`) values ('".$names[$n]." (проекция ".($i).")','".$bots[$n-1]."','','".$botz['maxhp']."', '".$poh['owner']."');"); $botz = mysql_insert_id(); $enemys[] = $botz; } } // array of teams $teams = array(); foreach($enemys as $v) { $teams[$poh['owner']][$v] = array(0,0,time()); $teams[$v][$poh['owner']] = array(0,0,time()); } // запись о битве mysql_query("INSERT INTO `battle` ( `id`,`coment`,`teams`,`timeout`,`type`,`status`,`t1`,`t2`,`to1`,`to2` ) VALUES ( NULL,'','".serialize($teams)."','5','1','0','".$poh['owner']."','".implode(";",$enemys)."','".time()."','".time()."' )"); $id = mysql_insert_id(); // апдейтим бота foreach($enemys as $v) { mysql_query("UPDATE `bots` SET `battle` = ".$id." WHERE `id` = ".$v." AND `for_id`={$poh['owner']} LIMIT 1;"); } // создаем лог //$rr = "<b>".nick3($user['id'])."</b> и <b>".nick3($bot)."</b>"; //mysql_query("INSERT INTO `logs` (`id`,`log`) VALUES('{$id}','Часы показывали <span class=date>".date("Y.m.d H.i")."</span>, когда ".$rr." бросили вызов друг другу. <BR>');"); addlog($id,"Часы показывали <span class=date>".date("Y.m.d H.i")."</span>, когда <b>".nick3($poh['owner'])."</b> вышел на битву с Хаосом... <BR>"); #chown ("backup/logs/battle".$id.".txt" , "www-data" ); #chgrp ("backup/logs/battle".$id.".txt" , "www-data" ); mysql_query("UPDATE users SET `battle` =".$id.",`zayavka`=0 WHERE `id`= ".$poh['owner'].";"); #addchp ('<font color=red>Внимание!</font> Новое пришествие...<BR>\'; top.frames[\'main\'].location=\'fbattle.php\'; var z = \' ','{[]}'.nick7 ($poh['owner']).'{[]}'); mysql_query("UPDATE `hellround_pohod` SET `volna`=`volna`+1 WHERE `id` = ".$poh['id']." LIMIT 1;"); ##echo "USER: ".$poh['owner']." New wave.\n"; //Удалим ботов, если завис /*$zavis_bot = mysql_fetch_array(mysql_query("SELECT `battle` FROM `bots` ORDER by id DESC LIMIT 1;")); $batles = mysql_fetch_array(mysql_query("SELECT * FROM `battle` WHERE `id`='{$zavis_bot['battle']}' LIMIT 1;")); echo $batles['to1']; if($batles['to1'] < time()) echo 'ok'; { mysql_query("DELETE FROM `bots` WHERE `battle` = '{$zavis_bot['battle']}' LIMIT 1 "); }*/ } } // задержка #sleep(2); } } ?>
Output for 7.0.0 - 7.2.0
Warning: include(/var/www/localhost/htdocs/connect.php): failed to open stream: No such file or directory in /in/D81XP on line 19 Warning: include(): Failed opening '/var/www/localhost/htdocs/connect.php' for inclusion (include_path='.:') in /in/D81XP on line 19 Warning: include(/var/www/localhost/htdocs/functions.php): failed to open stream: No such file or directory in /in/D81XP on line 21 Warning: include(): Failed opening '/var/www/localhost/htdocs/functions.php' for inclusion (include_path='.:') in /in/D81XP on line 21 Fatal error: Uncaught Error: Call to undefined function mysql_fetch_array() in /in/D81XP:28 Stack trace: #0 {main} thrown in /in/D81XP on line 28
Process exited with code 255.
Output for 5.5.0 - 5.6.25
Warning: include(/var/www/localhost/htdocs/connect.php): failed to open stream: No such file or directory in /in/D81XP on line 19 Warning: include(): Failed opening '/var/www/localhost/htdocs/connect.php' for inclusion (include_path='.:') in /in/D81XP on line 19 Warning: include(/var/www/localhost/htdocs/functions.php): failed to open stream: No such file or directory in /in/D81XP on line 21 Warning: include(): Failed opening '/var/www/localhost/htdocs/functions.php' for inclusion (include_path='.:') in /in/D81XP on line 21 Fatal error: Call to undefined function mysql_fetch_array() in /in/D81XP on line 28
Process exited with code 255.