Example #1
0
         unset($t);
     }
     $str .= "'{$type}','{$id}','<table class=t width=100%  {$b}><td {$t}>" . $c . "</td></table>', " . $add;
     return $str;
 }
 $str = '';
 foreach ($ar as $k => $v) {
     $str .= makecomment($v);
 }
 if ($b == "bgcolor=#3b484c") {
     $b = "bgcolor=#515e64";
 } else {
     $b = "bgcolor=#3b484c";
 }
 $file = fopen(gampath($id) . "/{$id}.res", "r");
 $st = fread($file, filesize(gampath($id) . "/{$id}.res"));
 $res = unserialize($st);
 $score1 = reset($res[Score]);
 $score2 = next($res[Score]);
 if ($score1 > $score2) {
     $winner = "Победил <b>" . $rst1[Login] . "!</b>";
 } elseif ($score2 > $score1) {
     $winner = "Победил <b>" . $rst2[Login] . "!</b>";
 } else {
     $winner = "Бой завершился вничью!";
 }
 $gstr = "";
 foreach ($res[Gladiators] as $k => $v) {
     if ($rst1[Gladiators][$k] || $rst2[Gladiators][$k]) {
         $gstr .= gladiatorname($k) . " - <img src=/images/up.gif width=11px height=11px title=Опыт><b>" . round($v[Exp]) . "</b>";
         if ($v[Injury]) {
Example #2
0
$hide_menu = 1;
$fname = gampath($id) . "/" . $id . ".gam";
function repairHash($array)
{
    foreach ($array as $k => $v) {
        $result[$k] = $v;
    }
    return $result;
}
require $site_path . "up.php";
$hide_finances = 1;
if ($id && file_exists($fname)) {
    $file = fopen($fname, "r");
    $str = fread($file, filesize($fname));
    $ar = explode("RST", $str);
    $game = unserialize(substr($ar[0], 39, strlen($ar[0]) - 4 - 39));
    $ar2 = explode("ORD", $ar[1]);
    $rst1 = unserialize(substr($ar2[0], 36));
    $ord1 = unserialize(substr($ar2[1], 36));
    $ar2 = explode("ORD", $ar[2]);
    $rst2 = unserialize(substr($ar2[0], 36));
    $ord2 = unserialize(substr($ar2[1], 36));
    $rst1[Gladiators] = repairHash($rst1[Gladiators]);
    $rst2[Gladiators] = repairHash($rst2[Gladiators]);
    $file = fopen(gampath($id) . "/{$id}.rep", "r");
    $str = fread($file, filesize(gampath($id) . "/{$id}.rep"));
    $ar = unserialize($str);
}
require $site_path . "left.php";
require "online_core.php";
require $site_path . "bottom.php";
Example #3
0
function generategame($id)
{
    global $site_path, $secpass, $k, $serialized;
    $path = gampath($id);
    if (!file_exists($path)) {
        mkdir_r($path);
    }
    $fname = $path . "/" . $id . ".gam";
    $file = fopen($fname, "w");
    //$fname=$site_path."files/gam/".$id.".gam";
    //$file=fopen($fname,"w");
    $q = mysql_query("select Date+60*Timeout Date,UserID1,UserID2,TypeID,ExtraGlad,LimitGlad,LimitSkl,TournamentID from ft_agreements where RecordID='{$id}'");
    $q = mysql_fetch_array($q, 1);
    $gam = $q;
    $gam[Date] = mktime();
    $gam[id] = $id;
    if ($q[Date]) {
        $str = serialize($gam) . getfile($site_path . "files/rst/" . $q[UserID1] . ".rst") . getfile($site_path . "files/ord/{$id}-" . $q[UserID1] . ".ord") . getfile($site_path . "files/rst/" . $q[UserID2] . ".rst") . getfile($site_path . "files/ord/{$id}-" . $q[UserID2] . ".ord");
        /*
        $time=microtime(1);
        for($i=1;$i<=1000;$i++)
        {
        	$a=gzcompress($str);
        }
        
        print "<br>".(microtime(1)-$time);
        
        
        $time=microtime(1);
        for($i=1;$i<=1000;$i++)
        {
        	$a=gzcompress($str,0);
        }
        
        print "<br>".(microtime(1)-$time);
        */
        //$str=bzcompress($str);
        fputs($file, "GAM" . pack("N", 0x1000000) . md5($str . $secpass) . $str);
        //fputs($file,$str);
        fclose($file);
        $res = exec("/var/www/gladiators_admin/gladcore {$fname}");
        $user1 = $q[UserID1];
        $user2 = $q[UserID2];
        $ar = unserialize($res);
        lock_rst($user1);
        lock_rst($user2);
        $rst1 = read_rst($user1);
        $rst2 = read_rst($user2);
        $score1 = reset($ar[Score]);
        $score2 = next($ar[Score]);
        $scorepoints1 = reset($ar[ScorePoints]);
        $scorepoints2 = next($ar[ScorePoints]);
        if ($score1 > $score2) {
            $rst1 = short_transfer_money($rst1, $ar[Money], 1, $user1, 26, $id);
            $rst1[Win]++;
            $rst2[Lose]++;
            $winner = $user1;
        } elseif ($score1 < $score2) {
            $rst2 = short_transfer_money($rst2, $ar[Money], 1, $user2, 26, $id);
            $rst2[Win]++;
            $rst1[Lose]++;
            $winner = $user2;
        } else {
            $rst1[Tie]++;
            $rst2[Tie]++;
            $rst1 = short_transfer_money($rst1, round($ar[Money] / 2), 1, $user1, 26, $id);
            $rst2 = short_transfer_money($rst2, round($ar[Money] / 2), 1, $user2, 26, $id);
        }
        runsql("insert into ft_battles(RecordID,UserID1,UserID2,Date,TypeID,ExtraGlad,LimitGlad,LimitSkl,\nTournamentID,Stage,Tour,Fight,Pair,NumFights,StageTypeID,WinnerID,ScorePoints1,ScorePoints2,Login1,Login2\n) \n(select RecordID,UserID1,UserID2,unix_timestamp(),TypeID,ExtraGlad,LimitGlad,LimitSkl,\nTournamentID,Stage,Tour,Fight,Pair,NumFights,StageTypeID,'{$winner}','{$scorepoints1}','{$scorepoints2}',Login1,Login2\nfrom ft_agreements where RecordID='{$id}')");
        //runsql("update ft_battles b set Login1=(select u.Login from ut_users u where u.UserID=b.UserID1) where b.RecordID='$id'");
        //runsql("update ft_battles b set Login2=(select u.Login from ut_users u where u.UserID=b.UserID2) where b.RecordID='$id'");
        runsql("delete from ft_agreements where RecordID='{$id}'");
        $serialized = $rst1[Gladiators];
        foreach ($rst1[Gladiators] as $k => $v) {
            if (!$rst1[Gladiators][$k][PercentTrain]) {
                $rst1[Gladiators][$k][PercentTrain] = 0;
            }
            $coef = 10 + (100 - $rst1[Gladiators][$k][PercentTrain]) * 30 / 100;
            $rst1[Gladiators][$k][Stamina] = strval(round(intval($rst1[Gladiators][$k][Stamina] + $coef * (mktime() - $rst1[Date]) / 3600), 2));
            if ($rst1[Gladiators][$k][Morale] != 0) {
                $mor = intval(round($rst1[Gladiators][$k][Morale] - $rst1[Gladiators][$k][Morale] / abs($rst1[Gladiators][$k][Morale]) * (mktime() - $rst1[Date]) / 3600));
                if ($mor * $rst1[Gladiators][$k][Morale] < 0) {
                    $rst1[Gladiators][$k][Morale] = 0;
                } else {
                    $rst1[Gladiators][$k][Morale] = $mor;
                }
            }
            //$rst1[Gladiators][$k][Injury]=intval(ceil($rst1[Gladiators][$k][Injury]-(mktime()-$rst1[Date])/3600));
            //if($rst1[Gladiators][$k][Injury]<0) $serialized[$k][Injury]=0;
            $exp = expgained($rst1);
            if ($exp) {
                $rst1[Gladiators][$k][Exp] = strval(round($rst1[Gladiators][$k][Exp] + $exp, 2));
                $rst1[Gladiators][$k][NextTrain] = strval(round($exp + $rst1[Gladiators][$k][NextTrain], 2));
            }
        }
        $rst1[TrainDate] = mktime();
        $serialized = $rst2[Gladiators];
        foreach ($rst2[Gladiators] as $k => $v) {
            if (!$rst2[Gladiators][$k][PercentTrain]) {
                $rst2[Gladiators][$k][PercentTrain] = 0;
            }
            $coef = 10 + (100 - $rst2[Gladiators][$k][PercentTrain]) * 30 / 100;
            $rst2[Gladiators][$k][Stamina] = strval(round(intval($rst2[Gladiators][$k][Stamina] + $coef * (mktime() - $rst2[Date]) / 3600), 2));
            if ($rst2[Gladiators][$k][Morale] != 0) {
                $mor = intval(round($rst2[Gladiators][$k][Morale] - $rst2[Gladiators][$k][Morale] / abs($rst2[Gladiators][$k][Morale]) * (mktime() - $rst2[Date]) / 3600));
                if ($mor * $rst2[Gladiators][$k][Morale] < 0) {
                    $rst2[Gladiators][$k][Morale] = 0;
                } else {
                    $rst2[Gladiators][$k][Morale] = $mor;
                }
            }
            //$rst2[Gladiators][$k][Injury]=intval(ceil($rst2[Gladiators][$k][Injury]-(mktime()-$rst2[Date])/3600));
            //if($rst2[Gladiators][$k][Injury]<0) $serialized[$k][Injury]=0;
            $exp = expgained($rst2);
            if ($exp) {
                $rst2[Gladiators][$k][Exp] = strval(round($rst2[Gladiators][$k][Exp] + $exp, 2));
                $rst2[Gladiators][$k][NextTrain] = strval(round($exp + $rst2[Gladiators][$k][NextTrain], 2));
            }
        }
        $rst2[TrainDate] = mktime();
        foreach ($ar[Gladiators] as $k => $v) {
            if ($v[Stamina] < 0) {
                $v[Stamina] = 0;
            }
            if ($rst1[Gladiators][$k]) {
                if ($winner == $user1) {
                    $rst1[Gladiators][$k][Win]++;
                } elseif ($winner == $user2) {
                    $rst1[Gladiators][$k][Lose]++;
                }
                $rst1[Gladiators][$k][Morale] = intval($v[Morale]);
                //$rst1[Gladiators][$k][Injury]=intval($v[Injury]);
                $rst1[Gladiators][$k][Stamina] = round($v[Stamina], 2);
                if ($v[Injury]) {
                    $rst1[Gladiators][$k][PercentTrain] = 0;
                    $rst1[Gladiators][$k][Stamina] = intval(-40 * $v[Injury]);
                }
                $rst1[Gladiators][$k][Exp] = strval(round($rst1[Gladiators][$k][Exp] + $v[Exp], 3));
                $rst1[Gladiators][$k][NextTrain] = strval(round($v[Exp] + $rst1[Gladiators][$k][NextTrain], 2));
            } elseif ($rst2[Gladiators][$k]) {
                if ($winner == $user2) {
                    $rst2[Gladiators][$k][Win]++;
                } elseif ($winner == $user1) {
                    $rst2[Gladiators][$k][Lose]++;
                }
                $rst2[Gladiators][$k][Morale] = intval($v[Morale]);
                //$rst2[Gladiators][$k][Injury]=intval($v[Injury]);
                $rst2[Gladiators][$k][Stamina] = round($v[Stamina], 2);
                if ($v[Injury]) {
                    $rst2[Gladiators][$k][PercentTrain] = 0;
                    $rst2[Gladiators][$k][Stamina] = intval(-40 * $v[Injury]);
                }
                $rst2[Gladiators][$k][Exp] = strval(round($rst2[Gladiators][$k][Exp] + $v[Exp], 3));
                $rst2[Gladiators][$k][NextTrain] = strval(round($v[Exp] + $rst2[Gladiators][$k][NextTrain], 2));
            }
        }
        $rst1[Date] = mktime();
        $rst2[Date] = mktime();
        write_rst($user1, $rst1);
        write_rst($user2, $rst2);
        unlock_rst($user1);
        unlock_rst($user2);
        if ($q[TournamentID]) {
            next_schedule($id);
        }
    }
}
Example #4
0
<?php

require '../../config.php';
require $engine_path . "cls/auth/session.php";
$type = "arena/fight";
unset($act);
//$fname=$site_path."files/gam/".$id.".gam";
$fname = gampath($id) . "/" . $id . ".gam";
if (file_exists($fname)) {
    header("Location:online.php?id={$id}");
} elseif ($id) {
    $agreement = select("select a.*,u1.Login Login1, u2.Login Login2,\na.Date+60*a.Timeout-unix_timestamp() Timeleft ,\na.Date+60*a.Timeout TimeLeft\n\t\t\tfrom ft_agreements a\n\t\t\tjoin ut_users u1 on u1.UserID=a.UserID1\n\t\t\tjoin ut_users u2 on u2.UserID=a.UserID2 \n\t\t\twhere a.RecordID='{$id}'");
    $q = $agreement;
    if ($q[Timeleft] <= 0 && !file_exists($fname) || file_exists($site_path . "files/ord/" . $id . "-{$q['UserID1']}.ord") && file_exists($site_path . "files/ord/" . $id . "-{$q['UserID2']}.ord")) {
        generategame($id);
        header("Location:online.php?id={$id}");
    }
}
require $site_path . "up.php";
require $site_path . "left.php";
?>
<center><img src="/images/art/arena.jpg" width=500px height=300px></center>
<?php 
if ($id) {
    $q = $agreement;
    if ($q[0]) {
        $user1 = $q[UserID1];
        $user2 = $q[UserID2];
        print "<center><div style='font-size:24pt;'><a href=/users/{$user1} style='color:FF9600;font-size:24pt;'>{$q['Login1']}</a> vs. <a href=/users/{$user2} style='color:D5D5D5;font-size:24pt;'>{$q['Login2']}</a></div><br><img src=\"/images/sep.gif\" height=1px width=180px><br><br>";
        print "Ожидание заявки противника. Таймаут: <input type=\"text\" id=\"Timer\" style=\"border:0;background-color:3B484C;color:E5CEA6\" readonly size=4>";
        print "<br><a href=/builder/?id={$id}>Вернуться к настройкам</a>";
Example #5
0
<?php

require "config.php";
$dh = opendir($site_path . "/files/gam/");
while ($file = readdir($dh)) {
    if ($file != "." && $file != ".." && (strstr($file, ".gam") || strstr($file, ".res") || strstr($file, ".rep"))) {
        $id = substr($file, 0, strpos($file, "."));
        $ext = substr($file, 1 + strpos($file, "."), 3);
        $fname = gampath($id) . "/" . $id . ".{$ext}";
        if (!file_exists(gampath($id))) {
            mkdir_r(gampath($id));
        }
        //print "copy($site_path /files/gam/ .$file,$fname)";
        copy($site_path . "files/gam/" . $file, $fname);
        //if($id!=1516) exit;
    }
}