<?php
if (!defined("STRESSWEB"))
die("Hacking!!!");
$_act = (isset($_POST["act"])) ? phpInjection(sqlInjection($_POST["act"])) : "";
if ($config["l2top"]["enable"] == "1")
{
$_vote_error = "";
$tmpServerList = array();
$tpl->get_template("vote.tpl");
$tpl->set_var('{voteID}', $config["l2top"]["id"]);
if ($_act == "")
{
$time = time();
if ((cache_get("l2top_time") + 1) > $time)
{
$time = (cache_get("l2top_time") + 1) - $time;
$time_min = date("i", $time);
$time_sec = date("s", $time);
$tpl->set_block("'\\[time\\](.*?)\\[/time\\]'si", "\\1");
$tpl->set_block("'\\[check\\](.*?)\\[/check\\]'si", "");
$tpl->set_block("'\\[vote\\](.*?)\\[/vote\\]'si", "");
$tpl->set_block("'\\[error\\](.*?)\\[/error\\]'si", "");
$tpl->set_var('{min}', $time_min);
$tpl->set_var('{sec}', $time_sec);
}
else
{
for ($i = 0; $i < $l2db["gameserver"]["count"]; $i++)
{
if ($l2db["gameserver"][$i]["on"] == "1" && $l2db["gameserver"][$i]["l2top"]["allow"] == "1")
{
$tmpServerList[$i] = $l2db["gameserver"][$i]["title"];
}
}
$tpl->set_block("'\\[time\\](.*?)\\[/time\\]'si", "");
$tpl->set_block("'\\[check\\](.*?)\\[/check\\]'si", "\\1");
$tpl->set_block("'\\[vote\\](.*?)\\[/vote\\]'si", "");
$tpl->set_block("'\\[error\\](.*?)\\[/error\\]'si", "");
$tpl->set_var('{selectServer}', select("server", $tmpServerList, $_serv_id, "style='width: 125px;'"));
$tpl->set_var("{l2sec_code}", "<span id=\"sw-captcha\"><img src=\"/inc/captcha/antibot.php\" alt=\"Код безопасности\" border=\"0\" /> <br /><a onclick=\"reload(); return false;\" href=\"#\">Обновить код</a></span>");
}
}
/**************************
* Vote
**************************/
if ($_act == "check")
{
$_vote_nick = $ldb->safe($_POST["character"]);
$_vote_sec_code = $ldb->safe($_POST["l2sec_code"]);
$_sess_sec_code = $_SESSION["sw_captcha"];
//Розкомментировать для отключения каптчи
//$_vote_sec_code = 1;
//$_sess_sec_code = 1;
if (empty($_vote_error) && ($_vote_nick == "" || $_vote_sec_code == ""))
{
$_vote_error = "<div class='error'>Вы не ввели ник персонажа или код с картинки. <a href='index.php?f=vote'>Назад</a></div>";
}
if (empty($_vote_error) && ($_vote_sec_code != $_sess_sec_code || !$_sess_sec_code))
{
$_vote_error = "<div class='error'>Введенный код не совпадает с указанным на картинке! <a href='index.php?f=vote'>Назад</a></div>";
}
if (empty($_vote_error) and is_numeric($_vote_nick))
{
$_vote_error = "<div class='error'>Имя вашего игрока содержит запрещенные символы. <a href='index.php?f=vote'>Назад</a></div>";
}
if (empty($_vote_error))
{
$query = $gdb[$_serv_id]->query($gdb[$_serv_id]->_parse_query($qList[$l2db_gs]["l2top"]["getChar"], array("name" => $_vote_nick)));
if ($gdb[$_serv_id]->numrows($query) == 1)
{
$tpl->set_block("'\\[time\\](.*?)\\[/time\\]'si", "");
$tpl->set_block("'\\[check\\](.*?)\\[/check\\]'si", "");
$tpl->set_block("'\\[vote\\](.*?)\\[/vote\\]'si", "\\1");
$tpl->set_block("'\\[error\\](.*?)\\[/error\\]'si", "");
$tpl->set_var('{server}', $_serv_id);
$tpl->set_var('{character}', $_vote_nick);
}
else
{
$_vote_error = "<div class='error'>Такой игрок на нашем сервере не существует. <a href='index.php?f=vote'>Назад</a></div>";
}
}
}
if ($_act == "get")
{
$name = $ldb->safe($_POST["name"]);
$lines = explode("\n", file_get_contents($config["l2top"]["url"]));
cache_set("l2top_time", time());
$top = array();
$n = 0;
$kk = array();
foreach ($lines as $line)
{
$date = substr($line, 0, 19);
$char = rtrim(substr($line, 20));
$isset_prefix = empty($l2db["gameserver"][$_serv_id]["l2top"]["prefix"]) ? false : true;
if ($isset_prefix && strval(strtolower($l2db["gameserver"][$_serv_id]["l2top"]["prefix"] . "-" . $name)) == strval(strtolower($char)))
{
$top[$n]['nick'] = $name;
$top[$n]['server'] = $_serv_id;
$top[$n]['date'] = $date;
$n++;
} elseif (!$isset_prefix && strval(strtolower($name)) == strval(strtolower($char)))
{
$top[$n]['nick'] = $name;
$top[$n]['server'] = $_serv_id;
$top[$n]['date'] = $date;
$n++;
}
}
if (empty($top))
{
$_vote_error = "<div class='error'>Ваш голос в L2Top.ru не найден. <a href='index.php?f=vote'>Назад</a></div>";
}
else
{
$bonus_count = 0;
$bonus_name = "";
$status = false;
for ($i = 0; $i < count($top); $i++)
{
$query = $ldb->query("SELECT `id` FROM `l2top` WHERE `nick`='{$top[$i]["nick"]}' AND `date` = '{$top[$i]["date"]}'");
if ($ldb->numrows($query) == 0)
{
$status = true;
$server = $top[$i]["server"];
$success = false;
$l2db_gs = $versionList[$l2db["gameserver"][$server]["version"]];
$character_data = $gdb[$server]->fetch_array($gdb[$server]->query($gdb[$server]->_parse_query($qList[$l2db_gs]["l2top"]["getChar"], array("name" => $top[$i]["nick"]))));
if ($l2db["gameserver"][$server]["l2top"]["bonus"] == "l2money")
{
$ldb->query("INSERT INTO `l2top` SET `nick` = '{$top[$i]["nick"]}', `date` = '{$top[$i]["date"]}', `server` = '{$server}', `success`='0'");
$bonus_name = $config["wm"]["money"];
$money = floatval($l2db["gameserver"][$server]["l2top"]["l2money_count"]);
$bonus_count += $money;
$query = $ldb->query("SELECT `money` FROM `stress_donate_money` WHERE `account`='{$character_data["account_name"]}'");
if ($ldb->numrows($query) == 1)
{
$ldb->query("UPDATE `stress_donate_money` SET `money` = `money` + {$money} WHERE `account` = '{$character_data["account_name"]}'");
}
else
{
$ldb->query("INSERT INTO `stress_donate_money` SET `account`='{$character_data["account_name"]}', `money` = '{$money}'");
}
if ($ldb->affectedrows() > 0)
$success = true;
}
else
{
$bonusType = null;
$bonus_name = "бонусных предметов";
if ($l2db["gameserver"][$server]["l2top"]["method"] == "telnet" && $character_data["online"] != 1)
{
$_vote_error = "<div class='error'>Ваш персонаж должен быть онлайн!</div>";
} elseif ($l2db["gameserver"][$server]["l2top"]["method"] == "mysql" && $character_data["online"] == 1)
{
$_vote_error = "<div class='error'>Ваш персонаж должен быть оффлайн!</div>";
} elseif ($l2db["gameserver"][$server]["l2top"]["method"] == "mysqltelnet")
{
$bonusType = ($character_data["online"] == 1) ? "telnet" : "mysql";
} elseif ($l2db["gameserver"][$server]["l2top"]["method"] != "telnet" && $l2db["gameserver"][$server]["l2top"]["method"] != "mysql")
{
$_vote_error = "<div class='error'>Ошибка, попробуйте еще раз!</div>";
}
if (empty($_vote_error) && ($l2db["gameserver"][$server]["l2top"]["method"] == "telnet" || $bonusType == "telnet"))
{
$ldb->query("INSERT INTO `l2top` SET `nick` = '{$top[$i]["nick"]}', `date` = '{$top[$i]["date"]}', `server` = '{$server}', `success`='0'");
$host = $l2db["gameserver"][$server]["server"]["host"];
$port = $l2db["gameserver"][$server]["telnet"]["port"];
$timeout = $l2db["gameserver"][$server]["telnet"]["timeout"];
$telnet = @fsockopen($host, $port, $errno, $errstr, $timeout);
if ($telnet)
{
@fputs($telnet, $l2db["gameserver"][$server]["telnet"]["pass"]);
@fputs($telnet, "\r\n");
if (!empty($l2db["gameserver"][$server]["telnet"]["gmname"]))
{
@fputs($telnet, $l2db["gameserver"][$server]["telnet"]["gmname"]);
@fputs($telnet, "\r\n");
}
$itemId = $l2db["gameserver"][$server]["l2top"]["itemID"];
$itemCount = $l2db["gameserver"][$server]["l2top"]["item_count"];
fputs($telnet, "give {$top[$i]["nick"]} {$itemId} {$itemCount}");
$success = true;
$bonus_count += $l2db["gameserver"][$server]["l2top"]["item_count"];
}
@fclose($telnet);
}
if (empty($_vote_error) && ($l2db["gameserver"][$server]["l2top"]["method"] == "mysql" || $bonusType == "mysql"))
{
$ldb->query("INSERT INTO `l2top` SET `nick` = '{$top[$i]["nick"]}', `date` = '{$top[$i]["date"]}', `server` = '{$server}', `success`='0'");
$query = $gdb[$server]->query($gdb[$server]->_parse_query($qList[$l2db_gs]["l2top"]["getItem"], array("ownerID" => $character_data["charID"], "itemID" => $l2db["gameserver"][$server]["l2top"]["itemID"])));
if ($item = $gdb[$server]->fetch_array($query))
{
$gdb[$server]->query($gdb[$server]->_parse_query($qList[$l2db_gs]["l2top"]["setItem"], array("ownerID" => $character_data["charID"], "itemID" => $item["item_id"], "count" => $item["count"] + $l2db["gameserver"][$server]["l2top"]["item_count"])));
if ($gdb[$server]->affectedrows() > 0)
{
$success = true;
$bonus_count += $l2db["gameserver"][$server]["l2top"]["item_count"];
}
}
else
{
$object_id = $gdb[$server]->fetch_array($gdb[$server]->query($gdb[$server]->_parse_query($qList[$l2db_gs]["l2top"]["getMax"])));
$gdb[$server]->query($gdb[$server]->_parse_query($qList[$l2db_gs]["l2top"]["insItem"], array("charID" => $character_data["charID"], "objectID" => $object_id["max"], "itemID" => $l2db["gameserver"][$server]["l2top"]["itemID"], "count" => $l2db["gameserver"][$server]["l2top"]["item_count"])));
if ($gdb[$server]->affectedrows() > 0)
{
$success = true;
$bonus_count += $l2db["gameserver"][$server]["l2top"]["item_count"];
}
}
}
}
if ($success == true)
{
$ldb->query("UPDATE `l2top` SET `success`='1' WHERE `nick` = '{$top[$i]["nick"]}' AND `date` = '{$top[$i]["date"]}'");
}
}
}
if ($status == false)
{
$_vote_error .= "<div class='error'>Вы уже получали призы. <a href='index.php?f=vote'>Назад</a></div>";
}
else
{
$_vote_error .= "<div class='noerror'>Вам зачислено {$bonus_name}: {$bonus_count}</div>";
}
}
}
if (!empty($_vote_error))
{
$tpl->set_block("'\\[time\\](.*?)\\[/time\\]'si", "");
$tpl->set_block("'\\[check\\](.*?)\\[/check\\]'si", "");
$tpl->set_block("'\\[vote\\](.*?)\\[/vote\\]'si", "");
$tpl->set_block("'\\[error\\](.*?)\\[/error\\]'si", "\\1");
$tpl->set_var("{error}", $_vote_error);
}
/**************************
* Top voters
**************************/
if ($config["l2top"]["top"] == "1")
{
$tpl->set_block("'\\[topVoters\\](.*?)\\[/topVoters\\]'si", "\\1");
$tpl->set_var("{top_count}", $config["l2top"]["top_count"]);
if (cache_get("l2vote_time") > $_TIME && $config["cache"]["allow"])
{
$votersList = cache_get("l2vote");
}
else
{
$votersList = "
<table cellpadding='3' cellspacing='3' width='90%' id='voteTab'>
<tr>
<th width='35'>#</th>
<th width=''>Персонаж</th>
<th width='70'>Голосов</th>
</tr>";
$month = date("m", time());
$sel_voters = $ldb->query($ldb->_parse_query($qList[$l2db_ls]["l2top"]["getVotersList"], array("time" => $month, "limit" => $config["l2top"]["top_count"])));
$n = 1;
while ($voters_data = $ldb->fetch_array($sel_voters))
{
$votersList .= "
<tr>
<td>{$n}</td>
<td>{$voters_data["nick"]}</td>
<td>{$voters_data["votes"]}</td>
</tr>";
$n++;
}
$votersList .= "</table>";
if ($config["cache"]["allow"])
{
cache_set("l2vote_time", $_TIME + 60 * $config["cache"]["vote"]);
cache_set("l2vote", $votersList);
}
}
$tpl->set_var("{votersList}", $votersList);
}
else
{
$tpl->set_block("'\\[topVoters\\](.*?)\\[/topVoters\\]'si", "");
}
$tpl->parse("content");
$tpl->clear();
}
else
{
$tpl->result["content"] = "<div class='error'>Система получения призов L2Top отключена!</div>";
}
?>
Вот код скрипта (vote.php). Уходит в штопор на этапе проверки наличия голоса в списках л2топ. Подскажите, че в нем не так?