Файл: _gladiators2_/gladiators2/gladiators/gladiators/system/modules/mod_building.php
Строк: 167
<?
if($_SESSION["build_set"])
{
$code_protection = "";
if(time()-$_SESSION["building_check"] >= 1200)
{
if($_POST["code"])
{
$code = trim($_POST["code"]);
if($_POST["code"] != $_SESSION["noautomationcode"])
$error = "введен не верный код с изображения";
elseif(time()-$_SESSION["building_check"] >= 2400)
{
$error = "Вы уволены из-за просрочки работы";
session_unregister('build_set','building_check','building_checktime');
$file = @file("../database/building/workers.dat");
$i = 0;
$find = 0;
while(!$find && $i<=(count($file)-1))
{
$row = explode("|",$file[$i]);
if(preg_match("/^(".$_SESSION["login"]."#)/",$row[0]))
{ unset($file[$i]); $find = 1; }
$i++;
}
if($find)
{
$fp = @fopen("../database/building/workers.dat","w");
@flock($fp,2);
@fwrite($fp,implode("",$file));
@flock($fp,3);
@fclose($fp);
}
$user->last_update_uron = time();
$user->hp = 0;
}
else
{
$file = @file("../database/building/workers.dat");
$i = 0;
$find = 0;
while(!$find && $i<=(count($file)-1))
{
$row = explode("|",$file[$i]);
if(preg_match("/^(".$_SESSION["login"]."#)/",$row[0]))
{
$row[1] += (time()-$_SESSION["building_checktime"]);
$row[2] += (time()-$_SESSION["building_checktime"]);
$find = 1;
}
$file[$i] = implode("|",$row);
$i++;
}
if($find)
{
$part = explode(",",$_SESSION["build_set"]);
session_register('building_check','build_set');
$building_check = time();
$build_set = ($part[0]+(time()-$_SESSION["building_checktime"])).",".$part[1];
$fp = @fopen("../database/building/workers.dat","w");
@flock($fp,2);
@fwrite($fp,implode("",$file));
@flock($fp,3);
@fclose($fp);
@session_unregister('building_checktime');
}
}
}
if(!$find)
{
if(!$_SESSION["building_checktime"])
{
@session_register('building_checktime');
$building_checktime = time();
}
$code_protection .= "<b>Введите контрольный код с изображения:</b><br><br><img src=".$config["img_server"]."/code/showcode.php?sid=".session_id().">
<form action=index.php method=post>
<input type='hidden' name='sid' value='".session_id()."'>
<input type='text' name='code'>
<input type=submit value='Проверить' class=button>
</form><br>";
}
}
}
if($_GET["act"]=="cancel")
{
if($_SESSION["build_set"])
{
sleep(3);
$file = @file("../database/building/workers.dat");
$i = 0;
$find = 0;
while(!$find && $i<=(count($file)-1))
{
$row = explode("|",$file[$i]);
if(preg_match("/^(".$_SESSION["login"]."#)/",$row[0]))
{ unset($file[$i]); $find = 1; }
$i++;
}
if($find)
{
$fp = @fopen("../database/building/workers.dat","w");
@flock($fp,2);
@fwrite($fp,implode("",$file));
@flock($fp,3);
@fclose($fp);
}
$part = explode(",",$_SESSION["build_set"]);
$perc = ((time()-$part[0])*100) / ($part[1]*60);
$hp = round(($perc * $user->maxhp) / 100);
$user->hp -= $hp;
$user->last_update_uron = time();
@session_unregister('build_set');
}
else
$error = "Вы не работаете...";
}
if($_SESSION["build_set"] && !$_SESSION["building_checktime"])
{
$build_row = explode(",",$_SESSION["build_set"]);
$a = ( $build_row[0]+$build_row[1]*60 )-time();
if($a <= 0)
{
sleep(3);
$file = @file("../database/building/workers.dat");
$i = 0;
$find = 0;
while(!$find && $i <= (count($file)-1))
{
$row = explode("|",$file[$i]);
if(preg_match("/^(".$_SESSION["login"]."#)/",$row[0]))
{
unset($file[$i]);
$find = 1;
}
$i++;
}
if($find)
{
$fp = @fopen("../database/building/workers.dat","w");
@flock($fp,2);
@fwrite($fp,implode("",$file));
@flock($fp,3);
@fclose($fp);
}
if($find)
{
$count_ext = $user->u/10;
$count_ext = explode(".",$count_ext);
$count_ext = $count_ext[0];
$user->hp = 0;
$user->money += $count_ext*0.5;
$user->last_update_uron = time();
session_unregister('build_set');
$scs = "Вы окончили работу. Выплачено ".ToFloat(($count_ext*0.5),2)." золота!";
}
}
}
if($_GET["act"]=="work" && $_POST["time"])
{
if(!$_SESSION["build_set"])
{
if($user->u < 10)
$error = "У вас не достаточно Удара, чтобы работать на Стройке! Минимальный Удар должен быть - 10";
elseif(!preg_match("/^[1-9][0-9.]{0,4}$/",$_POST["time"]))
$error = "Не верно указано время работы! ";
elseif($user->hp < $user->maxhp)
$error = "Вы можете работать только с полным HP, а сейчас восстанавливайтесь.";
else
{
sleep(3);
$file = @file("../database/building/workers.dat");
$i = 0;
$find = 0;
while(!$find && $i <= (count($file)-1))
{
$row = explode("|",$file[$i]);
if(preg_match("/^(".$_SESSION["login"]."#)/",$row[0]))
{
unset($file[$i]);
$find = 1;
}
$i++;
}
if(!$find)
{
$curr_time = time();
@session_register('build_set','building_check');
$build_set = time().",".$_POST["time"]*60;
$building_check = time();
$fp = @fopen("../database/building/workers.dat","a+");
@flock($fp,2);
@fwrite($fp,$_SESSION["login"]."#".$user->level."#".$user->klan."#".$user->align."|".$curr_time."|".($curr_time+($_POST["time"]*3600))."|n");
@flock($fp,3);
@fclose($fp);
}
}
}
else
$error = "Вы уже работаете...";
}
$online_workers = "";
$file = @file("../database/building/workers.dat");
for($i=0;$i<=count($file)-1;$i++)
{
$row = explode("|",$file[$i]);
if((time()-$row[2]) >= 3800 || (preg_match("/^(".$_SESSION["login"].")#/",$row[0]) && !$_SESSION["build_set"]))
unset($file[$i]);
}
$fp = @fopen("../database/building/workers.dat","w");
@flock($fp,2);
@fwrite($fp,implode("",$file));
@flock($fp,3);
@fclose($fp);
$file = @file("../database/building/workers.dat");
for($i=1;$i<=count($file)-1;$i++)
{
for($j=1;$j<=count($file)-1;$j++)
{
$row_online1 = explode("|",$file[$j-1]);
$row_online2 = explode("|",$file[$j]);
if($row_online2[3] < $row_online1[3])
{
$t = $file[$j-1];
$file[$j-1] = $file[$j];
$file[$j] = $t;
}
}
}
$count_online = 0;
for($i=0;$i<=count($file)-1;$i++)
{
$row = explode("|",$file[$i]);
if(time()-$row[2] <= 60)
{
$row_1 = explode("#",$row[0]);
$online_workers .= "<span onclick='top.PrivateSayTo("".$row_1[0]."");' style='cursor:hand;color:darkred;font-weight:bold;font-size:110%'>»</span> ".ch_info($row_1[0],$row_1[1],$row_1[3],$row_1[2],$config["img_server"])."<span class=comm> осталось: ";
$curr_time = ((time()-$row[1])/60);
$finish_time = (($row[2]-$row[1])/60);
$online_workers .= "<span class=comm>";
$time = $finish_time - $curr_time;
$a = explode(".",$time);
if($a[0] <= 0)
$online_workers .= "1";
else
$online_workers .= $a[0];
$online_workers .= " мин. </span><br>";
$count_online++;
}
}
if(!$count_online)
$online_workers = "в данный момент нет рабочих";
?>